pauseAllSounds
Pause everything that is playing. Each sound keeps its own position, so resumeAllSounds carries them all on from where they were. Handy for a pause menu.
pauseAllSounds(): 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 });
// Open the pause menu
soundHub.pauseAllSounds();
// Close it again
soundHub.resumeAllSounds();
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
- Only sounds that are playing are paused. Stopped and already paused sounds are left alone.
- It calls
pausefor each sound, so every one dispatches its ownpausedevent. Overlapping instances are paused too. - Streams from
loadStreamare included. - This pauses the sounds themselves. The audio context keeps running; see
suspendContextto stop the whole audio engine.
See also
resumeAllSounds: carry every paused sound on.stopAllSounds: stop everything and reset positions.muteAllSounds: silence everything but keep it playing.