From eb5f21bf5d42f2198b3f2aba395956319c94824a Mon Sep 17 00:00:00 2001 From: Aiden Vigue Date: Thu, 10 Jun 2021 17:54:14 -0700 Subject: [PATCH] Limit progress updates --- JellyfinPlayer/EpisodeItemView.swift | 4 ++-- JellyfinPlayer/LibrarySearchView.swift | 4 ++-- JellyfinPlayer/LibraryView.swift | 4 ++-- JellyfinPlayer/MovieItemView.swift | 6 +++--- JellyfinPlayer/SeriesItemView.swift | 1 + JellyfinPlayer/VideoPlayer.swift | 18 ++++++++++-------- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/JellyfinPlayer/EpisodeItemView.swift b/JellyfinPlayer/EpisodeItemView.swift index 6a8dbe8b..4854846f 100644 --- a/JellyfinPlayer/EpisodeItemView.swift +++ b/JellyfinPlayer/EpisodeItemView.swift @@ -459,8 +459,8 @@ struct EpisodeItemView: View { } } .onAppear(perform: { - favorite = item.userData!.isFavorite! - watched = item.userData!.played! + favorite = item.userData?.isFavorite ?? false + watched = item.userData?.played ?? false settingState = false }) .navigationBarTitleDisplayMode(.inline) diff --git a/JellyfinPlayer/LibrarySearchView.swift b/JellyfinPlayer/LibrarySearchView.swift index df315d70..795fca2f 100644 --- a/JellyfinPlayer/LibrarySearchView.swift +++ b/JellyfinPlayer/LibrarySearchView.swift @@ -85,12 +85,12 @@ struct LibrarySearchView: View { .foregroundColor(.primary) .lineLimit(1) if item.productionYear != nil { - Text(String(item.productionYear ?? 0)) + Text(String(item.productionYear!)) .foregroundColor(.secondary) .font(.caption) .fontWeight(.medium) } else { - Text(item.type!) + Text(item.type ?? "") } }.frame(width: 100) } diff --git a/JellyfinPlayer/LibraryView.swift b/JellyfinPlayer/LibraryView.swift index c7babc28..b49c4edc 100644 --- a/JellyfinPlayer/LibraryView.swift +++ b/JellyfinPlayer/LibraryView.swift @@ -123,12 +123,12 @@ struct LibraryView: View { .foregroundColor(.primary) .lineLimit(1) if item.productionYear != nil { - Text(String(item.productionYear ?? 0)) + Text(String(item.productionYear!)) .foregroundColor(.secondary) .font(.caption) .fontWeight(.medium) } else { - Text(item.type!) + Text(item.type ?? "") } }.frame(width: 100) } diff --git a/JellyfinPlayer/MovieItemView.swift b/JellyfinPlayer/MovieItemView.swift index f3f54dbe..8aa842bd 100644 --- a/JellyfinPlayer/MovieItemView.swift +++ b/JellyfinPlayer/MovieItemView.swift @@ -463,12 +463,12 @@ struct MovieItemView: View { } } .onAppear(perform: { - favorite = item.userData!.isFavorite! - watched = item.userData!.played! + favorite = item.userData?.isFavorite ?? false + watched = item.userData?.played ?? false settingState = false }) .navigationBarTitleDisplayMode(.inline) - .navigationTitle(item.name!) + .navigationTitle(item.name ?? "") .supportedOrientations(.allButUpsideDown) .overrideViewPreference(.unspecified) .preferredColorScheme(.none) diff --git a/JellyfinPlayer/SeriesItemView.swift b/JellyfinPlayer/SeriesItemView.swift index 3e14daa5..da4df6b0 100644 --- a/JellyfinPlayer/SeriesItemView.swift +++ b/JellyfinPlayer/SeriesItemView.swift @@ -92,6 +92,7 @@ struct SeriesItemView: View { } .overrideViewPreference(.unspecified) .navigationTitle(item.name ?? "") + .navigationBarTitleDisplayMode(.inline) } } } diff --git a/JellyfinPlayer/VideoPlayer.swift b/JellyfinPlayer/VideoPlayer.swift index 5f187423..0355babd 100644 --- a/JellyfinPlayer/VideoPlayer.swift +++ b/JellyfinPlayer/VideoPlayer.swift @@ -509,15 +509,17 @@ class PlayerViewController: UIViewController, VLCMediaDelegate, VLCMediaPlayerDe // MARK: Jellyfin Playstate updates func sendProgressReport(eventName: String) { - let progressInfo = PlaybackProgressInfo(canSeek: true, item: manifest, itemId: manifest.id, sessionId: playSessionId, mediaSourceId: manifest.id, audioStreamIndex: Int(selectedAudioTrack), subtitleStreamIndex: Int(selectedCaptionTrack), isPaused: (mediaPlayer.state == .paused), isMuted: false, positionTicks: Int64(mediaPlayer.position * Float(manifest.runTimeTicks!)), playbackStartTimeTicks: Int64(startTime), volumeLevel: 100, brightness: 100, aspectRatio: nil, playMethod: playbackItem.videoType, liveStreamId: nil, playSessionId: playSessionId, repeatMode: .repeatNone, nowPlayingQueue: [], playlistItemId: "playlistItem0") + if (eventName == "timeupdate" && mediaPlayer.state == .playing) || eventName != "timeupdate" { + let progressInfo = PlaybackProgressInfo(canSeek: true, item: manifest, itemId: manifest.id, sessionId: playSessionId, mediaSourceId: manifest.id, audioStreamIndex: Int(selectedAudioTrack), subtitleStreamIndex: Int(selectedCaptionTrack), isPaused: (mediaPlayer.state == .paused), isMuted: false, positionTicks: Int64(mediaPlayer.position * Float(manifest.runTimeTicks!)), playbackStartTimeTicks: Int64(startTime), volumeLevel: 100, brightness: 100, aspectRatio: nil, playMethod: playbackItem.videoType, liveStreamId: nil, playSessionId: playSessionId, repeatMode: .repeatNone, nowPlayingQueue: [], playlistItemId: "playlistItem0") - PlaystateAPI.reportPlaybackProgress(playbackProgressInfo: progressInfo) - .sink(receiveCompletion: { completion in - HandleAPIRequestCompletion(globalData: self.globalData, completion: completion) - }, receiveValue: { _ in - print("Playback progress report sent!") - }) - .store(in: &globalData.pendingAPIRequests) + PlaystateAPI.reportPlaybackProgress(playbackProgressInfo: progressInfo) + .sink(receiveCompletion: { completion in + HandleAPIRequestCompletion(globalData: self.globalData, completion: completion) + }, receiveValue: { _ in + print("Playback progress report sent!") + }) + .store(in: &globalData.pendingAPIRequests) + } } func sendStopReport() {