> ## 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.

# Sound Manager

> Manage CometChat Android UI Kit sounds for incoming and outgoing messages, calls, custom audio files, playback, and pause controls.

<Accordion title="AI Integration Quick Reference">
  | Field        | Value                                                                                                                                         |
  | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------- |
  | Package      | `com.cometchat:chat-uikit-android`                                                                                                            |
  | Import       | `com.cometchat.chatuikit.resources.soundmanager.CometChatSoundManager`                                                                        |
  | Play sound   | `CometChatSoundManager(context).play(Sound.incomingCall)` — or pass custom `@RawRes int` as second arg                                        |
  | Pause sound  | `CometChatSoundManager(context).pause()`                                                                                                      |
  | Sound events | `incomingCall`, `outgoingCall`, `incomingMessage`, `incomingMessageFromOther`, `outgoingMessage`                                              |
  | Source       | [GitHub](https://github.com/cometchat/cometchat-uikit-android/tree/v5/chatuikit/src/main/java/com/cometchat/chatuikit/resources/soundmanager) |
</Accordion>

Use `CometChatSoundManager` to play UI Kit audio cues for calls and messages.

## When to use this

* You want audible feedback for incoming or outgoing calls and messages.
* You need custom sounds for specific chat events.
* You want to pause or stop sound playback programmatically.

## Prerequisites

* CometChat UI Kit for Android is installed and initialized.
* You have access to an Android `Context`.
* Optional: You have sound files in `app/src/main/res/raw` for custom playback.

## Quick start

<Steps>
  <Step title="Create a sound manager">
    Instantiate `CometChatSoundManager` using a valid `Context`.
  </Step>

  <Step title="Play default sounds">
    Call `play(Sound)` for built-in UI Kit sounds.
  </Step>

  <Step title="Play custom sounds">
    Call `play(Sound, int)` with a file from `res/raw`.
  </Step>

  <Step title="Pause playback">
    Call `pause()` when you need to stop sound playback.
  </Step>

  <Step title="Build and verify">
    Run the app and confirm the expected sound plays for each event.
  </Step>
</Steps>

## Core concepts

* `CometChatSoundManager`: Manages playback of UI Kit sounds.
* `Sound`: Enum of supported sound events such as `incomingCall`, `outgoingMessage`, and `incomingMessageFromOther`.
* `R.raw`: Android raw resource IDs used for custom sounds.

### Available methods

* `play(Sound sound)`: Plays the default UI Kit sound for the given event.
* `play(Sound sound, int res)`: Plays a custom raw resource for the given event.
* `pause()`: Pauses any sound currently playing.

## Implementation

### Initialize `CometChatSoundManager`

What you're changing: Creating a sound manager instance.

* **Where to change it**: Any class where you have access to a `Context`.

* **Applies to**: All UI Kit sound playback.

* **Default behavior**: Sounds are not managed until you create the instance.

* **Override**: Instantiate `CometChatSoundManager` with a valid `Context`.

* **Code**:

<Tabs>
  <Tab title="Kotlin">
    ```kotlin SoundManagerHelper.kt lines theme={null}
    import android.content.Context
    import com.cometchat.chatuikit.shared.resources.soundmanager.CometChatSoundManager

    fun createSoundManager(context: Context): CometChatSoundManager {
        return CometChatSoundManager(context)
    }
    ```
  </Tab>

  <Tab title="Java">
    ```java SoundManagerHelper.java lines theme={null}
    import android.content.Context;
    import com.cometchat.chatuikit.shared.resources.soundmanager.CometChatSoundManager;

    public final class SoundManagerHelper {
        public static CometChatSoundManager createSoundManager(Context context) {
            return new CometChatSoundManager(context);
        }
    }
    ```
  </Tab>
</Tabs>

* **What this does**: Creates a sound manager you can reuse across your UI Kit screens.

* **Verify**: Call a play method and confirm audio plays.

### Play default and custom sounds

What you're changing: Triggering sound playback for chat events.

* **Where to change it**: The class that handles your chat or call UI logic.

* **Applies to**: Message and call events you choose to handle.

* **Default behavior**: UI Kit plays its built-in sounds when triggered.

* **Override**: Use `play(Sound, int)` to play a custom raw resource.

* **Code**:

<Tabs>
  <Tab title="Kotlin">
    ```kotlin SoundManagerUsage.kt lines theme={null}
    import android.content.Context
    import com.cometchat.chatuikit.shared.resources.soundmanager.CometChatSoundManager
    import com.cometchat.chatuikit.shared.resources.soundmanager.Sound

    fun playSounds(context: Context) {
        val soundManager = CometChatSoundManager(context)

        // Default sounds
        soundManager.play(Sound.incomingCall)
        soundManager.play(Sound.outgoingCall)
        soundManager.play(Sound.incomingMessage)
        soundManager.play(Sound.outgoingMessage)
        soundManager.play(Sound.incomingMessageFromOther)

        // Custom sounds
        soundManager.play(Sound.incomingCall, R.raw.incoming_call)
        soundManager.play(Sound.outgoingCall, R.raw.outgoing_call)
        soundManager.play(Sound.incomingMessage, R.raw.incoming_message)
        soundManager.play(Sound.outgoingMessage, R.raw.outgoing_message)
        soundManager.play(Sound.incomingMessageFromOther, R.raw.incoming_message_other)

        // Pause playback
        soundManager.pause()
    }
    ```
  </Tab>

  <Tab title="Java">
    ```java SoundManagerUsage.java lines theme={null}
    import android.content.Context;
    import com.cometchat.chatuikit.shared.resources.soundmanager.CometChatSoundManager;
    import com.cometchat.chatuikit.shared.resources.soundmanager.Sound;

    public class SoundManagerUsage {
        public static void playSounds(Context context) {
            CometChatSoundManager soundManager = new CometChatSoundManager(context);

            // Default sounds
            soundManager.play(Sound.incomingCall);
            soundManager.play(Sound.outgoingCall);
            soundManager.play(Sound.incomingMessage);
            soundManager.play(Sound.outgoingMessage);
            soundManager.play(Sound.incomingMessageFromOther);

            // Custom sounds
            soundManager.play(Sound.incomingCall, R.raw.incoming_call);
            soundManager.play(Sound.outgoingCall, R.raw.outgoing_call);
            soundManager.play(Sound.incomingMessage, R.raw.incoming_message);
            soundManager.play(Sound.outgoingMessage, R.raw.outgoing_message);
            soundManager.play(Sound.incomingMessageFromOther, R.raw.incoming_message_other);

            // Pause playback
            soundManager.pause();
        }
    }
    ```
  </Tab>
</Tabs>

* **What this does**: Plays default and custom sounds, then pauses playback.

* **Verify**: You hear the expected sound for each call and message event.

## Customization matrix

| What you want to change | Where                                                    | Property/API                     | Example                                                      |
| ----------------------- | -------------------------------------------------------- | -------------------------------- | ------------------------------------------------------------ |
| Create sound manager    | `app/src/main/java/<your_package>/SoundManagerHelper.kt` | `CometChatSoundManager(Context)` | `val soundManager = CometChatSoundManager(context)`          |
| Play default sounds     | `app/src/main/java/<your_package>/SoundManagerUsage.kt`  | `play(Sound)`                    | `soundManager.play(Sound.incomingCall)`                      |
| Play custom sounds      | `app/src/main/java/<your_package>/SoundManagerUsage.kt`  | `play(Sound, int)`               | `soundManager.play(Sound.incomingCall, R.raw.incoming_call)` |
| Pause playback          | `app/src/main/java/<your_package>/SoundManagerUsage.kt`  | `pause()`                        | `soundManager.pause()`                                       |
