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 AudioSequencer

Let's create our AudioSequencer object in a file called audioSequencer.js. We'll start by defining a few variables:

function AudioSequencer()
{
    var _events = [],
        _playbackRate = 1,
        _playing = false,
        eventHandler = undefined,
        timeoutID = 0;

First we define an _events array to hold all of the music events to play. The _playbackRate variable controls how fast the song plays. A value of 1 will be at normal speed, less than 1 slower, and more than 1 faster. The _playing variable is set to true while a song is playing. eventHandler will be set to a function that gets called when an event is fired, and timeoutID will contain the handle returned from setTimeout() in case the user stops the game and we need to cancel ...

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