1

We're trying to use a usb headset (speaker + microphone) on ios using native webrtc library (from cocoapods)

The following code activate the usb microphone:

- (void)handleRouteChange:(NSNotification *) notification
{
    NSLog(@"Route change");
    NSError *error;
    AVAudioSession* session = [AVAudioSession sharedInstance];
    [session setCategory:AVAudioSessionCategoryMultiRoute error:&error];
    for (AVAudioSessionPortDescription *destPort in session.availableInputs){
        NSLog(@"PORT DESC %@", destPort.portName);
        if ([destPort.portType isEqualToString:AVAudioSessionPortUSBAudio]) {
            NSLog(@"USB");
            [session setPreferredInput:destPort error:&error];
            [session setOutputDataSource:destPort.selectedDataSource error:&error];
            if (error!=nil){
                NSLog(@"Error %@", error);
            }
        }
    }
}

But we don't have any output in the usb speakers

Any tip?

Jose
  • 71
  • 3
  • 14
  • 1
    Is your USB headset supported in other iOS apps? WebRTC is for communication, and you are having issues with audio, seems unrelated. I have a tool that might help you debug audio configuration of your app: https://github.com/paiv/avaudiosession-explorer – paiv Jun 18 '21 at 04:11
  • 1
    Set up audio session when app is started. Activate audio session immediately before user needs to play or record audio. Remove `handleRouteChange` completely, if you are not sure why it's there. – paiv Jun 18 '21 at 06:57
  • @paiv USB is tested with player and recorder and works ok. webrtc constructs is own AVAudioSession that prevents access to the USB headset. – Jose Jun 18 '21 at 18:04
  • 1
    link the library you are using, and open an issue with its developer. – paiv Jun 18 '21 at 18:54
  • I believe the library is https://cocoapods.org/pods/GoogleWebRTC – Ben Butterworth Jun 19 '21 at 22:05
  • @Ben, yes it's the webrtc native library from google – Jose Jun 19 '21 at 22:52
  • 1
    @Jose that library provides RTCAudioSession and RTCAudioSessionDelegate. Start with a blank project, configure appropriate session category at app start, and describe why it does not work for you. – paiv Jun 20 '21 at 14:42
  • @Paiv solved with your help. Webrtc configures the session mode to AVAudioSessionModeVoiceChat. Changing the mode to AVAudioSessionModeDefault fix it ! thanks – Jose Jun 22 '21 at 10:22

0 Answers0