Skip to content Skip to sidebar Skip to footer

Videoview & Fullscreen & Orientation Changes - Android

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 pl

Solution 1:

I can recommend using Activity with VideoView in layout.

You can save position on orientation change like this

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

Then restore position and resume playing in onCreate method

@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.video);

    mVideoView = (VideoView) findViewById(R.id.video);
    MediaControllermediaController=newMediaController(this);
    mediaController.setAnchorView(mVideoView);
    mVideoView.setMediaController(mediaController);
    mVideoView.setOnCompletionListener(this);

    Intentintent= getIntent();
    path = intent.getExtras().getString("path");

    intpos=0;
    if (savedInstanceState != null) {
        pos = savedInstanceState.getInt("pos");
    }

    playVideoFromPos(pos);
}

Post a Comment for "Videoview & Fullscreen & Orientation Changes - Android"