2021-07-19 04:02:46 +05:30
|
|
|
import AVKit
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
final class PlayerViewController: NSViewController {
|
|
|
|
var video: Video!
|
|
|
|
|
|
|
|
var player = AVPlayer()
|
2021-08-23 00:43:33 +05:30
|
|
|
var playerState: PlayerState!
|
|
|
|
var playbackState: PlaybackState!
|
2021-07-19 04:02:46 +05:30
|
|
|
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-26 03:42:59 +05:30
|
|
|
playerState = PlayerState(playbackState: playbackState)
|
2021-08-23 00:43:33 +05:30
|
|
|
|
2021-07-19 04:02:46 +05:30
|
|
|
guard playerState.player == nil else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
playerState.player = player
|
|
|
|
playerView.player = playerState.player
|
|
|
|
|
2021-08-18 03:30:53 +05:30
|
|
|
playerView.allowsPictureInPicturePlayback = true
|
2021-07-19 04:02:46 +05:30
|
|
|
playerView.showsFullScreenToggleButton = true
|
|
|
|
|
|
|
|
view = playerView
|
|
|
|
|
|
|
|
playerState.loadVideo(video)
|
|
|
|
}
|
|
|
|
}
|