Skip to main content
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

1

Create a sound manager

Instantiate CometChatSoundManager using a valid Context.
2

Play default sounds

Call play(Sound) for built-in UI Kit sounds.
3

Play custom sounds

Call play(Sound, int) with a file from res/raw.
4

Pause playback

Call pause() when you need to stop sound playback.
5

Build and verify

Run the app and confirm the expected sound plays for each event.

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:
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:
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