7

I implemented a e-Reader that has embedded video players on it, I need a option to toggle fullscreen mode from the player.

My question is the following:

Which is the best way to play a video on fullscreen and let the user come back from this state to the page he is reading before and also keep the current time of the video.

Another complicated situation I need to handle is:

There's different visualizations of a page on portrait and landscape, if the user toggle fullscreen on portrait and rotate the device, the video should go to landscape mode and rescale the video to fit the screen, but if the user goes back from this page he should return to portrait once again.

I'm able to give more info if needed. Thanks in advance

Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167

1 Answers1

9

I can recommend using Activity with VideoView in layout.

You can save position on orientation change like this

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

Then restore position and resume playing in 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);
}
vasart
  • 6,692
  • 38
  • 39
  • 1
    Actually,the biggest problem is about removing the old videoview from the page and keep it's state consistent trough orientation changes. (Not recreate the background activity) – Marcos Vasconcelos Jul 11 '12 at 15:15
  • Ok we got mVideoView.getCurrentPosition() so how to set to videoview to this value. And main issue is to get time how much video has played and setting it – Tofeeq Ahmad Dec 15 '12 at 07:37
  • 2
    `mVideoView.getCurrentPosition()` gives you time how much video has played and you save it to `outState`. Then in `onCreate` you check if `savedInstanceState` has this saved time. In method `playVideoFromPos(int pos)` you can call `mVideoView.seekTo(pos);` and `mVideoView.start();`. That will do what you need. – vasart Dec 15 '12 at 08:23
  • 3
    bt i think it'll rebuffer it again – Kalpesh Lakhani Feb 28 '13 at 09:27
  • How to do this adapter class . I am using firebase recyler adpter please help me – Security Coding Dec 16 '21 at 06:29