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

35 lines
1.1 KiB
Swift
Raw Normal View History

2021-10-28 22:44:55 +05:30
import AVKit
import Foundation
final class PictureInPictureDelegate: NSObject, AVPlayerViewPictureInPictureDelegate {
var playerModel: PlayerModel!
func playerViewShouldAutomaticallyDismissAtPicture(inPictureStart _: AVPlayerView) -> Bool {
false
}
func playerViewWillStartPicture(inPicture _: AVPlayerView) {
2021-11-03 04:32:02 +05:30
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { [weak self] in
self?.playerModel.playingInPictureInPicture = true
self?.playerModel.hide()
2021-11-03 04:32:02 +05:30
}
2021-10-28 22:44:55 +05:30
}
func playerViewWillStopPicture(inPicture _: AVPlayerView) {
2021-11-03 04:32:02 +05:30
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { [weak self] in
self?.playerModel.playingInPictureInPicture = false
self?.playerModel.show()
2021-11-03 04:32:02 +05:30
}
2021-10-28 22:44:55 +05:30
}
func playerView(
_: AVPlayerView,
restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: (Bool) -> Void
) {
2021-11-03 04:32:02 +05:30
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { [weak self] in
self?.playerModel.show()
2021-11-03 04:32:02 +05:30
}
2021-10-28 22:44:55 +05:30
completionHandler(true)
}
}