From 193ba7af3fd82f98bb5db09f824e609081cb6518 Mon Sep 17 00:00:00 2001 From: derekxsun Date: Thu, 24 Nov 2022 20:53:06 +0800 Subject: [PATCH] update Picture-in-Picture for the App --- Emitron/Emitron/Support Files/Info.plist | 4 ++++ .../UI/Video/FullScreenVideoPlayer.swift | 21 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Emitron/Emitron/Support Files/Info.plist b/Emitron/Emitron/Support Files/Info.plist index 28afe878..ebb421cd 100644 --- a/Emitron/Emitron/Support Files/Info.plist +++ b/Emitron/Emitron/Support Files/Info.plist @@ -171,6 +171,10 @@ UIApplicationSupportsMultipleScenes + UIBackgroundModes + + audio + UILaunchStoryboardName LaunchScreen UIRequiredDeviceCapabilities diff --git a/Emitron/Emitron/UI/Video/FullScreenVideoPlayer.swift b/Emitron/Emitron/UI/Video/FullScreenVideoPlayer.swift index c88cd7a6..0deda2f3 100644 --- a/Emitron/Emitron/UI/Video/FullScreenVideoPlayer.swift +++ b/Emitron/Emitron/UI/Video/FullScreenVideoPlayer.swift @@ -86,7 +86,8 @@ extension FullScreenVideoPlayer: UIViewControllerRepresentable { private let model: VideoPlaybackViewModel private let handleDismissal: () -> Void private var playerIsPresented = false - + private var isDuringPip = false + @available(*, unavailable) required init?(coder: NSCoder) { preconditionFailure("init(coder:) has not been implemented") } @@ -124,6 +125,24 @@ extension FullScreenVideoPlayer.Presenter: AVPlayerViewControllerDelegate { willEndFullScreenPresentationWithAnimationCoordinator _: UIViewControllerTransitionCoordinator ) { model.stop() + print(isDuringPip) + if !isDuringPip { + handleDismissal() + } + } + + func playerViewController(_ playerViewController: AVPlayerViewController, restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: @escaping (Bool) -> Void) { + present(playerViewController, animated: false) { + completionHandler(true) + } + } + + func playerViewControllerWillStartPictureInPicture(_ playerViewController: AVPlayerViewController) { + isDuringPip = true + } + + func playerViewControllerWillStopPictureInPicture(_ playerViewController: AVPlayerViewController) { + isDuringPip = false handleDismissal() } }