视频结束后结束活动 [英] Ending an activity after a video ends

查看:48
本文介绍了视频结束后结束活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是 Android 开发新手,正在开发一款游戏.现在我现在有一个过场动画,它是在点击游戏的开始按钮后调用的视频视图.我希望能够在视频结束后立即结束过场动画活动,但我不知道该怎么做.起初我尝试在 onCreate 中放置一个 25 秒的计时器,但由于 onCreate 只发生一次,所以失败了.现在我有一个按钮来结束过场动画,但我的问题是如何让过场动画活动结束并在视频直接结束后调用游戏活动?

Hi I am new to android development and I'm working on a game. Right now I have a cutsceen right now which is a videoview that is called after hitting the start button of the game. I want to be able to be able to end the cutsceen activity immediately after the video ends, but I'm not sure how to do that. At first I tried putting a timer for 25 seconds in onCreate, but that failed since onCreate only happens once. As it is now I have a button to end to the cutsceen, but my question is how do I get the cutsceen activity to end and call the game activity after the video directly ends?

推荐答案

首先,我对游戏开发并不是很熟悉,但我想它会以同样的方式工作.无论如何,视频是否在 VideoView 中?如果是这样,您可以调用 setOnCompletionListener 以便您收到视频播放完毕的通知.

First off, I'm not really familiar with game development, but I guess it would work the same way. Anyway, is the video in a VideoView? If so, you can call setOnCompletionListener to it so you will be notified that the video is done playing.

然后您可以调用 finish() 在回调方法中的活动.

You can then call finish() on the activity in the callback method.

public void onCompletion(MediaPlayer mp) {
    finish(); //This will end the current activity
}

这篇关于视频结束后结束活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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