<!DOCTYPE html>
<html>
<body>
<h1>HTML DOM Events</h1>
<h2>The onvolumechange Event</h2>
<video id="myVideo" width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
<p>Try to change the volume.</p>
<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>
const video = document.getElementById("myVideo");
video.addEventListener("volumechange", getVolume);
function getVolume() {
document.getElementById("demo").innerHTML = "The audio volume is: " + video.volume;
}
function setHalfVolume() {
video.volume = 0.2;
}
function setFullVolume() {
video.volume = 1.0;
}
</script>
</body>
</html>