设置一个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();
每当我们收到错误,我们尝试重新连接。如果流结束,我们尝试立即重新连接。
大概你必须找到一些RTSP客户端代码,你可以直接使用它来确定流是否可用。然后,当它开始使用'VideoView'时。 – CommonsWare