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
|
2021-12-19 17:17:04 +00:00
|
|
|
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
|
2021-12-19 17:17:04 +00:00
|
|
|
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
|
2021-12-19 17:17:04 +00:00
|
|
|
self?.playerModel.show()
|
2021-11-02 23:02:02 +00:00
|
|
|
}
|
2021-10-28 17:14:55 +00:00
|
|
|
completionHandler(true)
|
|
|
|
}
|
|
|
|
}
|