Audio defaultMuted Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Audio

Description

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

To change the current muted state, use the muted property.

Set the defaultMuted property with the following Values

Value Description
true|false Sets whether the audio should be muted by default.
  • true - Indicates that the audio is muted by default
  • false - Default. Indicates that the audio is NOT muted by default

Return Value

A Boolean, returns true if the audio is muted by default, otherwise it returns false

The following code shows how to Set the audio to be muted by default:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<audio id="myAudio" controls>
  <source src="your.ogg" type="audio/ogg">
  <source src="your.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio><br>

<button onclick="getMuted()" type="button">Is the audio muted by default?</button>
<button onclick="setToMuted()" type="button">Set audio to be muted by default, and reload video</button>

<script>
var x = document.getElementById("myAudio");
function getMuted() {/*from   w  w w.  j  a v a2s  .  co  m*/
    console.log(x.defaultMuted);
}

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

</body>
</html>

Related Tutorials