Javascript examples for DOM HTML Element:Audio
The volume property sets or gets the audio volume of an audio, from 0.0 (silent) to 1.0 (loudest).
Set the volume property with the following Values
Value | Description |
---|---|
number | Sets the audio volume of the audio. Must be a number between 0.0 to 1.0 |
Example values:
A Number, representing the audio volume of the audio
The following code shows how to set audio volume to 20%:
<!DOCTYPE html> <html> <body> <audio id="myAudio" controls> <source src="your.ogg" type="audio/ogg"> <source src="your.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio>// w w w . ja v a 2 s .c o m <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() { console.log(x.volume); } function setHalfVolume() { x.volume = 0.2; } function setFullVolume() { x.volume = 1.0; } </script> </body> </html>