Javascript DOM HTML Audio muted Property set

Introduction

Turn off sound:

document.getElementById("myAudio").muted = 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="enableMute()" type="button">Mute sound</button>
<button onclick="disableMute()" type="button">Enable sound</button>
<button onclick="checkMute()" type="button">Check muted status</button>

<script>
var x = document.getElementById("myAudio");

function enableMute() { /* www.j a  va 2 s.  co m*/
  x.muted = true;
} 

function disableMute() { 
  x.muted = false;
}
 
function checkMute() { 
  document.getElementById("demo").innerHTML = x.muted;
} 
</script> 

</body> 
</html>

The muted property turns on and off audio sound.

This property mirrors the <audio> muted attribute.

If present, the <audio> muted attribute can turn on/off that the audio sound.

Property Values

Value Description
true turned OFF the audio
false Default. turn ON the audio

It returns a boolean.

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




PreviousNext

Related