From 2a3c58adbdb5dd33418338bcef818c2abcd24d05 Mon Sep 17 00:00:00 2001 From: Francesco <100066266+cranci1@users.noreply.github.com> Date: Tue, 3 Jun 2025 14:49:45 +0200 Subject: [PATCH] test presentation model --- Sora/Utils/MediaPlayer/VideoPlayerView.swift | 39 ++++++++++++++++++++ Sora/Views/MediaInfoView/MediaInfoView.swift | 35 +++++++++++------- Sulfur.xcodeproj/project.pbxproj | 4 ++ 3 files changed, 65 insertions(+), 13 deletions(-) create mode 100644 Sora/Utils/MediaPlayer/VideoPlayerView.swift diff --git a/Sora/Utils/MediaPlayer/VideoPlayerView.swift b/Sora/Utils/MediaPlayer/VideoPlayerView.swift new file mode 100644 index 0000000..d8087e4 --- /dev/null +++ b/Sora/Utils/MediaPlayer/VideoPlayerView.swift @@ -0,0 +1,39 @@ +// +// VideoPlayerView.swift +// Sora +// +// Created by Francesco on 3/06/25. +// + +import SwiftUI +import AVKit + +struct VideoPlayerView: UIViewControllerRepresentable { + let module: ScrapingModule + var streamUrl: String? + var fullUrl: String + var subtitles: String + var aniListID: Int + var headers: [String:String]? + var totalEpisodes: Int + var episodeNumber: Int + var episodeImageUrl: String + var mediaTitle: String + + func makeUIViewController(context: Context) -> VideoPlayerViewController { + let controller = VideoPlayerViewController(module: module) + controller.streamUrl = streamUrl + controller.fullUrl = fullUrl + controller.subtitles = subtitles + controller.aniListID = aniListID + controller.headers = headers + controller.totalEpisodes = totalEpisodes + controller.episodeNumber = episodeNumber + controller.episodeImageUrl = episodeImageUrl + controller.mediaTitle = mediaTitle + return controller + } + + func updateUIViewController(_ uiViewController: VideoPlayerViewController, context: Context) { + } +} diff --git a/Sora/Views/MediaInfoView/MediaInfoView.swift b/Sora/Views/MediaInfoView/MediaInfoView.swift index ef0eac3..dc3a1fe 100644 --- a/Sora/Views/MediaInfoView/MediaInfoView.swift +++ b/Sora/Views/MediaInfoView/MediaInfoView.swift @@ -5,6 +5,7 @@ // Created by Francesco on 05/01/25. // +import AVKit import SwiftUI import Kingfisher import SafariServices @@ -44,6 +45,9 @@ struct MediaInfoView: View { @State private var selectedEpisodeImage: String = "" @State private var selectedSeason: Int = 0 + @State private var isVideoPlayerPresented: Bool = false + @State private var videoPlayerView: VideoPlayerView? + @AppStorage("externalPlayer") private var externalPlayer: String = "Default" @AppStorage("episodeChunkSize") private var episodeChunkSize: Int = 100 @@ -135,6 +139,11 @@ struct MediaInfoView: View { bodyContent .navigationBarHidden(true) .ignoresSafeArea(.container, edges: .top) + .fullScreenCover(isPresented: $isVideoPlayerPresented) { + if let playerView = videoPlayerView { + playerView + } + } VStack { HStack { @@ -1342,19 +1351,19 @@ struct MediaInfoView: View { case "IINA": scheme = "iina://weblink?url=\(url)" case "Default": - let videoPlayerViewController = VideoPlayerViewController(module: module) - videoPlayerViewController.headers = headers - videoPlayerViewController.streamUrl = url - videoPlayerViewController.fullUrl = fullURL - videoPlayerViewController.episodeNumber = selectedEpisodeNumber - videoPlayerViewController.episodeImageUrl = selectedEpisodeImage - videoPlayerViewController.mediaTitle = title - 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) - } + self.videoPlayerView = VideoPlayerView( + module: module, + streamUrl: url, + fullUrl: fullURL, + subtitles: subtitles ?? "", + aniListID: itemID ?? 0, + headers: headers, + totalEpisodes: episodeLinks.count, + episodeNumber: selectedEpisodeNumber, + episodeImageUrl: selectedEpisodeImage, + mediaTitle: title + ) + self.isVideoPlayerPresented = true return default: break diff --git a/Sulfur.xcodeproj/project.pbxproj b/Sulfur.xcodeproj/project.pbxproj index 61d7e9c..90ec057 100644 --- a/Sulfur.xcodeproj/project.pbxproj +++ b/Sulfur.xcodeproj/project.pbxproj @@ -80,6 +80,7 @@ 13EA2BD52D32D97400C1EBD7 /* CustomPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13EA2BD12D32D97400C1EBD7 /* CustomPlayer.swift */; }; 13EA2BD62D32D97400C1EBD7 /* Double+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13EA2BD32D32D97400C1EBD7 /* Double+Extension.swift */; }; 13EA2BD92D32D98400C1EBD7 /* NormalPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13EA2BD82D32D98400C1EBD7 /* NormalPlayer.swift */; }; + 13FB8D392DEF269F008C3920 /* VideoPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13FB8D382DEF269F008C3920 /* VideoPlayerView.swift */; }; 1E26E9E72DA9577900B9DC02 /* VolumeSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E26E9E62DA9577900B9DC02 /* VolumeSlider.swift */; }; 1E47859B2DEBC5960095BF2F /* AnilistMatchPopupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E47859A2DEBC5960095BF2F /* AnilistMatchPopupView.swift */; }; 1E9FF1D32D403E49008AC100 /* SettingsViewLoggerFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E9FF1D22D403E42008AC100 /* SettingsViewLoggerFilter.swift */; }; @@ -171,6 +172,7 @@ 13EA2BD12D32D97400C1EBD7 /* CustomPlayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomPlayer.swift; sourceTree = ""; }; 13EA2BD32D32D97400C1EBD7 /* Double+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Double+Extension.swift"; sourceTree = ""; }; 13EA2BD82D32D98400C1EBD7 /* NormalPlayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NormalPlayer.swift; sourceTree = ""; }; + 13FB8D382DEF269F008C3920 /* VideoPlayerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoPlayerView.swift; sourceTree = ""; }; 1E26E9E62DA9577900B9DC02 /* VolumeSlider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VolumeSlider.swift; sourceTree = ""; }; 1E47859A2DEBC5960095BF2F /* AnilistMatchPopupView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnilistMatchPopupView.swift; sourceTree = ""; }; 1E9FF1D22D403E42008AC100 /* SettingsViewLoggerFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewLoggerFilter.swift; sourceTree = ""; }; @@ -540,6 +542,7 @@ 13EA2BD02D32D97400C1EBD7 /* CustomPlayer */, 13DC0C452D302C7500D0F966 /* VideoPlayer.swift */, 13EA2BD82D32D98400C1EBD7 /* NormalPlayer.swift */, + 13FB8D382DEF269F008C3920 /* VideoPlayerView.swift */, ); path = MediaPlayer; sourceTree = ""; @@ -762,6 +765,7 @@ 0457C59D2DE78267000AFBD9 /* BookmarkGridView.swift in Sources */, 0457C59E2DE78267000AFBD9 /* BookmarkLink.swift in Sources */, 0457C59F2DE78267000AFBD9 /* BookmarkGridItemView.swift in Sources */, + 13FB8D392DEF269F008C3920 /* VideoPlayerView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };