0

我似乎无法理解为什么这不起作用。我没有错误。我使用振荡器完成了这项工作,效果很好。仅供参考,这是该线程的延续: 使用 Web Audio API 将两个声音分配给两个 Div,并通过带有 javascript 的单击事件独立播放每个声音

代码:

<div id="divElement"></div>


<style> 

#divElement{
background-color: orange;
width:70px;
height:100px;
left:143px;
}

</style>

<script>

var context = new webkitAudioContext(),
    savedBuffer;

var playAudioFile = function () {
    var source = context.createBufferSource();
    var gainNode = context.createGainNode();
    source.buffer = savedBuffer;


 // START OF PROBLEM AREA: Gain not working but file still plays with no errors.

    source.connect(gainNode);           
    gainNode.connect(context.destination);
    gainNode.gain = 0;

 // END OF PROBLEM AREA

    source.noteOn(0); // Play sound immediately


};

var request = new XMLHttpRequest();

request.open('get', 'audio/A.mp3', true);
request.responseType = 'arraybuffer';

request.onload = function () {
        context.decodeAudioData(request.response,
             function(incomingBuffer) {

                 savedBuffer = incomingBuffer;

                 var divElement = document.getElementById("divElement");
                 divElement.addEventListener("click", playAudioFile , false);
             }
        );
};

request.send();

</script>
4

1 回答 1

7

试试gainNode.gain.value = 0吧。gainNode.gain是一个AudioGain具有属性的对象value

http://www.w3.org/TR/webaudio/#AudioGainNode

于 2012-11-12T09:16:31.163 回答