You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the following code, I cannot set the audio output to Receiver. I can get the Bluetooth and Speaker to be selected, and Bluetooth is always the priority.
Is there something I am doing wrong that is preventing the Receiver to be chosen? I can verify the Selected deviceType matches the strings in the if statement.
When selecting Handset, I get the" Successfully switched to handset (earpiece)" NSLog but Speaker gets selected
Your demo app always selects Speaker.
I am using pod 'AmazonChimeSDK', '0.26.1'
RCT_EXPORT_METHOD(setAudioOutput:(NSDictionary *)outputDevice
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
// Extract the deviceType from the outputDevice dictionary
NSString *deviceType = outputDevice[@"type"];
NSLog(@"Selected deviceType: %@", deviceType);
AVAudioSession *session = [AVAudioSession sharedInstance];
NSError *error = nil;
// Set the AVAudioSession category to handle both input and output devices.
BOOL success = [session setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker
error:&error];
if (!success || error) {
reject(@"session_error", @"Failed to set audio session category", error);
return;
}
// Activate the audio session to apply changes
NSError *activationError = nil;
BOOL isSessionActivated = [session setActive:YES error:&activationError];
if (!isSessionActivated || activationError) {
NSLog(@"Failed to activate audio session: %@", activationError);
reject(@"session_activation_error", @"Failed to activate audio session", activationError);
return;
}
// Handle switching output based on deviceType
if ([deviceType isEqualToString:@"BUILTIN_SPEAKER"]) {
// Set output to the built-in speaker
success = [session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];
if (success) {
NSLog(@"Successfully switched to built-in speaker");
resolve(@{@"selected": @"built-in speaker"});
} else {
NSLog(@"Error switching to built-in speaker: %@", error);
reject(@"output_error", @"Failed to set speaker as audio output", error);
}
}
else if ([deviceType isEqualToString:@"BLUETOOTH"]) {
// Set the audio session to allow Bluetooth input/output
success = [session setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionAllowBluetooth
error:&error];
if (success) {
NSLog(@"Successfully switched to Bluetooth");
resolve(@{@"selected": @"bluetooth"});
} else {
NSLog(@"Error switching to Bluetooth: %@", error);
reject(@"output_error", @"Failed to set Bluetooth audio output", error);
}
}
else {
// Explicitly select the handset (earpiece) without overriding the default to Bluetooth
NSArray<AVAudioSessionPortDescription *> *availableOutputs = session.currentRoute.outputs;
AVAudioSessionPortDescription *handsetPort = nil;
// Find the correct handset port (the earpiece or receiver)
for (AVAudioSessionPortDescription *port in availableOutputs) {
if ([port.portType isEqualToString:AVAudioSessionPortBuiltInReceiver]) {
handsetPort = port;
break;
}
}
if (handsetPort) {
// Explicitly set the earpiece (handset) as the output
success = [session setPreferredInput:handsetPort error:&error];
if (success) {
NSLog(@"Successfully switched to handset (earpiece)");
resolve(@{@"selected": @"handset"});
} else {
NSLog(@"Error switching to handset: %@", error);
reject(@"output_error", @"Failed to set handset as audio output", error);
}
} else {
NSLog(@"Handset not found.");
reject(@"output_error", @"Handset not found in available outputs", nil);
}
}
}
The text was updated successfully, but these errors were encountered:
Using the following code, I cannot set the audio output to Receiver. I can get the Bluetooth and Speaker to be selected, and Bluetooth is always the priority.
Is there something I am doing wrong that is preventing the Receiver to be chosen? I can verify the Selected deviceType matches the strings in the if statement.
When selecting Handset, I get the" Successfully switched to handset (earpiece)" NSLog but Speaker gets selected
Your demo app always selects Speaker.
I am using pod 'AmazonChimeSDK', '0.26.1'
The text was updated successfully, but these errors were encountered: