yattee/macOS/PlayerViewController.swift

44 lines
1.0 KiB
Swift
Raw Normal View History

2021-07-18 22:32:46 +00:00
import AVKit
import SwiftUI
final class PlayerViewController: NSViewController {
var video: Video!
2021-09-25 08:18:22 +00:00
var api: InvidiousAPI!
2021-07-18 22:32:46 +00:00
var player = AVPlayer()
2021-09-25 08:18:22 +00:00
var playerModel: PlayerModel!
var playback: PlaybackModel!
2021-07-18 22:32:46 +00:00
var playerView = AVPlayerView()
2021-09-25 08:18:22 +00:00
var resolution: Stream.ResolutionSetting!
2021-07-18 22:32:46 +00:00
override func viewDidDisappear() {
playerView.player?.replaceCurrentItem(with: nil)
playerView.player = nil
2021-09-25 08:18:22 +00:00
playerModel.player = nil
playerModel = nil
2021-07-18 22:32:46 +00:00
super.viewDidDisappear()
}
override func loadView() {
2021-09-25 08:18:22 +00:00
playerModel = PlayerModel(playback: playback, api: api, resolution: resolution)
2021-08-22 19:13:33 +00:00
guard playerModel.player.isNil else {
2021-07-18 22:32:46 +00:00
return
}
2021-09-25 08:18:22 +00:00
playerModel.player = player
playerView.player = playerModel.player
2021-07-18 22:32:46 +00:00
2021-08-17 22:00:53 +00:00
playerView.allowsPictureInPicturePlayback = true
2021-07-18 22:32:46 +00:00
playerView.showsFullScreenToggleButton = true
view = playerView
2021-09-25 08:18:22 +00:00
DispatchQueue.main.async {
self.playerModel.loadVideo(self.video)
}
2021-07-18 22:32:46 +00:00
}
}