Master Sound on/off function

Hi Matt (@popidev)

You can use javascript to implement the .muted property of HTML5 audio:

<audio id="sound1">
    <source src="....">
</audio>

using the below script on a button for example

var sound1 = document.getElementById("sound1");

sound1.muted = true; // mute

will mute the audio with the id sound1

If you want to mute more than one sound you can add the other sounds to the above script individually (duplicate with different ID’s) or you can use the audio tag for example

var sounds = document.getElementsByTagName("audio");
var muteBtn = document.getElementById("mute");

muteBtn.onclick = function () {

	for (var i = 0; i < sounds.length; ++i) {
    	
    		sounds[i].muted = true;
    }

}

Have a look at this to see if it helps!

D

1 Like