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)
])
}
}