android exoplayer 直播流,使用Exo-Media Player播放RTMP直播

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

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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值