Skip to main content

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​

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​

  • It calls stop for every sound that is not already stopped, so each one dispatches its own stopped event and loses running fades.
  • Streams from loadStream are stopped too, and each dispatches stopped.
  • The sounds stay loaded. Use unloadSound or reset to free them.

See also​