[译] Android ExoPlayer Rtmp HLS DASH SmoothStreaming 其他

来源:互联网 发布:mac版字体下载 编辑:程序博客网 时间:2024/05/21 21:43

https://medium.com/@KarthikPonnam/rtmp-player-android-using-exo-media-player-ac7a012b7a25


google exoplayer, 支持的格式蛮多的
https://github.com/google/exoplayer

DASH, SmoothStreaming, HLS, 其他

google exoplayer 开发文档
https://google.github.io/ExoPlayer/guide.html

但是不支持RTMP, 才有了下面的插件

github 源代码:
https://github.com/PonnamKarthik/RTMP-Exo-Player-Demo


使用Exo-Media Player的Rtmp Player Android
Hello Reader的,在我们开始之前
让我们看看什么是RTMP?
RTMP代表实时消息协议。它提供了音频,视频和数据从编码器到服务器的高性能传输,服务器通过互联网分发信号。许多流媒体提供商和编码器开发商都支持RTMP流媒体,包括Livestream。
在这里阅读有关rtmp的更多信息。
没有更多的理论让我们开始编码:-)


步骤1:

更改最低SDK版本

defaultConfig {     // ...     minSdkVersion 15     // ... }

因为为了使用这个扩展-rtmp库,所需的最小sdk是15
编辑您的build.gradle文件并添加以下两个依赖项

compile 'com.google.android.exoplayer:exoplayer:r2.5.1'compile 'com.google.android.exoplayer:extension-rtmp:r2.5.1'

然后同步你的项目


第2步:

在布局文件中创建一个简单的exoplayer视图

<com.google.android.exoplayer2.ui.SimpleExoPlayerView                                      android:layout_width="match_parent"                                   android:layout_height="match_parent"                                   android:id="@+id/simple_player">                       </com.google.android.exoplayer2.ui.SimpleExoPlayerView>

第3步:
现在在您的玩家活动中添加行来准备播放

//initiate Player//Create a default TrackSelectorHandler mainHandler = new Handler();BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);//Create the playerSimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);SimpleExoPlayerView simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.simple_player);simpleExoPlayerView.setPlayer(player);RtmpDataSourceFactory rtmpDataSourceFactory = new RtmpDataSourceFactory();// Produces Extractor instances for parsing the media data.ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();// This is the MediaSource representing the media to be played.MediaSource videoSource = new ExtractorMediaSource(Uri.parse("rtmp://184.72.239.149/vod/mp4:bigbuckbunny_750.mp4"),                rtmpDataSourceFactory, extractorsFactory, null, null);// Prepare the player with the source.player.prepare(videoSource);

运行你的代码,rtmp流将在你的应用程序中播放,大小约为2.5Mb
在这里下载项目。
如果您觉得这篇文章有用,请推荐并分享。
Android的RTMPExoplayer现场直播Android开发


附录:
【VLC-Android】vlc-android简例(14年的帖子)
http://www.cnblogs.com/over140/p/3932784.html


end