audio.js

audio.js is a drop-in javascript library that allows HTML5's <audio> tag to be used anywhere.

It uses native <audio> where available and falls back to an invisible flash player to emulate it for other browsers. It provides a consistent html player UI to all browsers which can be styled used standard css.

It plays mp3s. No ogg. Because, lets be honest, in the real world, no one really exports ogg files.

Download audio.js

Installation

  1. Put audio.js, player-graphics.gif & audiojs.swf in the same folder.

  2. Include the audio.js file:

    <script src="/audiojs/audio.js"></script>
  3. Initialise audio.js:

    <script>
      audiojs.events.ready(function() {
        var as = audiojs.createAll();
      });
    </script>
  4. Then you can use <audio> wherever you like in your HTML:

    <audio src="/mp3/juicy.mp3" preload="auto" />

Examples

A series of API tests & examples for using and extending audio.js

Example 1 Playlist player

Example 2 Multiple players, testing preload, loop & autoplay attributes

Browser support

With Flash as a fallback, it should work pretty much anywhere.
It has been verified to work across:

Source code

All efforts have been made to keep the source as clean and readable as possible. Until we release more detailed documentation, the annotated source is the best reference for usage.

Annotated source / Source on Github