I have this code for playing a video on a VideoView
myVideoView = (VideoView) findViewById(R.id.VideoView);
myVideoView.setVideoURI(Uri.parse(path));
myVideoView.requestFocus();
myVideoView.start();
When video is finish playing I get message :" Sorry, this video can't be played". I want to cache the moment when video is finish playing. How can I do this?
Here is my code :
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video);
Bundle extras = getIntent().getExtras();
path = extras.getString("path");
idPlaylist = extras.getString("idPlaylist");
timer = extras.getString("timer");
myVideoView = (VideoView) findViewById(R.id.VideoView);
myVideoView.setVideoURI(Uri.parse(path));
myVideoView.requestFocus();
myVideoView.start();
myVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
Intent i = new Intent(getBaseContext(),
com.PlayerOrange.ViewPlaylist.class);
i.putExtra("id", idPlaylist);
i.putExtra("timer", timer);
startActivity(i);
finish();
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
System.out.println("Playing "+myVideoView.isPlaying());
if ((keyCode == KeyEvent.KEYCODE_BACK) && (myVideoView.isPlaying()==true)) {
//nothing happens
} else {
Intent i = new Intent(getBaseContext(),
com.PlayerOrange.ViewPlaylist.class);
i.putExtra("id", idPlaylist);
i.putExtra("timer", timer);
startActivity(i);
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
Have you tried?
myVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer vmp) {
Intent i = new Intent(getBaseContext(),
com.PlayerOrange.ViewPlaylist.class);
i.putExtra("id", idPlaylist);
i.putExtra("timer", timer);
startActivity(i);
currentActivityName.finish();
}
});
Also make sure your myVideoView not to have as static. If yes, then remove static..
More info here
Look at Starting Activity when video is finished playing
Android – Video/Music player sample
Playing Video
OnCompletion video notification on MediaController and VideView usage?
Android - Listener (or handler) for video finish
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With