-
Notifications
You must be signed in to change notification settings - Fork 575
Description
Hi,
I'm trying to create an app for playing audio books that has really fine grained controls via headset buttons
(MediaButtons).
Unfortunately I did not find any way to implement or receive ACTION_UP
or LONGPRESS
events while running in the background (app as a foreground service). The recommended way of implementing custom MediaButton behaviour is (to my knowledge) implementing
MediaLibrarySession.Callback
withoverride fun onMediaButtonEvent(session: MediaSession, controllerInfo: ControllerInfo, intent: Intent)
My Example project:
https://github.com/pilabor/Voice/blob/df3415bd4e57e24ada1c777d2c0997b8ed7c0342/playback/src/main/kotlin/voice/playback/session/LibrarySessionCallback.kt#L315
Unfortunately this does not offer the possibility of capturing LONGPRESS
events while in background (e.g. screen off). When in foreground, a LONGPRESS
delays the emitted event for 1000ms
, which is also unfortunate, because combinations like KEY_DOWN
, KEY_UP
to e.g. run a player action next track
has to be delayed for at least 1050ms to wait for a possible LONGPRESS
coming after that, which makes all control patterns feel laggy (650ms would be the timing that feels right).
On old Apple iPods the following headset click patterns where implemented (CLICK
means keydown + keyup, LONGPRESS
means holding keydown:
1 CLICK
- Play / Pause2 CLICK
- Next track or chapter3 CLICK
- Previous track or chapterLONGPRESS
- read out current track title1 CLICK + LONGPRESS
- fast forward as long as the button is held down2 CLICK + LONGPRESS
- rewind as long as the button is held down
I can't implement these on Android with its current state and I would love to have more control over the button patterns.
Is there any way to capture raw KEY_DOWN
and KEY_UP
events without ANY delay or is the current state intended behavior somehow?
Feel free to convert this into a feature request, if required.