这是indexloc提供的服务,不要输入任何密码
Skip to content

More fine grained control over MediaButton events possible (e.g. LONGPRESS)? #2637

@sandreas

Description

@sandreas

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.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions