【发布时间】:2015-01-24 19:09:53
【问题描述】:
我有下面的代码来播放加载到缓冲区中的特定声音。
sound1.gainNode = context.createGain();
sound1.source = context.createBufferSource();
sound1.source.buffer = soundBuffers[num];
sound1.source.connect(sound1.gainNode);
sound1.gainNode.connect(context.destination);
sound1.source.looping = true;
sound1.source.start(0);
以下是我如何调用更改音量方法:
<input type="range" min="0" max="100" value="70" id="playBtn1_vol" onchange="changeVolume(this,sound1Gain)" style="display:none">
这是改变音量的方法:
function changeVolume = function(element,soundNo){
var volume = element.value;
var fraction = parseInt(element.value) / parseInt(element.max);
// Using an x^2 progression as it gives a better sound than linear.
soundNo.gainNode.gain.value = fraction * fraction;
};
在我尝试使用增益使音量正常工作之前,它播放得很好,但现在它坏了,我找不到它有什么问题。如果有人能指出我正确的方向,将不胜感激。
【问题讨论】:
-
你的 onchange="changeVolume(this,sound1Gain)" 应该是 onchange="changeVolume(this,sound1gainNode)" 吗?
-
我已尝试进行此更改,但我主要担心的是在我添加增益之前播放的声音现在无法播放?
标签: audio web-applications safari volume web-audio-api