Skip to main content

mute

Silence one sound. It keeps playing, just without being heard, and its volume is remembered for unmute.

mute(id: string): void;

Parameters​

ParameterTypeDefaultDescription
idstringrequiredID 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​

Try it

Mute without stopping

Idle
Statestopped
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.
  • getSoundVolume keeps returning the volume from before the mute.
  • The sound stays muted until unmute, toggleMute or setSoundVolume. Playing it again does not unmute it; a volume passed to play() becomes the volume unmute returns to. Before 6.4.0 a fresh play() ended the mute.
  • Dispatches SoundEventsEnum.MUTED ('muted'). Works on streams from loadStream too. For an id that is not loaded, the error is logged, stored for getLastError and dispatched as an error event.

See also​