Forcing volume buttons to STEAM_MUSIC while Android app is in background

6 views
Skip to first unread message

Jonathan Baudanza

unread,
Jun 19, 2022, 6:22:16 PM (6 days ago) Jun 19
to discuss-webrtc
I have an Android app that is using libwebrtc for doing voice conference calls.

My goal is to be able to move all my webrtc audio from STREAM_VOICE onto STREAM_MUSIC. I'm doing this so that it will be possible to turn the volume down to zero, which is not possible on STREAM_VOICE.

I'm able to successfully redirect webrtc audio to STREAM_MUSIC by setting the audio attributes when I initialize the JavaAudioDeviceModule. I'm using the same audio attributes in my AudioFocusRequest.

While webrtc is enabled, I set the AudioManager mode to MODE_IN_COMMUNICATION. My understanding is that this is required to get echo cancellation and possibly other features to work correctly. However, this has the side effect of forcing the system to route the device volume control events to STREAM_VOICE, even though STREAM_MUSIC is active.

I can override this behavior while the app is active by using an onKeyDown handler in my activity. However, when the app is in the background, I'm not able to do this.

If I disable MODE_IN_COMMUNICATION, the volume buttons will control STREAM_MUSIC, which is what I want. But, libwebrtc has a lot of warnings in the comments saying not to do this. So I'm a little hesitant to ship it like this.

Is there another way I can force the phone volume buttons to control the STEAM_MUSIC while the app is in the background?

Thank you!
Reply all
Reply to author
Forward
0 new messages