<!DOCTYPE html>
<html>
<body>
<audio id="myAudio" controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<p>Click the buttons to get or set the volume of the audio player.</p>
<button onclick="getVolume()" type="button">What is the volume?</button>
<button onclick="setHalfVolume()" type="button">Set volume to 0.2</button>
<button onclick="setFullVolume()" type="button">Set volume to 1.0</button>
<script>
var x = document.getElementById("myAudio");
function getVolume() {
alert(x.volume);
}
function setHalfVolume() {
x.volume = 0.2;
}
function setFullVolume() {
x.volume = 1.0;
}
</script>
</body>
</html>