Videoview暂停和恢复 [英] Videoview Pausing and resuming

查看:1229
本文介绍了Videoview暂停和恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是android开发的新手,正在编写游戏.我的游戏中有过场动画在每个关卡开始之前播放,过场动画是通过videoview完成的.我的问题是,在应用程序暂停时,过场动画会在恢复后从头开始.

I am new to android development and I am programming a game. My game has cutsceens that play before each level starts, cutsceens which are done through videoview. My problem is, that upon an application pause, the cutsceen starts from the beginning again when resumed.

    @Override
public void onPause() {
    super.onPause();
    video.pause();
}
@Override
public void onResume()
{
    super.onResume();
    video.resume();
}

我们的问题是该视频实际上并没有从我们暂停的位置继续播放,而是从头开始播放.

Our issue is that the video doesn't actually resume from where we paused it, but from the beginning.

推荐答案

您可以使用此

@Override
public void onPause() {
    Log.d(TAG, "onPause called");
    super.onPause();
    stopPosition = videoView.getCurrentPosition(); //stopPosition is an int
    videoView.pause();
}
@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
}

原始帖子

这篇关于Videoview暂停和恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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