Using the volume property to set the volume: - Javascript DOM Event

Javascript examples for DOM Event:onvolumechange

Description

Using the volume property to set the volume:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<video id="myVideo" width="320" height="240" controls>
  <source src="your.mp4" type="video/mp4">
  <source src="your.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>/*from  w w w  .  j  a v  a 2s .c o  m*/

<button onclick="setHalfVolume()" type="button">Set volume to 0.2</button>
<button onclick="setFullVolume()" type="button">Set volume to 1.0</button>

<p id="demo"></p>

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

x.addEventListener("volumechange", getVolume);

function getVolume() {
    document.getElementById("demo").innerHTML = "The audio volume is: " + x.volume;
}

function setHalfVolume() {
    x.volume = 0.2;
}

function setFullVolume() {
    x.volume = 1.0;
}
</script>

</body>
</html>

Related Tutorials