2017-08-05 78 views
0

我正在使用vitamio庫在android中播放視頻流。儘管我可以使用它播放rtsp流,但我無法播放udp流。vitamio無法在android中播放udp streaming

我綜合vitamio通過gradle這個

compile 'me.neavo:vitamio:4.2.2' 

,並用它的活動就像下面

 setContentView(R.layout.activity_main); 
     if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this)) //it will check the include library of Vitamio 
      return; 

     mVideoView = (VideoView) findViewById(R.id.videoView); 
     Vitamio.initialize(this); 
     mVideoView.setVideoPath("udp://@192.168.0.104:1234"); 
     //mVideoView.setVideoPath("rtsp://192.168.0.104:8554/ss"); 
     mVideoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH); 
     mVideoView.setBufferSize(2048); 
     mVideoView.requestFocus(); 
     mVideoView.start(); 
     mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { 
      @Override 
      public void onPrepared(MediaPlayer mediaPlayer) { 
       mediaPlayer.setPlaybackSpeed(1.0f); 
      } 


     }); 
     mVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() { 
      @Override 
      public boolean onError(MediaPlayer mp, int what, int extra) { 
       return false; 
      } 
     }); 

這裏是我的代碼佈局

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="me.example.vitamiotest.MainActivity"> 

    <io.vov.vitamio.widget.VideoView 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:id="@+id/videoView" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

</android.support.constraint.ConstraintLayout> 

我試圖chaning網址udp://@192.168.0.104:1234(刪除@)沒有運氣。 rtsp流媒體播放效果很好。

這裏有一點需要注意的是,這些流媒體實際上並不是實時在某些遠程網址上進行流媒體直播。我從我的PC使用流媒體vlc192.168.0.104是我的電腦的本地IP。在rtsp的情況下,我可以播放rtsp://192.168.0.104:8554/ss這個網址,但udp沒有工作,在日誌中沒有錯誤味精。

回答

0

在你的電腦上試試這個udp流或使用其他軟件; 在我的應用程序中,udp steam正在播放右鍵。

mVideoView.setVideoPath("udp://@238.0.0.1:1234");