我正在尝试使用 libstreaming api 接收在 android 应用程序中创建的 rtsp 流。它以 h264 和 aac 编码。我尝试使用提供的代码在 VLC 播放器和另一个 android 设备上观看它,但它似乎不起作用。
日志猫:
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.");
}