Skip to main content
Control audio during an active call session. These methods allow you to mute/unmute the local microphone and change the audio output device.

Prerequisites

Get CallSession Instance

All audio control methods are called on the CallSession singleton:
val callSession = CallSession.getInstance()

Mute Audio

Mute the local microphone. Other participants will no longer hear you.
callSession.muteAudio()
When you mute your audio, the onAudioMuted() callback is triggered on your MediaEventsListener.

Unmute Audio

Unmute the local microphone to resume transmitting audio.
callSession.unMuteAudio()
When you unmute your audio, the onAudioUnMuted() callback is triggered on your MediaEventsListener.

Set Audio Mode

Change the audio output device during a call. This allows users to switch between speaker, earpiece, Bluetooth, or headphones.
// Switch to speaker
callSession.setAudioMode(AudioMode.SPEAKER)

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

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

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

AudioMode Enum

ValueDescription
SPEAKERRoute audio through the device speaker
EARPIECERoute audio through the phone earpiece
BLUETOOTHRoute audio through a connected Bluetooth device
HEADPHONESRoute audio through connected wired headphones
When the audio mode changes, the onAudioModeChanged(AudioMode) callback is triggered on your MediaEventsListener.

Listen for Audio Events

Register a MediaEventsListener to receive callbacks when audio state changes:
callSession.addMediaEventsListener(this, object : MediaEventsListener {
    override fun onAudioMuted() {
        Log.d(TAG, "Audio muted")
        // Update UI to show muted state
    }

    override fun onAudioUnMuted() {
        Log.d(TAG, "Audio unmuted")
        // Update UI to show unmuted state
    }

    override fun onAudioModeChanged(audioMode: AudioMode) {
        Log.d(TAG, "Audio mode changed to: ${audioMode.value}")
        // Update UI to reflect new audio mode
    }

    // Other MediaEventsListener callbacks...
    override fun onRecordingStarted() {}
    override fun onRecordingStopped() {}
    override fun onScreenShareStarted() {}
    override fun onScreenShareStopped() {}
    override fun onCameraFacingChanged(cameraFacing: CameraFacing) {}
    override fun onVideoPaused() {}
    override fun onVideoResumed() {}
})

Initial Audio Settings

You can configure the initial audio state when joining a session using SessionSettings:
val sessionSettings = CometChatCalls.SessionSettingsBuilder()
    .startAudioMuted(true)           // Start with microphone muted
    .setAudioMode(AudioMode.SPEAKER) // Start with speaker output
    .build()

Next Steps