diff --git a/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationListener.kt b/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationListener.kt index ef58fbed..3fa291c4 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationListener.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationListener.kt @@ -29,9 +29,14 @@ class PlayerNotificationListener(var playerNotificationService:PlayerNotificatio Log.d(tag, "onNotificationCancelled not dismissed by user") // When stop button is pressed on the notification I guess it isn't considered "dismissedByUser" so we need to close playback ourselves - if (!PlayerNotificationService.isClosed) { + if (!PlayerNotificationService.isClosed && !PlayerNotificationService.isSwitchingPlayer) { Log.d(tag, "PNS is not closed - closing it now") playerNotificationService.closePlayback() + } else if (PlayerNotificationService.isSwitchingPlayer) { + // When switching from cast player to exo player and vice versa the notification is cancelled and posted again + // so we don't want to cancel the playback during this switch + Log.d(tag, "PNS is switching player") + PlayerNotificationService.isSwitchingPlayer = false } } } 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 6afe9c84..f69c197c 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 @@ -50,6 +50,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { var isStarted = false var isClosed = false var isUnmeteredNetwork = false + var isSwitchingPlayer = false // Used when switching between cast player and exoplayer } interface ClientEventEmitter { @@ -309,8 +310,6 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { val seekBackTime = DeviceManager.deviceData.deviceSettings?.jumpBackwardsTimeMs ?: 10000 val seekForwardTime = DeviceManager.deviceData.deviceSettings?.jumpForwardTimeMs ?: 10000 - Log.d(tag, "Seek Back Time $seekBackTime") - Log.d(tag, "Seek Forward Time $seekForwardTime") mPlayer = ExoPlayer.Builder(this) .setLoadControl(customLoadControl) @@ -413,7 +412,6 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { currentPlayer.setPlaybackSpeed(playbackRateToUse) currentPlayer.prepare() - } else if (castPlayer != null) { val currentTrackIndex = playbackSession.getCurrentTrackIndex() val currentTrackTime = playbackSession.getCurrentTrackTimeMs() @@ -477,6 +475,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { return } else { Log.d(tag, "switchToPlayer: Switching to cast player from exo player stop exo player") + isSwitchingPlayer = true mPlayer.stop() } } else { @@ -485,6 +484,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { return } else if (castPlayer != null) { Log.d(tag, "switchToPlayer: Switching to exo player from cast player stop cast player") + isSwitchingPlayer = true castPlayer?.stop() } } @@ -548,10 +548,6 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { return currentPlaybackSession?.totalDurationMs ?: 0L } - fun getCurrentBookTitle() : String? { - return currentPlaybackSession?.displayTitle - } - fun getCurrentPlaybackSessionCopy() :PlaybackSession? { return currentPlaybackSession?.clone() } @@ -656,10 +652,6 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { return } currentPlayer.volume = 1F - if (currentPlayer == castPlayer) { - Log.d(tag, "CAST Player set on play ${currentPlayer.isLoading} || ${currentPlayer.duration} | ${currentPlayer.currentPosition}") - } - currentPlayer.play() }