Skip to main content
Control audio output routing during calls. Switch between speaker, earpiece, Bluetooth, and wired headphones based on user preference or device availability.

Available Audio Modes

ModeDescription
.speakerRoutes audio through the device loudspeaker
.earpieceRoutes audio through the phone earpiece (for private calls)
.bluetoothRoutes audio through a connected Bluetooth device
.headphonesRoutes 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 ?? "")")
    }
)

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")

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) {}
}

Hide Audio Mode Button

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()
The SDK automatically detects connected audio devices. If Bluetooth or wired headphones are connected, they become available as audio mode options.