VideoAdHost is a SwiftUI view that does the bridging: place it over your player, set its ad, and it shows. It is part of KontextVideoSDK; there is nothing else to add.
A player screen
Keep the player, theVideoAds and the ad on screen in a model the screen owns with @StateObject:
VideoAdHost
- Setting the ad shows it. A loaded ad shows once the host is on screen with a size. Set
nil, or another ad, and the one shown is dismissed; it is dismissed too when the host leaves the view hierarchy. - Every format. An overlay or pause ad shows where the host is placed. A linear ad is presented full screen from the top view controller; the host never dismisses it: it ends by itself or by the viewer, and
onEndstill arrives. - The host is the ad’s delegate. Hear the ad through the host’s closures, not
ad.delegate. onShowFailedgets the reasonshowwould throw:anotherAdShowing,contentPaused,containerTooSmall, …- Taps outside the ad go through to your player, so your own gestures keep working.
Keep the ads on the model
SwiftUI recreates view structs. Keep theVideoAds on your @StateObject model, not in the view: releasing a VideoAds ends its ads. Call ads.destroy() when the viewer actually leaves the episode (your back button, the next episode), not in onDisappear: a linear ad covers your view, and SwiftUI calls onDisappear for that too.
In a feed
Give each page its own model and host, and set the 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. See Ads in a feed.