Audio.js with Volume Control


Hits: 13111  

I was working on HTML5 MP3 Player Project using audio.js and I got Audio.js with Volume Control to control the volume for the Flash alternative player?

Volume Control - audio.js

<script>
      audiojs.events.ready(function() {
        var as = audiojs.createAll(),
            audio = as[0],
            ids = ['vol-0', 'vol-10', 'vol-40', 'vol-70', 'vol-100'];
        for (var i = 0, ii = ids.length; i < ii; i++) {
          var elem = document.getElementById(ids[i]),
              volume = ids[i].split('-')[1];
          elem.setAttribute('data-volume', volume / 100)
          elem.onclick = function(e) {
            audio.setVolume(this.getAttribute('data-volume'));
            e.preventDefault();
            return false;
          }
        }
        
      });
    </script>
<audio src="audiofile.mp3"></audio>
    <p><a href="#" id="vol-0">Volume: 0%</a></p>
    <p><a href="#" id="vol-10">Volume: 10%</a></p>
    <p><a href="#" id="vol-40">Volume: 40%</a></p>
    <p><a href="#" id="vol-70">Volume: 70%</a></p>
    <p><a href="#" id="vol-100">Volume: 100%</a></p>

You can also use the same volume as in https://github.com/dz0ny/AudioJS

Published by

Sandeep Verma

I’m an Entrepreneur. I’m proud to work as Blogger, LAMP Programmer, Linux Admin, Web Consultant, Cloud Manager, Apps Developer, Searcher. Concentrate > Observe > Imagine > Launch