Android VideoView not playing sequential videos

匿名 (未验证) 提交于 2019-12-03 03:02:02

问题:

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 

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!