What is the correct way to detect EXT-X-ENDLIST tag from a HLS Playlist with AVPlayer ?

Hi,

I would like to know what is the recommended way to detect the end of a live HLS playlist (sliding window) which contains the EXT-X-ENDLIST end tag ?

I tried to do this:
  1. Observing the currentItem's duration property. It often works, but sometimes currentItem's duration remains indefinite even if EXT-X-ENDLIST hls end tag was appended to the playlist. To me:

    • if duration.isIndefinite, we're LIVE

    • if duration.isValid && !duration.isIndefinite, it's VOD

  2. Observe playbackType from AVPlayerItem's last accessLogEvent with AVPlayerItemNewAccessLogEntryNotification. It seems the most reliable and work 100% of the time, but accessLog is never refreshed when playing a live playlist and is refreshed only after seeking. I would prefer a more reactive way to know when a live has ended...

Playlist example where currentItem's duration remains indefinite event if end tag is present (iPhone XR, iOS 14.4.1):

Code Block swift
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:8
#EXT-X-MEDIA-SEQUENCE:302
#EXT-X-PROGRAM-DATE-TIME:2021-05-20T13:30:32.000Z
#EXT-X-KEY:METHOD=AES-128,URI="https://example.akamaized.net/serve.key"
#EXTINF:8.00000,
remote_00302.ts
#EXT-X-PROGRAM-DATE-TIME:2021-05-20T13:30:40.000Z
#EXTINF:8.00000,
remote_00303.ts
...
#EXT-X-PROGRAM-DATE-TIME:2021-05-20T14:00:08.000Z
#EXTINF:8.00000,
remote_00524.ts
#EXT-X-PROGRAM-DATE-TIME:2021-05-20T14:00:16.000Z
#EXTINF:8.00000,
remote_00525.ts
#EXT-X-PROGRAM-DATE-TIME:2021-05-20T14:00:24.000Z
#EXTINF:5.13333,
remote_00526.ts
#EXT-X-ENDLIST

Should i file a bug for this ? Or i'm doing it in the wrong way ?

Thank you for your help,

Paul.

I think, "detect the end of a live HLS playlist", is a misunderstanding.

As I understand it, HLS has three types:

  • VOD - has EXT-X-PLAYLIST-TYPE:VOD; contains all segments; has an EXT-X-ENDLIST tag
  • EVENT - has EXT-X-PLAYLIST-TYPE:EVENT; periodically refetched, each time getting longer; eventually adds an EXT-X-ENDLIST tag
  • LIVE - does not have EXT-X-PLAYLIST-TYPE; periodically refetched, with sliding window; NEVER gets an EXT-X-ENDLIST tag.

I agree that a strict reading of sections 6.2.1 and 6.2.2 would seem to imply that an EXT-X-ENDLIST tag can be added to a live playlist, but I have never seen anyone do that. I would suggest a bug report or contacting Apple Developer Support in order to get clarification.

I agree that a strict reading of sections 6.2.1 and 6.2.2 would seem to imply that an EXT-X-ENDLIST tag can be added to a live playlist, but I have never seen anyone do that.

For example, if we want events 6 hours long with a 30 minutes sliding window, we would like to remove some parts of the playlist. According to the standard, an HLS playlist which has EXT-X-PLAYLIST-TYPE: EVENT MUST NOT change or delete any part of the Playlist file; it MAY append lines to it.

So we fall in the third case LIVE which doesn't have EXT-X-PLAYLIST-TYPE (my example) and which allows remove part of the playlist file. And as you said, it seems to be perfectly valid to have an EXT-X-ENDLIST tag at the end of it in this case.

I think that the end tag is detected because playbackType property changes from LIVE to VOD, but the duration never seems to be updated.

Thank you for you answer, I'll contact Apple Developer Support and I'll file a bug report if needed.

I think you should file a bug if you have a case where AVPlayerItem.duration remains indefinite after loading the playlist containing an EXT-X-ENDLIST tag. Don't forget to install the CoreMedia (HTTP Live Streaming) logging profile from the Profiles and Logs page and grab a sysdiagnose to attach to your bug after reproducing it.

Note that if there are separate playlists for audio or subtitles that they should contain EXT-X-ENDLIST tags as well.

What is the correct way to detect EXT-X-ENDLIST tag from a HLS Playlist with AVPlayer ?
 
 
Q