KontextVideo.shared.initialize(with:) runs at launch.
Every format follows the same four steps:
VideoAds(content:)for the video the viewer is watching.ads.format()asks the server and returns aVideoAd.ad.load()renders the creative off screen, so showing it later is instant. Orad.reject()if you won’t use it.ad.show()at the moment you choose. OnedidEndcallback when it is over.
1. Create the video’s ads
OneVideoAds per video (episode). Creating it sends nothing.
id and language are required; everything else improves targeting, so send what you have.
Tell the SDK where the content is playing, so events carry the content playhead:
AVPlayer, set ads.playheadProvider = { seconds } instead.
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 ownshow().
- Overlay
- Pause
- Linear
A strip over the player while the episode plays, at a moment you pick. It goes away by itself after a few seconds.To take it away earlier, call
dismiss() on it.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
ImplementVideoAdDelegate. 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.
- Overlay
- Pause
- Linear
Your content kept playing, so there is nothing to resume.
6. Tear down
Calldestroy() 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:- Overlay
- Pause
- Linear