yattee/macOS/AppleAVPlayerViewController.swift

35 lines
940 B
Swift
Raw Normal View History

2022-02-16 20:23:11 +00:00
import AVKit
import SwiftUI
2022-02-27 20:31:17 +00:00
final class AppleAVPlayerViewController: NSViewController {
2022-02-16 20:23:11 +00:00
var playerModel: PlayerModel!
var playerView = AVPlayerView()
var pictureInPictureDelegate = PictureInPictureDelegate()
var aspectRatio: Double? {
let ratio = Double(playerView.videoBounds.width) / Double(playerView.videoBounds.height)
if !ratio.isFinite {
return VideoPlayerView.defaultAspectRatio
}
return [ratio, 1.0].max()!
}
override func viewDidDisappear() {
super.viewDidDisappear()
}
override func loadView() {
2022-02-27 20:31:17 +00:00
playerView.player = playerModel.avPlayerBackend.avPlayer
2022-02-16 20:23:11 +00:00
pictureInPictureDelegate.playerModel = playerModel
playerView.allowsPictureInPicturePlayback = true
playerView.showsFullScreenToggleButton = true
playerView.pictureInPictureDelegate = pictureInPictureDelegate
view = playerView
}
}