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

# Audio Modes

> Configure CometChat Calls SDK v5 audio modes on Android for speakers, earpiece, Bluetooth, routing, and call audio behavior.

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:

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

  <Tab title="Java">
    ```java theme={null}
    SessionSettings sessionSettings = new CometChatCalls.SessionSettingsBuilder()
        .setAudioMode(AudioMode.SPEAKER)
        .build();

    CometChatCalls.joinSession(sessionId, sessionSettings, callViewContainer,
        new CometChatCalls.CallbackListener<CallSession>() {
            @Override
            public void onSuccess(CallSession callSession) {
                Log.d(TAG, "Joined with speaker mode");
            }

            @Override
            public void onError(CometChatException e) {
                Log.e(TAG, "Failed: " + e.getMessage());
            }
        }
    );
    ```
  </Tab>
</Tabs>

## Change Audio Mode During Call

Switch audio modes dynamically during an active call:

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

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

## Listen for Audio Mode Changes

Monitor audio mode changes using `MediaEventsListener`:

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

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

    callSession.addMediaEventsListener(this, new MediaEventsListener() {
        @Override
        public void onAudioModeChanged(AudioMode audioMode) {
            switch (audioMode) {
                case SPEAKER:
                    Log.d(TAG, "Switched to speaker");
                    break;
                case EARPIECE:
                    Log.d(TAG, "Switched to earpiece");
                    break;
                case BLUETOOTH:
                    Log.d(TAG, "Switched to Bluetooth");
                    break;
                case HEADPHONES:
                    Log.d(TAG, "Switched to headphones");
                    break;
            }
            // Update audio mode button icon
            updateAudioModeIcon(audioMode);
        }

        // Other callbacks...
    });
    ```
  </Tab>
</Tabs>

## Hide Audio Mode Button

To prevent users from changing the audio mode, hide the button in the call UI:

<Tabs>
  <Tab title="Kotlin">
    ```kotlin theme={null}
    val sessionSettings = CometChatCalls.SessionSettingsBuilder()
        .setAudioMode(AudioMode.SPEAKER) // Fixed audio mode
        .hideAudioModeButton(true)       // Hide toggle button
        .build()
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    SessionSettings sessionSettings = new CometChatCalls.SessionSettingsBuilder()
        .setAudioMode(AudioMode.SPEAKER) // Fixed audio mode
        .hideAudioModeButton(true)       // Hide toggle button
        .build();
    ```
  </Tab>
</Tabs>

<Note>
  The SDK automatically detects connected audio devices. If Bluetooth or wired headphones are connected, they become available as audio mode options.
</Note>
