diff --git a/Sora.xcodeproj/project.xcworkspace/xcuserdata/Francesco.xcuserdatad/UserInterfaceState.xcuserstate b/Sora.xcodeproj/project.xcworkspace/xcuserdata/Francesco.xcuserdatad/UserInterfaceState.xcuserstate index 32d15d5..b0223cf 100644 Binary files a/Sora.xcodeproj/project.xcworkspace/xcuserdata/Francesco.xcuserdatad/UserInterfaceState.xcuserstate and b/Sora.xcodeproj/project.xcworkspace/xcuserdata/Francesco.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Sora/Utils/CustomPlayer/CustomPlayer.swift b/Sora/Utils/CustomPlayer/CustomPlayer.swift index 8748230..2814aa4 100644 --- a/Sora/Utils/CustomPlayer/CustomPlayer.swift +++ b/Sora/Utils/CustomPlayer/CustomPlayer.swift @@ -32,6 +32,8 @@ struct CustomMediaPlayer: View { @State private var showControls = false @State private var inactivityTimer: Timer? @State private var timeObserverToken: Any? + @State private var isVideoLoaded = false + @State private var showWatchNextButton = true @Environment(\.presentationMode) var presentationMode let module: ModuleStruct @@ -76,6 +78,7 @@ struct CustomMediaPlayer: View { currentTime = time.seconds if let itemDuration = player.currentItem?.duration.seconds, itemDuration.isFinite && !itemDuration.isNaN { duration = itemDuration + isVideoLoaded = true } } startUpdatingCurrentTime() @@ -152,7 +155,7 @@ struct CustomMediaPlayer: View { .padding(.horizontal, 32) } Spacer() - if duration - currentTime <= duration * 0.10 && currentTime != duration { + if duration - currentTime <= duration * 0.10 && currentTime != duration && showWatchNextButton { Button(action: { player.pause() presentationMode.wrappedValue.dismiss() @@ -170,6 +173,13 @@ struct CustomMediaPlayer: View { .cornerRadius(32) } .padding(.trailing, 10) + .onAppear { + if UserDefaults.standard.bool(forKey: "hideNextButton") { + DispatchQueue.main.asyncAfter(deadline: .now() + 5) { + showWatchNextButton = false + } + } + } } if showControls { Menu { @@ -203,13 +213,14 @@ struct CustomMediaPlayer: View { emptyColor: .white.opacity(0.3), height: 28, onEditingChanged: { editing in - if !editing { + if !editing && isVideoLoaded { player.seek(to: CMTime(seconds: currentTime, preferredTimescale: 600)) } } ) .padding(.horizontal, 32) .padding(.bottom, 10) + .disabled(!isVideoLoaded) } } } diff --git a/Sora/Views/MediaViews/MediaExtraction.swift b/Sora/Views/MediaViews/MediaExtraction.swift index accb81f..d5d68a7 100644 --- a/Sora/Views/MediaViews/MediaExtraction.swift +++ b/Sora/Views/MediaViews/MediaExtraction.swift @@ -10,6 +10,9 @@ import SwiftSoup extension MediaView { func fetchItemDetails() { + guard !isFetchingStream else { return } + isFetchingStream = true + guard let url = URL(string: item.href.hasPrefix("https") ? item.href : "\(module.module[0].details.baseURL.hasSuffix("/") ? module.module[0].details.baseURL : "\(module.module[0].details.baseURL)/")\(item.href.hasPrefix("/") ? String(item.href.dropFirst()) : item.href)") else { return } URLSession.custom.dataTask(with: url) { data, _, error in @@ -47,6 +50,7 @@ extension MediaView { Logger.shared.log("Error parsing HTML: \(error)") } }.resume() + isFetchingStream = false } func fetchEpisodeStream(urlString: String) { diff --git a/Sora/Views/MediaViews/MediaView.swift b/Sora/Views/MediaViews/MediaView.swift index b53d50f..7abe54f 100644 --- a/Sora/Views/MediaViews/MediaView.swift +++ b/Sora/Views/MediaViews/MediaView.swift @@ -26,7 +26,8 @@ struct MediaView: View { @State private var selectedEpisode: String = "" @State private var selectedEpisodeNumber: Int = 0 @State private var episodeRange: ClosedRange = 0...99 - @State private var selectedRange: String = "1-100" + @State var selectedRange: String = "1-100" + @State var isFetchingStream: Bool = false @AppStorage("externalPlayer") private var externalPlayer: String = "Default" @StateObject private var libraryManager = LibraryManager.shared diff --git a/Sora/Views/SettingsViews/SubPages/SettingsPlayerView.swift b/Sora/Views/SettingsViews/SubPages/SettingsPlayerView.swift index 429c001..195997a 100644 --- a/Sora/Views/SettingsViews/SubPages/SettingsPlayerView.swift +++ b/Sora/Views/SettingsViews/SubPages/SettingsPlayerView.swift @@ -10,6 +10,7 @@ import SwiftUI struct SettingsPlayerView: View { @AppStorage("externalPlayer") private var externalPlayer: String = "Default" @AppStorage("AlwaysLandscape") private var isAlwaysLandscape = false + @AppStorage("hideNextButton") private var isHideNextButton = false @AppStorage("holdSpeedPlayer") private var holdSpeedPlayer: Double = 2.0 var body: some View { @@ -52,6 +53,9 @@ struct SettingsPlayerView: View { } } + Toggle("Hide 'Watch Next' after 5s", isOn: $isHideNextButton) + .tint(.accentColor) + HStack { Text("Hold Speed:") Spacer()