> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://fastpix.com/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://fastpix.com/docs/_mcp/server.

# Manage playlists

> Learn how to create and navigate playlists in the FastPix iOS Player.

Learn how to create and navigate playlists in the FastPix iOS Player.

The FastPix iOS Player supports playlists, letting you manage and navigate multiple videos within a single playback session.

## Create a playlist

Define a list of `FastPixPlaylistItem` objects. Each item includes a playback ID, title, description, thumbnail, and duration. Tokens are optional.

```swift
let playlist = [
    FastPixPlaylistItem(
        playbackId: "<PLAYBACK_ID_1>",
        title: "Episode 1: <TITLE>",
        description: "<DESCRIPTION>",
        thumbnail: "https://example.com/thumbnail1.jpg",
        duration: "01:00:00", // format HH:MM:SS
        token: "<PLAYBACK_TOKEN>",   // optional
        drmToken: "<DRM_TOKEN>"      // optional
    ),
    FastPixPlaylistItem(
        playbackId: "<PLAYBACK_ID_2>",
        title: "Episode 2: <TITLE>",
        description: "<DESCRIPTION>",
        thumbnail: "https://example.com/thumbnail2.jpg",
        duration: "00:45:00",
        token: "<PLAYBACK_TOKEN>",
        drmToken: "<DRM_TOKEN>"
    ),
    FastPixPlaylistItem(
        playbackId: "<PLAYBACK_ID_3>",
        title: "Episode 3: <TITLE>",
        description: "<DESCRIPTION>",
        thumbnail: "https://example.com/thumbnail3.jpg",
        duration: "00:30:00",
        token: "<PLAYBACK_TOKEN>",
        drmToken: "<DRM_TOKEN>"
    )
]
```

## Add the playlist to the player

```swift
playerViewController.addPlaylist(playlist)
```

## Enable auto-play

Automatically play the next item in the playlist when the current one finishes:

```swift
playerViewController.isAutoPlayEnabled = true
```

## Hide default controls

If you want to use a custom UI with your playlist, hide the SDK's built-in controls:

```swift
playerViewController.hideDefaultControls = true
```

## Observe playlist state changes

Use `NotificationCenter` to observe playlist state updates (for example, when the current item changes). This lets you update your UI—titles, buttons, progress indicators—whenever the playlist state changes.

```swift
override func viewDidLoad() {
    super.viewDidLoad()
    setupPlaylistStateObserver()
}

private func setupPlaylistStateObserver() {
    NotificationCenter.default.addObserver(
        self,
        selector: #selector(playlistStateChanged),
        name: Notification.Name("FastPixPlaylistStateChanged"),
        object: playerViewController  // Observe the specific player instance
    )
}

@objc private func playlistStateChanged(_ notification: Notification) {
    DispatchQueue.main.async {
        self.updateCurrentTitle()
        self.updateButtonVisibility()

        if let current = self.playerViewController.currentPlaylistItem {
            NSLog("current item: \(current)")
        }
    }
}
```

## Navigate the playlist

The SDK provides built-in methods to move between playlist items. You can connect these to custom UI buttons like **Next**, **Previous**, or **Jump to Episode**.

The index is zero-based—`jumpTo(index: 0)` plays the first item.

```swift
// Go to the next playlist item
playerViewController.next()

// Go back to the previous playlist item
playerViewController.previous()

// Jump to a specific item (for example, index 2)
playerViewController.jumpTo(index: 2)
```

Combine these navigation methods with the playlist state observer to dynamically update the UI as the current item changes.