How To Start Activity After VideoView End
Solution 1:
This is what the MediaPlayer.OnCompletionListener
is for. Checking if the video is playing won't tell you if the user paused it for some reason before it's finished.
Simply call setOnCompletionListener()
on your VideoView
and register a callback. The callback will be called both in the case where the video completes successfully, and if playback terminates due to an error. So...
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
//Start a new activity or do whatever else you want here
}
});
You might also check the VideoView Documentation for other useful methods.
HTH.
Solution 2:
You could maybe create a Thread
which keeps checking whether videoView.isPlaying()
. When it returns False
, you could open up your new activity
.
Thread t = new Thread(){
public void run(){
while (videoView.isPlaying() == True)
{
try{
sleep(1000);
}
catch(Exception e){};
}
Intent h = new Intent(this, new.class);
startActivity(h);
}
};
t.start();
But I haven't used VideoView
before so I don't know what other features it has!
Solution 3:
This one has a delay in case the video is still loading and not playing
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Thread t = new Thread(){
public void run(){
while (video.isPlaying() == true)
{
try{
sleep(1000);
}
catch(Exception e){};
}
Intent in = new Intent(getApplicationContext(),
Main_Activity.class);
startActivity(in);
}
};
t.start();
}
}, 2000);
Solution 4:
Simply add
mediaplayer.setLooping(true)
if you want to repeat this video. it will start repeating itself.
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);//for repeating the same Video
mVideoView.start();
}
});
Post a Comment for "How To Start Activity After VideoView End"