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 with
override 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 / Pause
2 CLICK - Next track or chapter
3 CLICK - Previous track or chapter
LONGPRESS - read out current track title
1 CLICK + LONGPRESS - fast forward as long as the button is held down
2 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_UPevents without ANY delay or is the current state intended behavior somehow?
Feel free to convert this into a feature request, if required.
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_UPorLONGPRESSevents while running in the background (app as a foreground service). The recommended way of implementing custom MediaButton behaviour is (to my knowledge) implementingMediaLibrarySession.Callbackwithoverride 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
LONGPRESSevents while in background (e.g. screen off). When in foreground, aLONGPRESSdelays the emitted event for1000ms, which is also unfortunate, because combinations likeKEY_DOWN,KEY_UPto e.g. run a player actionnext trackhas to be delayed for at least 1050ms to wait for a possibleLONGPRESScoming 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 (
CLICKmeans keydown + keyup,LONGPRESSmeans 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 downI 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_DOWNandKEY_UPevents without ANY delay or is the current state intended behavior somehow?Feel free to convert this into a feature request, if required.