I am new to android development in eclipse ( because my computer is low config PC ). I will try making tv application like stream .m3u8 files over network. how to archive this with exoplayer? It is very confusing to me.
答案 0 :(得分:0)
m3u
或m3u8
是媒体播放列表的文件类型,就是这样。内容将采用HLS
HLS
是:
Apple Inc实施的基于HTTP的媒体流通信协议
(但非Apple产品可以流式传输)
这是一个教程,https://possiblemobile.com/2016/03/hls-exoplayer/但是旧版本的exoplayer (因为exoplayer
最近经历了很多变化)。
以下是我用来播放m3u8文件的工作版本(MyURL
是指向m3u8
(播放列表)文件的http链接:
首先启动玩家:
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoFactory);
LoadControl loadControl = new DefaultLoadControl();
// Create Player
player = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector, loadControl);
然后添加HlsMediaSource
Handler mHandler = new Handler();
String userAgent = Util.getUserAgent(this, "User Agent");
DataSource.Factory dataSourceFactory = new DefaultHttpDataSourceFactory(
userAgent, null,
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
1800000,
true);
HlsMediaSource mediaSource = new HlsMediaSource(MyURL, dataSourceFactory, 1800000,
mHandler, null);
player.setPlayWhenReady(true);
player.prepare(mediaSource);
使用HLS,对于m3u8很像使用带有默认MediaSource
的exoplayer,除非您应该使用HlsMediaSource
而不是