Android videoview简历无效

时间:2017-01-27 11:01:57

标签: android android-videoview resume pause

我一直在使用Android中的VideoView播放视频。

OnPause of fragment我暂停视频并存储搜索时间

    @Override
    public void onPause() {
            super.onPause();

        if (videoview != null && videoview.isPlaying()) {
            videoview.pause();
            seekTime = videoview.getCurrentPosition();

        }
    }

OnResume我正在尝试使用 -

恢复视频
        @Override
        public void onResume() {
            super.onResume();
            videoview.seekTo(seekTime);
            //vvOnboardingVideos.resume();// this is not working for now - need to investigate
            videoview.start();   
        }

视频从一开始播放。

我有什么问题吗?请建议。

2 个答案:

答案 0 :(得分:1)

尝试扭转操作顺序:

        @Override
        public void onResume() {
            super.onResume();
            videoview.start();
            videoview.seekTo(seekTime);   
        }

答案 1 :(得分:0)

试试这个:

onpause()调用

时保存视频位置
// This gets called before onPause
    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        stopPosition = videoView.getCurrentPosition(); 
        videoView.pause();
        outState.putInt("video_position", stopPosition);
    } 

然后在onCreate()加载捆绑包中的stopPosition

@Override
    protected void onCreate(Bundle args) {
        super.onCreate(args);
        if( args != null ) {
            stopPosition = args.getInt("video_position");
        }
    }

使用以下方式恢复视频:

@Override
    public void onResume() {
        super.onResume();
        Log.d("Tag", "onResume");
        videoView.seekTo(stopPosition);
        videoView.start(); //Or use videoView.resume() if it doesn't work.
    }