HTML5 Game - Get Media volume

Description

Get Media volume

Demo

ResultView the demo in separate window

<!DOCTYPE html>
<html>
  <head>
    <title>Chapter 3 - Volume</title>
  </head>/*from w w w. jav a  2s  .  c o m*/

  <body>
    <audio controls>
        <source src='http://java2s.com/style/demo/your.ogg' type='audio/ogg; codecs=vorbis'>
         <source src='http://java2s.com/style/demo/your.mp3' type='audio/mpeg'>
    </audio>
    <script>
      let ele = document.querySelector('audio');
      //if you have a video tag
      // let ele = document.querySelector('video'); 

function getVolume()  {
  return ele.volume;
}

let vol = 0.5; // The volume you want to set it to 
  
console.log(ele.volume); 
  
ele.volume = vol; 
  
console.log(ele.volume); 
      </script>
  </body>
</html>

Related Topic