1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 13:50:32 +05:30
yattee/macOS/PlayerViewController.swift

35 lines
906 B
Swift
Raw Normal View History

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
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 15:12:24 +05:30
func viewDidDisappear() {
2021-07-19 04:02:46 +05:30
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
}
}