문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top