removeSound
Remove a sound from the hub for good. It does everything unloadSound does and also forgets the url, so the id has to be loaded with a url again before it can play.
removeSound(id: string): void;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
id | string | required | ID of the sound or stream to remove. |
Returns
Nothing.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('rain', '/audio/rain.mp3');
soundHub.removeSound('rain');
soundHub.hasSound('rain'); // false
soundHub.getSoundUrls('rain'); // []
Good to know
- Like
unloadSound, it stops a buffered sound (dispatchingstopped), then dispatchesunloaded. - For a stream it does exactly what
unloadSounddoes. A stream has no url on file to forget. - An id that is not loaded is ignored silently. The url of a sound that is registered but not loaded is not forgotten in that case.
- Overlapping instances and sprite sounds are separate entries and stay in the hub.
See also
unloadSound: free the audio but keep the url for a reload.hasSound: check whether an id is still loaded.reset: clear the whole hub at once.