Set video volume to 20%:
document.getElementById("myVideo").volume = 0.2;
Click the buttons to get or set the volume of the video.
<!DOCTYPE html> <html> <body> <p id="demo"></p> <video id="myVideo" width="100" height="100" controls> <source src="video.mp4" type="video/mp4"> <source src="video.ogg" type="video/ogg"> Your browser does not support the video tag. </video>//from ww w.j a v a 2s .co m <button onclick="getVolume()" type="button">Get 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("myVideo"); function getVolume() { document.getElementById("demo").innerHTML = x.volume; } function setHalfVolume() { x.volume = 0.2; } function setFullVolume() { x.volume = 1.0; } </script> </body> </html>
The volume property sets or gets the audio volume of a video, from 0.0 (silent) to 1.0 (loudest).
Property Values
Value | Description |
---|---|
number | Specifies the audio volume of the video. Must be a number between 0.0 to 1.0 |
Example values:
The volume property returns a Number representing the audio volume of the video.