I am trying to build an android app that will loop a video! The problem is that it never loops! It plays the video only once! During debugging i realized that the "myVideoView.setOnCompletionListener" is being executed but the video doesn't play! I also try "mp.reset()" inside the CompletionListener. Maybe i am missing something in a different file, such as the Manifest?
Any thoughts? Here is my code:
final VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
myVideoView.setVideoURI(Uri.parse(SrcPath));
myVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer arg0) {
myVideoView.requestFocus();
myVideoView.start();
}
});
myVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
myVideoView.setVideoURI(Uri.parse(SrcPath));
}
});
Try onPreparedListener
instead of onCompletionListener
:
myVideoView.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
Hope this helps.
Try this.
myVideoView = (VideoView) findViewById(R.id.videoView1);
myVideoView.setVideoPath(video_path);
myVideoView.setMediaController(new MediaController(this));
myVideoView.start();
myVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
myVideoView.start();
}
});
By that after completion of your video start again...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With