Schedule AVPlayerInterstitialEvent for Live HLS

334 Views Asked by At

I am working on an application that streams HLS video and I would like to use AVPlayerInterstitialEventController to schedule a priority event (i.e. Emergency Alert) during a Live stream.

The only way I have been able to reliably accomplish this is if my HLS content is VOD, where the AVPlayerInterstitalEvent is configured with a time property and scheduled on the controller. This works fine.

However, I cannot get this to work when the primary content is a Live stream. AVPlayerInterstitialEvent is configured with a Date property.

I have confirmed:

  • The HLS playlist for the primary asset contains EXT-X-PROGRAM-DATE-TIME tag so the Event Date can be mapped into the primary item's timeline.
  • The date property of the AVPlayerInterstitialEvent is sufficiently ahead (> 60 seconds) of the current playback position.
  • Using Charles Proxy, I do not see any player networking for the Event's URL.
  • The Player's transport bar is updated with an "ad pod" for the event and it moves towards the live point on the transport bar. Despite this, the video never switches to the interstitial.

The only way I have achieved this is to set AVPlayerInterstitialEvents cue property to joinCue. In this case, I suspect the Event Controller just ignores the Date since the desired behavior is to play before content starts. This is not sufficient for my use case though.


A snippet of my code to set the controller follows. I am using a basic SwiftUI VideoPlayer for native playback controls.

let currentItem = player.currentItem

let event = AVPlayerInterstitialEvent(primaryItem: currentItem,
identifier: evt.id,
date: evt.date,
templateItems: [AVPlayerItem(url: evt.url)],
restrictions: [],
resumptionOffset: CMTime.indefinite)

event.willPlayOnce = true
eventController.events = [event]

Any help or insight is appreciated.


Update:

I was able to get an AVPlayerInterstitialEvent to play on a LIVE asset but I needed to manipulate the HLS media playlist to do so. I used a Charles Proxy re-write and added a Date range tag to the media playlist, e.g. #EXT-X-DATERANGE:ID="ad1",CLASS="com.apple.hls.interstitial",START-DATE="2023-04-25T19:13:00.000Z",DURATION=72.0,X-ASSET-URI="https://myEvent.m3u8",X-RESTRICT="SKIP,JUMP"

Here, I observed the same behavior as before where the ad pod was rendered and moved towards the live edge of my stream. This time the Player switched to the interstitial and I was able to watch the event and see it switch back.

My remaining Question is why doesn't this work with client-side scheduling?

Late-binding Server-side ads via Date Range tags is an advertised feature of AVPlayerInterstitialEvent but the HLS manipulation is a bit cumbersome and I'd prefer to use the API to schedule it client-side.

Links:

0

There are 0 best solutions below