简体   繁体   English

无法在Android MediaPlayer中流式传输RTSP视频

[英]Unable to stream RTSP video in Android MediaPlayer

I'm trying to stream a video from an RTSP server. 我正在尝试从RTSP服务器流式传输视频。 I want to run the video inside my app. 我想在我的应用程序中运行视频。 I have tried three different approaches and only one of them seems to work: 我尝试了三种不同的方法,但似乎只有一种可行:

  1. Using VideoView (does not work). 使用VideoView(无效)。
  2. Using native player (works). 使用本机播放器(有效)。
  3. Using MediaPlayer (does not work). 使用MediaPlayer(无效)。

I want to display the video on MediaPlayer but unable to do it. 我想在MediaPlayer上显示视频,但无法执行。

Here is the code: 这是代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



    /* 1. Using VideoView, error: "Cannot play video"
    VideoView vidView = (VideoView) findViewById(R.id.myVideo);

    String vidAdress = "rtsp://10.42.0.91:5554/camera";
    Uri vidUri = Uri.parse(vidAdress);

    vidView.setVideoURI(vidUri);

    vidView.start();

    */

    //Using native player (implicit intent), works.
    String mediaURL = "rtsp://10.42.0.91:5554/camera";
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(mediaURL));
    startActivity(intent);

    /* Using MediaPlayer (doesn't work). Error: "Cannot create MediaPlayer"
and setDataSource.
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

    try
    {
        mediaPlayer.setDataSource("rtsp://10.42.0.91:5554/camera");
        mediaPlayer.prepare();
        mediaPlayer.start();
    }
    catch (IOException ex)
    {
        ex.printStackTrace();
    }
    */

http:10.42.0.91:8080/playlist.m3u looks like this: http:10.42.0.91:8080 / playlist.m3u看起来像这样:

#EXTM3U #EXTM3U

#PLAYLIST:RTSP Camera Server #EXTINF:-1, Active camera rtsp://10.42.0.91:5554/camera #EXTINF:319, 3/3/16 PM 3:08: 35 MB rtsp://10.42.0.91:5554/record160303_1500 #EXTINF:1047, 3/3/16 PM 2:15: 106.4 MB rtsp://10.42.0.91:5554/record160303_1400 #EXTINF:1364, All records 141.4 MB rtsp://10.42.0.91:5554/record #EXTINF:-1, Back camera rtsp://10.42.0.91:5554/back #EXTINF:-1, Front camera rtsp://10.42.0.91:5554/front #PLAYLIST:RTSP摄像机服务器#EXTINF:-1,活动摄像机rtsp://10.42.0.91:5554 / camera #EXTINF:319,3/3/16 PM 3:08:35 MB rtsp://10.42.0.91: 5554 / record160303_1500 #EXTINF:1047,3/3/16 PM 2:15:106.4 MB rtsp://10.42.0.91:5554 / record160303_1400 #EXTINF:1364,所有记录141.4 MB rtsp://10.42.0.91:5554 /记录#EXTINF:-1,后置摄像头rtsp://10.42.0.91:5554 / back #EXTINF:-1,后置摄像头rtsp://10.42.0.91:5554 / front

I've just finished a basic application that can display RTSP H.264(Even high profile) in the Android MediaPlayer. 我刚刚完成了一个基本应用程序,该程序可以在Android MediaPlayer中显示RTSP H.264(甚至是高配置)。 I was experimenting and researching how I should implement it, when I came across this video . 当我看到此视频时,我正在实验和研究如何实现它。 It is quite easy to implement and source code is also provided. 它非常容易实现,并且还提供了源代码。 I use Android version 5.1.1, it doesn't seem to work on 4.4 and below. 我使用的是Android版本5.1.1,但在4.4及以下版本上似乎无法使用。 My goal is to make it work on 4.1 and up, so I'll edit or comment when I got that working. 我的目标是使其在4.1或更高版本上运行,因此我将在工作时对其进行编辑或评论。

I hope this explains everything you need. 我希望这能解释您需要的一切。 Just tell me if it still does not work and I'll try to help you out. 请告诉我它是否仍然无法正常工作,我会尽力帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM