obo
obo

Reputation: 1662

Android 3.x / HLS how to start at the end of the stream

I am playing an HLS stream with the following code :

mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource("http://iphoned5.akamai.com.edgesuite.net/mhbarron/nasatv/nasatv_all.m3u8");
mediaPlayer.setDisplay(holder);
mediaPlayer.setOnBufferingUpdateListener(this);
mediaPlayer.setOnCompletionListener(this);
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.setOnVideoSizeChangedListener(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.prepareAsync();

With this code, what I see in the video is about 5 minutes late according to the same stream played into VLC.

The player is starting to play the first chunk of the .m3u8 file. But the hls specification precises that the first chunk are the older and the last the newest. So the player should start to play the last chunk of the file.

I suspect there is something to do with the parameters of the setDataSource method but I cannot figure how.

Upvotes: 4

Views: 3692

Answers (2)

Bob Cowherd
Bob Cowherd

Reputation: 156

I encountered the same issue - it looks like when you start a live HLS feed (that does NOT have the EXT-X-ENDLIST tag) on Android, there is a bug in the core HLS parsing components that fails to start at the live point (end of the feed), and instead starts at the beginning of the stream.

There is a bug filed on code.google.com about this - you can 'star' or upvote it there:

http://code.google.com/p/android/issues/detail?id=37156

Upvotes: 3

Florian Pilz
Florian Pilz

Reputation: 337

I don't believe the HLS specification does not explicitly state which segment to start with for, but usually it starts on the third last segment for live hls.

The stream you are referring to is a Video on Demand (VOD) HLS source. The only difference is that the playlist is terminated using a #EXT-X-ENDLIST. Which causes:

  • the player not refreshing the playlist
  • starting at the very first chunk.
$ curl http://iphoned5.akamai.com.edgesuite.net/mhbarron/nasatv/nasatv_700.m3u8
...
#EXTINF:10,
http://iphoned5.akamai.com.edgesuite.net/mhbarron/nasatv/nasatv_700/Seg_060110_103747_44/nasatv_700_060110_103747_87966.ts
#EXTINF:0,
http://iphoned5.akamai.com.edgesuite.net/mhbarron/nasatv/nasatv_700/Seg_060110_103747_44/nasatv_700_060110_103747_87967.ts
#EXT-X-ENDLIST

Have a look at at the Envivio page I believe they have some live HLS channels you can test with.

A general comment: don't rely on VLC when it comes to testing HLS.

Upvotes: 1

Related Questions