diff --git a/android/app/src/main/java/com/audiobookshelf/app/player/MediaProgressSyncer.kt b/android/app/src/main/java/com/audiobookshelf/app/player/MediaProgressSyncer.kt index c8803565..99ee91b2 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/player/MediaProgressSyncer.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/player/MediaProgressSyncer.kt @@ -74,14 +74,14 @@ class MediaProgressSyncer(val playerNotificationService:PlayerNotificationServic } } - fun stop(cb: () -> Unit) { + fun stop(shouldSync:Boolean? = true, cb: () -> Unit) { if (!listeningTimerRunning) return listeningTimerTask?.cancel() listeningTimerTask = null listeningTimerRunning = false Log.d(tag, "stop: Stopping listening for $currentDisplayTitle") - val currentTime = playerNotificationService.getCurrentTimeSeconds() + val currentTime = if (shouldSync == true) playerNotificationService.getCurrentTimeSeconds() else 0.0 if (currentTime > 0) { // Current time should always be > 0 on stop sync(true, currentTime) { reset() diff --git a/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt b/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt index 870fabaf..7e0fe773 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt @@ -438,7 +438,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { apiHandler.playLibraryItem(libraryItemId, episodeId, playItemRequestPayload) { if (it == null) { // Play request failed clientEventEmitter?.onPlaybackFailed(errorMessage) - closePlayback() + closePlayback(true) } else { Handler(Looper.getMainLooper()).post { preparePlayer(it, true, null) @@ -447,7 +447,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { } } else { clientEventEmitter?.onPlaybackFailed(errorMessage) - closePlayback() + closePlayback(true) } } } @@ -705,12 +705,12 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { currentPlayer.setPlaybackSpeed(speed) } - fun closePlayback() { + fun closePlayback(calledOnError:Boolean? = false) { Log.d(tag, "closePlayback") if (mediaProgressSyncer.listeningTimerRunning) { Log.i(tag, "About to close playback so stopping media progress syncer first") - mediaProgressSyncer.stop { - Log.d(tag, "Media Progress syncer stopped and synced") + mediaProgressSyncer.stop(calledOnError == false) { // If closing on error then do not sync progress (causes exception) + Log.d(tag, "Media Progress syncer stopped") } }