Reputation: 3226
I have an application that makes a list of videos with play button. When I click on the play button, a separate activity is started using intent. I just want that when the video playback is finished, the activity should automatically finish itself and go back to the main Activity. Here is my code for creating videoview.
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.videoview);
Intent i = getIntent();
Bundle extras = i.getExtras();
filename = extras.getString("videofilename");
mVideoView = (VideoView)findViewById(R.id.videoview);
path=filename;
if (path == "") {
Toast.makeText(
ViewVideo.this,
"no video selected,
Toast.LENGTH_LONG).show();
} else {
mVideoView.setVideoPath(path);
mc = new MediaController(this);
mVideoView.setMediaController(mc);
mVideoView.requestFocus();
mVideoView.start();
}
}
any suggestions???
Upvotes: 1
Views: 1778
Reputation: 137282
Register an OnCompletionListener to the videoView, in the listener implement the call to finish()
.
Edit (to answer to comment):
use the method setOnCompletionListener:
mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion (MediaPlayer mp) {
// your code to clean up and finish the activity...
}
});
Upvotes: 4
Reputation: 5151
You can set a MediaPlayer.OnCompletionListener
on the VideoView
using VideoView.setOnCompletionListener
, you'll then be able to finish the containing activity when the video finishes playing.
Upvotes: 3