我使用VideoView播放mp4和m3u8文件。我在片段中加载VideoView并将其放在Activity中,这里是片段中的代码加载视频网址:
if(currentPossition == 0 || isCompleted) {
Uri path = Uri.parse(videoUrl);
videoView.setVideoURI(path);
videoView.requestFocus();
controller.setAnchorView(videoView);
controller.setMediaPlayer(videoView);
videoView.setMediaController(controller);
}else{
videoView.seekTo(currentPossition);
videoView.start();
}
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
在类VideoView中,我发现第一次创建表面时调用了回调SurfaceHolder.Callback mSHCallback
和函数surfaceCreated(SurfaceHolder holder)
。所以,我的视频第一次播放,问题是当我破坏片段(surfaceDestroyed(SurfaceHolder holder)
调用并且mSurfaceHolder = null)并在getSupportFragmentManager中再次替换时,回调SurfaceHolder.Callback
在我触摸之前未调用VideoVideo或单击活动中的按钮控件。有没有帮助这个问题?