Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android VideoView repetition

I have an application with a VideoView, in order to make the video play on a loop I use an onCompletionListner to call setVideoPath() again, like this:

    mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer arg0) {
             mVideoView.start();

        }
    });


    mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        public void onCompletion(MediaPlayer mp) {
                //I have a log statment here, so I can see that it is making it this far.
                mp.reset(); // <--- I added this recently to try to fix the problem
                mVideoView.setVideoPath(file.getAbsolutePath());
        }
    });

This setup works well on all devices I've come across so far, I never had any trouble with it not repeating.

However the Motorola Xoom that I am testing on was recently upgraded to ICS. Now that it is on ICS this will work for a while and loop the video. But eventually (I've added a counter and some Logs, there does not appear to be any pattern to how many times it successfully loops before stopping) it will quit looping and just sit on a freeze frame of the first frame in the movie.

Does anyone know what could cause this not to loop properly any more? OR does anyone know of another way to get a VideoView to loop properly that does work under ICS still?

like image 582
FoamyGuy Avatar asked Feb 01 '12 14:02

FoamyGuy


2 Answers

If you have only one video to play you can setLooping(true) in your on prepared listener.

myVideoView.setOnPreparedListener(new OnPreparedListener() {

        @Override
        public void onPrepared(MediaPlayer mp) {
            // TODO Auto-generated method stub
            mp.setLooping(true);

        }
    });

and you're done.

like image 176
Dario Defilippi Avatar answered Oct 25 '22 03:10

Dario Defilippi


So far this:

mp.reset();

inside the onComplete callback seems to fix it. Would be very interested if anyone can explain what is going on with it.

like image 27
FoamyGuy Avatar answered Oct 25 '22 01:10

FoamyGuy