Created
July 12, 2021 17:46
-
-
Save atulkhatri/1dfd7907ee192856a9ada288f1e43e51 to your computer and use it in GitHub Desktop.
tvOS Bootcamp Player
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PlayerViewController: AVPlayerViewController { | |
var asset: AssetModel? | |
var rail: RailModel? | |
var initialized: Bool = false | |
override func viewDidAppear(_ animated: Bool) { | |
super.viewDidAppear(animated) | |
if !initialized { | |
if asset != nil { | |
startAssetPlayback() | |
} | |
} | |
initialized = true | |
} | |
private func startAssetPlayback() { | |
if let url = asset?.url.toUrl { | |
let playerItem = AVPlayerItem(url: url) | |
player = AVPlayer(playerItem: playerItem) | |
} | |
player?.play() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment