Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to change from speaker to bluetooth device instead it is routing audio to phone earpiece #223

Open
yashecosmob opened this issue May 8, 2023 · 8 comments

Comments

@yashecosmob
Copy link

As I am using setAudioRoute to set back to bluetooth and I am not able to switch

await InCallManager.setAudioRoute(‘’,'BLUETOOTH').then((response) => {
})

iOS Native function

RCT_EXPORT_METHOD(setAudioRoute: (NSString *)uuid
                 inputName:(NSString *)inputName
                 resolver:(RCTPromiseResolveBlock)resolve
                 rejecter:(RCTPromiseRejectBlock)reject)
{
#ifdef DEBUG
   NSLog(@"[RNCallKeep][setAudioRoutesetAudioRoute] - inputName: %@", inputName);
#endif
   @try {
       NSError* err = nil;
       AVAudioSession* myAudioSession = [AVAudioSession sharedInstance];
       if ([inputName isEqualToString:@"Speaker"]) {
           BOOL isOverrided = [myAudioSession overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&err];
           if(!isOverrided){
               [NSException raise:@"overrideOutputAudioPort failed" format:@"error: %@", err];
           }
           resolve(@"Speaker");
           return;
       }


       NSArray *ports = [RNInCallManager getAudioInputs];
       for (AVAudioSessionPortDescription *port in ports) {
           if ([port.portName isEqualToString:inputName]) {
               BOOL isSetted = [myAudioSession setPreferredInput:(AVAudioSessionPortDescription *)port error:&err];
               if(!isSetted){
                   [NSException raise:@"setPreferredInput failed" format:@"error: %@", err];
               }
               resolve(inputName);
               return;
           }
       }
   }
   @catch ( NSException *e ){
       NSLog(@"[RNCallKeep][setAudioRoute] exception: %@",e);
       reject(@"Failure to set audio route", e, nil);
   }
}

What I tried:

  • Setting the setAudioRoute directly
  • Setting the route to bluetooth directly from avaudiosessionListener
@gustavo-amaro
Copy link

Same here. Any updates?

@wilmxre
Copy link

wilmxre commented Nov 1, 2023

@yashecosmob @gustavo-amaro did you find a solution?

@anhquangtech
Copy link

anhquangtech commented Jan 24, 2024

In my case outgoing call. I must request bluetooth permission https://github.com/zoontek/react-native-permissions before.
Note:

  • setAudioRoute only working in android.
  • For IOS, you can use function InCallManager.setForceSpeakerphoneOn(true/false); to switch audio. Note function setSpeakerphoneOn not working when connect bluetooth device.

@zxar7
Copy link

zxar7 commented Feb 15, 2024

@anhquangtech Can you elaborate on how InCallManager.setForceSpeakerphoneOn(true/false) can be used to switch audio. Especially in iOS. I'm trying to connect to bluetooth in iOS and wasn't able to do so with this method. Is there documentation about the same?

@wilmxre
Copy link

wilmxre commented Feb 15, 2024

InCallManager.setForceSpeakerphoneOn(true/false) is just to route the audio to the Speakers, it has no effect for Bluetooth. For Bluetooth, try InCallManager.chooseAudioRoute('BLUETOOTH'). Be aware that for incoming call, the call has to connect and only after you can route the audio to Bluetooth. So either way try calling the routing method with a button press after the call connection was already established, to test it, or just call it with a setTimeout of a few seconds.

@zxar7
Copy link

zxar7 commented Feb 15, 2024

@wilmxre Does this mean that it needs to be set a few seconds after InCallManager.start()?
Also InCallManager.chooseAudioRoute('BLUETOOTH') just returns the error TypeError: undefined is not a function. I'm not sure it works anymore.

@zxar7
Copy link

zxar7 commented Feb 15, 2024

Oddly enough in Android the InCallManager.start() alone seems to route it correctly between the phone's mic and bluetooth. But the same does not work for iOS.

@katiahr
Copy link

katiahr commented Jun 14, 2024

InCallManager.chooseAudioRoute('BLUETOOTH') not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants