mute
Silence one sound. It keeps playing, just without being heard, and its volume is remembered for unmute.
mute(id: string): void;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
id | string | required | ID of the sound or stream to mute. |
Returns
Nothing.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('music', '/audio/theme.mp3');
soundHub.play('music', { loop: true });
// Still playing, just silent
soundHub.mute('music');
// Back to the volume it had
soundHub.unmute('music');
Try it
Mute without stopping
IdleStatestopped
Mutedno
A muted sound keeps playing in silence, so unmuting comes back at the right point in the track.
Code
Your clicks show up here as soundhub calls
Good to know
- Muting a sound that is already muted does nothing, so a second call cannot overwrite the remembered volume with
0. getSoundVolumekeeps returning the volume from before the mute.- The sound stays muted until
unmute,toggleMuteorsetSoundVolume. Playing it again does not unmute it; avolumepassed toplay()becomes the volumeunmutereturns to. Before 6.4.0 a freshplay()ended the mute. - Dispatches
SoundEventsEnum.MUTED('muted'). Works on streams fromloadStreamtoo. For an id that is not loaded, the error is logged, stored forgetLastErrorand dispatched as anerrorevent.
See also
unmute: bring the sound back.toggleMute: one call for a mute button.muteAllSounds: silence everything at once.