1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/macOS/PlayerViewController.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)
}
}
}