Minor improvements

This commit is contained in:
Arkadiusz Fal
2022-05-29 22:13:21 +02:00
parent 046ec6d916
commit 06a6126eb5
4 changed files with 28 additions and 22 deletions

View File

@@ -169,8 +169,7 @@ final class AVPlayerBackend: PlayerBackend {
}
#else
func closePiP(wasPlaying: Bool) {
controller?.playerView.player = nil
controller?.playerView.player = avPlayer
model.pipController?.stopPictureInPicture()
guard wasPlaying else {
return

View File

@@ -19,16 +19,21 @@ final class PiPDelegate: NSObject, AVPictureInPictureControllerDelegate {
}
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)
guard let player = player else {
return
}
if player.avPlayerBackend.switchToMPVOnPipClose,
!player.currentItem.isNil {
DispatchQueue.main.async {
player.avPlayerBackend.switchToMPVOnPipClose = false
player.saveTime {
player.changeActiveBackend(from: .appleAVPlayer, to: .mpv)
}
}
}
player?.playingInPictureInPicture = false
player.playingInPictureInPicture = false
}
func pictureInPictureControllerWillStopPictureInPicture(_: AVPictureInPictureController) {}
@@ -37,7 +42,10 @@ final class PiPDelegate: NSObject, AVPictureInPictureControllerDelegate {
_: AVPictureInPictureController,
restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: @escaping (Bool) -> Void
) {
player?.show()
if !player.currentItem.isNil {
player?.show()
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
completionHandler(true)
}