O'Reilly logo

HTML5 Web Application Development By Example Beginner's guide by J.M. Gustafson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – creating an AudioManager object

Let's encapsulate the loading of audio files into a re-usable object. We will create a new object called AudioManager and place it in a file named audioManager.js. This object will abstract all of the code needed to load, cache, and access audio files.

The constructor for our object takes one parameter named audioPath, which is the path to where audio files are stored:

function AudioManager(audioPath)
{
    audioPath = audioPath || "";
    var audios = {},
        audioExt = getSupportedFileTypeExt();

If audioPath isn't defined, we default it to an empty string. Then we add a variable named audios which is an object that will be used to cache all of the <audio> elements that are loaded. Finally, we define a variable ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required