diff --git a/Sora/Utils/MediaPlayer/VideoPlayer.swift b/Sora/Utils/MediaPlayer/VideoPlayer.swift index 58a9a65..10376d1 100644 --- a/Sora/Utils/MediaPlayer/VideoPlayer.swift +++ b/Sora/Utils/MediaPlayer/VideoPlayer.swift @@ -25,6 +25,8 @@ class VideoPlayerViewController: UIViewController { var episodeImageUrl: String = "" var mediaTitle: String = "" + var detachedWindow: UIWindow? + init(module: ScrapingModule) { self.module = module super.init(nibName: nil, bundle: nil) diff --git a/Sora/Views/MediaInfoView/MediaInfoView.swift b/Sora/Views/MediaInfoView/MediaInfoView.swift index b020fcb..5157e25 100644 --- a/Sora/Views/MediaInfoView/MediaInfoView.swift +++ b/Sora/Views/MediaInfoView/MediaInfoView.swift @@ -1248,8 +1248,7 @@ struct MediaInfoView: View { var title: String = "" var streamUrl: String = "" var headers: [String:String]? = nil - if let sources = sources as? [String] - { + if let sources = sources as? [String] { if index + 1 < sources.count { if !sources[index].lowercased().contains("http") { title = sources[index] @@ -1265,16 +1264,11 @@ struct MediaInfoView: View { streamUrl = sources[index] index += 1 } - } - else if let sources = sources as? [[String: Any]] - { - if let currTitle = sources[index]["title"] as? String - { + } else if let sources = sources as? [[String: Any]] { + if let currTitle = sources[index]["title"] as? String { title = currTitle streamUrl = (sources[index]["streamUrl"] as? String) ?? "" - } - else - { + } else { title = "Stream \(streamIndex)" streamUrl = (sources[index]["streamUrl"] as? String)! } @@ -1361,9 +1355,7 @@ struct MediaInfoView: View { videoPlayerViewController.aniListID = itemID ?? 0 videoPlayerViewController.modalPresentationStyle = .fullScreen - if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, let rootVC = windowScene.windows.first?.rootViewController { - rootVC.present(videoPlayerViewController, animated: true, completion: nil) - } + presentPlayerWithDetachedContext(videoPlayerViewController: videoPlayerViewController) return default: break @@ -1974,4 +1966,19 @@ if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScen } }.resume() } + + private func presentPlayerWithDetachedContext(videoPlayerViewController: VideoPlayerViewController) { + 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() + + videoPlayerViewController.detachedWindow = detachedWindow + hostingController.present(videoPlayerViewController, animated: true, completion: nil) + } }