使用Exo-Media Player播放RTMP直播

TOmDD發表於2020-06-10

 build.gradle:

compile 'com.google.android.exoplayer:exoplayer:2.7.3'     
compile 'com.google.android.exoplayer:extension-rtmp:2.7.3'

activity程式碼:

//initiate Player    
//Create a default TrackSelector    
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();    
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);    
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);    
//Create the player    
SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);    
PlayerView playerView = findViewById(R.id.simple_player);    
playerView.setPlayer(player);    
RtmpDataSourceFactory rtmpDataSourceFactory = new RtmpDataSourceFactory();    
// This is the MediaSource representing the media to be played.    
MediaSource videoSource = new ExtractorMediaSource.Factory(rtmpDataSourceFactory)    
.createMediaSource(Uri.parse("rtmp://stream1.livestreamingservices.com:1935/tvmlive/tvmlive"));    
// Prepare the player with the source.    
player.prepare(videoSource);    
//auto start playing    
player.setPlayWhenReady(true);



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69965015/viewspace-2697335/,如需轉載,請註明出處,否則將追究法律責任。

相關文章