Skip to main content
The SDK draws ads with Android Views. so.kontext:video-compose adds two Compose functions, so a screen does not write the host view, the effects and the listener wiring itself.

Add the module

It works with Compose 1.6 or later and uses your app’s own Compose version.

A player screen

Loading the ad early makes show instant: keep a loaded ad in state and set it as adOnScreen at the moment.

rememberVideoAds

  • Creates the episode’s VideoAds, and a new one when content.id changes.
  • Destroys it when the composition leaves, or when the episode changes. Destroying ends the ad on screen, a linear ad too: move to the next episode after a post-roll’s onEnded.
  • A rotation recreates the composition, and with it the VideoAds. Declare android:configChanges for rotation on the Activity, or keep the VideoAds in a ViewModel (below).

VideoAdHost

  • Every format. An overlay or pause ad shows where the host is placed. A linear ad is shown full screen from the Activity hosting the composition; it is never dismissed by the host, and ends by itself or by the viewer.
  • The host owns the ad’s listener. Hear the ad through the host’s callbacks, not ad.listener.
  • Leaving the composition dismisses an overlay or pause ad on screen.

Ads that survive a rotation

Keep the VideoAds and the ad in a ViewModel; the host shows whatever the state holds:

A vertical pager

Give each page its own VideoAds and host; show an ad on the current page only:
An ad on a page swiped away ends within about a second (INTERRUPTED), freeing the screen for the next page’s ad.

Without the module

The same, by hand: host a remembered FrameLayout with AndroidView, call show(container) on it, set the ad’s listener in a DisposableEffect and clear it in onDispose, and destroy the VideoAds in onDispose. For a linear ad, pass the Activity hosting the composition to show(activity).