mirror of
https://github.com/yattee/yattee.git
synced 2024-11-09 15:58:20 +00:00
41 lines
934 B
Swift
41 lines
934 B
Swift
import AVKit
|
|
import SwiftUI
|
|
|
|
final class PlayerViewController: NSViewController {
|
|
var video: Video!
|
|
|
|
var player = AVPlayer()
|
|
var playerState: PlayerState!
|
|
var playbackState: PlaybackState!
|
|
var playerView = AVPlayerView()
|
|
|
|
override func viewDidDisappear() {
|
|
playerView.player?.replaceCurrentItem(with: nil)
|
|
playerView.player = nil
|
|
|
|
playerState.player = nil
|
|
playerState = nil
|
|
|
|
super.viewDidDisappear()
|
|
}
|
|
|
|
override func loadView() {
|
|
playerState = PlayerState()
|
|
playerState.playbackState = playbackState
|
|
|
|
guard playerState.player == nil else {
|
|
return
|
|
}
|
|
|
|
playerState.player = player
|
|
playerView.player = playerState.player
|
|
|
|
playerView.allowsPictureInPicturePlayback = true
|
|
playerView.showsFullScreenToggleButton = true
|
|
|
|
view = playerView
|
|
|
|
playerState.loadVideo(video)
|
|
}
|
|
}
|