Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android VideoView not playing sequential videos

I want to play 2 videos in a row. The first video always plays just fine. After it finishes, you can see in the log that it sets the new video URL, but then SurfaceView throws an error and the VideoView just freezes with the last frame of the first video. Nothing else happens. Any thoughts ? Thanks !

LE: Surprisingly, the OnPreparedListener gets called for the second video.

LE2: Sometimes the second video plays just fine, sometimes it doesn't... and I haven't changed a line of code between when it worked and when not. It's purely random...

LE3: Quick solution is add this line before you set the new video URL:

mVideoView.setVisibility(View.GONE);

Code from OnCompletionListener:

setCurrentPlaybackUrl(); // sets mCurrentMediaUrl to the second video URL
mVideoView.setVideoPath(mCurrentMediaUrl);
mVideoView.start();

This is the log output when the first video finishes playback:

10-22 12:32:35.762: I/AwesomePlayer(126): setDataSource_l('https://xx/TestingVideo_lo.mp4')
10-22 12:32:35.762: E/BufferQueue(123): [SurfaceView] connect: already connected (cur=3, req=3)
10-22 12:32:35.762: E/MediaPlayerService(126): setVideoSurfaceTexture failed: -22
10-22 12:32:35.762: E/BufferQueue(123): [SurfaceView] connect: already connected (cur=3, req=3)
10-22 12:32:35.762: E/MediaPlayerService(126): setVideoSurfaceTexture failed: -22
like image 484
Bogdan Zurac Avatar asked Oct 07 '22 05:10

Bogdan Zurac


1 Answers

Try on the onCompletion(MediaPlayer mp) , to add mp.stop() and then do your stuff .

EDIT: I have tried this and it's working:

videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
       play_video();
}
});

play_video();

where play_video is the following method :

void play_video() {
    Uri uri = Uri.parse(video_link);
    videoView.setVideoURI(uri);    
    videoView.requestFocus();
    videoView.setVisibility(View.VISIBLE);
    videoView.start();

 }

The only difference is that I played the same video twice, not two different videos.

like image 142
Iulia Barbu Avatar answered Oct 10 '22 02:10

Iulia Barbu