从 libstreaming 播放 rtsp 流

Playing rtsp stream from libstreaming

我正在尝试使用 libstreaming api 接收在 android 应用程序中创建的 rtsp 流。它以 h264 和 aac 编码。我尝试使用提供的代码在 VLC 播放器和另一台 android 设备上观看它,但它似乎不起作用。

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.");
}

来自您的 Logcat 错误:

RTSPSource: Server picked invalid RTP/RTCP port pair 39108-49193, RTP port must be even, RTCP port must be one higher

看来您应该修改您的 libstreaming 服务器端端口。该错误指定 "RTP port must be even, RTCP port must be one higher",因此您可以分别将其设置为 39108、39109。修改您的服务器代码并重试?