Skip to main content
Every request and event carries where the viewer is in the episode, and overlay and pause ads follow the playback: an overlay shows over playing content only and goes away when the viewer pauses; a pause ad goes away when the content plays again after a pause seen while the ad is on screen, however the viewer resumed it. Give the SDK your player once the episode starts playing. With an AVPlayer, hand it over; the SDK reads its time and watches its playback (see AVPlayer):
With a TTSDK player (TTVideoEngine), add the KontextVideoTTSDK product of the same package and hand over the engine, ads.track(ttVideoEngine: engine) { episode.id }; see TTSDK player. With any other player, conform it to ContentPlayer: its position in seconds, and whether it plays. Buffering and seeking count as playing.
If your player already publishes its state, return it as isPlayingPublisher and an overlay ends the moment the viewer pauses; otherwise the SDK checks isPlaying four times a second while an overlay is on screen. The SDK keeps your ContentPlayer until destroy() or the next track(_:), so a small wrapper needs no other reference; an AVPlayer is held weakly, as your app owns it. A wrapper that references the VideoAds (or the object owning it) keeps both alive until destroy(): call destroy() when the viewer leaves, or do not reference the ads from it. If your player can tell which episode it plays, return it as currentItem (an id or a URL; a new value for each loop of a looped episode). The SDK compares it with the value at track(_:), reading it as the content plays: once it differs, this episode’s overlay and pause ads throw invalidated(.contentChanged) at show, and one on screen ends with .interrupted. The other optional members (playbackSpeed, seekPublisher, contentChangedPublisher) are in the API reference. 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.