Documentation Index
Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Control audio output routing during calls. Switch between speaker, earpiece, Bluetooth, and wired headphones based on user preference or device availability.
Available Audio Modes
| Mode | Description |
|---|
.speaker | Routes audio through the device loudspeaker |
.earpiece | Routes audio through the phone earpiece (for private calls) |
.bluetooth | Routes audio through a connected Bluetooth device |
.headphones | Routes audio through wired headphones |
Set Initial Audio Mode
Configure the audio mode when joining a session:
let sessionSettings = CometChatCalls.sessionSettingsBuilder
.setAudioMode(.speaker)
.build()
CometChatCalls.joinSession(
sessionID: sessionId,
callSetting: sessionSettings,
container: callViewContainer,
onSuccess: { message in
print("Joined with speaker mode")
},
onError: { error in
print("Failed: \(error?.errorDescription ?? "")")
}
)
SessionSettings *sessionSettings = [[[CometChatCalls sessionSettingsBuilder]
setAudioMode:AudioModeTypeSpeaker]
build];
[CometChatCalls joinSessionWithSessionID:sessionId
callSetting:sessionSettings
container:self.callViewContainer
onSuccess:^(NSString * message) {
NSLog(@"Joined with speaker mode");
} onError:^(CometChatCallException * error) {
NSLog(@"Failed: %@", error.errorDescription);
}];
Change Audio Mode During Call
Switch audio modes dynamically during an active call:
// Switch to speaker
CallSession.shared.setAudioMode("SPEAKER")
// Switch to earpiece
CallSession.shared.setAudioMode("EARPIECE")
// Switch to Bluetooth
CallSession.shared.setAudioMode("BLUETOOTH")
// Switch to wired headphones
CallSession.shared.setAudioMode("HEADPHONES")
// Switch to speaker
[[CallSession shared] setAudioMode:@"SPEAKER"];
// Switch to earpiece
[[CallSession shared] setAudioMode:@"EARPIECE"];
// Switch to Bluetooth
[[CallSession shared] setAudioMode:@"BLUETOOTH"];
// Switch to wired headphones
[[CallSession shared] setAudioMode:@"HEADPHONES"];
Listen for Audio Mode Changes
Monitor audio mode changes using MediaEventsListener:
class CallViewController: UIViewController, MediaEventsListener {
override func viewDidLoad() {
super.viewDidLoad()
CallSession.shared.addMediaEventsListener(self)
}
deinit {
CallSession.shared.removeMediaEventsListener(self)
}
func onAudioModeChanged(audioModeType: AudioModeType) {
switch audioModeType {
case .speaker:
print("Switched to speaker")
case .earpiece:
print("Switched to earpiece")
case .bluetooth:
print("Switched to Bluetooth")
case .headphones:
print("Switched to headphones")
default:
break
}
// Update audio mode button icon
updateAudioModeIcon(audioModeType)
}
// Other callbacks...
func onAudioMuted() {}
func onAudioUnMuted() {}
func onVideoPaused() {}
func onVideoResumed() {}
func onRecordingStarted() {}
func onRecordingStopped() {}
func onScreenShareStarted() {}
func onScreenShareStopped() {}
func onCameraFacingChanged(cameraFacing: CameraFacing) {}
}
@interface CallViewController () <MediaEventsListener>
@end
@implementation CallViewController
- (void)viewDidLoad {
[super viewDidLoad];
[[CallSession shared] addMediaEventsListener:self];
}
- (void)dealloc {
[[CallSession shared] removeMediaEventsListener:self];
}
- (void)onAudioModeChangedWithAudioModeType:(AudioModeType)audioModeType {
// Update audio mode button icon
[self updateAudioModeIcon:audioModeType];
}
// Other callbacks...
@end
To prevent users from changing the audio mode, hide the button in the call UI:
let sessionSettings = CometChatCalls.sessionSettingsBuilder
.setAudioMode(.speaker) // Fixed audio mode
.hideAudioModeButton(true) // Hide toggle button
.build()
SessionSettings *sessionSettings = [[[[CometChatCalls sessionSettingsBuilder]
setAudioMode:AudioModeTypeSpeaker]
hideAudioModeButton:YES]
build];
The SDK automatically detects connected audio devices. If Bluetooth or wired headphones are connected, they become available as audio mode options.