Reapply "test again"

This reverts commit 42fb670abb.
This commit is contained in:
Francesco 2025-06-03 20:27:46 +02:00
parent 49f541755c
commit fa65ff7740
3 changed files with 37 additions and 14 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")
@ -1827,16 +1828,15 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
}
@objc func dismissTapped() {
if let presentingViewController = self.presentingViewController {
presentingViewController.dismiss(animated: true, completion: nil)
} else {
dismiss(animated: true, completion: nil)
dismiss(animated: true) { [weak self] in
self?.detachedWindow = nil
}
}
@objc func watchNextTapped() {
player.pause()
dismiss(animated: true) { [weak self] in
self?.detachedWindow = nil
self?.onWatchNext()
}
}

View file

@ -24,6 +24,7 @@ class VideoPlayerViewController: UIViewController {
var episodeNumber: Int = 0
var episodeImageUrl: String = ""
var mediaTitle: String = ""
var detachedWindow: UIWindow?
init(module: ScrapingModule) {
self.module = module

View file

@ -1375,11 +1375,7 @@ struct MediaInfoView: View {
videoPlayerViewController.aniListID = itemID ?? 0
videoPlayerViewController.modalPresentationStyle = .overFullScreen
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first,
let currentVC = window.rootViewController?.presentedViewController ?? window.rootViewController {
currentVC.present(videoPlayerViewController, animated: true, completion: nil)
}
presentPlayerWithDetachedContext(videoPlayerViewController: videoPlayerViewController)
return
default:
break
@ -1417,11 +1413,7 @@ struct MediaInfoView: View {
customMediaPlayer.modalPresentationStyle = .overFullScreen
Logger.shared.log("Opening custom media player with stream URL: \(url), and subtitles URL: \(String(describing: subtitles))", type: "Stream")
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first,
let currentVC = window.rootViewController?.presentedViewController ?? window.rootViewController {
currentVC.present(customMediaPlayer, animated: true, completion: nil)
}
presentPlayerWithDetachedContext(customMediaPlayer: customMediaPlayer)
}
}
}
@ -2004,4 +1996,34 @@ struct MediaInfoView: View {
}
}.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)
}
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)
}
}