Skip to content Skip to sidebar Skip to footer

How To Start Activity After Videoview End

I have Activity , in this activity i have video . After this video i wish run another activity . I try make stupid things in java :) but it doesnt work . Help me pls . My clear jav

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(newMediaPlayer.OnCompletionListener() {
    publicvoidonCompletion(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(){
    publicvoidrun(){

        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
            publicvoidrun() {
                Thread t = new Thread(){
                    publicvoidrun(){

                        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(newMediaPlayer.OnPreparedListener() {
                @OverridepublicvoidonPrepared(MediaPlayer mp) {
                    mp.setLooping(true);//for repeating the same Video
                    mVideoView.start();
                }
            });

Post a Comment for "How To Start Activity After Videoview End"