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:
-
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.
-
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.
-
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
tosinglePoint
for a point on the timeline or tofill
for a range on the timeline. -
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
Discover media performance metrics in AVFoundation
Discover how you can monitor, analyze, and improve user experience with the new media performance APIs. Explore how to monitor AVPlayer performance for HLS assets using different AVMetricEvents, and learn how to use these metrics to understand and triage player performance issues.
Enhance ad experiences with HLS interstitials
Explore how HLS Interstitials can help you seamlessly insert advertisements into your HLS content. We’ll also show you how to use integrated timeline to tune your UI experience and build SharePlay for interstitials.