Switch Output Speaker in Native Android Framework

1,238 views
Skip to first unread message

Lars Bork

unread,
Jan 28, 2017, 6:57:26 AM1/28/17
to discuss-webrtc
Hello,

I would like to be able to set the speaker that should be used to output WebRtc audio streams. Right now the earpiece is always used, but sometimes I want to listen to the stream loudly (e.g. in a car).

On iOS I can do this by manipulating the AVAudioSession:

[[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];


This approach is suggested oftenly, but it does not work for me:

audioManager.setSpeakerphoneOn(on);


Do you know how I can change the speaker output?

Henrik Andreasson

unread,
Jan 30, 2017, 7:34:48 AM1/30/17
to discuss-webrtc
We have not added these parts to the native audio layer in Android since it works better to leave it for the
application level.

One (rather complex since it also support BT) example in AppRTCMobile can be found here and there is a UI in the demo client
where you can force usage of the speaker phone. Note that the demo also uses a proximity sensor which 
should switch between earpiece and speakerphone automatically.

But to summarize: using the setSpeakerphoneOn() API on the AudioManager is the correct approach.

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrtc+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/ae17bc1d-07df-465e-abf6-0f93a7c715bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lars Bork

unread,
Jan 31, 2017, 9:28:39 AM1/31/17
to discuss-webrtc
Thanks, Henrik. My problem was that I did not include the proper permissions.
This permission is required in order to change the audio speaker:

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

Am Montag, 30. Januar 2017 13:34:48 UTC+1 schrieb Henrik Andreassson:
We have not added these parts to the native audio layer in Android since it works better to leave it for the
application level.

One (rather complex since it also support BT) example in AppRTCMobile can be found here and there is a UI in the demo client
where you can force usage of the speaker phone. Note that the demo also uses a proximity sensor which 
should switch between earpiece and speakerphone automatically.

But to summarize: using the setSpeakerphoneOn() API on the AudioManager is the correct approach.
On Sat, Jan 28, 2017 at 12:57 PM, Lars Bork <polarapps...@gmail.com> wrote:
Hello,

I would like to be able to set the speaker that should be used to output WebRtc audio streams. Right now the earpiece is always used, but sometimes I want to listen to the stream loudly (e.g. in a car).

On iOS I can do this by manipulating the AVAudioSession:

[[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];


This approach is suggested oftenly, but it does not work for me:

audioManager.setSpeakerphoneOn(on);


Do you know how I can change the speaker output?

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages