Skip to content

Commit

Permalink
Handle HEADSETHOOK as 'play' in MediaButtonReceiver.onReceive
Browse files Browse the repository at this point in the history
Issue: #1581

PiperOrigin-RevId: 662515428
(cherry picked from commit c48c051)
  • Loading branch information
icbaker authored and tianyif committed Aug 21, 2024
1 parent eebf081 commit 07e9c65
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
action, as
[documented](https://developer.android.com/reference/androidx/media3/session/MediaSession#media-key-events-mapping)
([#1493](https://github.com/androidx/media/issues/1493)).
* Handle `KEYCODE_HEADSETHOOK` as a 'play' command in
`MediaButtonReceiver` when deciding whether to ignore it to avoid a
`ForegroundServiceDidNotStartInTimeException`
([#1581](https://github.com/google/ExoPlayer/issues/1581)).
* UI:
* Downloads:
* OkHttp Extension:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public final void onReceive(Context context, @Nullable Intent intent) {
KeyEvent keyEvent = checkNotNull(intent.getExtras()).getParcelable(Intent.EXTRA_KEY_EVENT);
if (keyEvent != null
&& keyEvent.getKeyCode() != KeyEvent.KEYCODE_MEDIA_PLAY
&& keyEvent.getKeyCode() != KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
&& keyEvent.getKeyCode() != KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE
&& keyEvent.getKeyCode() != KeyEvent.KEYCODE_HEADSETHOOK) {
// Starting with Android 8 (API 26), the service must be started immediately in the
// foreground when being started. Also starting with Android 8, the system sends media
// button intents to this receiver only when the session is released or not active, meaning
Expand Down

0 comments on commit 07e9c65

Please sign in to comment.