AI Agent Component Spec
AI Agent Component Spec
| 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 |
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/rawfor custom playback.
Quick start
Core concepts
CometChatSoundManager: Manages playback of UI Kit sounds.Sound: Enum of supported sound events such asincomingCall,outgoingMessage, andincomingMessageFromOther.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
CometChatSoundManagerwith a validContext. - Code:
- Kotlin
- Java
SoundManagerHelper.kt
- 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:
- Kotlin
- Java
SoundManagerUsage.kt
- 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() |