From 78ccc085457ee1f4d668c5d3a9a87001d6d195a1 Mon Sep 17 00:00:00 2001 From: cranci1 <100066266+cranci1@users.noreply.github.com> Date: Sun, 2 Feb 2025 09:48:37 +0100 Subject: [PATCH] uh idk --- .../Components/MusicProgressSlider.swift | 2 +- Sora/Views/MediaInfoView/MediaInfoView.swift | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Sora/MediaPlayer/CustomPlayer/Components/MusicProgressSlider.swift b/Sora/MediaPlayer/CustomPlayer/Components/MusicProgressSlider.swift index 8bbb950..30a94fc 100644 --- a/Sora/MediaPlayer/CustomPlayer/Components/MusicProgressSlider.swift +++ b/Sora/MediaPlayer/CustomPlayer/Components/MusicProgressSlider.swift @@ -35,7 +35,7 @@ struct MusicProgressSlider: View { .mask({ HStack { Rectangle() - .frame(width: max(bounds.size.width * CGFloat((localRealProgress + localTempProgress)), 0), alignment: .leading) + .frame(width: max((bounds.size.width * CGFloat(localRealProgress + localTempProgress)).isFinite ? bounds.size.width * CGFloat(localRealProgress + localTempProgress) : 0, 0), alignment: .leading) Spacer(minLength: 0) } }) diff --git a/Sora/Views/MediaInfoView/MediaInfoView.swift b/Sora/Views/MediaInfoView/MediaInfoView.swift index 5ffd9fb..2d44266 100644 --- a/Sora/Views/MediaInfoView/MediaInfoView.swift +++ b/Sora/Views/MediaInfoView/MediaInfoView.swift @@ -34,6 +34,9 @@ struct MediaInfoView: View { @State var isRefetching: Bool = true @State var isFetchingEpisode: Bool = false + @State private var selectedEpisode: String = "" + @State private var selectedEpisodeNumber: Int = 0 + @AppStorage("externalPlayer") private var externalPlayer: String = "Default" @AppStorage("episodeChunkSize") private var episodeChunkSize: Int = 100 @@ -384,6 +387,26 @@ struct MediaInfoView: View { scheme = "outplayer://\(url)" case "nPlayer": scheme = "nplayer-\(url)" + case "Sora": + let customMediaPlayer = CustomMediaPlayer( + module: module, + urlString: url, + fullUrl: fullURL, + title: title, + episodeNumber: selectedEpisodeNumber, + onWatchNext: { + selectNextEpisode() + } + ) + let hostingController = UIHostingController(rootView: customMediaPlayer) + hostingController.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(hostingController, animated: true, completion: nil) + } + return default: break } @@ -404,6 +427,19 @@ struct MediaInfoView: View { } } } + + private func selectNextEpisode() { + guard let currentEpisodeIndex = episodeLinks.firstIndex(where: { $0.href == selectedEpisode }) else { return } + let nextEpisodeIndex = currentEpisodeIndex + 1 + print(nextEpisodeIndex) + if nextEpisodeIndex < episodeLinks.count { + selectedEpisode = episodeLinks[nextEpisodeIndex].href + selectedEpisodeNumber = episodeLinks[nextEpisodeIndex].number + let nextEpisodeURL = episodeLinks[nextEpisodeIndex].href + fetchStream(href: nextEpisodeURL) + print(nextEpisodeURL) + } + } private func openSafariViewController(with urlString: String) { guard let url = URL(string: urlString) else {