yattee/macOS/MacOSPiPDelegate.swift

32 lines
933 B
Swift
Raw Permalink Normal View History

2023-05-20 22:18:10 +00:00
import AVKit
import Foundation
final class MacOSPiPDelegate: NSObject, AVPlayerViewPictureInPictureDelegate {
2023-05-22 20:48:11 +00:00
static let shared = MacOSPiPDelegate()
2023-05-20 22:18:10 +00:00
var playerModel: PlayerModel { .shared }
func playerViewShouldAutomaticallyDismissAtPicture(inPictureStart _: AVPlayerView) -> Bool {
false
}
func playerViewWillStartPicture(inPicture _: AVPlayerView) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { [weak self] in
self?.playerModel.playingInPictureInPicture = true
self?.playerModel.hide()
}
}
func playerViewWillStopPicture(inPicture _: AVPlayerView) {
2023-05-22 20:48:11 +00:00
playerModel.show()
playerModel.playingInPictureInPicture = false
2023-05-20 22:18:10 +00:00
}
func playerView(
_: AVPlayerView,
restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: (Bool) -> Void
) {
completionHandler(true)
}
}