@Composable
fun EpisodeScreen(content: KontextVideo.Content, player: ExoPlayer) {
val ads = rememberVideoAds(content) { it.track(player) }
var adOnScreen by remember { mutableStateOf<VideoAd?>(null) }
val scope = rememberCoroutineScope()
Box(Modifier.fillMaxSize()) {
AndroidView(factory = { PlayerView(it).apply { this.player = player } }, modifier = Modifier.fillMaxSize())
VideoAdHost(
ad = adOnScreen,
modifier = Modifier.fillMaxSize(),
onEnded = { _, reason ->
adOnScreen = null
if (reason == VideoAd.EndReason.RESUMED) player.play()
},
)
}
// 观众暂停:展示暂停广告
val onPause = {
player.pause()
scope.launch {
adOnScreen = try { ads.format(AdFormat.PAUSE).apply { load() } } catch (e: VideoAdException) { null }
}
}
}