Skip to content Skip to sidebar Skip to footer

Starting Activity When Video Is Finished Playing

In my Android app, I am trying to simply go back to my main Activity once a video that I am playing ends. I have tried many workarounds, but I can't find a way to call StartActivi

Solution 1:

If you know the time of the video then you try:

String uri1 = "android.resource://" + getPackageName() + "/" + R.raw.race3;
        vd.setVideoURI(Uri.parse(uri1)); 
        vd.start();

new Thread() {
             public void run() {
                     try{

                             sleep(50000);
                     } catch (Exception e) {

                     }
                   Intent intent = new Intent(Video.this, Another.class);
                   startActivity(intent);
                   finish();
             }
     }.start();

if you don't know the time then you get the time as:

int vtime = vd.getDuration();

And then at thread sleep you just put this integer.


Solution 2:

If you started the Video Activity from the Activity you would like to go back to later, just calling finish() at the end of the video will do the job.

Starting the main Activity again creates a not necessarily wanted stack of activities.


Post a Comment for "Starting Activity When Video Is Finished Playing"