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);
本文详细介绍了如何在Android应用中利用ExoPlayer库播放RTMP流媒体。首先,在build.gradle文件中引入ExoPlayer和RTMP扩展库。接着,创建DefaultBandwidthMeter和AdaptiveTrackSelection,然后通过ExoPlayerFactory创建SimpleExoPlayer实例。在PlayerView中设置播放器,并使用RtmpDataSourceFactory创建MediaSource。最后,准备播放器并启动播放。
694

被折叠的 条评论
为什么被折叠?



