更改媒体播放器 URI
我有以下工作代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.player);
videoView = (VideoView)this.findViewById(R.id.videoView);
playVideo();
// video finish listener
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.start();
}
});
}
public void playVideo() {
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
videoView.setVideoURI(Uri.parse("http://sayedhashimi.com/downloads/android/movie.mp4"));
videoView.requestFocus();
}
我只想在视频结束时更改 MediaPlayer 数据源(setOnCompletionListener)。
I have the following working code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.player);
videoView = (VideoView)this.findViewById(R.id.videoView);
playVideo();
// video finish listener
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.start();
}
});
}
public void playVideo() {
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
videoView.setVideoURI(Uri.parse("http://sayedhashimi.com/downloads/android/movie.mp4"));
videoView.requestFocus();
}
I just want to change the MediaPlayer data source when the video finishes (setOnCompletionListener).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在研究同样的问题。这是我想出的:
I'm working on this same issue. Here is what I've come up with:
这是我的解决方案:
我尝试的任何其他方法都给我带来了错误,如上所述这里。
每次创建新的媒体播放器不会对性能造成太大损害,因为无论如何您很可能一次只有一个。
希望有帮助; )
Here is my solution:
Anything else I tried gave me errors as mentioned here.
Creating new media player every time won't be that harmful for performance as you will most likely have only one at a time anyway.
hope it helps ; )