2022-05-21 02:53:14 +05:30
|
|
|
import AVKit
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
final class PiPDelegate: NSObject, AVPictureInPictureControllerDelegate {
|
|
|
|
var player: PlayerModel!
|
|
|
|
|
|
|
|
func pictureInPictureController(
|
|
|
|
_: AVPictureInPictureController,
|
|
|
|
failedToStartPictureInPictureWithError error: Error
|
|
|
|
) {
|
|
|
|
print(error.localizedDescription)
|
|
|
|
}
|
|
|
|
|
|
|
|
func pictureInPictureControllerWillStartPictureInPicture(_: AVPictureInPictureController) {}
|
|
|
|
|
2022-05-22 02:28:11 +05:30
|
|
|
func pictureInPictureControllerDidStartPictureInPicture(_: AVPictureInPictureController) {
|
|
|
|
player?.playingInPictureInPicture = true
|
|
|
|
player?.avPlayerBackend.startPictureInPictureOnPlay = false
|
|
|
|
}
|
2022-05-21 02:53:14 +05:30
|
|
|
|
|
|
|
func pictureInPictureControllerDidStopPictureInPicture(_: AVPictureInPictureController) {
|
|
|
|
if player?.avPlayerBackend.switchToMPVOnPipClose ?? false {
|
|
|
|
DispatchQueue.main.async { [weak player] in
|
|
|
|
player?.avPlayerBackend.switchToMPVOnPipClose = false
|
|
|
|
player?.saveTime { [weak player] in
|
|
|
|
player?.changeActiveBackend(from: .appleAVPlayer, to: .mpv)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-22 02:28:11 +05:30
|
|
|
|
|
|
|
player?.playingInPictureInPicture = false
|
2022-05-21 02:53:14 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func pictureInPictureControllerWillStopPictureInPicture(_: AVPictureInPictureController) {}
|
|
|
|
|
|
|
|
func pictureInPictureController(
|
|
|
|
_: AVPictureInPictureController,
|
2022-05-22 02:28:11 +05:30
|
|
|
restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: @escaping (Bool) -> Void
|
|
|
|
) {
|
|
|
|
completionHandler(true)
|
|
|
|
}
|
2022-05-21 02:53:14 +05:30
|
|
|
}
|