> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kontext.so/llms.txt
> Use this file to discover all available pages before exploring further.

# 下一集

> 当前一集播放时创建下一集的 `VideoAds`，预取它的广告，观众离开时销毁当前的。

当前一集播放时创建下一集的 `VideoAds`，预取它的广告，观众离开时销毁当前的。任意数量的实例可以同时存在；SDK 让整个应用同一时间最多一个广告在屏幕上。

```swift theme={null}
let next = VideoAds(content: nextEpisode)
Task { nextLinear = try? await next.format(.linear); try? await nextLinear?.load() }

// 观众继续看下一集时：
ads.destroy()
ads = next
ads.track(player)     // 播放器现在播放下一集
```

在剧集真正开始在播放器中播放时调用 `track(_:)`，而不是创建时：在那之前播放器的时间属于上一集。

对于片尾广告，在这一集播完时展示它的线性广告，并且只在它的 `didEnd` 中切到下一集：`destroy()` 也会结束屏幕上的广告，线性广告也不例外。

```swift theme={null}
func episodeFinished() {
    do {
        guard let postRoll else { return nextEpisode() }
        try postRoll.show()                  // 此时调用 destroy() 会结束它
    } catch {
        nextEpisode()                        // 没有展示
    }
}

func videoAd(_ ad: VideoAd, didEnd reason: VideoAd.EndReason) {
    if ad === postRoll { nextEpisode() }
}

func nextEpisode() {
    ads.destroy()                            // 在片尾广告的 didEnd 之后，绝不在之前
    ads = next
    ads.track(player)
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.