From 91721a35066cc69b8d6b1de06a4c828061fbe7b2 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Fri, 5 Aug 2022 22:37:38 +0200 Subject: [PATCH] Improve PiP close animation --- Model/Player/PiPDelegate.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Model/Player/PiPDelegate.swift b/Model/Player/PiPDelegate.swift index d618d0b8..082261ef 100644 --- a/Model/Player/PiPDelegate.swift +++ b/Model/Player/PiPDelegate.swift @@ -1,5 +1,6 @@ import AVKit import Foundation +import SwiftUI final class PiPDelegate: NSObject, AVPictureInPictureControllerDelegate { var player: PlayerModel! @@ -45,16 +46,23 @@ final class PiPDelegate: NSObject, AVPictureInPictureControllerDelegate { ) { var delay = 0.0 #if os(iOS) - if player.currentItem.isNil { + if !player.presentingPlayer { delay = 0.5 } + if player.currentItem.isNil { + delay = 1 + } #endif if !player.currentItem.isNil, !player.musicMode { player?.show() } - DispatchQueue.main.asyncAfter(deadline: .now() + delay) { + DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in + withAnimation(.linear(duration: 0.3)) { + self?.player.playingInPictureInPicture = false + } + completionHandler(true) } }