> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-v6-beta2-flutter-uikit.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Audio Controls

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

## Prerequisites

* An active [call session](/calls/android/join-session)
* Access to the `CallSession` instance

## Get CallSession Instance

All audio control methods are called on the `CallSession` singleton:

<Tabs>
  <Tab title="Kotlin">
    ```kotlin theme={null}
    val callSession = CallSession.getInstance()
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    CallSession callSession = CallSession.getInstance();
    ```
  </Tab>
</Tabs>

***

## Mute Audio

Mute the local microphone. Other participants will no longer hear you.

<Tabs>
  <Tab title="Kotlin">
    ```kotlin theme={null}
    callSession.muteAudio()
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    callSession.muteAudio();
    ```
  </Tab>
</Tabs>

<Note>
  When you mute your audio, the `onAudioMuted()` callback is triggered on your `MediaEventsListener`.
</Note>

***

## Unmute Audio

Unmute the local microphone to resume transmitting audio.

<Tabs>
  <Tab title="Kotlin">
    ```kotlin theme={null}
    callSession.unMuteAudio()
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    callSession.unMuteAudio();
    ```
  </Tab>
</Tabs>

<Note>
  When you unmute your audio, the `onAudioUnMuted()` callback is triggered on your `MediaEventsListener`.
</Note>

***

## Set Audio Mode

Change the audio output device during a call. This allows users to switch between speaker, earpiece, Bluetooth, or headphones.

<Tabs>
  <Tab title="Kotlin">
    ```kotlin theme={null}
    // 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)
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    // 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);
    ```
  </Tab>
</Tabs>

### AudioMode Enum

| Value        | Description                                      |
| ------------ | ------------------------------------------------ |
| `SPEAKER`    | Route audio through the device speaker           |
| `EARPIECE`   | Route audio through the phone earpiece           |
| `BLUETOOTH`  | Route audio through a connected Bluetooth device |
| `HEADPHONES` | Route audio through connected wired headphones   |

<Note>
  When the audio mode changes, the `onAudioModeChanged(AudioMode)` callback is triggered on your `MediaEventsListener`.
</Note>

***

## Listen for Audio Events

Register a `MediaEventsListener` to receive callbacks when audio state changes:

<Tabs>
  <Tab title="Kotlin">
    ```kotlin theme={null}
    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() {}
    })
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    callSession.addMediaEventsListener(this, new MediaEventsListener() {
        @Override
        public void onAudioMuted() {
            Log.d(TAG, "Audio muted");
            // Update UI to show muted state
        }

        @Override
        public void onAudioUnMuted() {
            Log.d(TAG, "Audio unmuted");
            // Update UI to reflect unmuted state
        }

        @Override
        public void onAudioModeChanged(AudioMode audioMode) {
            Log.d(TAG, "Audio mode changed to: " + audioMode.getValue());
            // Update UI to reflect new audio mode
        }

        // Other MediaEventsListener callbacks...
        @Override
        public void onRecordingStarted() {}
        @Override
        public void onRecordingStopped() {}
        @Override
        public void onScreenShareStarted() {}
        @Override
        public void onScreenShareStopped() {}
        @Override
        public void onCameraFacingChanged(CameraFacing cameraFacing) {}
        @Override
        public void onVideoPaused() {}
        @Override
        public void onVideoResumed() {}
    });
    ```
  </Tab>
</Tabs>

***

## Initial Audio Settings

You can configure the initial audio state when joining a session using `SessionSettings`:

<Tabs>
  <Tab title="Kotlin">
    ```kotlin theme={null}
    val sessionSettings = CometChatCalls.SessionSettingsBuilder()
        .startAudioMuted(true)           // Start with microphone muted
        .setAudioMode(AudioMode.SPEAKER) // Start with speaker output
        .build()
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    SessionSettings sessionSettings = new CometChatCalls.SessionSettingsBuilder()
        .startAudioMuted(true)           // Start with microphone muted
        .setAudioMode(AudioMode.SPEAKER) // Start with speaker output
        .build();
    ```
  </Tab>
</Tabs>

## Next Steps

<CardGroup cols={2}>
  <Card title="Video Controls" icon="video" href="/calls/android/video-controls">
    Control video during calls
  </Card>

  <Card title="Media Events Listener" icon="bell" href="/calls/android/media-events-listener">
    Handle all media events
  </Card>
</CardGroup>
