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:
val sessionSettings = CometChatCalls.SessionSettingsBuilder()
    .setAudioMode(AudioMode.SPEAKER)
    .build()

CometChatCalls.joinSession(sessionId, sessionSettings, callViewContainer,
    object : CometChatCalls.CallbackListener<CallSession>() {
        override fun onSuccess(callSession: CallSession) {
            Log.d(TAG, "Joined with speaker mode")
        }

        override fun onError(e: CometChatException) {
            Log.e(TAG, "Failed: ${e.message}")
        }
    }
)

Change Audio Mode During Call

Switch audio modes dynamically during an active call:
val callSession = CallSession.getInstance()

// Switch to speaker
callSession.setAudioMode(AudioMode.SPEAKER)

// Switch to earpiece
callSession.setAudioMode(AudioMode.EARPIECE)

// Switch to Bluetooth
callSession.setAudioMode(AudioMode.BLUETOOTH)

// Switch to wired headphones
callSession.setAudioMode(AudioMode.HEADPHONES)

Listen for Audio Mode Changes

Monitor audio mode changes using MediaEventsListener:
val callSession = CallSession.getInstance()

callSession.addMediaEventsListener(this, object : MediaEventsListener() {
    override fun onAudioModeChanged(audioMode: AudioMode) {
        when (audioMode) {
            AudioMode.SPEAKER -> Log.d(TAG, "Switched to speaker")
            AudioMode.EARPIECE -> Log.d(TAG, "Switched to earpiece")
            AudioMode.BLUETOOTH -> Log.d(TAG, "Switched to Bluetooth")
            AudioMode.HEADPHONES -> Log.d(TAG, "Switched to headphones")
        }
        // Update audio mode button icon
        updateAudioModeIcon(audioMode)
    }

    // Other callbacks...
    override fun onAudioMuted() {}
    override fun onAudioUnMuted() {}
    override fun onVideoPaused() {}
    override fun onVideoResumed() {}
    override fun onRecordingStarted() {}
    override fun onRecordingStopped() {}
    override fun onScreenShareStarted() {}
    override fun onScreenShareStopped() {}
    override fun onCameraFacingChanged(facing: CameraFacing) {}
})

Hide Audio Mode Button

To prevent users from changing the audio mode, hide the button in the call UI:
val sessionSettings = CometChatCalls.SessionSettingsBuilder()
    .setAudioMode(AudioMode.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.