androidandroid-mediasessionmediabrowserservicecompat

Bluetooth Headset media buttons not working on Android using media2 nor media3


I'm building an app which needs to trigger an audio menu. For that purpose I need to intercept clicks on media buttons, specifically the play/pause button.

It is working fine using wired headsets and using the media button present in the Notification for my foreground service.

But I do not receive media button events when I use a Bluetooth Headset.

I am missing something because the UAMP and media3 samples work.

Question is : what am I missing ?

The samples are so complex I could not find out, I wish there was a sample code not using ExoPlayer but there is not.

I made a sample project demonstrating the issue here : https://github.com/Ryfacto/MediaBluetoothHeadsetIssue.

Thank you for your help, I'm really desperate. 😩


Solution

  • The problem seems related to an android bug when using TTS to play audio.

    See this answer : Catching android media button events

    This issue is known by Google and referenced here : https://issuetracker.google.com/issues/249741615