Audio tag GUI not visible

Bunny Rabbit picture Bunny Rabbit · Aug 15, 2012 · Viewed 8.2k times · Source

I have included the audio tag on a page as

<audio src='a.mp3' preload='auto'>
</audio>

but its not working, i can't see anything on the page.

But when i include audiojs as

  <script src="/static/js/audiojs/audio.min.js"></script>
  <script>
    audiojs.events.ready(function() {
      var as = audiojs.createAll();
    });

  </script>

I am left wondering why is that so ?

Answer

papercutexit picture papercutexit · Aug 15, 2012

From what I've learned, src is an element inside audio, not an attribute. So your code should look like this:

<audio controls="controls">
  <source src="song.ogg" type="audio/ogg" />
  <source src="song.mp3" type="audio/mpeg" />
  Your browser does not support the audio element.
</audio>

(Source)

Edit: src can also be an attribute, so that wasn't your problem. In order for the browser to display anything for audio, you need the "controls" attribute. However, if you don't want the default controls, add html buttons and control the start/stop etc. of the audio with JavaScript.