termux-api icon indicating copy to clipboard operation
termux-api copied to clipboard

Media Button Receiver

Open Neo-Oli opened this issue 8 years ago • 5 comments

We talked about this on the IRC before. A command that would register itself as Media Key Receiver, so that the Play/Pause, Next and Back could be captured. It would probably make sense if it would just print something like "KEY_NEXT" (but as close to the Android API as possible) to stdout.

Neo-Oli avatar Jan 30 '17 18:01 Neo-Oli

Maybe instead of just a media button receiver, this could become a general event monitor. I imagine something like this:

$ termux-event-monitor
{"type"="media_key", "value": "play"}
{"type"="media_key", "value": "next"}
{"type": "telephony","value": {"direction": "incoming","event": "start", "number":"0123456789"}}
{"type": "telephony","value": {"direction": "incoming","event": "end", "number":"0123456789"}}
{"type"="media_key", "value": "play"}

Events that I would like to be able to receive:

  • Media button keys (to control mpv)
  • Telephony events (to automatically play/pause mpv)
  • Screen on/off
  • Wifi on/off
  • Wifi connected/disconnected
  • Bluetooth connected/disconnected
  • Impending reboot
  • SMS received
  • Device Plugged/unplugged
  • Orientation changed

I wonder how Tasker does it. Is there some event log in Android that has all this information?

Neo-Oli avatar Apr 27 '17 13:04 Neo-Oli

Afaik most of those are intents or broadcasts. It would require to register for each of those intents and broadcasts to receive them, something that would be very useful.

Roughly the problem could be separated in this parts:

  • register a few well known intent handlers such as android.intent.action.MEDIA_BUTTON and handle those
  • catch (almost) all intents using techniques similar to https://f-droid.org/repository/browse/?fdfilter=intentintercept&fdid=uk.co.ashtonbrsc.android.intentintercept
  • get at content providers like this app: https://f-droid.org/repository/browse/?fdfilter=content+provider&fdid=de.k3b.android.contentproviderhelper
  • do nifty protocol specific things like https://f-droid.org/repository/browse/?fdfilter=broadcast&fdid=com.samebits.beacon.locator

ghost avatar May 19 '17 20:05 ghost

I use mpv on termux and I would love to show media buttons, then write a script to interact with mpv when pressed

JJRcop avatar Jul 27 '22 17:07 JJRcop