我有这个简单的视频流播放器:
if (play) {
myVideoView.stopPlayback();
myVideoView.clearFocus();
myVideoView = null;
button5.setText("Start");
play = false;
} else {
// dialog = ProgressDialog.show(Main.this, "Feldolgozás",
// "A videó töltődik");
progressBar = new ProgressDialog(v.getContext());
progressBar.setCancelable(true);
progressBar.setMessage("A video töltődik ...");
progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.show();
myVideoView = (VideoView) findViewById(R.id.myvideoview);
myVideoView.setVideoURI(Uri.parse(SrcPath));
RelativeLayout.LayoutParams videoviewlp = new RelativeLayout.LayoutParams(
500, 480);
videoviewlp.addRule(RelativeLayout.CENTER_HORIZONTAL,
RelativeLayout.TRUE);
videoviewlp.addRule(RelativeLayout.CENTER_VERTICAL,
RelativeLayout.TRUE);
myVideoView.setLayoutParams(videoviewlp);
myVideoView.invalidate();
myVideoView.requestFocus();
myVideoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
// mp.setOnCompletionListener(this);
mp.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
public void onBufferingUpdate(
MediaPlayer mPlayer, int percent) {
progressBar.setProgress(percent);
if (percent == 100) {
//dialog.dismiss();
progressBar.dismiss();
// Toast.makeText(getApplicationContext(),
// "100%", Toast.LENGTH_LONG).show();
}
}
});
mp.start();
// myVideoView.start();
}
});
play = true;
button5.setText("Stop");
}
}
如何检查视频流是否已结束或丢失? 如果丢失按钮应更改为启动和停止视频... 坦克为你的水壶!
更新:我认为问题出在vlc rtsp流上,因为它说youtube rtsp结束时...
答案 0 :(得分:1)
您可以尝试使用VideoView
的以下侦听器:
public void setOnCompletionListener (MediaPlayer.OnCompletionListener l)
注册媒体文件结尾时要调用的回调 在播放期间已到达。
public void setOnErrorListener (MediaPlayer.OnErrorListener l)
注册回放期间发生错误时要调用的回调 或设置。如果未指定侦听器,或者侦听器已返回 false,VideoView会通知用户任何错误。