我实现了一个带有嵌入式视频播放器的电子阅读器,我需要一个选项来从播放器中切换到全屏模式。
我的问题是:
最佳的方法是什么,可以在全屏模式下播放视频,并让用户返回之前阅读的页面,并保留当前视频的时间。
我需要处理另一种复杂的情况:
在纵向和横向上,页面有不同的可视化效果,如果用户在纵向上切换到全屏并旋转设备,则视频应该进入横向模式并重新调整视频以适合屏幕大小,但如果用户从此页面返回,则应再次返回纵向。
如果需要更多信息,我可以提供。
谢谢。
我实现了一个带有嵌入式视频播放器的电子阅读器,我需要一个选项来从播放器中切换到全屏模式。
我的问题是:
最佳的方法是什么,可以在全屏模式下播放视频,并让用户返回之前阅读的页面,并保留当前视频的时间。
我需要处理另一种复杂的情况:
在纵向和横向上,页面有不同的可视化效果,如果用户在纵向上切换到全屏并旋转设备,则视频应该进入横向模式并重新调整视频以适合屏幕大小,但如果用户从此页面返回,则应再次返回纵向。
如果需要更多信息,我可以提供。
谢谢。
VideoView
的Activity
。您可以像这样在屏幕方向更改时保存位置。@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (mVideoView.isPlaying()) outState.putInt("pos", mVideoView.getCurrentPosition());
}
在onCreate方法中恢复位置并继续播放。
@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);
}
mVideoView.getCurrentPosition()
可以获取视频已播放的时间,你可以将其保存到outState
中。然后在onCreate
方法中,检查是否有保存的时间。在playVideoFromPos(int pos)
方法中,你可以调用mVideoView.seekTo(pos);
和mVideoView.start();
来实现所需功能。 - vasart