Skip to content

MediaButtonReceiver and KEYCODE_HEADSETHOOK #1581

Closed

Description

@DavidEdwardsBL

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

Activity

  1. DavidEdwardsBL commented on Aug 1, 2024

    @DavidEdwardsBL
    Author

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

  2. icbaker commented on Aug 5, 2024

    @icbaker
    Collaborator

    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?

  3. DavidEdwardsBL commented on Aug 5, 2024

    @DavidEdwardsBL
    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.

  4. icbaker commented on Aug 13, 2024

    @icbaker
    Collaborator

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

  5. locked and limited conversation to collaborators on Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions