Skip to main content
FieldValue
Packagecometchat_uikit_shared
Importimport 'package:cometchat_uikit_shared/cometchat_uikit_shared.dart';
ClassSoundManager (singleton)
Play soundSoundManager().play(sound: Sound.incomingMessage)
Stop soundSoundManager().stop()
Sound eventsincomingMessage, outgoingMessage, incomingMessageFromOther, incomingCall, outgoingCall
SourceGitHub
SoundManager is a singleton helper class for managing and playing audio cues — incoming/outgoing calls and messages.

Methods

play

Plays the default or custom audio for a sound event.
void play({
  required Sound sound,
  String? customSound,
  String? packageName,
  bool? isLooping,
})
ParameterTypeDescription
soundSoundRequired. The sound event type to play
customSoundString?Optional. Asset path for custom sound file
packageNameString?Optional. Package name when using sounds from another plugin
isLoopingbool?Optional. Whether to loop the sound (default: false)
// Play default sounds
SoundManager().play(sound: Sound.incomingMessage);
SoundManager().play(sound: Sound.outgoingMessage);

// Play custom sound
SoundManager().play(
  sound: Sound.outgoingMessage,
  customSound: "assets/custom_sound.wav",
);

// Play looping sound (e.g., for incoming call)
SoundManager().play(
  sound: Sound.incomingCall,
  isLooping: true,
);

stop

Stops any currently playing sound.
SoundManager().stop();

Sound Enum

ValueDefault AssetWhen it plays
incomingMessageassets/sound/incoming_message.wavNew message received
outgoingMessageassets/sound/outgoing_message.wavMessage sent
incomingMessageFromOtherassets/sound/incoming_message.wavMessage from another conversation
incomingCallassets/sound/incoming_call.wavIncoming call detected
outgoingCallassets/sound/outgoing_call.wavOutgoing call initiated

Usage

import 'package:cometchat_uikit_shared/cometchat_uikit_shared.dart';

// Play incoming message sound
SoundManager().play(sound: Sound.incomingMessage);

// Play outgoing call sound
SoundManager().play(sound: Sound.outgoingCall);

// Play custom notification sound
SoundManager().play(
  sound: Sound.incomingMessage,
  customSound: "assets/sounds/notification.mp3",
);

// Play looping ringtone for incoming call
SoundManager().play(
  sound: Sound.incomingCall,
  isLooping: true,
);

// Stop any playing sound
SoundManager().stop();
Sound behavior varies by OS when the app is in the background.