Loading several ads at once
To have several formats ready at once, ask for them and load them concurrently. Each format is requested and rendered in parallel, and one format without an ad leaves the others untouched:Running your own auction
VideoAd carries the price before anything is rendered, so you can compare it with other networks and decide:
price.value is a CPM in price.currency. price.precision says whether it is a DSP’s clearing price (EXACT) or a forecast for house demand (ESTIMATED).
reject tells the server at once, and the server tells the advertiser its win produced no impression. Use Outbid when another network won on price, with the winning price and the network, so we can optimize our bids for your traffic; NotUsed (the default) for any other reason: the moment passed, the viewer left. Rejecting is optional; an ad you never use is settled when it expires or when you call destroy().
Handling no-fill
format() throws VideoAdException.NoFill when the server has nothing for the format. It is not a failure and the SDK never retries by itself; ask again at a later moment.
Giving the SDK your player
Every request and event carries where the viewer is in the episode, and an overlay follows the playback: it shows over playing content only and goes away when the viewer pauses. Give the SDK your player once the episode starts playing. With a Media3 player (ExoPlayer, MediaController), add so.kontext:video-media3 and hand it over; the SDK reads its time and listens to its playback. The player must run on the main looper:
VideoAdsPlayer: its position in milliseconds, and whether it plays. Buffering and seeking count as playing.
addListener and removeListener and call the VideoAdsPlayer.Listener on each change (onIsPlayingChanged, onSeek, onContentChanged): an overlay then ends the moment the viewer pauses. Otherwise the SDK checks isPlaying four times a second while an overlay is on screen. The SDK holds the adapter until destroy() or the next track, so let the adapter hold your player weakly.
Call track when this episode starts playing, not when you create the VideoAds: until then the player’s time belongs to the previous episode. Before that the SDK sends 0, which is right for a prefetch.
Keeping the ad clear of your controls
An overlay strip sits at the bottom or top of the container, a pause card at the top; the SDK keeps both clear of the system bars and display cutout that overlap the container. If your player draws its own controls there (a title, a progress bar, buttons), pass the space they take asinsets:
Insetsisandroidx.core.graphics.Insets, in pixels. They add to the system bars and cutout: measure from their edge, not from the screen’s.- They stay while the ad is shown, through resizes and rotations. If your controls change size while an ad is on screen, the ad keeps the insets it was shown with.
- The ad still has to fit at half its size or more. Insets count against the space, so
ContainerTooSmallincludes them. - A full-screen pause ad ignores them: it fills the container, and its own controls keep clear of the edges.
The next episode
Create the next episode’sVideoAds while the current one plays, prefetch its ads, and destroy the current one when the viewer leaves. Any number can be alive at once; the SDK keeps at most one ad on screen in the whole app.
track when the episode actually starts in the player, not at creation: before that the player’s time belongs to the previous episode.
Who the viewer is
Set what you know onKontextVideo; the next request carries it:
Consent is read for you: on every request the SDK reads the IAB keys your consent platform writes to the default See TCF & CMP.
SharedPreferences (TCF, GPP, US Privacy). Only when the SDK cannot detect a signal, because your app has no such platform or keeps a signal elsewhere, set it yourself. A value your consent platform wrote still wins.Following the screen’s lifecycle
AVideoAds belongs to the screen that shows the episode: create it when the screen opens, destroy() it when the screen goes.
- In an Activity, call
destroy()inonDestroy(); in a Fragment, inonDestroyView(). - A linear ad runs in the SDK’s own Activity, over yours: your Activity is stopped, not destroyed, and the ad’s end reaches your listener when it returns.
- An Activity recreated on rotation runs
onDestroy()too, and with itdestroy(). The example app keeps its player Activity across rotation withandroid:configChanges. - The ad holds its listener until
onAdEndedhas run, so a listener that is your Activity stays reachable until the ad ends.
Using it from Jetpack Compose
The SDK draws overlay and pause ads with Android Views, which Compose hosts withAndroidView. A linear ad needs nothing extra: show(activity) starts the SDK’s Activity over whatever Compose is showing. An overlay or pause ad goes into a ViewGroup; give it a FrameLayout laid over the player:
- Create the
FrameLayoutonce and keep it withremember: a container that leaves the window takes the ad with it (INTERRUPTED). - Key the
VideoAdson the episode, and destroy it in theDisposableEffect’sonDispose, so it goes when the screen or the episode goes. - For a linear ad, pass the
Activitythat hosts your composition toshow(activity).
From Java
Every type has a builder, and everysuspend call has a callback variant that delivers on the main thread:
show, reject and dismiss declare VideoAdException, so Java requires the try. Sealed values are singletons: NoFillReason.NoAdMatch.INSTANCE, VideoAd.RejectReason.NotUsed.INSTANCE.