Skip to main content

removeFromSoundGroup

Remove a sound from a group's member list. The sound keeps playing and stays loaded.

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

Parameters​

ParameterTypeDefaultDescription
groupNamestringrequiredName of the group.
soundIdstringrequiredID of the sound or instance to take out.

Returns​

Nothing.

Example​

import { SoundHub } from 'soundhub';

const soundHub = new SoundHub();
await soundHub.loadSound('rain', '/audio/rain.mp3');

soundHub.createSoundGroup('ambience', { maxInstances: 2 });
soundHub.addToSoundGroup('ambience', 'rain');

soundHub.removeFromSoundGroup('ambience', 'rain');
soundHub.getGroup('ambience')?.sounds.has('rain'); // false

Good to know​

  • It only updates the member list. The sound is not stopped, and the group's play options that were merged into it stay.
  • The sound forgets the group, so the next play leaves it out. Before 6.4.0 it kept the link and play() put it straight back in.
  • Options the group gave the sound through its playOptions stay on the sound.
  • An unknown group name does nothing apart from a debug log. An id that is not in the group is ignored.
  • No event is dispatched.

See also​