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 ↗Code shown on screen · 1 snippet
Client schedules an ad pod at 10s into primary asset
// 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() Related sessions
-
11 min -
15 min