mirror of
https://github.com/yattee/yattee.git
synced 2024-11-10 00:08:21 +00:00
44 lines
1.0 KiB
Swift
44 lines
1.0 KiB
Swift
import AVKit
|
|
import SwiftUI
|
|
|
|
final class PlayerViewController: NSViewController {
|
|
var video: Video!
|
|
|
|
var api: InvidiousAPI!
|
|
var player = AVPlayer()
|
|
var playerModel: PlayerModel!
|
|
var playback: PlaybackModel!
|
|
var playerView = AVPlayerView()
|
|
var resolution: Stream.ResolutionSetting!
|
|
|
|
override func viewDidDisappear() {
|
|
playerView.player?.replaceCurrentItem(with: nil)
|
|
playerView.player = nil
|
|
|
|
playerModel.player = nil
|
|
playerModel = nil
|
|
|
|
super.viewDidDisappear()
|
|
}
|
|
|
|
override func loadView() {
|
|
playerModel = PlayerModel(playback: playback, api: api, resolution: resolution)
|
|
|
|
guard playerModel.player.isNil else {
|
|
return
|
|
}
|
|
|
|
playerModel.player = player
|
|
playerView.player = playerModel.player
|
|
|
|
playerView.allowsPictureInPicturePlayback = true
|
|
playerView.showsFullScreenToggleButton = true
|
|
|
|
view = playerView
|
|
|
|
DispatchQueue.main.async {
|
|
self.playerModel.loadVideo(self.video)
|
|
}
|
|
}
|
|
}
|