yattee/macOS/AVPlayerViewController.swift

35 lines
919 B
Swift
Raw Normal View History

2022-02-16 20:23:11 +00:00
import AVKit
import SwiftUI
final class AVPlayerViewController: NSViewController {
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() {
playerView.player = playerModel.avPlayer
pictureInPictureDelegate.playerModel = playerModel
playerView.allowsPictureInPicturePlayback = true
playerView.showsFullScreenToggleButton = true
playerView.pictureInPictureDelegate = pictureInPictureDelegate
view = playerView
}
}