【发布时间】:2014-11-18 21:32:51
【问题描述】:
当我使用以下代码淡入文件时,它无法按预期工作。我希望在 5 秒内从 0 逐渐淡入到 1,相反,在播放文件的 5 秒内我会突然改变增益立即从 0 变为 1。我不明白什么?
soundObj.play = function() {
playSound.buffer = soundObj.soundToPlay;
playSound.connect(gainNode);
gainNode.gain.value = 0;
gainNode.gain.exponentialRampToValueAtTime(1, audioContext.currentTime + 5);
gainNode.connect(audioContext.destination);
playSound.start(audioContext.currentTime);
}
更新/编辑
我将上面的代码更改为以下代码,它似乎可以工作,现在我正在研究为什么。我添加了一些cmets。主要询问是否需要添加setValueAtTime方法,gain.value属性默认值是否需要非零值。
soundObj.play = function() {
playSound.buffer = soundObj.soundToPlay;
playSound.connect(gainNode);
gainNode.gain.value = 0.001; // If set to 0 it doesn't fade in
gainNode.gain.setValueAtTime(gainNode.gain.value, audioContext.currentTime); // Is this needed to have the other RampToValue methods work ?
gainNode.gain.exponentialRampToValueAtTime(1, audioContext.currentTime + 7);
gainNode.connect(audioContext.destination);
playSound.start(audioContext.currentTime);
}
【问题讨论】:
标签: javascript asp.net-web-api html5-audio web-audio-api