From 9d795430859318b36df39be00475e56160507e57 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Mon, 30 May 2022 21:00:53 +0200 Subject: [PATCH] Improve animations --- Model/Player/PiPDelegate.swift | 9 ++++++++- Model/Player/PlayerModel.swift | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Model/Player/PiPDelegate.swift b/Model/Player/PiPDelegate.swift index 2a33e98e..7f4db8fa 100644 --- a/Model/Player/PiPDelegate.swift +++ b/Model/Player/PiPDelegate.swift @@ -43,11 +43,18 @@ final class PiPDelegate: NSObject, AVPictureInPictureControllerDelegate { _: AVPictureInPictureController, restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: @escaping (Bool) -> Void ) { + var delay = 0.0 + #if os(iOS) + if player.currentItem.isNil { + delay = 0.5 + } + #endif + if !player.currentItem.isNil { player?.show() } - DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { + DispatchQueue.main.asyncAfter(deadline: .now() + delay) { completionHandler(true) } } diff --git a/Model/Player/PlayerModel.swift b/Model/Player/PlayerModel.swift index 89fa9753..d0c336f4 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -206,9 +206,11 @@ final class PlayerModel: ObservableObject { } func play(_ video: Video, at time: CMTime? = nil, showingPlayer: Bool = true) { + pause() + var delay = 0.0 - #if !os(macOS) - delay = 0.3 + #if os(iOS) + delay = 0.5 #endif DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in