yattee/macOS/PlayerViewController.swift

35 lines
906 B
Swift
Raw Permalink Normal View History

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
var aspectRatio: Double? {
let ratio = Double(playerView.videoBounds.width) / Double(playerView.videoBounds.height)
if !ratio.isFinite {
return VideoPlayerView.defaultAspectRatio
}
return [ratio, 1.0].max()!
}
2024-02-02 09:42:24 +00:00
func viewDidDisappear() {
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
}
}