Time for action – adding the audio sequencer

Let's add the audio sequencer to the game panel. We will go into the GamePanel object and add an instance of AudioSequencer to it:

function GamePanel(audioManager)
{
    var sequencer = new AudioSequencer();

Next let's write the public setOptions() method, which is called from the startGame() method of PianoHeroApp. It takes three parameters; the song name, playback rate, and whether to play the game or the song in practice mode:

    this.setOptions = function(songName, rate, playGame)
    {
        sequencer.events(musicData[songName])
                 .playbackRate(rate);
        practiceMode = !playGame;
        return this;
    };

The first thing we do is set the events() property of the audio sequencer to the data for the song to play. We get the song data ...

Get HTML5 Web Application Development By Example Beginner's guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.