如果你在soundmanager2中有两个声音,通常你可以同时播放两个声音,在Android和其他手机上调用播放一个声音会停止所有其他声音。
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
有什么方法可以在Android上运行多个声音?如果没有,有什么方法我可以检测到这种能力一次只能运行一个声音吗?
推理:我想在游戏中持续播放背景音乐,并在理想情况下播放声音而不停止背景音乐。
答案 0 :(得分:0)
我没有找到在Android上运行多个声音的方法,但我所做的是检测声音是否已被此限制停止并重新启动它们在声音播放完毕后的位置。
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
});
}
}
});