Skip to main content
This is the 10-minute integration. Before you start, complete Installation so KontextVideo.initialize 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 onAdEnded callback when it is over.
format() and load() are suspend functions; the snippets call them from lifecycleScope. From Java, use their callback variants; see From Java.

1. Create the video’s ads

One VideoAds per video (episode). Creating it sends nothing. Keep it as long as you use its ads, for example as a property of your player Activity or Fragment, and call destroy() when the screen goes: dropping the reference does not end its ads.
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:
track(Player) comes with so.kontext:video-media3. For a player that is not a Media3 Player, implement 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 VideoAdException.NoFill 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 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(container) 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 VideoAdListener. Every method has an empty default; the one you need is onAdEnded. 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: in onDestroy() of an Activity, onDestroyView() of a Fragment, or the onDispose of a DisposableEffect in Compose. It drops every held ad, tells the server which ones were not used, and ends the one on screen.

The whole thing

One Activity per episode, playing in an ExoPlayer. Pick the tab for your format: