Skip to navigation

Complete integration example

A full example showing how to set up the FastPix iOS Player with video playback and data integration.

Basic player setup

This example creates a VideoPlayerViewController that configures an AVPlayerViewController, attaches it to the view hierarchy, and starts playback.

import UIKit
import FastPixPlayerSDK
import AVKit
class VideoPlayerViewController: UIViewController {
// Playback ID and Token for streaming (set dynamically)
var playbackID = ""
var playbackToken = ""
// Lazy initialization of AVPlayerViewController
lazy var playerViewController = AVPlayerViewController()
// MARK: - View Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
// Prepare and attach the AVPlayerViewController to the view
prepareAvPlayerController()
// Start playback
playerViewController.player?.play()
}
// MARK: - AVPlayer Setup
/// Sets up the AVPlayerViewController and attaches it to the view hierarchy
func prepareAvPlayerController() {
// Add playerViewController as a child
playerViewController.willMove(toParent: self)
addChild(playerViewController)
view.addSubview(playerViewController.view)
playerViewController.didMove(toParent: self)
// Disable autoresizing mask constraints
playerViewController.view.translatesAutoresizingMaskIntoConstraints = false
// Constrain player view to safe area
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)
])
}
}

What’s next