Skip to main content
This is the 10-minute integration. Before you start, complete Installation so KontextVideo.shared.initialize(with:) runs at launch. Every format follows the same four steps:
  1. VideoAds(content:) for the video the viewer is watching.
  2. ads.format() asks the server and returns a VideoAd.
  3. ad.load() renders the creative off screen, so showing it later is instant. Or ad.reject() if you won’t use it.
  4. ad.show() at the moment you choose. One didEnd callback when it is over.

1. Create the video’s ads

One VideoAds per video (episode). Creating it sends nothing. Keep it alive as long as you use its ads, for example as a property of your player screen or model: releasing it ends its ads, as destroy() does.
Only id and language are required; everything else improves targeting, so send what you have. Give the SDK your player, so events carry the content playhead and an overlay follows playback:
For a player that is not an AVPlayer, conform it to VideoAdsPlayer and pass it the same way.

2. Get an ad

format() asks the server for an ad of the format you pass. Ask early, when the episode opens, not at the moment you want to show the ad: the request and the load take a moment, and the ad should appear instantly. It throws VideoAdError.noFill(reason:) when the server has nothing. That is normal, not a failure; ask again later.

3. Load it, or reject it

load() renders the creative off screen and returns once it is ready, so show() is instant. If you decide not to use the ad, call try overlayAd?.reject() and the advertiser is told.

4. Show it

Each format has its own moment and its own show().
A strip over the player while the episode plays, at a moment you pick. It goes away by itself after a few seconds, or as soon as the viewer pauses. Show it while the content plays: over paused content show(in:) throws contentPaused.
To take it away earlier, call dismiss() on it. If your own controls sit over the player, keep the ad clear of them with insets; see Keeping the ad clear of your controls.
show() either throws, and nothing happened, or the ad is on screen. From then on the SDK runs it until it ends.

5. React to the end

Implement VideoAdDelegate. Every method has an empty default; the one you need is didEnd. It arrives exactly once per shown ad, whoever ended it, so put your resume logic there and nowhere else, and ask for the next ad from there, so it is ready early.
Your content kept playing, so there is nothing to resume.

6. Tear down

Call destroy() when the viewer leaves the video. It drops every held ad, tells the server which ones were not used, and ends the one on screen.

The whole thing

One controller per episode. Pick the tab for your format: