Skip to navigation

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.

import UIKit
import FastPixPlayerSDK
import AVKit
class VideoPlayerViewController: UIViewController {
var playbackID = ""
lazy var playerViewController = AVPlayerViewController()
override func viewDidLoad() {
super.viewDidLoad()
// Attach the player to the view
prepareAvPlayerController()
// Start playback
playerViewController.prepare(playbackID: playbackID)
playerViewController.player?.play()
}
func prepareAvPlayerController() {
playerViewController.willMove(toParent: self)
addChild(playerViewController)
view.addSubview(playerViewController.view)
playerViewController.didMove(toParent: self)
playerViewController.view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
playerViewController.view.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
playerViewController.view.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
playerViewController.view.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
playerViewController.view.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
])
}
}

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.
// Play an on-demand video (default stream type)
playerViewController.prepare(playbackID: playbackID)

What’s next