Skip to main content

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​

Try it

Control every sound at once

Idle
tokyo-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 pause for each sound, so every one dispatches its own paused event. Overlapping instances are paused too.
  • Streams from loadStream are included.
  • This pauses the sounds themselves. The audio context keeps running; see suspendContext to stop the whole audio engine.

See also​