我正在尝试仅在rtsp视频流可用时使用VideoView显示视频。我看到很多例子,人们使用按钮启动VideoView,但没有关于如何监听传入流的内容。
video_stream.setVideoPath("rtsp://MY_IP/stream");
video_stream.requestFocus();
video_stream.start();
如果我尝试在有流之前执行此操作,我就无法播放此视频"。如果我事先启动了流,它就能正常运行。
答案 0 :(得分:0)
设置一个onErrorListener,设置一个onCompleteListener,像我上面那样启动流。
video_stream.setOnErrorListener(new OnErrorListener() {
public boolean onError(MediaPlayer mp,int what, int extra) {video_stream.setVideoPath("rtsp://IP/stream");
video_stream.requestFocus();
video_stream.start();}
});video_stream.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
video_stream.setVideoPath("rtsp://IP/stream");
video_stream.requestFocus();
video_stream.start();
}
});video_stream.setVideoPath("rtsp://IP/stream");
video_stream.requestFocus();
video_stream.start();
每当我们收到错误时,我们都会尝试重新连接。如果流结束,我们会立即尝试重新连接。