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
Mute everything at once
Idletokyo-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, sogetSoundVolumestill returns its own value andgetGlobalVolumereturns0. - Streams from
loadStreamare also muted one by one withmute, and each dispatchesmuted. - Calling it twice is safe: the remembered master volume is not overwritten with
0. setGlobalVolumewhile muted stores the new value for when you unmute, but does not make anything audible.- Dispatches
SoundEventsEnum.MUTE_GLOBAL('mute_global').
See also
unmuteAllSounds: bring the mix back.toggleGlobalMute: one call for a global mute button.fadeGlobalOut: fade to silence instead of cutting.