androidx / androidx/media

In `MediaButtonReceiver`, don't always bail out for `KeyEvent != play`

Open
#3,340 2 comments 0 reactions 1 assignee View on GitHub

@marcbaechinger is already working on this.

Since Jul 22, 2026.

enhancement
Dominant language
Java
Stars
3k
Forks
955
Avg merge
12d 14h
Merged PRs (30d)
2

Description

Use case description

I recently switched an app from a custom playback service to the more "standardized" media3 MediaLibraryService. A problem I ran into is that a simulated media pause button event (sent as a broadcast) does not work anymore. This seems to be a deliberate decision; the MediaButtonReceiver bails out for key events that are not "play":

https://github.com/androidx/media/blob/aceb0bc9da047b1ddc29ed493af7a0751aeb8acb/libraries/session/src/main/java/androidx/media3/session/MediaButtonReceiver.java#L162-L165

Proposed solution

Is there a way for MediaButtonReceiver to detect whether the service it wants to start is already running? If it is already running, we do not risk a ForegroundServiceDidNotStartInTimeException by sending the key event to it. So it should be safe to relay all the other key events (pause, fast forward, etc) as well.

Alternatives considered
  • Writing our own MediaButtonReceiver to do exactly that would of course be possible. However, I feel like adding this to the main media3 library as some kind of backwards compatibility layer could benefit additional users of the library and avoid them spending as much time on this as I have. Also, it avoids adding a bunch of custom code around media3 that needs to stay in sync with the original media3 implementation.
  • Contact all third party app developers who control media playback and ask them to implement control via media sessions. I'm not convinced that I can convince several third party developers to do that. This is also not something we can tell to our users: "your macro button no longer works because we made a change forcing the developer of your macro button app to update their app". (even though our app update is in beta, we already got reports about two different 3rd party media control apps no longer working)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.