> ## 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.

# The next episode

> Create the next episode's `VideoAds` while the current one plays, prefetch its ads, and destroy the current one when the viewer leaves.

Create the next episode's `VideoAds` while the current one plays, prefetch its ads, and destroy the current one when the viewer leaves. Any number can be alive at once; the SDK keeps at most one ad on screen in the whole app.

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

// When the viewer moves on:
ads.destroy()
ads = next
ads.track(player)     // the player now plays the next episode
```

Call `track(_:)` when the episode actually starts in the player, not at creation: before that the player's time belongs to the previous episode.

For a post-roll, show this episode's linear ad when it finishes, and move on only from its `didEnd`: `destroy()` ends the ad on screen too, a linear ad included.

```swift theme={null}
func episodeFinished() {
    do {
        guard let postRoll else { return nextEpisode() }
        try postRoll.show()                  // destroy() now would end it
    } catch {
        nextEpisode()                        // not shown
    }
}

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

func nextEpisode() {
    ads.destroy()                            // after the post-roll's didEnd, never before
    ads = next
    ads.track(player)
}
```


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