Skip to main content

muteAllSounds

Silence everything at once. The sounds keep playing, and the master volume is remembered for unmuteAllSounds.

muteAllSounds(): 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 });

soundHub.muteAllSounds();

// Later
soundHub.unmuteAllSounds();

Try it​

Try it

Mute everything at once

Idle
tokyo-trainstopped
bells-melodystopped
techno-tunestopped
Masteraudible

The three sounds keep playing while muted. Only the master output goes silent.

Code
Your clicks show up here as soundhub calls

Good to know​

  • It sets the master gain to 0. The volume of each buffered sound is not touched, so getSoundVolume still returns its own value and getGlobalVolume returns 0.
  • Streams from loadStream are also muted one by one with mute, and each dispatches muted.
  • Calling it twice is safe: the remembered master volume is not overwritten with 0.
  • setGlobalVolume while muted stores the new value for when you unmute, but does not make anything audible.
  • Dispatches SoundEventsEnum.MUTE_GLOBAL ('mute_global').

See also​