使用exoplayer 簡單的播放HLS協議 程式碼如下:
DefaultBandwidthMeter BANDWIDTH_METER = new DefaultBandwidthMeter();
String userAgent = Util.getUserAgent(this, "ExoPlayerDemo");
DefaultDataSourceFactory mediaDataSourceFactory = new DefaultDataSourceFactory(this, BANDWIDTH_METER,
new DefaultHttpDataSourceFactory(userAgent, BANDWIDTH_METER));
String fileName = "http://live.xmcdn.com/live/59/64.m3u8";
Uri uri = Uri.parse(fileName);
if (fileName.endsWith(".m3u8")){
mediaSource = new HlsMediaSource.Factory(mediaDataSourceFactory)
.createMediaSource(uri, null, null);
}
TrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
DefaultTrackSelector trackSelector = new DefaultTrackSelector(trackSelectionFactory);
DefaultRenderersFactory renderersFactory =
new DefaultRenderersFactory(this, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER);
player = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector);
player.addListener(this);
player.setPlayWhenReady(true);
if(mediaSource!=null) {
player.prepare(mediaSource);
}
複製程式碼