Skip to content

Commit 07e9c65

Browse files
icbakertianyif
authored andcommitted
Handle HEADSETHOOK as 'play' in MediaButtonReceiver.onReceive
Issue: #1581 PiperOrigin-RevId: 662515428 (cherry picked from commit c48c051)
1 parent eebf081 commit 07e9c65

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

RELEASENOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
action, as
3434
[documented](https://developer.android.com/reference/androidx/media3/session/MediaSession#media-key-events-mapping)
3535
([#1493](https://github.com/androidx/media/issues/1493)).
36+
* Handle `KEYCODE_HEADSETHOOK` as a 'play' command in
37+
`MediaButtonReceiver` when deciding whether to ignore it to avoid a
38+
`ForegroundServiceDidNotStartInTimeException`
39+
([#1581](https://github.com/google/ExoPlayer/issues/1581)).
3640
* UI:
3741
* Downloads:
3842
* OkHttp Extension:

libraries/session/src/main/java/androidx/media3/session/MediaButtonReceiver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ public final void onReceive(Context context, @Nullable Intent intent) {
123123
KeyEvent keyEvent = checkNotNull(intent.getExtras()).getParcelable(Intent.EXTRA_KEY_EVENT);
124124
if (keyEvent != null
125125
&& keyEvent.getKeyCode() != KeyEvent.KEYCODE_MEDIA_PLAY
126-
&& keyEvent.getKeyCode() != KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
126+
&& keyEvent.getKeyCode() != KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE
127+
&& keyEvent.getKeyCode() != KeyEvent.KEYCODE_HEADSETHOOK) {
127128
// Starting with Android 8 (API 26), the service must be started immediately in the
128129
// foreground when being started. Also starting with Android 8, the system sends media
129130
// button intents to this receiver only when the session is released or not active, meaning

0 commit comments

Comments
 (0)