Repository navigation
Description
Summary
On Android 13+ the lockscreen "Live notifications" media card and the Quick-Settings media output panel only show 2 of the 5 controls that the in-app player exposes. The system tile shows [<<, ▶/||] (and sometimes [<<, ▶] while paused); the in-app expanded notification correctly shows all 5 ([Prev | −seek | Play/Pause | +seek | Next]).
This has been worked on in three commits, all of which fixed a different problem than the one that turned out to be the real cause. The current state on dev is the b60e925 build (commit 27d1772 reverted a later broken attempt). Notification has 5 controls, system tile has 2.
Symptoms
- Lockscreen "Live notifications" card:
[<<, ▶]only (no Prev, no +seek, no Next). - Quick-Settings media output panel: same.
- Expanded notification: all 5 buttons, working.
- In-app reader/library mini-player: all 5 buttons, working.
- Tapping play/pause on the system tile works correctly (the system
ACTION_PLAY_PAUSEis honored).
Environment
androidx.media3:media3-session:1.3.1(pergradle/libs.versions.toml).- Android 13+ (system surface changed; on older Android the notification itself is the surface, so 5 controls appear).
- Affected surfaces: lockscreen media card, Quick-Settings media output panel.
What has been tried
-
PR fix(player): expand lockscreen & in-app media tile to 5 controls, honor skip-duration setting #11 /
c82fc24"expand lockscreen & in-app media tile to 5 controls" — fixed the expanded notification to render 5 actions. Did not address the system tile. The notification-side fix is correct and stays. The system tile was not affected because the system tile does not read the notification's compact-view indices. -
b60e925"publish 5-button customLayout to MediaSession" — addedMediaSession.Builder.setCustomLayout(...)inPlaybackService.onCreatewith 5CommandButtons usingPlayer.COMMAND_*shortcuts. This did not change the system tile becausePlayerWrapper.createPlaybackStateCompat(verified against the AAR viajavapofmedia3-session-1.3.1.aar) only adds a button toPlaybackStateCompat.customActionswhen the button'ssessionCommand.commandCode == COMMAND_CODE_CUSTOM(value 0).Player.COMMAND_*buttons are silently dropped at that filter. -
7d54659"use custom SessionCommands so 5 buttons actually appear on lockscreen/QS tile" — replacedPlayer.COMMAND_*with customSessionCommands and added aMediaSession.Callbackthat dispatches the four unique actions (Prev/Next/PlayPause/SEEK_BY) inonCustomCommand. After install + force-stop, the user got "Playback service unavailable." in the in-app reader. Reverted in27d1772because the failure mode wasn't diagnosed and shipping unverified code had broken the service. No logcat was captured at the time.
Hypothesis (unverified)
The fix in 7d54659 is the right shape: use CommandButton.setSessionCommand(SessionCommand(action, extras)) with COMMAND_CODE_CUSTOM so the buttons survive PlayerWrapper.createPlaybackStateCompat's filter, and handle the dispatch in a MediaSession.Callback.onCustomCommand. What made it throw on device isn't known yet — the most likely candidates are:
- A Hilt injection or annotation-processor issue (callback inner class, generics).
- A
MediaSession.ConnectionResult.AcceptedResultBuilderAPI misuse in 1.3.1. - Something specific to the user's
PlaybackStateconfiguration (e.g.setMediaNotificationProvidercalled beforeMediaSession.Builder).
The bytecode of MediaSession.Builder.build() and MediaSessionImpl.<init> (Media3 1.3.1) shows no checkNotNull or checkArgument on the inputs we pass (customLayout, callback, player), so a build-time throw from those is unlikely. The throw is more likely in Media3's MediaSessionLegacyStub.<init> or a later step (e.g. notification controller connect), neither of which has been ruled out yet.
Diagnostic logging to land next
To find the actual exception, PlaybackService.onCreate and the callback are being instrumented with android.util.Log calls. After the next build, the user will install + force-stop + open a book, then run:
adb logcat -d -s LibravaultPlayback:V AndroidRuntime:E *:S
The logcat output should pin down which step in onCreate is throwing and why. Once the real cause is known, the fix can be done with confidence and a Robolectric or instrumented test added so the regression can't happen again.
Acceptance criteria
- The system media tile (lockscreen + Quick-Settings) renders all 5 controls: Prev, −seek, Play/Pause, +seek, Next.
- Tapping any of the 5 controls on the system tile actually drives the player.
-
PlaybackServicestarts without throwing inonCreate(no "Playback service unavailable." in the in-app reader). - A regression test exists in the repo that fails if this regresses (Robolectric or instrumented test that exercises the service start path).
Related
- PR fix(player): expand lockscreen & in-app media tile to 5 controls, honor skip-duration setting #11: fix(player): expand lockscreen & in-app media tile to 5 controls, honor skip-duration setting #11
feature/player/.../service/LibravaultNotificationProvider.ktfeature/player/.../service/PlaybackService.ktfeature/player/.../service/PlayerModule.ktfeature/player/.../service/CustomCommandActions.kt(introduced in7d54659, removed by27d1772)
Activity
chore(player): add Log.e breadcrumbs to PlaybackService to diagnose '…
libravault-xyz commentedon Jul 16, 2026
Update after bytecode analysis of
media3-session-1.3.1.aarI decompiled the actual AAR (not just the source) and read the bytecode byte-for-byte. Here's what I now know with high confidence.
What is certain (from bytecode)
PlayerWrapper.createPlaybackStateCompatfilterscustomLayoutbefore adding anything toPlaybackStateCompat.customActions. Reading the bytecode at thefor (i = 0; i < customLayout.size(); i++)loop:So:
Player.COMMAND_*buttons (nosessionCommand) → skipped. My hypothesis was right.SessionCommandwithcommandCode != COMMAND_CODE_CUSTOM→ skipped.SessionCommandwithcommandCode == COMMAND_CODE_CUSTOMbut!isEnabled→ skipped.CommandButton.isEnabled(button, availableSessionCommands, availablePlayerCommands)(also decompiled):button.sessionCommand != null: returnsavailableSessionCommands.contains(button.sessionCommand).button.playerCommand != COMMAND_INVALID: returnsavailablePlayerCommands.contains(button.playerCommand).MediaSessionImpl.<init>seedsplayerWrapper.availableSessionCommands = EMPTYandplayerWrapper.availablePlayerCommands = EMPTY. ThePlayerWrapperctor is called fromMediaSessionImplwith the result of anAcceptedResultBuilder.build()that has no.setAvailableSessionCommands()/.setAvailablePlayerCommands()calls — so both fields default to EMPTY.MediaSessionImpl.onConnectOnHandleronly writes back toplayerWrapperviasetAvailableFrameworkControllerCommands(sessionCmds, playerCmds)when the connecting controller isisMediaNotificationController(controller)— i.e. the app's ownMediaControllerconnecting back (package name matches app's, controllerVersion != 0, with theMediaNotificationManagerconnection hint). This setsisMediaNotificationControllerConnected = true. From that point on, systemui (com.android.systemui, controllerVersion == 0) hits the auto-accept branch (offset 0-59) and getsplayerWrapper.getCustomLayout()/getAvailableSessionCommands()/getAvailablePlayerCommands().So the race to get the system tile to show 5 buttons is: the app's own
MediaController(created byMediaNotificationManager) must connect first and return aConnectionResultwithavailableSessionCommandscontaining the same custom session commands we publish incustomLayout. Without aCallback.onConnect, no controller returns non-emptyavailableSessionCommands, so all session-command buttons failisEnabledand get filtered out.What I'm still missing
I cannot explain from the bytecode alone why the user's lockscreen currently shows 2 buttons (
<<and▶/PlayPause) rather than 0 or 5. The standardactionsbitmask increatePlaybackStateCompatis computed as:If
availablePlayerCommands == EMPTY,actionsonly containsACTION_SET_RATING— i.e. the system should render no transport buttons at all. Yet the user sees<<and▶. So something IS populatingavailablePlayerCommandson the system controller's connection.The most likely possibilities I haven't ruled out:
com.android.systemui(orcom.samsung.android.app.spage/com.sec.android.app.launcher) connects as themedia notification controller, not assystemui— i.e. Samsung routes the lockscreen surface through a different package that happens to satisfyisMediaNotificationController'spackageName == context.packageNametest under some other condition. That would explain whyavailablePlayerCommandsis non-empty on first connect.Without logcat from the user's device, I cannot tell which. The diagnostic-instrumentation commit
2d675ba(currently ondevHEAD) will surface the answer — install it, force-stop, open the book, then run:If logcat shows
MediaButtonCallback.onConnect: pkg=com.android.systemuiorpkg=com.samsung...then it's case #1 above and the architecture is fine — we just needCallback.onConnectto return the right commands for systemui. If it showspkg=xyz.libravault.reader, then the app's own controller is the one populating things.What I will NOT do
I will not push another
7d54659-style fix without logcat. That attempt was based on a partial read; the next one will be based on full evidence. The2d675babuild is currently in~/Downloads/libravault-dev-fdroid-debug.apk(md59070c554935f5e8b65c0034e4885e17c).What I'm now confident the right fix looks like
Given the bytecode analysis, the fix is almost certainly a
MediaSession.Callback.onConnectthat returns aConnectionResult.AcceptedResultBuilder(session).setAvailableSessionCommands(SessionCommands containing PREVIOUS, NEXT, PLAY_PAUSE, SEEK_BY).setAvailablePlayerCommands(<standard 5 Player.Command intents for the seek/play/preview set>).build()— for any connecting controller, including systemui. This populates the controller-sideavailableSessionCommandssoisEnabledpasses for session-command buttons increatePlaybackStateCompat, AND populatesavailablePlayerCommands(via theisMediaNotificationControllerbranch) so the next systemui connect sees the proper commands in the auto-accept path.But I won't ship that without first seeing the logcat from
2d675bato confirm exactly which controller (systemui or app-internal) is what populatesavailablePlayerCommandstoday.libravault-xyz commentedon Jul 16, 2026
Confirmed root cause:
dev(b60e925state, post-27d1772revert) is still on the approach that point 2 in this issue already showed doesn't work — nothing regressed further, but nothing was fixed either.PlaybackService.onCreatecallsbuilder.setCustomLayout(standardStrip)wherestandardStripcomes fromLibravaultNotificationProvider.buildStandardStrip, and every button there is built with.setPlayerCommand(Player.COMMAND_SEEK_*...)— none has asessionCommand.Two independent consumers of this:
getMediaButtons/addNotificationActions) buildsRemoteViewsactions straight from theCommandButtonlist — doesn't care aboutsessionCommand. This is why the expanded notification is fine.PlaybackStateCompat, built via Media3's legacy bridge (PlayerWrapper.createPlaybackStateCompat). That bridge only forwards acustomLayoutentry intoPlaybackStateCompat.customActionswhensessionCommand?.commandCode == COMMAND_CODE_CUSTOM. Player-command buttons havesessionCommand == null, so all 5 get filtered out before the tile sees them.What the tile shows instead is the standard-actions bitmask, derived automatically from
Player.Commandsavailability, independent ofcustomLayout:ACTION_PLAY_PAUSE(always) +ACTION_REWIND(COMMAND_SEEK_BACKavailable) =[<<, ▶/||]. Prev/Next are disabled (single-item audiobook playlist), which is why they drop out too.So attempt 3 (
7d54659) was the right shape — realSessionCommands withCOMMAND_CODE_CUSTOM+MediaSession.Callback.onCustomCommandis the only path that populatescustomActions. It just crashed ("Playback service unavailable.") before the cause was captured. Recommend reapplying7d54659on a branch with the existingLog.i/Log.einstrumentation inPlaybackService.onCreateand actually grabbing:before any further revert, so the real exception (DI,
AcceptedResultBuildermisuse, or ordering withsetMediaNotificationProvider) gets identified instead of guessed at again.chore(version): bump to 0.4.2-alpha (versionCode 7) for lockscreen mi…
test(player): cover PlaybackService, and add the repo's first Hilt te…