Video and Full Screen and Orientation Changes - Android

I implemented an e-Reader in which video players are built-in, I need the option of switching full-screen mode from the player.

My question is this:

What is the best way to play the video in full screen and allow the user to return from this state to the page that he is reading before, as well as save the current video time.

Another difficult situation that I need to deal with:

There are different page renderings on the portrait and landscape, if the user switches the full-screen mode to the portrait and rotates the device, the video should go into landscape mode and scale the video to fit the screen, but if the user returns from this, he must again return to the portrait.

If necessary, I can provide more information. thanks in advance

+6
source share
1 answer

I can recommend using Activity with VideoView in layout.

You can save a position when changing orientation, for example,

 @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); if (mVideoView.isPlaying()) outState.putInt("pos", mVideoView.getCurrentPosition()); } 

Then restore the position and resume playback in the onCreate method

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.video); mVideoView = (VideoView) findViewById(R.id.video); MediaController mediaController = new MediaController(this); mediaController.setAnchorView(mVideoView); mVideoView.setMediaController(mediaController); mVideoView.setOnCompletionListener(this); Intent intent = getIntent(); path = intent.getExtras().getString("path"); int pos = 0; if (savedInstanceState != null) { pos = savedInstanceState.getInt("pos"); } playVideoFromPos(pos); } 
+9
source

Source: https://habr.com/ru/post/920168/


All Articles