How do I schedule ads in an HLS stream?

Generated on 7/31/2024

1 search

To schedule ads in an HLS stream, you can use HLS interstitials. Here’s a brief overview of how you can do it:

  1. Specify the Start Date: You can schedule an interstitial ad by specifying the start date in the content's program date time. For example, to schedule an ad 5 seconds into the content, you set the start date as 5 seconds in the content's program date time. The primary content will play up to 5 seconds, then the interstitial ad will play, and finally, the primary content will resume after the ad completes.

  2. Use the Integrated Timeline API: Apple introduced a new AVFoundation API called Integrated Timeline, which provides a data model for timing and sequence of playback of content within interstitials. This API helps in building new UI experiences and enables seamless navigation in and out of interstitials.

  3. Signaling Interstitials: You can signal interstitials on the timeline using the new HLS syntax. For example, you can create an interstitial event and set a property called timelineOccupancy to singlePoint for a point on the timeline or to fill for a range on the timeline.

  4. Example App: In the sample app provided in the session, an example called "fill interstitial" includes a range interstitial scheduled at 10 seconds into the content. The transport bar shows the interstitial with a yellow range starting at 10 seconds, and playback transitions to the interstitial at the expected time.

For more detailed information, you can refer to the session Enhance ad experiences with HLS interstitials at WWDC 2024.

Relevant Sessions

  1. Enhance ad experiences with HLS interstitials
  2. Discover media performance metrics in AVFoundation