hell yeah

This commit is contained in:
Francesco 2025-06-03 15:17:02 +02:00
parent 519744616e
commit 7e1d10aa08
2 changed files with 17 additions and 7 deletions

View file

@ -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")

View file

@ -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)
}
}