所以我有这个应用程序,每次循环播放声音时都需要有淡入淡出效果,以便过渡顺利进行。
我正在使用 SoundManager 2。
更新代码:
$(document).ready(function () {
alert("Testing sound");
soundManager.flashVersion = 9;
soundManager.url = '/assets/soundmanager/swf/';
soundManager.onready(function(){
soundManager.createSound({
id:"EngineIdle",
url:"/assets/sounds/EngineIdle.ogg",
stream: true,
autoPlay: true,
multiShot: false,
volume: 0,
onplay:function() {
var fadingin = setInterval(fadein, 20);
},
onfinish:function() {
clearInterval('fadingout'); //We declared the interval as a variable earlier so we can cancel it
soundManager.play('EngineIdle');
}
});
var FadeOutTime = 2;
soundManager.onPosition('EngineIdle', FadeOutTime, function(){var fadingout = setInterval(fadeout, 20)});
});
function fadein() {
var s = soundManager.getSoundById('EngineIdle');//Again, unoptimal
if (s.volume == 100) {
clearInterval('fadingin');
return
}
s.setVolume(s.volume + 20);
}
function fadeout() {
var s = soundManager.getSoundById('EngineIdle'); //This is unoptimal to call each time, but you can fix that
if (s.volume > 0) {
s.setVolume(s.volume - 20);
}
}
});
关于如何在同一声音的每个过渡之间获得交叉淡入淡出的循环的任何想法?