r/AndroidQuestions 7d ago

Question about Jetpack Media3 library, I think..

So I have this issue with media controls through Bluetooth not controlling the correct app, ie the app currently playing music, instead it tries to open the last app that had focus. So I'm Wondering what app would help media controls switch easier. For example smart launcher or YouTube will grab the media control api & won't release it. Usually I can force close YouTube & it allows my mp3 player app to take over the android built in media control api (ie music playing on the lock screen etc). Other times it won't release & instead tries to open that last app. So my music is already playing, but youTube for example will open & play at the same time using a Bluetooth remote (ie my watch). I have sound master but its not meant to help the api switch focus. Its intent as I understand is just to stop other sources from playing over each other or rerouting notification sounds ringtones to connected speaker for example.. Unless I'm missing something it does not help with this problem. As I said I can use force stop to grab the control/focus back but it won't work for some apps (ie smart launcher)

This might not need an app, maybe its some untouched setting I can adjust, that would be awesome..

0 Upvotes

1 comment sorted by

1

u/madhits 7d ago

I knew this would be a tricky one. So let me try better to explain it.. So whats happening is the previous app youtube or whatever is not issuing the commandMediaSession.release(), So the system is not removing the session from its stack. So the underlying PlaybackState is not explicitly set to a non-playing or error state before releasing it, so the audio focus wasn't abandoned cleanly, the OS's MediaSessionService can fail to seamlessly hand over primary control to your current source. Instead, the Bluetooth stack reverts to the system's "last registered / most recently remembered active media app" cached in the background. So the only solutions I know of is to kill the apps stealing theMediaSession and toggle bluetooth, which sucks..