I\'m trying to develop an android application that plays more than one video in one videoview. When one is finished, the second has to start and so on.
My videos are
Well you are getting error because you are trying to initialize videoview again before reseting it. Make a change to your code like this.
myVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
startOtherVid();
}
});
Now make method startOtherVid()
and initialize videoview here after releasing the previous one.
private void startOtherVid(){
myVideoView.stopPlayback();
videoUri = Uri.parse("android.resource://" + getActivity().getPackageName() + "/"
+ videoNames.get(VideoI));
myVideoView.setVideoURI(videoUri);
myVideoView.start();
....
.....
}
This way you will release one videoview object and create again. There will be a short time to load, but you can handle it visually.
Edit
You can also release mediaplayer object and solve your problem.
public void onCompletion(MediaPlayer mp) {
try {
mp.reset();
videoUri = Uri.parse("android.resource://" + getActivity().getPackageName() + "/"
+ videoNames.get(VideoI));
myVideoView.setVideoURI(videoUri);
myVideoView.start();
}
catch(Exception e){e.printstacktrace();}
});
Cheers.:)