Repository navigation
fix(android): resolve media button handling - #48
Conversation
|
Hi @a-tunc Apologies for the slow response—I've been quite busy with school lately. I believe this should now be resolved in the latest branch. If you get a chance, could you give it a try with your headset and verify if media controls are functioning properly? Thank you so much for your patience and for reporting this! |
|
Hi @wyrindev , I used this branch for testing: I tested it on an Android 11 device with a bluetooth headset. Unfortunately media control buttons on the headset still do not work. What I mean is there is no response from the example app whichever button I press on the headphones. Here is the output of logcat command and I added some comments to shed a light to what I did when. I hope this helps. |
|
😳 Thanks for the report and logs. I'll look into this. |
|
After investigating the audio routing dispatch mechanism ( Verified on Android 11 (API 30) and modern Android versions—media button events are routed. |
|
Tested on Android 11 device. I tested pause/play buttons as well as skip-to-previous and skip-to-next buttons. All of them work perfectly.! Thank you for your time/effort to get this working. |
Description
Fixes #38.
This PR addresses hardware and Bluetooth media button key event dispatching on Android and introduces audio source switching to the example application.
Changes
1. Android Media Button Handling
MediaButtonReceiver: Added an explicitBroadcastReceiverto handleACTION_MEDIA_BUTTONintents and routeKeyEventdirectly to the activeFlutterMediaSessionServiceinstance in memory, avoidingForegroundServiceStartNotAllowedExceptionon Android 12+.handleMediaKeyEventinFlutterMediaSessionServiceso key events from bothMediaSession.Callback.onMediaButtonEventandonStartCommandshare consistent dispatch logic to Flutter.USAGE_MEDIAandCONTENT_TYPE_MUSICto forward player attributes for better system audio routing compatibility.setMediaButtonReceiverreflection calls onsessionCompat, aligning with standard Media3 automated session binding.2. Example App Improvements
SettingsPanel(OfficialSoundHelix vs. CloudflareCDN) to accommodate varied network latency across regions.example/android/app/build.gradle.ktsto dynamically support AGP 9.0+ built-in Kotlin while safely configuringjvmTarget = 17for both KGP 1.x and 2.x..gitignore: Aligned root.gitignorewith the standard Flutter repository template.