0
我正嘗試使用libstreaming api接收在android應用中創建的rtsp流。它以h264和aac編碼。我試圖在VLC播放器和另一個使用提供的代碼的Android設備上觀看它,但它似乎不起作用。從libstreaming播放rtsp流
的logcat:
05-08 15:10:43.266 5631-5631/net.majorkernelpanic.example1 E/WIFIIP: Unable to get host address.
05-08 15:10:43.992 1311-5663/? E/RTSPSource: Server picked invalid RTP/RTCP port pair 39108-49193, RTP port must be even, RTCP port must be one higher.
代碼:
String url2 = "rtsp://ip address:port";
SurfaceView mSurfaceView = (SurfaceView)findViewById(R.id.surface_video);
SurfaceHolder holder = mSurfaceView.getHolder();
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(url2);
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mediaPlayer.setDisplay(holder);
mediaPlayer.start();
}
});
mediaPlayer.prepareAsync(); // prepare async to not block main thread
} catch (IOException ex) {
System.out.println(ex.toString());
System.out.println("Unable to connect.");
}