Treat KEYCODE_MEDIA_PLAY as explicit play instead of a play/pause toggle#5426
Draft
joashrajin wants to merge 1 commit into
Draft
Treat KEYCODE_MEDIA_PLAY as explicit play instead of a play/pause toggle#5426joashrajin wants to merge 1 commit into
joashrajin wants to merge 1 commit into
Conversation
Car head units (and other media controllers) send an explicit KEYCODE_MEDIA_PLAY to resume playback - e.g. ZLink5/Android Auto sends it when shifting out of reverse. Both media-session paths mapped it to a single-tap play/pause toggle, so it paused already-playing audio. Keep KEYCODE_MEDIA_PLAY routed through MediaEventQueue (preserving the Pixel Buds spurious-duplicate suppression after next/previous), but when a single tap originates from KEYCODE_MEDIA_PLAY, resume instead of toggling. PLAY_PAUSE/HEADSETHOOK still toggle. Fixes #3919
Collaborator
Generated by 🚫 Danger |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an Android Auto / car head-unit regression where an explicit KEYCODE_MEDIA_PLAY event (commonly sent to resume playback) was being treated as a play/pause toggle, causing already-playing audio to pause unexpectedly. The change is applied in both the Media3 and legacy MediaSession paths to ensure consistent behavior regardless of the media3_session feature flag.
Changes:
- Treat
KEYCODE_MEDIA_PLAYsingle-tap as an explicit play/resume command (callsplayQueueSuspend) instead ofplayPausetoggle. - Preserve
KEYCODE_MEDIA_PLAY_PAUSEandKEYCODE_HEADSETHOOKas toggle behavior. - Update/adjust unit test coverage to assert the new
KEYCODE_MEDIA_PLAYsemantics.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/Media3SessionCallback.kt | In the Media3 session callback path, route KEYCODE_MEDIA_PLAY single-taps to explicit resume (playQueueSuspend) instead of toggling. |
| modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/MediaSessionManager.kt | In the legacy MediaSessionCompat callback path, treat KEYCODE_MEDIA_PLAY single-taps as explicit play/resume while leaving toggle keys unchanged. |
| modules/services/repositories/src/test/java/au/com/shiftyjelly/pocketcasts/repositories/playback/Media3SessionCallbackTest.kt | Update the regression test to verify KEYCODE_MEDIA_PLAY triggers playQueueSuspend and never calls playPause. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Car head units and some other media controllers send an explicit
KEYCODE_MEDIA_PLAYto resume playback — for example, a Chinese head unitrunning ZLink5/Android Auto sends it when shifting out of reverse. Both
media-session code paths mapped
KEYCODE_MEDIA_PLAYto a single-tapplay/pause toggle, so when audio was already playing the toggle paused it.
This matches the reporter's logs: a
KEYCODE_MEDIA_PLAYfromgearheadimmediately followed by "Paused - Not transient".
KEYCODE_MEDIA_PLAYis an explicit play command, distinct fromKEYCODE_MEDIA_PLAY_PAUSE(toggle) andKEYCODE_HEADSETHOOK(toggle). This PRmakes a single tap originating from
KEYCODE_MEDIA_PLAYresume playbackrather than toggle, so it never pauses already-playing audio.
The key still flows through
MediaEventQueue, preserving the existingsuppression of the spurious
KEYCODE_MEDIA_PLAYthat some Bluetooth headphones(e.g. Pixel Buds) emit right after a next/previous gesture.
KEYCODE_MEDIA_PAUSEwas already handled correctly and is unchanged.
Changed in both playback paths so the fix applies regardless of the
media3_sessionfeature flag:Media3SessionCallback— the Media3 rollout pathMediaSessionManager— the legacy path that ships on release builds todayFixes #3919
Testing Instructions
These steps simulate the car's media-button behaviour with ADB (keycode 126 =
KEYCODE_MEDIA_PLAY, 85 =KEYCODE_MEDIA_PLAY_PAUSE). Repeat with the Media3MediaSession dev toggle both OFF and ON to cover both code paths.
adb shell input keyevent 126.adb shell input keyevent 126again.adb shell input keyevent 85.KEYCODE_MEDIA_PLAY_PAUSEstill toggles (pauses), confirming toggle behaviour is unchanged.Automated coverage:
Media3SessionCallbackTest—KEYCODE_MEDIA_PLAY resumes playback instead of toggling(updated), and theexisting
KEYCODE_MEDIA_PLAY_PAUSE single tap calls playPausestill passes.Screenshots or Screencast
Checklist
./gradlew spotlessApplyto automatically apply formatting/linting)modules/services/localization/src/main/res/values/strings.xmlI have tested any UI changes...