Android VideoView在点击之前不会调用onSurfaceCreated

时间:2016-06-05 14:05:16

标签: android android-fragments surfaceview android-videoview

我使用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或单击活动中的按钮控件。有没有帮助这个问题?

0 个答案:

没有答案