gpt4 book ai didi

javascript - SoundManager2 在 Android 上同时播放多个声音

转载 作者:行者123 更新时间:2023-11-28 07:02:21 26 4
gpt4 key购买 nike

如果 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 上运行多个声音吗?如果没有,有什么方法可以检测到这种能力,一次只运行一个声音?

推理:我希望游戏中有持续的背景音乐,并在理想的情况下播放声音,而无需停止背景音乐。

最佳答案

我没有找到在 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
});
}
}
});

关于javascript - SoundManager2 在 Android 上同时播放多个声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32019552/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com