【发布时间】:2017-07-02 00:45:59
【问题描述】:
我正在做一个项目,我目前正在尝试使用音频上下文生成音调。到目前为止,这是我想出的:
$("#btn").click(function(){
var context = new (window.AudioContext || window.webkitAudioContext)();
var osc = context.createOscillator(); // instantiate an oscillator
osc.type = 'sine'; // this is the default - also square, sawtooth, triangle
osc.frequency.value = 440; // Hz
osc.connect(context.destination); // connect it to the destination
osc.start(); // start the oscillator
osc.stop(context.currentTime + 1);
})
我从 stackoverflow 获得了解决方案。它完美地表达了我正在寻找的音调。但是,它仅适用于少于六次的激活。换句话说,当我点击按钮(id === "btn")超过六次时,它不再发出声音。
这里是 jsFiddle.net 链接,其语法与上述 click here 相同
你能帮我解决这个问题吗?
【问题讨论】:
标签: javascript jquery html css