Cordova-plugin-iosrtc: iOS plays audio out of earpiece, not loud speaker.

Created on 2 Jun 2015  路  20Comments  路  Source: cordova-rtc/cordova-plugin-iosrtc

It would be good to have a toggle on which speaker to use. It appears to be defaulting to earpiece speaker which doesn't work well for video calls.

Most helpful comment

The WebRTC library is managing the system AVAudioSession on its own, so you have to use the audioroute plugin right after audio starts playing (you can technically do it a bit earlier, but anyway) because otherwise (libwebrtc) it will change your route.

Google has plans to allow for a more manual control of this, but that work hasn't landed in libwebrtc yet, so we have to juggle with timing.

All 20 comments

Good point. However, there is nothing in the libwebrtc Objective-C API to select which audio output to use for a RTCAudioTrack. Even worse, once a PeerConnection is connected and a remote MediaStream is generated, the audio track of the the mediastream is just magically "rendered". I mean: the plugin does absolutely nothing with the RTCAudioTrack.

Just check the code to realize that nothing is being explicitly donde with the audio track of a RTCMediaStream.

BTW this is something to report to the Google's libwebrtc project. I'll do it in the next days.

For now I've just sent a mail to discuss-webrtc asking about this topic:

https://groups.google.com/forum/#!topic/discuss-webrtc/q4bttvVMB4I

I'm currently getting around this by adding

var session: AVAudioSession = AVAudioSession.sharedInstance()
session.overrideOutputAudioPort(AVAudioSessionPortOverride.Speaker, error: nil);

on render.

How does that work? Should I call that for each new "call"? should that session variable be referenced not to be garbage collected?

So is it possible to use that to create some sort of toggle on the javascript side? Can it be called while the session is active?

@ibc I don't think you would need to reference the session variable, as it is a singleton, so just grabbing the sharedInstance() every time should be fine.

OK, I will add a JS binding for calling that method.

This is implemented in 1.2.6: 8b557978212ad0daf14e7fe2c16535f6da6ddd67

One problem with this solution is that iOS will force the speaker when a user has headphones plugged in.

There may be a Cordova plugin that detects headphones plugged in.

Anyone running into this, you might be interested in https://github.com/saghul/cordova-plugin-audioroute

Hi @ibc was wondering if you could show in your docs how to use @saghul Audioroute plugin to route audio to speakers. I know he said something detecting AVAudioSession but I really have no clue where to start from. Thanks

@cozzbie I have no idea.

tears, sobs and pain Thank you. @ibc

@cozzbie You can try something like that:

cordova.plugins.audioroute.overrideOutput('speaker', 
  function(success) {
    // Success
  },
  function(error) {
    // Error
  }
);

Already doing that but it doesn't work. Was thinking maybe it was the line I was calling it from so I asked @saghul and he said we should listen for AVAudioSession something and I am at a loss as to how to go about that. @oscarvadillog

Audio is not coming through the specified device on my ipad when I specify speaker as the audio output ussing audioroute plugin @oscarvadillog @saghul

The WebRTC library is managing the system AVAudioSession on its own, so you have to use the audioroute plugin right after audio starts playing (you can technically do it a bit earlier, but anyway) because otherwise (libwebrtc) it will change your route.

Google has plans to allow for a more manual control of this, but that work hasn't landed in libwebrtc yet, so we have to juggle with timing.

it works with the plugin mentioned by, @oscarvadillog

just call it after the audio session was established, for example for a working test, copy and paste after your videocall was established in safari's console.

cordova.plugins.audioroute.overrideOutput('speaker',
function(success) {
// Success
alert("success");
console.log("success",success);
},
function(error) {
// Error
alert("error");
console.log("error",error);
}
);

solved with me by using this plugin cordova-plugin-audioinput .

PS: in case of make a video call after remote stream added make

setTimeout(() => {
AudioToggle.setAudioMode(AudioToggle.SPEAKER);
}, 2000);
}
Was this page helpful?
0 / 5 - 0 ratings