Horje

How to Run "myFunction" when the volume of the audio changes - HTML onvolumechange Attribute

Audio Example. Change the volume of the audio. This example demonstrates how to use the "onvolumenchange" attribute on an AUDIO element.
index.html
Example: HTML
<!DOCTYPE html> 
<html> 
<body> 

<p id="demo">Change the volume of the audio:</p>

<audio id="myAudio" controls onvolumechange="myFunction()">
  <source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_2MG.mp3" type="audio/ogg">
  <source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_2MG.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "You changed the volume";
}
</script> 

<p>This example demonstrates how to use the "onvolumenchange" attribute on an AUDIO element.</p>

</body> 
</html>

Output should be:

How to Run "myFunction" when the volume of the audio changes - HTML onvolumechange Attribute




Type:
html
Category:
Web Tutorial
Sub Category:
HTML Attribute
Uploaded by:
Admin