Reputation: 545
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
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
Reputation: 24625
I don't know the details of how the video player works, but my hunch is you have to:
Override onSaveInstanceState to save the place in the video (maybe a timestamp?)
Override onRestoreInstanceState to reload the video and seek to the point saved in step 1
Upvotes: 1