Javascript DOM onvolumechange Event

Introduction

Execute a JavaScript when the volume of a video has been changed:

This example demonstrates how to assign an "onvolumechange" event to a video element.

Try to change the volume in the bottom right corner.

View in separate window

<!DOCTYPE html>
<html>
<body>
<video controls onvolumechange="myFunction()">
  <source src="video.mp4" type="video/mp4">
  <source src="video.ogg" type="video/ogg">
  Your browser does not support HTML5 video.
</video>//from www. jav a 2  s  . c om

<p id="demo"></p>
<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "The volume has been changed!";
}
</script>

</body>
</html>

The onvolumechange event occurs each time the volume of a video/audio has been changed.

You can use the volume property of the Audio/Video Object to set or return the audio volume of an audio/video.




PreviousNext

Related