gpt4 book ai didi

android - 从 onResume 继续播放 VideoView

转载 作者:IT老高 更新时间:2023-10-28 23:38:25 30 4
gpt4 key购买 nike

我有一个 VideoView,当我启动电子邮件 Intent 时它会暂停。完成电子邮件 Intent 后,我希望 videoView 继续播放,但是它会从头开始。

@Override
public void onPause() {
Log.d(TAG, "onPause called");
super.onPause();
videoView.pause();
}
@Override
public void onResume() {
super.onResume();
Log.d(TAG, "onResume called");
videoView.start();//resume() doesnt work
}

如何让 videoView 从中断处恢复。

最佳答案

这个呢:

@Override
public void onResume() {
super.onResume();
Log.d(TAG, "onResume called");
videoView.seekTo(stopPosition);
videoView.start(); //Or use resume() if it doesn't work. I'm not sure
}

// This gets called before onPause so pause video here.
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
stopPosition = videoView.getCurrentPosition();
videoView.pause();
outState.putInt("position", stopPosition);
}

然后在你的 onCreate() 中调用 bundle 中的 stopPosition 并全局设置

@Override
protected void onCreate(Bundle args) {
super.onCreate(args);
if( args != null ) {
stopPosition = args.getInt("position");
}

关于android - 从 onResume 继续播放 VideoView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11960730/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com