Dunfey · Hotel WWDC as data, est. 1983
Front desk everything
Years
Topics

2022 Audio & Video

WWDC22 · 9 min · Audio & Video

What’s new in HLS Interstitials

HLS Interstitials can help you create seamless transitions in video content between advertisements, other interstitials, and your HLS streams. Learn how you can optimize your ad inventory, fine-tune interstitial presentation with SNAP-IN/OUT when using HLS, and more.

Watch at developer.apple.com ↗

Transcript all transcripts

Code shown on screen · 1 snippet

Client schedules an ad pod at 10s into primary asset swift · at 7:58 ↗
// Client schedules an ad pod at 10s into primary asset
 let player  = AVPlayer( url: movieURL )  // no ads in primary asset
 let controller = AVPlayerInterstitialEventController( primaryPlayer: player )
 let adPodTemplates = [AVPlayerItem( url: ad1URL ), AVPlayerItem( url: ad2URL )]
 let event = AVPlayerInterstitialEvent( primaryItem: player.currentItem,
                              time: CMTime( seconds: 10, preferredTimescale: 1 ),
                                      )
 event.templateItems = adPodTemplates
 event.identifier = "Ad1"
 event.restrictions = []
 event.resumptionOffset = .zero
 event.playoutLimit = .invalid
 event.cue = .none
 
 controller.events = [event]
 player.currentItem.translatesPlayerInterstitialEvents = true
 let vc = AVPlayerViewController()
 vc.player = player
 player.play()