1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 06:40:32 +05:30
yattee/macOS/MacOSPiPDelegate.swift

32 lines
933 B
Swift
Raw Normal View History

2023-05-21 03:48:10 +05:30
import AVKit
import Foundation
final class MacOSPiPDelegate: NSObject, AVPlayerViewPictureInPictureDelegate {
2023-05-23 02:18:11 +05:30
static let shared = MacOSPiPDelegate()
2023-05-21 03:48:10 +05:30
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-23 02:18:11 +05:30
playerModel.show()
playerModel.playingInPictureInPicture = false
2023-05-21 03:48:10 +05:30
}
func playerView(
_: AVPlayerView,
restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: (Bool) -> Void
) {
completionHandler(true)
}
}