From 7e1d10aa089bf1023cb425c19899fc849dcee7ac Mon Sep 17 00:00:00 2001 From: Francesco <100066266+cranci1@users.noreply.github.com> Date: Tue, 3 Jun 2025 15:17:02 +0200 Subject: [PATCH] hell yeah --- .../CustomPlayer/CustomPlayer.swift | 1 + Sora/Views/MediaInfoView/MediaInfoView.swift | 23 +++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Sora/Utils/MediaPlayer/CustomPlayer/CustomPlayer.swift b/Sora/Utils/MediaPlayer/CustomPlayer/CustomPlayer.swift index 685acb5..5afb454 100644 --- a/Sora/Utils/MediaPlayer/CustomPlayer/CustomPlayer.swift +++ b/Sora/Utils/MediaPlayer/CustomPlayer/CustomPlayer.swift @@ -41,6 +41,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele var currentTimeVal: Double = 0.0 var duration: Double = 0.0 var isVideoLoaded = false + var detachedWindow: UIWindow? private var isHoldPauseEnabled: Bool { UserDefaults.standard.bool(forKey: "holdForPauseEnabled") diff --git a/Sora/Views/MediaInfoView/MediaInfoView.swift b/Sora/Views/MediaInfoView/MediaInfoView.swift index 5157e25..e6991f9 100644 --- a/Sora/Views/MediaInfoView/MediaInfoView.swift +++ b/Sora/Views/MediaInfoView/MediaInfoView.swift @@ -1393,13 +1393,7 @@ struct MediaInfoView: View { customMediaPlayer.modalPresentationStyle = .fullScreen Logger.shared.log("Opening custom media player with url: \(url)") -if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, - let rootVC = windowScene.windows.first?.rootViewController { - rootVC.present(customMediaPlayer, animated: true, completion: nil) -} else { - Logger.shared.log("Failed to find root view controller", type: "Error") - DropManager.shared.showDrop(title: "Error", subtitle: "Failed to present player", duration: 2.0, icon: UIImage(systemName: "xmark.circle")) -} + presentPlayerWithDetachedContext(customMediaPlayer: customMediaPlayer) } } } @@ -1981,4 +1975,19 @@ if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScen videoPlayerViewController.detachedWindow = detachedWindow hostingController.present(videoPlayerViewController, animated: true, completion: nil) } + + private func presentPlayerWithDetachedContext(customMediaPlayer: CustomMediaPlayerViewController) { + guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene else { return } + + let detachedWindow = UIWindow(windowScene: windowScene) + let hostingController = UIViewController() + hostingController.view.backgroundColor = .clear + detachedWindow.rootViewController = hostingController + detachedWindow.backgroundColor = .clear + detachedWindow.windowLevel = .normal + 1 + detachedWindow.makeKeyAndVisible() + + customMediaPlayer.detachedWindow = detachedWindow + hostingController.present(customMediaPlayer, animated: true, completion: nil) + } }