2021-07-18 22:32:46 +00:00
|
|
|
import AVKit
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
final class PlayerViewController: NSViewController {
|
2021-09-25 08:18:22 +00:00
|
|
|
var playerModel: PlayerModel!
|
2021-07-18 22:32:46 +00:00
|
|
|
var playerView = AVPlayerView()
|
2021-10-28 17:14:55 +00:00
|
|
|
var pictureInPictureDelegate = PictureInPictureDelegate()
|
2021-07-18 22:32:46 +00:00
|
|
|
|
|
|
|
override func viewDidDisappear() {
|
2021-10-28 17:14:55 +00:00
|
|
|
if !playerModel.playingInPictureInPicture {
|
|
|
|
playerModel.pause()
|
|
|
|
}
|
2021-07-18 22:32:46 +00:00
|
|
|
super.viewDidDisappear()
|
|
|
|
}
|
|
|
|
|
|
|
|
override func loadView() {
|
2021-09-25 08:18:22 +00:00
|
|
|
playerView.player = playerModel.player
|
2021-10-28 17:14:55 +00:00
|
|
|
pictureInPictureDelegate.playerModel = playerModel
|
2021-07-18 22:32:46 +00:00
|
|
|
|
2021-08-17 22:00:53 +00:00
|
|
|
playerView.allowsPictureInPicturePlayback = true
|
2021-07-18 22:32:46 +00:00
|
|
|
playerView.showsFullScreenToggleButton = true
|
|
|
|
|
2021-10-28 17:14:55 +00:00
|
|
|
playerView.pictureInPictureDelegate = pictureInPictureDelegate
|
|
|
|
|
2021-07-18 22:32:46 +00:00
|
|
|
view = playerView
|
|
|
|
}
|
|
|
|
}
|