Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VideoView looping videos Replenish

I have an application with a VideoView that will keep looping the same video over and over until a user does something to the device(touch screen, etc) Currently I am using the OnCompletionListener() to restart the video once it ends. This works properly on every device I have tested, except for the Samsung Replenish.

Here is my code:

    mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        public void onCompletion(MediaPlayer mp) {
            mVideoView.setVideoPath(file.getAbsolutePath());
            mVideoView.start();
        }
    });

What happens on the Replenish is the video plays all the way through once but then is never started again and the screen goes all black (But backlight still turned on). On every other device I've tested on with this exact same code it has worked to repeat the video. Does anyone know of anything specific about the Replenish that could cause this error? I thought maybe delaying the calls to setVideoPath(), and start() by 200-300ms might help it, but that had no affect. I am really at a loss here.

I am seeing these messages in my Log:

ERROR/QCvdec(87): Omx Flush issued when vdec is not initialized yet.

ERROR/QCvdec(87): OMXCORE-SM:Recieved command DISABLE (2)

ERROR/QCvdec(87): Omx Flush issued when vdec is not initialized yet.

ERROR/QCvdec(87): OMXCORE-SM:Recieved command ENABLE (3)

But these logs are happening both when the video starts (the first time it plays) and when it fails to start again. so I am not sure if they are related to my problem

Edit:

I just tried setting mVideoView to null, and then getting a new reference to it with findViewById() right before the setVideoPath(). I know this would complicate the way the OnCompletionListener is set up. But regardless of that it didn't work anyway, still the same dark screen.

Edit 2:

I've started to notice that sometimes the video doesn't even start the first time. I am using these same two lines to start it up the first time:

        mVideoView.setVideoPath(file.getAbsolutePath());
        mVideoView.start();

It seems to start more consistantly, but not quite 100% when its the first time it is being played.

Edit 3: This is how I have it set up now. I am manually setting the OnPreparedListener to start the video for me. So I added this to my onCreate()

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

Then when I am ready to restart the video I just call only the setVideoPath() method, Like this:

mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
    public void onCompletion(MediaPlayer mp) {
        mVideoView.setVideoPath(file.getAbsolutePath());
        
    }
});

This seems to be doing the trick. I am letting it run for a while to find out for sure though.

Edit 4:

@MByD In the code for VideoView setVideoPath() is a wrapper for setVideoUri(). setVideoURI() is setting mStartWhenPrepared = false; The default OnPreparedListener checks this switch to decide whether to start playback or not. That is why it doesn't start with the default listener. I haven't looked into it more than that, but there may be a setter method that lets me change the mStartWhenPrepared value to true, which would cause the video to be started from the default listener.

like image 957
FoamyGuy Avatar asked Oct 25 '22 03:10

FoamyGuy


1 Answers

Have you tryed to prepare() your video before you call .start()?

from the docs: http://developer.android.com/reference/android/media/MediaPlayer.html#prepare%28%29

with a OnPreparedListener you can start your video when its ready.

like image 106
Michele Avatar answered Oct 27 '22 10:10

Michele