Fix Android Auto seek buttons doing nothing for car-initiated playback (#466)

Two issues prevented the head unit seek controls from working:

1. Books started from the Android Auto browse screen never populated
   MediaRepository's playingBook state, which is only set by the phone
   UI flow. Since rewind/forward/previousTrack/nextTrack all bail out
   silently on a null playingBook, every seek button on the head unit
   was a no-op while pause kept working (it bypasses MediaRepository).
   onSetMediaItems now registers the fetched book with MediaRepository.

2. The rewind/forward buttons were assigned to SLOT_OVERFLOW, leaving
   the primary back/forward slots to chapter navigation. Swapped so the
   configurable rewind/forward occupy the primary slots, matching
   audiobook app conventions, with chapter navigation in the overflow.

Verified end-to-end on the Desktop Head Unit: commands confirmed
arriving via logcat and seeks now applied for books started from the
car screen.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
jetracer
2026-07-09 05:00:22 -04:00
committed by GitHub
parent b710a25383
commit c93d0c013f
2 changed files with 17 additions and 4 deletions

View File

@@ -113,7 +113,7 @@ class MediaLibrarySessionCallback
.setSessionCommand(prevChapterCommand)
.setDisplayName("Previous Chapter")
.setEnabled(true)
.setSlots(CommandButton.SLOT_BACK)
.setSlots(CommandButton.SLOT_OVERFLOW)
.build()
val nextChapterButton =
@@ -121,7 +121,7 @@ class MediaLibrarySessionCallback
.Builder(CommandButton.ICON_NEXT)
.setSessionCommand(nextChapterCommand)
.setDisplayName("Next Chapter")
.setSlots(CommandButton.SLOT_FORWARD)
.setSlots(CommandButton.SLOT_OVERFLOW)
.setEnabled(true)
.build()
@@ -131,7 +131,7 @@ class MediaLibrarySessionCallback
.setSessionCommand(rewindCommand)
.setDisplayName("Rewind")
.setEnabled(true)
.setSlots(CommandButton.SLOT_OVERFLOW)
.setSlots(CommandButton.SLOT_BACK)
.build()
val forwardButton =
@@ -139,7 +139,7 @@ class MediaLibrarySessionCallback
.Builder(CommandButton.ICON_SKIP_FORWARD)
.setSessionCommand(forwardCommand)
.setDisplayName("Forward")
.setSlots(CommandButton.SLOT_OVERFLOW)
.setSlots(CommandButton.SLOT_FORWARD)
.setEnabled(true)
.build()
@@ -210,6 +210,7 @@ class MediaLibrarySessionCallback
preferences.savePlayingItem(it)
playbackSynchronizationService.startPlaybackSynchronization(it)
}
mediaRepository.registerPlayingBook(it)
PlaybackService.bookToChapterMediaItems(it)
},
onFailure = { MediaItemsWithStartPosition(emptyList(), 0, 0) },

View File

@@ -415,6 +415,18 @@ class MediaRepository
_isPlaybackReady.value = false
}
fun registerPlayingBook(book: DetailedItem) {
val sameBook = _playingBook.value?.same(book) ?: false
if (sameBook.not()) {
Timber.d("Registering playing book prepared via media session: ${book.id}")
_totalPosition.value = book.progress?.currentTime ?: 0.0
_playingBook.value = book
_isPlaybackReady.value = true
}
}
private fun startPreparingPlayback(book: DetailedItem) {
val sameBook = _playingBook.value?.same(book) ?: false