VideoView&全屏和方向更改-Android [英] VideoView & Fullscreen & Orientation changes - Android

本文介绍了VideoView&全屏和方向更改-Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了一个内置了视频播放器的电子阅读器,我需要一个选项来从播放器切换到全屏模式.

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

我的问题如下:

哪种方法是在全屏模式下播放视频的最佳方法,它可以使用户从此状态返回到他之前正在阅读的页面,并保留视频的当前时间.

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

推荐答案

我建议在布局中将ActivityVideoView一起使用.

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());
}

然后恢复位置并在onCreate方法中继续播放

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);
}

这篇关于VideoView&全屏和方向更改-Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆