2021-07-18 22:32:46 +00:00
|
|
|
import AVKit
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
final class PlayerViewController: NSViewController {
|
|
|
|
var video: Video!
|
|
|
|
|
|
|
|
var player = AVPlayer()
|
2021-08-22 19:13:33 +00:00
|
|
|
var playerState: PlayerState!
|
|
|
|
var playbackState: PlaybackState!
|
2021-07-18 22:32:46 +00:00
|
|
|
var playerView = AVPlayerView()
|
|
|
|
|
|
|
|
override func viewDidDisappear() {
|
|
|
|
playerView.player?.replaceCurrentItem(with: nil)
|
|
|
|
playerView.player = nil
|
|
|
|
|
|
|
|
playerState.player = nil
|
|
|
|
playerState = nil
|
|
|
|
|
|
|
|
super.viewDidDisappear()
|
|
|
|
}
|
|
|
|
|
|
|
|
override func loadView() {
|
2021-08-25 22:12:59 +00:00
|
|
|
playerState = PlayerState(playbackState: playbackState)
|
2021-08-22 19:13:33 +00:00
|
|
|
|
2021-07-18 22:32:46 +00:00
|
|
|
guard playerState.player == nil else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
playerState.player = player
|
|
|
|
playerView.player = playerState.player
|
|
|
|
|
2021-08-17 22:00:53 +00:00
|
|
|
playerView.allowsPictureInPicturePlayback = true
|
2021-07-18 22:32:46 +00:00
|
|
|
playerView.showsFullScreenToggleButton = true
|
|
|
|
|
|
|
|
view = playerView
|
|
|
|
|
|
|
|
playerState.loadVideo(video)
|
|
|
|
}
|
|
|
|
}
|