stopAllSounds
Stop everything at once, for example when a level ends or a scene changes. Paused sounds are stopped too, and every position goes back to the start.
stopAllSounds(): void;
Parameters
This method takes no parameters.
Returns
Nothing.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSounds([
{ id: 'music', url: '/audio/theme.mp3' },
{ id: 'rain', url: '/audio/rain.mp3' },
]);
soundHub.play('music', { loop: true });
soundHub.play('rain', { loop: true });
// Level over
soundHub.stopAllSounds();
Try it
Control every sound at once
Idletokyo-trainstopped
bells-melodystopped
techno-tunestopped
One call reaches every sound. Each state comes from the events the library sends.
Code
Your clicks show up here as soundhub calls
Good to know
- It calls
stopfor every sound that is not already stopped, so each one dispatches its ownstoppedevent and loses running fades. - Streams from
loadStreamare stopped too, and each dispatchesstopped. - The sounds stay loaded. Use
unloadSoundorresetto free them.
See also
stop: stop a single sound.pauseAllSounds: halt everything but keep positions.fadeGlobalOut: fade the whole mix out first.