Manage playlists

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.

1let playlist = [
2 FastPixPlaylistItem(
3 playbackId: "<PLAYBACK_ID_1>",
4 title: "Episode 1: <TITLE>",
5 description: "<DESCRIPTION>",
6 thumbnail: "https://example.com/thumbnail1.jpg",
7 duration: "01:00:00", // format HH:MM:SS
8 token: "<PLAYBACK_TOKEN>", // optional
9 drmToken: "<DRM_TOKEN>" // optional
10 ),
11 FastPixPlaylistItem(
12 playbackId: "<PLAYBACK_ID_2>",
13 title: "Episode 2: <TITLE>",
14 description: "<DESCRIPTION>",
15 thumbnail: "https://example.com/thumbnail2.jpg",
16 duration: "00:45:00",
17 token: "<PLAYBACK_TOKEN>",
18 drmToken: "<DRM_TOKEN>"
19 ),
20 FastPixPlaylistItem(
21 playbackId: "<PLAYBACK_ID_3>",
22 title: "Episode 3: <TITLE>",
23 description: "<DESCRIPTION>",
24 thumbnail: "https://example.com/thumbnail3.jpg",
25 duration: "00:30:00",
26 token: "<PLAYBACK_TOKEN>",
27 drmToken: "<DRM_TOKEN>"
28 )
29]

Add the playlist to the player

1playerViewController.addPlaylist(playlist)

Enable auto-play

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

1playerViewController.isAutoPlayEnabled = true

Hide default controls

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

1playerViewController.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.

1override func viewDidLoad() {
2 super.viewDidLoad()
3 setupPlaylistStateObserver()
4}
5
6private func setupPlaylistStateObserver() {
7 NotificationCenter.default.addObserver(
8 self,
9 selector: #selector(playlistStateChanged),
10 name: Notification.Name("FastPixPlaylistStateChanged"),
11 object: playerViewController // Observe the specific player instance
12 )
13}
14
15@objc private func playlistStateChanged(_ notification: Notification) {
16 DispatchQueue.main.async {
17 self.updateCurrentTitle()
18 self.updateButtonVisibility()
19
20 if let current = self.playerViewController.currentPlaylistItem {
21 NSLog("current item: \(current)")
22 }
23 }
24}

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.

1// Go to the next playlist item
2playerViewController.next()
3
4// Go back to the previous playlist item
5playerViewController.previous()
6
7// Jump to a specific item (for example, index 2)
8playerViewController.jumpTo(index: 2)

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