我想在用户单击图像时播放声音。我正在使用 SoudManager 插件。
在这里你可以检查我在做什么:
soundManager.setup({
url: 'swf',
onready: function() {
soundCarro = soundManager.createSound({
id: 'soundCarro',
url: 'sound/carro_camona.mp3'
});
soundMoto = soundManager.createSound({
id: 'soundMoto',
url: 'sound/moto_camona.mp3'
});
soundNautico = soundManager.createSound({
id: 'soundNautico',
url: 'sound/nautico_camona.mp3'
});
}
});
如您所见,我创建了 3 个声音对象(soundCarro、soundMoto 和 soundNautico)。
这里是动作,当用户单击它时,会调用 scrollTo 函数:
<img id="ca" class="ca logo" onclick="scrollTo('secao-carros',true);" src="images/svg/CAhome.svg">
在这里你可以看到 scrollTo 函数:
function scrollTo(target,sound){
if(sound){
var delay = 0;
if(target == 'secao-carros'){
soundCarro.play();
delay = 700;
duration = 750;
}
if(target == 'secao-motos'){
soundMoto.play();
delay = 900;
duration = 750;
}
if(target == 'secao-nauticos'){
soundNautico.play();
delay = 850;
duration = 2000;
}
$('html, body').delay(delay).animate({ scrollTop: $('#'+target).offset().top }, {duration: duration});
}else{
$('html, body').animate({ scrollTop: $('#'+target).offset().top }, {duration: 750});
}
}
如您所见,在此函数中,我执行创建的声音对象(例如:soundNautico.play();)。
问题是,在 iPad 和 Android 设备上,这种声音的执行会有很大的延迟,但在桌面浏览器中它可以完美运行!
我怎样才能防止这种延迟?