How to keep playing video while changing to landscape mode android

前端 未结 3 1132
野的像风
野的像风 2020-12-08 15:02

I\'m playing video (on VideoView) on portrait mode (not on full screen) and when I change to

landscape mode the video stop.

When I change it to

3条回答
  •  隐瞒了意图╮
    2020-12-08 15:35

    Unless you specify otherwise, a configuration change (such as a change in screen orientation, language, input devices, etc) will cause your current activity to be destroyed, going through the normal activity lifecycle process of onPause(), onStop(), and onDestroy() as appropriate. If the activity had been in the foreground or visible to the user, once onDestroy() is called in that instance then a new instance of the activity will be created, with whatever savedInstanceState the previous instance had generated from onSaveInstanceState(Bundle).

    So what happened behind the scenes: currnet VideoView Activity (landscape) is destroyed, a new VideoView Activity (portrait) is created due screenOrientation configuration has been changed, and destoryed immidiately (where you can see the effects on screen), last activity in stack is shown.

    Try to handle this methods and check

        @Override
    protected void onResume() {
        mVideoView.resume();
        super.onResume();
    }
    
    @Override
    protected void onPause() {
        mVideoView.suspend();
        super.onPause();
    }
    
    @Override
    protected void onDestroy() {
        mVideoView.stopPlayback();
        super.onDestroy();
    }
    

提交回复
热议问题