Scottish-Tech-Army / Soundscape-Android

This is the source for an Android version of the original iOS Soundscape app
https://scottish-tech-army.github.io/Soundscape-Android/
Other
2 stars 2 forks source link

Handle media controls from headphones #141

Open davecraig opened 3 days ago

davecraig commented 3 days ago

I got this one from the tutorials. The text there is:

You can access certain features in Soundscape with the help of the media control buttons on your headphones. This functionality works with any wired or Bluetooth headphones that have media control buttons like Play, Pause, Next, Previous and others. Different headphones may include different buttons so please refer to the list of actions below to determine which ones are available to you.

Also note that this feature only works with headphones that support Apple's media controls (such as play and pause). Headphone media controls can be used while Soundscape is running. This is true whether you are currently in Soundscape or while Soundscape is in the background and even while your device is locked. Note however that headphone media control buttons will not work with Soundscape if you are playing audio like music, podcasts or videos with another app.

Obviously we can ignore the mention of Apple here and support whatever we can via Android. The tutorial goes on to explain that you can access the following features in Soundscape using the media control buttons on your headphones:

⏯ Play/Pause: Mute any current callouts and if the audio beacon is set, toggle the beacon audio.

⏭ Next: Callout "My Location".

⏮ Previous: Repeat last callout.

⏩ Skip Forward: Toggle callouts On and Off.

⏪ Skip Backward: Callout "Around Me".

The interaction will be with the soundscape foreground service as it needs to work when the phone is locked. We should also support and test external media controls e.g. https://www.amazon.co.uk/dp/B07JQ8Q6X6.

davecraig commented 1 day ago

In order to get the media control button input it looks like we'll need to make our SoundscapeService a MediaSessionService see https://developer.android.com/media/media3/session/background-playback. I've started work on a branch named media-transport-controls on my fork. To create a MediaSession we also need a dummy media player. This all seems rather hard work for what we need so I've put it aside and will mull it over and confer.