检测视频视图何时停止播放
我有这段代码用于在 VideoView
上播放视频,
myVideoView = (VideoView) findViewById(R.id.VideoView);
myVideoView.setVideoURI(Uri.parse(path));
myVideoView.requestFocus();
myVideoView.start();
当视频播放完毕时,我收到消息:“抱歉,无法播放该视频”。我想缓存视频播放完毕的那一刻。我该怎么做?
这是我的代码:
@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);
}
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你尝试过吗?
还要确保您的 myVideoView 不是静态的。如果是,则删除静态...
更多信息 这里
看看视频播放完毕后启动 Activity
Android – 视频/音乐播放器示例
播放视频
OnCompletion 视频通知MediaController 和 VideView 用法?
Android - 视频监听器(或处理程序)完成
Have you tried?
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