Ending an activity after a video ends
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 en开发者_开发技巧ds?
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.
You can then call finish() on the activity in the callback method.
public void onCompletion(MediaPlayer mp) {
finish(); //This will end the current activity
}
myVideoView.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
//write your code after complete video play
}
});
精彩评论