Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MediaButtonReceiver and KEYCODE_HEADSETHOOK #1581

Closed
1 task
DavidEdwardsBL opened this issue Aug 1, 2024 · 4 comments
Closed
1 task

MediaButtonReceiver and KEYCODE_HEADSETHOOK #1581

DavidEdwardsBL opened this issue Aug 1, 2024 · 4 comments
Assignees
Labels

Comments

@DavidEdwardsBL
Copy link

Version

Media3 main branch

More version details

No response

Devices that reproduce the issue

SDK_INT >= 26

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

  1. Run a media app
  2. Play some content
  3. Pause it
  4. Swipe the app away from recents
  5. Make a headset hook event adb shell input keyevent 79

Expected result

The App should behave as if a play event was received.

Actual result

The App delivers

Ignore key event that is not a play command on API 26 or above to avoid an 'ForegroundServiceDidNotStartInTimeException'

Related issue: #1493

The headset hook key event is not taken into account when only allowing a play command through the MediaButtonReceiver.

Media

n/a

Bug Report

@DavidEdwardsBL
Copy link
Author

@icbaker I was going to post in the previous issue, but thought this is perhaps unique enough for a new issue.

@icbaker
Copy link
Collaborator

icbaker commented Aug 5, 2024

Would you be able to clarify if this is a change/regression introduced in 1.4.0 (i.e. not present in 1.3.1, and maybe caused by c64dacf), or a longstanding inconsistency where we are not handling HEADSETHOOK the same way as PLAY?

@DavidEdwardsBL
Copy link
Author

The code in question is quite old:

https://github.com/androidx/media/blame/b01c6ffcb3fca3d038476dab5d3bc9c9f2010781/libraries/session/src/main/java/androidx/media3/session/MediaButtonReceiver.java#L133

This part exists over a year, so it is not a problem introduced in 1.4.0.

The issue is here:

      if (keyEvent != null
          && keyEvent.getKeyCode() != KeyEvent.KEYCODE_MEDIA_PLAY
          && keyEvent.getKeyCode() != KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {

Whereby KEYCODE_MEDIA_PLAY and KEYCODE_MEDIA_PLAY_PAUSE are detected, but not the KEYCODE_HEADSETHOOK.

copybara-service bot pushed a commit that referenced this issue Aug 13, 2024
Issue: #1581

#cherrypick

PiperOrigin-RevId: 662515428
@icbaker
Copy link
Collaborator

icbaker commented Aug 13, 2024

Thanks for the extra info - this should be resolved by the commit linked above.

@icbaker icbaker closed this as completed Aug 13, 2024
colinkho pushed a commit to colinkho/media that referenced this issue Aug 15, 2024
tianyif pushed a commit that referenced this issue Aug 22, 2024
Issue: #1581

PiperOrigin-RevId: 662515428
(cherry picked from commit c48c051)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants