2016-01-06 184 views
3

我一直致力于通过RTSP显示直播视频的Android应用程序。 假设我有一个通过H264包一个运作良好的RTSP服务器,并查看我们应该连接到rtsp://1.2.3.4:5555/streamvlc-android-sdk - 无法查看RTSP实时视频

于是,我就使用本机的MediaPlayer \ VideoView流,但没有运气(视频是2后卡住播放-3秒,所以我装mrmaffen的VLC-Android的SDK(可以发现here)和用下面的代码:

  ArrayList<String> options = new ArrayList<String>(); 
      options.add("--no-drop-late-frames"); 
      options.add("--no-skip-frames"); 
      options.add("-vvv"); 
      videoVlc = new LibVLC(options); 

      newVideoMediaPlayer = new org.videolan.libvlc.MediaPlayer(videoVlc); 
      final IVLCVout vOut = newVideoMediaPlayer.getVLCVout(); 
      vOut.addCallback(this); 
      vOut.setVideoView(videoView); //videoView is a pre-defined view which is part of the layout 
      vOut.attachViews(); 
      newVideoMediaPlayer.setEventListener(this); 

      Media videoMedia = new Media (videoVlc, Uri.parse(mVideoPath)); 
      newVideoMediaPlayer.setMedia(videoMedia); 
      newVideoMediaPlayer.play(); 

的问题是,我看到空白屏幕

请请注意,当我仅将音频流与RTSP链接时,它可以正常工作。

是否有人熟知这个SDK并对这个问题有所了解? 在此先感谢

+0

有你使用[VLC-Android的SDK(解决了这个问题https://github.com/ mrmaffen/VLC-Android的SDK)? –

回答

1

我玩RTSP与下面的代码

try { 
     Uri rtspUri=Uri.parse("rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"); 


     final MediaWrapper mw = new MediaWrapper(rtspUri); 
     mw.removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO); 
     mw.addFlags(MediaWrapper.MEDIA_VIDEO); 

     MediaWrapperListPlayer.getInstance().getMediaList().add(mw); 

     VLCInstance.getMainMediaPlayer().setEventListener(this); 
    VLCInstance.get().setOnHardwareAccelerationError(this); 


    final IVLCVout vlcVout = VLCInstance.getMainMediaPlayer().getVLCVout(); 
    vlcVout.addCallback(this); 
    vlcVout.setVideoView(mSurfaceView); 
    vlcVout.attachViews(); 
    final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); 
    final String aout = VLCOptions.getAout(pref); 
    VLCInstance.getMainMediaPlayer().setAudioOutput(aout); 
    MediaWrapperListPlayer.getInstance().playIndex(this, 0); 

    } catch (Exception e) { 
     Log.e(TAG, e.toString()); 
    } 

,当你打的事件流,则需要启用视频轨道。

private void onPlaying() { 
    stopLoadingAnimation(); 
    VLCInstance.getMainMediaPlayer().setVideoTrackEnabled(true); 
} 

这可能有助于你

0

尝试增加此选项:

--rtsp-tcp 
+0

谢谢,它的工作!即使Google Play的Android版VLC也无法播放某些数据流(因为它没有此选项)。在代码中:options.add(“ - rtsp-tcp”);新的LibVLC(上下文,选项); –