Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Video doesn't loop Android VideoView

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));

           }
        });
like image 557
ChristosBacharakis Avatar asked Nov 30 '22 02:11

ChristosBacharakis


2 Answers

Try onPreparedListener instead of onCompletionListener:

myVideoView.setOnPreparedListener(new OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
        mp.setLooping(true);
    }
});

Hope this helps.

like image 181
Suleman Khan Avatar answered Dec 04 '22 20:12

Suleman Khan


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...

like image 23
Mr.Sandy Avatar answered Dec 04 '22 20:12

Mr.Sandy