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
|
|
|
|
2021-11-07 17:53:00 +00:00
|
|
|
var aspectRatio: Double? {
|
|
|
|
let ratio = Double(playerView.videoBounds.width) / Double(playerView.videoBounds.height)
|
|
|
|
|
|
|
|
if !ratio.isFinite {
|
|
|
|
return VideoPlayerView.defaultAspectRatio
|
|
|
|
}
|
|
|
|
|
|
|
|
return [ratio, 1.0].max()!
|
|
|
|
}
|
|
|
|
|
2021-07-18 22:32:46 +00:00
|
|
|
override func viewDidDisappear() {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|