2021-07-19 04:02:46 +05:30
|
|
|
import AVKit
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
final class PlayerViewController: NSViewController {
|
2021-09-25 13:48:22 +05:30
|
|
|
var playerModel: PlayerModel!
|
2021-07-19 04:02:46 +05:30
|
|
|
var playerView = AVPlayerView()
|
2021-10-28 22:44:55 +05:30
|
|
|
var pictureInPictureDelegate = PictureInPictureDelegate()
|
2021-07-19 04:02:46 +05:30
|
|
|
|
2021-11-07 23:23:00 +05:30
|
|
|
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-19 04:02:46 +05:30
|
|
|
override func viewDidDisappear() {
|
|
|
|
super.viewDidDisappear()
|
|
|
|
}
|
|
|
|
|
|
|
|
override func loadView() {
|
2021-09-25 13:48:22 +05:30
|
|
|
playerView.player = playerModel.player
|
2021-10-28 22:44:55 +05:30
|
|
|
pictureInPictureDelegate.playerModel = playerModel
|
2021-07-19 04:02:46 +05:30
|
|
|
|
2021-08-18 03:30:53 +05:30
|
|
|
playerView.allowsPictureInPicturePlayback = true
|
2021-07-19 04:02:46 +05:30
|
|
|
playerView.showsFullScreenToggleButton = true
|
|
|
|
|
2021-10-28 22:44:55 +05:30
|
|
|
playerView.pictureInPictureDelegate = pictureInPictureDelegate
|
|
|
|
|
2021-07-19 04:02:46 +05:30
|
|
|
view = playerView
|
|
|
|
}
|
|
|
|
}
|