How to Check if Sound is Muted in Howler.js

This article explains how to detect the mute status of your audio when using the Howler.js library. You will learn how to check the global mute state of the entire application as well as how to check the mute state of individual sound instances and specific playback IDs.

Checking the Global Mute State

Howler.js manages global audio states using the global Howler object. To check if all sounds in your application are currently muted, you can access the semi-private _muted property on the Howler object.

// Returns true if globally muted, false otherwise
const isGloballyMuted = Howler._muted;

if (isGloballyMuted) {
    console.log("All sounds are currently muted.");
}

Checking Individual Sound Mute State

If you want to check the mute status of a specific Howl instance, you can use the .mute() method. When called without any arguments, this method acts as a getter and returns a boolean indicating whether the specific sound instance is muted.

// Create a new sound instance
const sound = new Howl({
  src: ['sound.mp3']
});

// Check if this specific sound instance is muted
const isMuted = sound.mute();

if (isMuted) {
    console.log("This sound is muted.");
}

Checking Mute State for a Specific Sound ID

In Howler.js, a single Howl instance can play multiple overlapping sounds, each assigned a unique playback ID. If you need to check the mute status of a specific playback ID rather than the entire Howl instance, pass undefined as the first argument and the playback ID as the second argument to the .mute() method.

const sound = new Howl({
  src: ['sound.mp3']
});

// Play the sound and capture its unique ID
const soundId = sound.play();

// Check the mute status of this specific playback ID
const isIdMuted = sound.mute(undefined, soundId);

if (isIdMuted) {
    console.log(`Sound playback with ID ${soundId} is muted.`);
}