I am making VOIP app and now we required to connect voice calls with Bluetooth. We tried to connect the call with Bluetooth but not hear anything.
/* Initialize audio session category and mode */
{
AVAudioSession *sess = [AVAudioSession sharedInstance];
pj_bool_t err;
if ([sess respondsToSelector:@selector(setCategory:withOptions:error:)])
{
err = [sess setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionAllowBluetooth
error:nil] != YES;
} else {
err = [sess setCategory:AVAudioSessionCategoryPlayAndRecord
error:nil] != YES;
}
if (err) {
PJ_LOG(3, (THIS_FILE,
"Warning: failed settting audio session category"));
}
if ([sess respondsToSelector:@selector(setMode:error:)] &&
[sess setMode:AVAudioSessionModeVoiceChat error:nil] != YES)
{
PJ_LOG(3, (THIS_FILE, "Warning: failed settting audio mode"));
}
}
Above code added in pjmedia-audiodev->coreaudio_dev.m file.
Also tried below code :-
+(void)EnableBluethooth
{
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory: AVAudioSessionCategoryPlayAndRecord
error:
nil];
[audioSession setActive: YES error: nil];
UInt32 allowBluetoothInput = 1;
OSStatus ostatus = AudioSessionSetProperty (
kAudioSessionProperty_OverrideCategoryEnableBluetoothInput,
sizeof(allowBluetoothInput), &allowBluetoothInput);
pjmedia_aud_dev_route route = PJMEDIA_AUD_DEV_ROUTE_BLUETOOTH;
pj_status_t status =
pjsua_snd_set_setting(PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE, &route,
PJ_TRUE);
NSLog(@"statuys is--->%d",status);
NSLog(@"status = %x", ostatus);
}
+(void)DisableBluethooth
{
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory: AVAudioSessionCategoryPlayAndRecord
error: nil];
[audioSession setActive: NO error: nil];
pjmedia_aud_dev_route route = PJMEDIA_AUD_DEV_ROUTE_BLUETOOTH;
pjsua_snd_set_setting(PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE, &route,
PJ_FALSE);
}
Code execute but not able to hear voice using Bluetooth. If anyone have an idea of enabling Bluetooth for pjsip then please give me.
Thank you.
After setting the AVAudioSessionCategory and port, set the preferredInput as bluetooth port, so the bluetooth will be activated. Please follow the below code and call
switchBluetooth
method.