Android上的RTP / RTSP流式传输出错

时间:2015-09-28 16:14:37

标签: java android streaming rtsp rtp

我正在构建一个流媒体应用程序,依靠MediaPlayer播放通过RTP / RTSP流式传输的视频(使用VLC Media Player作为服务器)。

这是相关活动的代码:

public class MediaPlayerActivity extends Activity implements SurfaceHolder.Callback, MediaPlayer.OnPreparedListener  {

private MediaPlayer mediaPlayer;
private SurfaceHolder vidHolder;
private SurfaceView surfaceVideo;
private String address;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_media_player);
    Intent intent=getIntent();
    Bundle b=intent.getExtras();
    address=b.getString("EXTRA_ADDRESS");
    surfaceVideo =(SurfaceView)findViewById(R.id.surfaceVideo);
    vidHolder = surfaceVideo.getHolder();
    vidHolder.addCallback(this);
}

@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
}

@Override
public void surfaceCreated(SurfaceHolder arg0) {
    try {
        mediaPlayer = new MediaPlayer();
        mediaPlayer.setDisplay(vidHolder);
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mediaPlayer.setDataSource(getApplicationContext(), Uri.parse(address));
        mediaPlayer.setOnPreparedListener(this);
        mediaPlayer.prepareAsync();
    }
    catch(Exception e){
        e.printStackTrace();
    }
}

@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
    mediaPlayer.release();
}

@Override
public void onPrepared(MediaPlayer mp) {
    mediaPlayer.start();
}

如您所见,活动从其他活动获取流的URL。当我启动应用程序以通过 RTP 接收流时,我在logcat上获得以下输出:

09-28 17:50:44.000    1223-1223/com.example.cosmickone.mystreamingapp E/MediaPlayer-JNI﹕ android_media_MediaPlayer_setDataSourceAndHeaders : start showDialog  drm_status = -1
09-28 17:50:44.000    1223-1223/com.example.cosmickone.mystreamingapp E/MediaPlayer-JNI﹕ android_media_MediaPlayer_setDataSourceAndHeaders : end showDialog
09-28 17:50:44.270    1223-1240/com.example.cosmickone.mystreamingapp E/MediaPlayer﹕ error (1, -1003)
09-28 17:50:44.290    1223-1223/com.example.cosmickone.mystreamingapp E/MediaPlayer﹕ Error (1,-1003)

当我想打开 RTSP 流时,这是logcat上显示的错误:

09-28 17:49:25.370    1223-1223/com.example.cosmickone.mystreamingapp E/MediaPlayer-JNI﹕ android_media_MediaPlayer_setDataSourceAndHeaders : start showDialog  drm_status = -1
09-28 17:49:25.370    1223-1223/com.example.cosmickone.mystreamingapp E/MediaPlayer-JNI﹕ android_media_MediaPlayer_setDataSourceAndHeaders : end showDialog
09-28 17:49:25.370    1223-1239/com.example.cosmickone.mystreamingapp E/MediaPlayer﹕ error (1, -2147483648)
09-28 17:49:25.410    1223-1223/com.example.cosmickone.mystreamingapp E/MediaPlayer﹕ Error (1,-2147483648)

我已经成功地在Windows和Android上接收了VLC客户端上的流,我正在尝试使用不同格式的各种文件,所以我会放弃这是因为媒体编解码器或错误的服务器设置。我正在我的本地网络上测试它,所以端口/防火墙不应该有问题,我错了吗?

有人可以告诉我我做错了吗?

编辑:我已经在我的清单上获得了INTERNET许可。

0 个答案:

没有答案