Skip to main content

Sound Manager

Overview

The SoundManager is a helper class responsible for managing and playing various types of audio in the CometChat UI Kit. This includes sound events for incoming and outgoing messages and calls.

Methods

Play Sound

The SoundManager plays pre-defined or custom sounds based on user interactions with the chat interface. If no custom sound file is provided, the default sound is played.

  • play(): This method plays different types of sounds for incoming and outgoing calls and messages.
// Play sound with default sound:
SoundManager().play(sound: Sound.incomingMessage); //To play default incoming message sound
SoundManager().play(sound: Sound.outgoingMessage);//To play default outgoing message sound

CometChat sound will behave differently with different type of OS in case of background playing

Stop Sound

The SoundManager can Stop different types of sounds for incoming and outgoing calls and messages using the following method:

  • stop(): This method Stops any sound currently being played.
SoundManager().stop();

Usage

Here is how to use SoundManager:

//Play sound with custom sound
SoundManager().play(sound: Sound.outgoingMessage, customSound: "assetPath"); //To custom message sound

By using the SoundManager, you can enhance the user experience in your chat application by integrating audible cues for chat interactions.

The table below lists down various Sound enum cases and the corresponding assets played for them:

SoundAsset
incomingMessageassets/sound/incoming_message.wav
outgoingMessageassets/sound/outgoing_message.wav
incomingMessageFromOtherassets/sound/incoming_message.wav
outgoingCallassets/sound/outgoing_call.wav
incomingCallassets/sound/incoming_call.wav