问题描述:

If you have two sounds in soundmanager2 normally you can play both at the same time, on android and other mobiles calling play on one sound will stop all other sounds.

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"

});

}

}).beginDelayedInit();

$("#horse").click(function () {

soundManager.play("horse"); // <- stops other sounds on mobile :(

});

$("#music").click(function() {

soundManager.play("music"); // <- stops other sounds on mobile :(

});

http://jsbin.com/hopapagefa/1/edit?html,js,output

Is there some way i can run multiple sounds on android? If not is there some way i can detect this ability to only run one sound at once?

reasoning: I want to have constant background music in a game and play a sound when something happens ideally without stopping the background music.

网友答案:

I didn't find a way to run multiple sounds on android but what i did was detect if sounds had been stopped by this limitation and the restart them where they were once the sound had finished playing e.g.

var isPlaying = function (name) {
    return soundManager.getSoundById(name).playState == 1;
};

// we want to play horse music over our background music
var oldPosition = soundManager.getSoundById('music').position;
soundManager.play("horse", {
    onfinish: function() {
        if(!isPlaying('music')) { 
            // mobile devices must have cut the background music off :(

            // should probably check if its still appropriate to replay the background music
            soundManager.play("music", {
                position: oldPosition
            });
        }
    }
});
相关阅读:
Top