1

I installed some alarms, then I configured them... then I configured the phone settings the standard wake signal for a long music.

I ended up that something is playing music in my ear, in the background, and I have no way to know, which app is doing it.

1

1 Answer 1

5

Try this command inside adb shell dumpsys media_session | grep -E "Media button session is.*userId=0"

It will output like this

blueline:/ $ dumpsys media_session | grep -E "Media button session is.*userId=0"
  Media button session is com.bsbportal.music/media_session (userId=0)

Here is a single liner command for getting the package name of app playing the audio

dumpsys media_session | grep -E "Media button session is.*userId=0" | sed "s/.*Media button session is//g" | cut -d'/' -f1 | xargs

blueline:/ $ dumpsys media_session | grep -E "Media button session is.*userId=0" | sed "s/.*Media button session is//g" | cut -d'/' -f1 | xargs
com.bsbportal.music
blueline:/ $ dumpsys media_session | grep -E "Media button session is.*userId=0" | sed "s/.*Media button session is//g" | cut -d'/' -f1 | xargs
com.google.android.youtube
blueline:/ $

If you've paused the Music playing apps then you would get the same above output.

If you really wanna confirm if the audio/music or some content is really being played then you can combine the above command with another one to check its playback state.

dumpsys media_session | grep -E "Media button session is.*userId=0" -A11 | grep "state=" | sed "s/.*{state=//g" | cut -d ',' -f1

Returns "3" for playing state and "2" for paused state.

blueline:/ $ dumpsys media_session | grep -E "Media button session is.*userId=0" -A11 | grep "state=" | sed "s/.*{state=//g" | cut -d ',' -f1
2
blueline:/ $

All my tests were done on Google Pixel 3 running on Android 12, the shell commands might return a different output on different Android versions so make sure to fine tune them. (Or revert back to me if you need any help)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .