From d16c009360bd302e21bf6905b2b5e7e9a36a7bae Mon Sep 17 00:00:00 2001 From: cranci1 <100066266+cranci1@users.noreply.github.com> Date: Fri, 31 Jan 2025 15:42:40 +0100 Subject: [PATCH] added external player --- Sora/Views/MediaInfoView/MediaInfoView.swift | 35 ++++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/Sora/Views/MediaInfoView/MediaInfoView.swift b/Sora/Views/MediaInfoView/MediaInfoView.swift index 9fd6d47..58bf03f 100644 --- a/Sora/Views/MediaInfoView/MediaInfoView.swift +++ b/Sora/Views/MediaInfoView/MediaInfoView.swift @@ -372,14 +372,35 @@ struct MediaInfoView: View { func playStream(url: String, fullURL: String) { DispatchQueue.main.async { - let videoPlayerViewController = VideoPlayerViewController(module: module) - videoPlayerViewController.streamUrl = url - videoPlayerViewController.fullUrl = fullURL - videoPlayerViewController.modalPresentationStyle = .fullScreen + let externalPlayer = UserDefaults.standard.string(forKey: "externalPlayer") ?? "Default" + var scheme: String? - if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, - let rootVC = windowScene.windows.first?.rootViewController { - rootVC.present(videoPlayerViewController, animated: true, completion: nil) + switch externalPlayer { + case "Infuse": + scheme = "infuse://x-callback-url/play?url=\(url)" + case "VLC": + scheme = "vlc://\(url)" + case "OutPlayer": + scheme = "outplayer://\(url)" + case "nPlayer": + scheme = "nplayer-\(url)" + default: + break + } + + if let scheme = scheme, let url = URL(string: scheme), UIApplication.shared.canOpenURL(url) { + UIApplication.shared.open(url, options: [:], completionHandler: nil) + Logger.shared.log("Opening external app with scheme: \(url)", type: "General") + } else { + let videoPlayerViewController = VideoPlayerViewController(module: module) + videoPlayerViewController.streamUrl = url + videoPlayerViewController.fullUrl = fullURL + 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) + } } } }