Reputation: 2433
I have the following working code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.player);
videoView = (VideoView)this.findViewById(R.id.videoView);
playVideo();
// video finish listener
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.start();
}
});
}
public void playVideo() {
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
videoView.setVideoURI(Uri.parse("http://sayedhashimi.com/downloads/android/movie.mp4"));
videoView.requestFocus();
}
I just want to change the MediaPlayer data source when the video finishes (setOnCompletionListener).
Upvotes: 5
Views: 7930
Reputation: 41
Here is my solution:
mp.release()
mp = createNew(context,newUri)
mp.start()
Anything else I tried gave me errors as mentioned here. Creating new media player every time won't be that harmful for performance as you will most likely have only one at a time anyway.
hope it helps ; )
Upvotes: 0
Reputation: 6575
I'm working on this same issue. Here is what I've come up with:
public void onCompletion(MediaPlayer mp) {
mp.reset();
mp.setDataSource(this, newUri);
mp.start();
}
Upvotes: 9