Skip to main content

Overview

CometChatSoundManager is a helper class that manages audio playback in the CometChat UI Kit. It handles sound events for incoming and outgoing messages and calls, supporting both default sounds and custom audio files.

Methods

Play Sound

The play(sound:customSound:) method triggers audio playback based on user interactions with the chat interface. If no custom sound file is provided, the default sound for that event type is played.
play(sound: Sound, customSound: URL?)
ParameterTypeDescription
soundSoundThe type of sound event (e.g., .incomingMessage, .outgoingMessage, .incomingCall, .outgoingCall)
customSoundURL?Optional URL to a custom sound file. If nil, the default sound is used.

Pause Sound

The pause() method stops any sound currently being played by the SoundManager.
pause()

Usage

Playing Default Sounds

Play the default sound for an incoming message:
// Play the default incoming message sound
CometChatSoundManager().play(sound: .incomingMessage)

Playing Custom Sounds

Provide a custom audio file URL to override the default sound:
// Play a custom sound for incoming messages
if let customSoundURL = Bundle.main.url(forResource: "customSound", withExtension: "wav") {
    CometChatSoundManager().play(sound: .incomingMessage, customSound: customSoundURL)
}

Pausing Sounds

Stop any currently playing sound:
// Pause the currently playing sound
CometChatSoundManager().pause()

Sound Types

The Sound enum provides the following options:
Sound TypeDescription
.incomingMessagePlayed when a new message is received
.outgoingMessagePlayed when a message is sent
.incomingCallPlayed when an incoming call is received
.outgoingCallPlayed when initiating an outgoing call

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