yattee/macOS/PictureInPictureDelegate.swift

35 lines
1.1 KiB
Swift
Raw Normal View History

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