Skip to main content

SoundGroup

The SoundGroup interface defines how sound groups are configured.

export interface SoundGroup {
maxInstances?: number;
playOptions?: PlayOptions;
}

Group Management Methods

createSoundGroup

createSoundGroup(groupName: string, options: SoundGroup): void;

Create a new sound group with a specified name and options. Groups allow you to control multiple sounds collectively.

addToSoundGroup

addToSoundGroup(groupName: string, soundId: string): void;

Add a sound to a group by its ID and the group name. The sound inherits group-level settings.

removeFromSoundGroup

removeFromSoundGroup(groupName: string, soundId: string): void;

Remove a sound from a group by its ID and the group name.

getGroup

getGroup(groupName: string): SoundGroup | undefined;

Get a sound group by its name.

removeSoundGroup

removeSoundGroup(groupName: string): void;

Remove a sound group by its name, stopping all sounds in the group.


Example

await soundManager.loadSounds([
{ id: 'tokyo-train', url: 'tokyo-train-melody.mp3' },
{ id: 'bells-melody', url: 'bells-melody.mp3' },
{ id: 'techno-tune', url: 'techno-tune.mp3' }
]);

// Create an ambient group
soundManager.createSoundGroup('ambient-group', {});

// Add sounds to the group
soundManager.addToSoundGroup('ambient-group', 'tokyo-train');
soundManager.addToSoundGroup('ambient-group', 'bells-melody');
soundManager.addToSoundGroup('ambient-group', 'techno-tune');

// Play each sound in the group
soundManager.play('tokyo-train', { loop: true, volume: 0.5 });
soundManager.play('bells-melody', { loop: true, volume: 0.5 });
soundManager.play('techno-tune', { loop: true, volume: 0.5 });

// Remove when done
soundManager.removeSoundGroup('ambient-group');

Sound Group: ambient-group

Try it: Create a group with createSoundGroup(name, options), add sounds with addToSoundGroup(name, id), then control them together. Groups also support volume and pan settings via SoundGroup options.