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.

1import UIKit
2import FastPixPlayerSDK
3import AVKit
4
5class VideoPlayerViewController: UIViewController {
6
7 // Playback ID and Token for streaming (set dynamically)
8 var playbackID = ""
9 var playbackToken = ""
10
11 // Lazy initialization of AVPlayerViewController
12 lazy var playerViewController = AVPlayerViewController()
13
14 // MARK: - View Lifecycle
15
16 override func viewDidLoad() {
17 super.viewDidLoad()
18
19 // Prepare and attach the AVPlayerViewController to the view
20 prepareAvPlayerController()
21
22 // Start playback
23 playerViewController.player?.play()
24 }
25
26 // MARK: - AVPlayer Setup
27
28 /// Sets up the AVPlayerViewController and attaches it to the view hierarchy
29 func prepareAvPlayerController() {
30 // Add playerViewController as a child
31 playerViewController.willMove(toParent: self)
32 addChild(playerViewController)
33 view.addSubview(playerViewController.view)
34 playerViewController.didMove(toParent: self)
35
36 // Disable autoresizing mask constraints
37 playerViewController.view.translatesAutoresizingMaskIntoConstraints = false
38
39 // Constrain player view to safe area
40 NSLayoutConstraint.activate([
41 playerViewController.view.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
42 playerViewController.view.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
43 playerViewController.view.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
44 playerViewController.view.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
45 ])
46 }
47}

What’s next