Kendall
Kendall

Reputation: 5255

using SoundManager 2 js to play multiple files

I'm using SoundManager2.js as my framework for cross browser audio features. I'm trying to understand the documentation but I'm having some trouble stopping one audio file and playing another.

Can someone give me an example of loading multiple audio files and being able to "swap/ switch" between them using the framework?

Upvotes: 0

Views: 2873

Answers (1)

megawac
megawac

Reputation: 11363

You can call soundManager.stopAll() or soundManager.pauseAll() (documentation) before you start your desired sound. Believe the below code should work kind of just picked and chose from some code I've written before:

soundManager.setup({
    preferFlash: false,
    //, url: "swf/"
    onready: function () {
        soundManager.createSound({
            url: [
                "http://www.html5rocks.com/en/tutorials/audio/quick/test.mp3", "http://www.html5rocks.com/en/tutorials/audio/quick/test.ogg"
            ],
            id: "music"
        });
        soundManager.createSound({
            url: [
                "http://www.w3schools.com/html/horse.mp3", "http://www.w3schools.com/html/horse.ogg"
            ],
            id: "horse"
        });
        soundManager.play("music"); //start playing annoying music
    }
}).beginDelayedInit();

And to start horse and pause all other sounds currently playing in a click event:

$("#horse").click(function () {
    soundManager.stopAll();
    soundManager.play("horse");
});

DEMO

Upvotes: 5

Related Questions