Play uploaded videos

Learn how to play a FastPix video in your iOS app using a playback ID.

The FastPix iOS Player SDK uses AVPlayerViewController to stream videos. You provide a playback ID (generated when you upload a video to FastPix), and the SDK handles the rest.

Prerequisites

Set up the player

To play a video, create an AVPlayerViewController, attach it to your view hierarchy, and call the prepare method with your playback ID.

1import UIKit
2import FastPixPlayerSDK
3import AVKit
4
5class VideoPlayerViewController: UIViewController {
6
7 var playbackID = ""
8
9 lazy var playerViewController = AVPlayerViewController()
10
11 override func viewDidLoad() {
12 super.viewDidLoad()
13
14 // Attach the player to the view
15 prepareAvPlayerController()
16
17 // Start playback
18 playerViewController.prepare(playbackID: playbackID)
19 playerViewController.player?.play()
20 }
21
22 func prepareAvPlayerController() {
23 playerViewController.willMove(toParent: self)
24 addChild(playerViewController)
25 view.addSubview(playerViewController.view)
26 playerViewController.didMove(toParent: self)
27
28 playerViewController.view.translatesAutoresizingMaskIntoConstraints = false
29
30 NSLayoutConstraint.activate([
31 playerViewController.view.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
32 playerViewController.view.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
33 playerViewController.view.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
34 playerViewController.view.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
35 ])
36 }
37}

Key parameters

The prepare method accepts two parameters:

  • playbackId (required): A unique identifier for the video asset. Make sure you use the correct playback ID to load the intended video.
  • streamType (optional): Specifies whether the content is "on-demand" or "live". Defaults to "on-demand" if not set.
1// Play an on-demand video (default stream type)
2playerViewController.prepare(playbackID: playbackID)

What’s next