user1542141
user1542141

Reputation: 31

when video finished go back to activity

I have some videos using videoView. everything is running well, but when the video is finished nothing happens, the phone stay on dark screen waiting to pres play again or the blink back on the phone.

I want that when videos is finished, go back to the activity before. this is my code.

    public class chapterone extends Activity {

@Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.videoplayer);

        VideoView videoView =
        (VideoView)this.findViewById(R.id.videoView);
        MediaController mc = new MediaController(this);
        videoView.setMediaController(mc);
        videoView.setVideoURI(Uri.parse(
                "http://video.com/episode/" +
                "cotton1.mp4"));


        /* videoView.setVideoPath(
        Environment.getExternalStoragePublicDirectory(
        Environment.DIRECTORY_MOVIES) +
        "/movie.mp4");
        */



        videoView.requestFocus();
        videoView.start();


        }
        }

the URL is only an example.

Upvotes: 1

Views: 2920

Answers (2)

user1542141
user1542141

Reputation: 31

i hope can help i found this, but i am not sure if is correct uset it

videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){
        @Override
        public void onCompletion(MediaPlayer mp){
            // invoke your activity here

        Intent i = new Intent(chapterone.this, videoserie.class);
             startActivity(i);  

        } 
    });

Upvotes: 2

AkashG
AkashG

Reputation: 7888

videoView.setOnCompletionListener(completionListener);
    OnCompletionListener completionListener=new OnCompletionListener() {

        public void onCompletion(MediaPlayer mp) {
            mp.stop();
            chapterone.this.finish();
        }
    };

Upvotes: 3

Related Questions