Control playback using headset media buttons when using Android Select to Speak functionality



  • What I ideally want to achieve: TTS for any text I see on my phone, with the user experience similar to my podcast app.

    My current approach: Use https://support.google.com/accessibility/android/answer/7349565?hl=en functionality.
    This works to read the text on the screen, works in the background, etc which is great. But it totally ignores any attempt to control the playback using media buttons on my headphones.

    Question:
    How do I make Select to Speak work with media buttons on headphones:

    • Play/pause
    • Skip back/forward (ideally allowing me specify time interval for this)

    Or is there an alternative to Select to Speak that works better with media controls?



  • You may be able to set up a custom accessibility service ( https://developer.android.com/guide/topics/ui/accessibility/service ) and listen for KEYCODE_MEDIA_PLAY_PAUSE using a background service ( https://stackoverflow.com/questions/21175914/determine-if-headphones-are-plugged-in-through-appwidgetprovider-pause-music-wh ).

    Then, as you described, the custom accessibility service could detect that you've short-pressed (KEYCODE_MEDIA_PLAY_PAUSE) or long-pressed (KEYCODE_VOICE_ASSIST) the button on your headphones.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2