Javascript DOM HTML Audio defaultMuted Property

Introduction

Mute the audio:

document.getElementById("myAudio").defaultMuted = true;

View in separate window

<!DOCTYPE html> 
<html> 
<body> 

<audio id="myAudio" controls>
  <source src="sound.ogg" type="audio/ogg">
  <source src="sound.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio><br>
<p id="demo"></p>
<button onclick="getMuted()" type="button">Is the audio muted by default?</button>
<button onclick="setToMuted()" type="button">Mute audio, and reload video</button>

<script>
var x = document.getElementById("myAudio");
function getMuted() { /*from  ww w  .  ja  v a2  s  .  c  om*/
  document.getElementById("demo").innerHTML = x.defaultMuted;
} 

function setToMuted() { 
  x.defaultMuted = true;
  x.load()
} 
</script> 

</body> 
</html>

The defaultMuted property sets or gets whether the audio should be muted by default.

This property changes the default muted state, and it does not mute the current audio.

To mute the playing audion, use the muted property.

Possible values:

Value Description
true the audio is muted by default
false Default. the audio is NOT muted by default

The defaultMuted property returns a boolean value.

It returns true if the audio is muted by default, otherwise it returns false.




PreviousNext

Related