title: Show current volume of html5 audio with javascript?
body: <p>I have coded in PHP/JavaScript and styled (CSS) to my liking a html5 audio soundboard, this scans a dir for mp3's, puts the found files in a PHP array and then displays 'an instance' of my custom-styled 'player' for each file it finds.</p>
  
  <p>I have included volume up and down buttons for this and would like to know if it is possible to display the current volume value (probably using javascript) when the volume is being changed, or even all the time but updating as it's changed?</p>
  
  <p>I have done a fair old amount of searching for answers to this question but can only find answers for turning the volume up and down or setting an initial value etc, nothing for actually showing its current value, maybe it's the phrases I'm using to search (I've sure tried to word the searches in as many different ways as possible) but try as I might I can't seem to find any example code for me to try on this one so any help would be appreciated.</p>
  
  <p>Here is the full current code..</p>
  
  <pre><code>&lt;head&gt;
  &lt;meta id="setViewport" name="viewport" content="width=device-width, initial-scale=0.6, user-scalable=no"&gt;
  &lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"&gt;&lt;/script&gt; 
  &lt;script type="text/javascript" src="date_time.js"&gt;&lt;/script&gt;
  &lt;script&gt;
  if (screen.width &gt; 590) {
      var mvp = document.getElementById('setViewport');
      mvp.setAttribute('content','width=980 user-scalable=no');
  }
  &lt;/script&gt;
  &lt;meta name="mobile-web-app-capable" content="yes"&gt;
  &lt;meta name="HandheldFriendly" content="true" /&gt;
  &lt;meta name="google" content="notranslate" /&gt;
  
  &lt;style&gt;
  
  body {
    padding: 0px;
    background-color: black;
    color: white;
  
  }
  
  
  .singlesoundcontainer {
  display:inline-block;
  border: 3px solid #44c767;
  border-radius: 20px;
  background-color: #2b2d2f;
  opacity: 0.8;
  padding:5px;
  margin-right:8px;
  margin-bottom:18px;
  width:200px;
  text-align: center;
  font-weight:600;
  -webkit-box-shadow: 3px 3px 4px 1px #2a592a;
  -moz-box-shadow: 3px 3px 4px 1px #2a592a;
  box-shadow: 3px 3px 4px 1px #2a592a;    
  }
  
  .playbuttons {
      box-shadow:inset 0px 1px 0px 0px #a4e271;
      background:linear-gradient(to bottom, #89c403 5%, #77a809 100%);
      background-color:#89c403;
      border-radius:26px;
      border:1px solid #74b807;
      cursor:pointer;
      padding: 6px 8px;
      display: inline-block;
      margin-right: 6px;
  }
  .playbuttons:hover {
      background:linear-gradient(to bottom, #77a809 5%, #89c403 100%);
      background-color:#77a809;
  }
  .playbuttons:active {
      position:relative;
      top:1px;
  }
  .stopbuttons {
      box-shadow: inset 0px 1px 0px 0px #8a2a21;
      background: linear-gradient(to bottom, #c62d1f 5%, #f24437 100%);
          background-color: rgba(0, 0, 0, 0);
      background-color: #c62d1f;
      border-radius: 26px;
      border: 1px solid #d02718;
      float: right;
      cursor: pointer;
      color: #ffffff;
      font-family: Arial;
      font-size: 15px;
      font-weight: bold;
      padding: 20px 2px 20px 0px;
      text-decoration: none;
      text-shadow: 0px 1px 0px #810e05;
      white-space: normal;
      word-wrap: break-word;
      width: 98px;
      height: 82px;
  
  }
  .stopbuttons:hover {
      background:linear-gradient(to bottom, #f24437 5%, #c62d1f 100%);
      background-color:#f24437;
  }
  .stopbuttons:active {
      position:relative;
      top:1px;
  }
  
  .bottom_buttonwrapper {
      text-align: center;
      margin-top:8px;
      display:inline-block;
  }
  
  .playertime {
  box-shadow: inset 0px 2px 2px 0px #fff;
  background: linear-gradient(to bottom, #222 5%, #626262 100%);
  background-color: rgba(0, 0, 0, 0);
  background-color: #242415;
  border-radius: 8px;
  border: 1px solid #000;
  display:inline-block;
  cursor: default;
  color: #ffffff;
  font-family: Arial;
  font-size: 32px;
  font-weight: bold;
  padding: 0px 8px;
  margin-left: 6px;
  text-decoration: none;
  text-shadow: 0px 3px 0px #000;
  }
  
  .pause_button {
      box-shadow: inset 0px 1px 0px 0px #000;
      background: linear-gradient(to bottom, #cfff4a 5%, #D0BA00 100%);
      background-color: rgba(0, 0, 0, 0);
      background-color: rgba(0, 0, 0, 0);
      background-color: #e8d900;
      border-radius: 26px;
      border: 1px solid #000;
      display: inline-block;
      cursor: pointer;
      padding: 4px 36px;
      text-decoration: none;
      text-shadow: 0px 1px 0px #810e05;
      margin-top: 8px;
      margin-left: 10px;
  }
  .pause_button:hover {
      background:linear-gradient(to bottom, #f24437 5%, #c62d1f 100%);
      background-color:#f24437;
  }
  .pause_button:active {
      background:linear-gradient(to bottom, #f24437 5%, #c62d1f 100%);
      background-color:#f24437;
  }
  
  .vol_buttons {
      box-shadow: inset 0px 1px 0px 0px #FDFAFF;
      background: linear-gradient(to bottom, #E8E8E8 5%, #5E5E5E 100%);
          background-color: rgba(0, 0, 0, 0);
      background-color: rgba(0, 0, 0, 0);
      background-color: #AEAEAE;
      border-radius: 16px;
      border: 1px solid #000;
      cursor: pointer;
      color: black;
      display: inline-block;
      font-family: Arial;
      font-size: 15px;
      font-weight: bold;
  padding: 8px 26px;
      margin-right: 4px;
      margin-left: 4px;
  
  }
  &lt;/style&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;div id="container" style="width:99%; max-width:99%;"&gt;
  &lt;span id="date_time"&gt;&lt;/span&gt;
  &lt;script type="text/javascript"&gt;window.onload = date_time('date_time');&lt;/script&gt; &lt;br&gt;
  &lt;?php
  $files = scandir('audio');
  $files = array_slice($files, 2);
  $files = array_combine(range(1, count($files)), $files);
  foreach ($files as $id =&gt; $file) {
  //ID for for targeting by id
  //echo $id;
  
  //file url to feed to player
  //echo $file;
  
  //trimmed file url to act as title (removes first 3 and last 4 chars so '01 name.mp3' becomes 'name')
  //echo substr($file, 3, -4);
  
  
  { ?&gt;
  &lt;div class="singlesoundcontainer"&gt; &lt;svg viewBox="-4 0 180 24"&gt;&lt;text style="font: bold; fill: white;" x="0" y="15"&gt;&lt;?php echo substr($file, 3, -4); ?&gt;&lt;/text&gt;&lt;/svg&gt;
    &lt;audio id="player&lt;?php echo $id;?&gt;" src="audio/&lt;?php echo $file; ?&gt;"&gt;&lt;/audio&gt;
    &lt;button class="playbuttons" ontouchstart="document.getElementById('player&lt;?php echo $id;?&gt;').play()" onclick="document.getElementById('player&lt;?php echo $id;?&gt;').play()"&gt;&lt;img style="padding-left:5px; width: 71px; height: 70px;" alt="Media Play Button" src="images/play_button.png"&gt;&lt;/button&gt; 
    &lt;button class="stopbuttons"  ontouchstart="document.getElementById('player&lt;?php echo $id;?&gt;'); player&lt;?php echo $id;?&gt;.pause(); player&lt;?php echo $id;?&gt;.currentTime = 0;" onclick="document.getElementById('player&lt;?php echo $id;?&gt;'); player&lt;?php echo $id;?&gt;.pause(); player&lt;?php echo $id;?&gt;.currentTime = 0;"&gt;Stop/Reload &lt;small&gt;&lt;small&gt;+Show Track Length&lt;/small&gt;&lt;/small&gt;&lt;/button&gt;&lt;br&gt;
  
     &lt;button class="playertime"&gt;&lt;span id="time_mins&lt;?php echo $id;?&gt;"&gt;0:00&lt;/span&gt;&lt;span id="time_secs&lt;?php echo $id;?&gt;" style="colour:white;"&gt;&lt;/span&gt;&lt;/button&gt;
     &lt;button class="pause_button" ontouchstart="document.getElementById('player&lt;?php echo $id;?&gt;').pause()" onclick="document.getElementById('player&lt;?php echo $id;?&gt;').pause()"&gt;&lt;img style="padding-left:0px; height: 30px;" alt="Media Play Button" src="images/pause_button2.png"&gt;&lt;/button&gt;
    &lt;div class="bottom_buttonwrapper"&gt;
    &lt;button class="vol_buttons" ontouchstart="document.getElementById('player&lt;?php echo $id;?&gt;').volume -= 0.1" onclick="document.getElementById('player&lt;?php echo $id;?&gt;').volume -= 0.01"&gt;Vol -&lt;/button&gt;
    &lt;button class="vol_buttons" ontouchstart="document.getElementById('player&lt;?php echo $id;?&gt;').volume += 0.1" onclick="document.getElementById('player&lt;?php echo $id;?&gt;').volume += 0.01"&gt;Vol +&lt;/button&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;script&gt;
  // Get the audio element with id from variable
  var aud&lt;?php echo $id;?&gt; = document.getElementById('player&lt;?php echo $id;?&gt;');
  // Assign an ontimeupdate event to the audio element, and execute a function if the current playback position has changed
  aud&lt;?php echo $id;?&gt;.ontimeupdate = function() {myFunction&lt;?php echo $id;?&gt;()};
  function myFunction&lt;?php echo $id;?&gt;() {
    // Display the current position of the audio in a p element with id from var
    var seconds = Math.round((aud&lt;?php echo $id;?&gt;.duration - aud&lt;?php echo $id;?&gt;.currentTime) %60);
    document.getElementById('time_mins&lt;?php echo $id;?&gt;').innerHTML = Math.floor((aud&lt;?php echo $id;?&gt;.duration - aud&lt;?php echo $id;?&gt;.currentTime) /60) + ":";
    document.getElementById('time_secs&lt;?php echo $id;?&gt;').innerHTML = String("0" + seconds).slice(-2);
  
  }
  &lt;/script&gt;
  &lt;?php }  
  }
  ?&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>(Tips and pointers about my current code are welcome but bear in mind I'm very new and amateur at this so please be nice!) PS: I know i should probably move the CSS to its own .css file and not use negative margins and depreciated code too! :-/ </p>