Chris
Chris

Reputation: 545

Android - Video Restart or Resume

I am writing a simple android application with a class that extends activity, that plays a video from a url on the web. There is a button on top that on click takes the user to a web page.

What I want to do is when the user is browsing the web page, if he hits the back button, I want him to come back to the main activity and restart the video. Is there a way to do this?

Also, is there a way the video can be resumed from where it left off?

Thank you. Chris

Upvotes: 2

Views: 6980

Answers (2)

Spigolo Vivo
Spigolo Vivo

Reputation: 39

Try this.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.video_view);

    videoView = (VideoView) findViewById(R.id.video_surface);
    mc = new MediaController(this);
    videoView.setMediaController(mc);

    videoView.setVideoURI(Uri.parse("myUri"));
    videoView.start();
}


@Override
public void onResume(){
    super.onResume();
    videoView.resume();
}

@Override
public void onPause(){
    super.onPause();
    videoView.suspend();
}

Upvotes: 2

Brandon O'Rourke
Brandon O'Rourke

Reputation: 24625

I don't know the details of how the video player works, but my hunch is you have to:

  1. Override onSaveInstanceState to save the place in the video (maybe a timestamp?)

  2. Override onRestoreInstanceState to reload the video and seek to the point saved in step 1

Upvotes: 1

Related Questions