Scenario
After joining a voice channel, the volume buttons on an Android device no longer adjust the media volume.
Resolution
When you join a voice channel on an Android device, the volume buttons automatically change from adjusting the media volume to the voice volume. This change is not due to Vivox, but occurs due to the use of the AudioManager.MODE_IN_COMMUNICATION mode. You can change this behavior by overriding the button key events.
In the following example code, which would be added to your Activity, the button keys events are captured and used to set the MediaPlayer volume:
@Override public boolean dispatchKeyEvent(KeyEvent event) { int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: ((AudioManager)getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI); return true; case KeyEvent.KEYCODE_VOLUME_DOWN: ((AudioManager)getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI); return true; default: return super.dispatchKeyEvent(event); } }
Depending on your needs, you can add more logic in the cases where the keys can also be used to modify the AudioManager.STREAM_VOICE_CALL. This could be triggered with some kind of UI toggle between the AudioManager.STREAM_MUSIC and AudioManager.STREAM_VOICE_CALL. It is also possible to make two calls with one push so both media and voice are adjusted.