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

573 Views Asked by At

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.

2

There are 2 best solutions below

0
nverinaud On BEST ANSWER

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

2
1234567 On

If you use media3 it supports your requirements

reference

https://youtu.be/sTIBDcyCmCg?t=737

you just need to extend MediaSessionService/medialibraryservice and override onGetSession

Details of MediaSessionService/medialibraryservice