mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Transform double-tap of HEADSETHOOK
to skip-to-next
As reported in Issue: androidx/media#1493 we already use `HEADSETHOOK` to start waiting for a double-tap, but we don't consider it for the second tap. Similarly, we previously considered `PLAY` for the second tap, but not the first. Only `HEADSETHOOK` and `PLAY_PAUSE` are [documented](https://developer.android.com/reference/androidx/media3/session/MediaSession#media-key-events-mapping) to transform double-tap to `seekToNext`. So this change removes the `PLAY` detection from the second tap. #cherrypick PiperOrigin-RevId: 651017522
This commit is contained in:
parent
e8778d77fa
commit
c64dacf3df
@ -64,6 +64,10 @@
|
|||||||
playback can't be suppressed without the system crashing the service
|
playback can't be suppressed without the system crashing the service
|
||||||
with a `ForegroundServiceDidNotStartInTimeException`
|
with a `ForegroundServiceDidNotStartInTimeException`
|
||||||
([#1528](https://github.com/google/ExoPlayer/issues/1528)).
|
([#1528](https://github.com/google/ExoPlayer/issues/1528)).
|
||||||
|
* Transform a double-tap of `KEYCODE_HEADSETHOOK` into a 'seek to next'
|
||||||
|
action, as
|
||||||
|
[documented](https://developer.android.com/reference/androidx/media3/session/MediaSession#media-key-events-mapping)
|
||||||
|
([#1493](https://github.com/androidx/media/issues/1493)).
|
||||||
* UI:
|
* UI:
|
||||||
* Downloads:
|
* Downloads:
|
||||||
* OkHttp Extension:
|
* OkHttp Extension:
|
||||||
|
@ -1242,7 +1242,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isMediaNotificationControllerConnected()) {
|
if (!isMediaNotificationControllerConnected()) {
|
||||||
if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE && doubleTapCompleted) {
|
if ((keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_HEADSETHOOK)
|
||||||
|
&& doubleTapCompleted) {
|
||||||
// Double tap completion for legacy when media notification controller is disabled.
|
// Double tap completion for legacy when media notification controller is disabled.
|
||||||
sessionLegacyStub.onSkipToNext();
|
sessionLegacyStub.onSkipToNext();
|
||||||
return true;
|
return true;
|
||||||
@ -1262,7 +1263,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
ControllerInfo controllerInfo = checkNotNull(instance.getMediaNotificationControllerInfo());
|
ControllerInfo controllerInfo = checkNotNull(instance.getMediaNotificationControllerInfo());
|
||||||
Runnable command;
|
Runnable command;
|
||||||
int keyCode = keyEvent.getKeyCode();
|
int keyCode = keyEvent.getKeyCode();
|
||||||
if ((keyCode == KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KEYCODE_MEDIA_PLAY)
|
if ((keyCode == KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_HEADSETHOOK)
|
||||||
&& doubleTapCompleted) {
|
&& doubleTapCompleted) {
|
||||||
keyCode = KEYCODE_MEDIA_NEXT;
|
keyCode = KEYCODE_MEDIA_NEXT;
|
||||||
}
|
}
|
||||||
|
@ -346,6 +346,20 @@ public class MediaSessionKeyEventTest {
|
|||||||
player.awaitMethodCalled(MockPlayer.METHOD_SEEK_TO_NEXT, TIMEOUT_MS);
|
player.awaitMethodCalled(MockPlayer.METHOD_SEEK_TO_NEXT, TIMEOUT_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void playPauseKeyEvent_doubleTapOnHeadsetHook_seekNext() throws Exception {
|
||||||
|
Assume.assumeTrue(Util.SDK_INT >= 21); // TODO: b/199064299 - Lower minSdk to 19.
|
||||||
|
handler.postAndSync(
|
||||||
|
() -> {
|
||||||
|
player.playWhenReady = true;
|
||||||
|
player.playbackState = Player.STATE_READY;
|
||||||
|
});
|
||||||
|
|
||||||
|
dispatchMediaKeyEvent(KeyEvent.KEYCODE_HEADSETHOOK, /* doubleTap= */ true);
|
||||||
|
|
||||||
|
player.awaitMethodCalled(MockPlayer.METHOD_SEEK_TO_NEXT, TIMEOUT_MS);
|
||||||
|
}
|
||||||
|
|
||||||
private MediaController connectMediaNotificationController() throws Exception {
|
private MediaController connectMediaNotificationController() throws Exception {
|
||||||
return threadTestRule
|
return threadTestRule
|
||||||
.getHandler()
|
.getHandler()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user