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
Raw Normal View History

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