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

I play 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(); 

Using this code, what I see in the video was about 5 minutes late according to the same stream that plays in the VLC.

The player begins to play the first fragment of the .m3u8 file. But the hls specification indicates that the first fragment is the oldest and the last last. Thus, the player should start playing the last fragment of the file.

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

+4
source share
2 answers

I ran into the same problem - it seems that when you launch the live HLS channel (which does not have the EXT-X-ENDLIST tag) on ​​Android, there is an error in the main components of HLS parsing that do not start from the current point (end of feed) and instead this starts at the beginning of the stream.

There is an error about this on code.google.com: you can "show" it or transfer it there:

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

+2
source

I do not think that the HLS specification clearly does not indicate for which segment to start work, but usually it starts with the third last segment for live hls.

The stream you are referencing is the source of the HLS Video on Demand (VOD). The only difference is that the playlist ends with # EXT-X-ENDLIST. What causes:

  • non-refreshing player
  • starting with the very first fragment.
  $ 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

Take a look at the Envivio page. I believe that they have some HLS channels with which you can test.

General comment: Don't rely on VLC when it comes to HLS testing.

+1
source

Source: https://habr.com/ru/post/1395634/


All Articles