0
votes

In a WebRT app that does video chat, I want to set cell phones to play sound using speakerphone, not earpiece.

I've tried using the AppRTCAudioManager(which wraps AudioManager) to set mute and set speakerphone, using the AudioManager directly to set mute, placing the code in different methods, etc.

android.permission.MODIFY_AUDIO_SETTINGS is granted.

private void gotRemoteStream(MediaStream stream){
...
runOnUiThread(new Runnable() {
            @Override
            public void run() {
...
audioManager = AppRTCAudioManager.create(context);...
audioManager.start((x, y) -> {}) // a callback that does logging, omitted for clarity

// First try setting audio device with the AppRTCAudioManager, which wraps AudioManager.
audioManager.selectAudioDevice(AppRTCAudioManager.AudioDevice.SPEAKER_PHONE);

AppRTCAudioManager.AudioDevice ad = audioManager.getSelectedAudioDevice(); 
//Shows SPEAKER_PHONE, but sound still plays from earpiece.


// Next try it with the AudioManager itself.
AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
                    am.setMode(AudioManager.MODE_IN_COMMUNICATION);
                    am.setMicrophoneMute(true);
                    am.setSpeakerphoneOn(true);
                    boolean mute = am.isMicrophoneMute(); //false
                    boolean on = am.isSpeakerphoneOn(); //false
}

The audioManager.getSelectedAudioDevice method shows the audio device as speakerphone, but am.isSpeakerphoneOn reveals that speakerphone is still off.

Also, setting the microphone to mute with am.setMicrophoneMute doesn't do anything. am.IsMicrophone mute still says false.

Thanks in advance for any help.

UPDATE: my cell phone mysteriously started playing thru speakerphone. But the AudioManager code still doesn't do anything. I changed the AudioManager code to select EARPIECE as the audio device, but now it still plays thru speakerphone.

1

1 Answers

0
votes

Finally found the answer; I had mistyped the permission <uses-permission android:name="audioid.permission.MODIFY_AUDIO_SETTINGS"/>! Apparently the Android Studio compiler doesn't check for errors in the Manifest file. So it didn't alert me I had typed "audioid" instead of "android".