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.
Asked
Active
Viewed 4,630 times
1
-
It kind of is, except I think the questioner (among other people probably, myself included at one point) don't realize that m3u8 files need `HLS` streaming – Nevermore Feb 01 '18 at 21:22
1 Answers
1
m3u
or m3u8
is a file type for media playlists, that's it. The content is going to be in the format HLS
HLS
is:
HTTP-based media streaming communications protocol implemented by Apple Inc
(but non Apple products can stream it)
Here is a tutorial, https://possiblemobile.com/2016/03/hls-exoplayer/ but it's for an old version of exoplayer (because exoplayer
has been going through lots of changes lately).
Here is a working version I use to play m3u8 files (MyURL
is a http link to an m3u8
(playlist) file:
First initiate the player:
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);
Then add the 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);
Using HLS, for m3u8 is a lot like using exoplayer with the default MediaSource
, except you should use the HlsMediaSource
instead

Nevermore
- 7,141
- 5
- 42
- 64