removeSoundGroup
Delete a group and stop every sound in it. Use it when a scene ends and all of its sounds should go quiet at once.
removeSoundGroup(groupName: string): void;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
groupName | string | required | Name of the group to remove. |
Returns
Nothing.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSounds([
{ id: 'rain', url: '/audio/rain.mp3' },
{ id: 'click', url: '/audio/click.mp3' },
]);
soundHub.createSoundGroup('level-1');
soundHub.play('rain', { loop: true, groupId: 'level-1' });
soundHub.play('click', { overlap: true, groupId: 'level-1' });
// Level over: stop everything in the group
soundHub.removeSoundGroup('level-1');
soundHub.getGroup('level-1'); // undefined
soundHub.play('rain'); // still loaded, plays outside any group
Good to know
- Every member is stopped, playing or not, which dispatches a
stoppedevent for each one that is still in the hub. - Overlapping instances such as
'click:1'are removed from the hub along with the group. - A loaded sound stays in the hub and simply leaves the group, so you can play it again. The group play options that were merged into it are not taken back.
- An unknown group name does nothing apart from a debug log.
See also
createSoundGroup: make a group.removeFromSoundGroup: take out one sound and keep the group.stopAllSounds: stop everything, grouped or not.soundGroup: overview of sound groups.