Skip to content

Commit c48c051

Browse files
icbakercopybara-github
authored andcommitted
Handle HEADSETHOOK as 'play' in MediaButtonReceiver.onReceive
Issue: androidx/media#1581 #cherrypick PiperOrigin-RevId: 662515428
1 parent 2d527b0 commit c48c051

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

RELEASENOTES.md

+4
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@
100100
action, as
101101
[documented](https://developer.android.com/reference/androidx/media3/session/MediaSession#media-key-events-mapping)
102102
([#1493](https://github.com/androidx/media/issues/1493)).
103+
* Handle `KEYCODE_HEADSETHOOK` as a 'play' command in
104+
`MediaButtonReceiver` when deciding whether to ignore it to avoid a
105+
`ForegroundServiceDidNotStartInTimeException`
106+
([#1581](https://github.com/google/ExoPlayer/issues/1581)).
103107
* UI:
104108
* Downloads:
105109
* OkHttp Extension:

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ public final void onReceive(Context context, @Nullable Intent intent) {
128128
}
129129
if (Util.SDK_INT >= 26) {
130130
if (keyEvent.getKeyCode() != KeyEvent.KEYCODE_MEDIA_PLAY
131-
&& keyEvent.getKeyCode() != KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
131+
&& keyEvent.getKeyCode() != KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE
132+
&& keyEvent.getKeyCode() != KeyEvent.KEYCODE_HEADSETHOOK) {
132133
// Starting with Android 8 (API 26), the service must be started immediately in the
133134
// foreground when being started. Also starting with Android 8, the system sends media
134135
// button intents to this receiver only when the session is released or not active, meaning

0 commit comments

Comments
 (0)