0
我已經做了一個函數,在被調用4次後會產生一個鼓聲,它會停止使用錯誤:TypeError:null不是一個對象(評估'audioCtx.sampleRate' ) 顯示在控制檯中。 有什麼不對的功能 我的代碼是:audiocontext讀取8次後返回空值
drum = function(){
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var frameCount = audioCtx.sampleRate/20
var myArrayBuffer = audioCtx.createBuffer(1, frameCount, audioCtx.sampleRate);
var nowBuffering = myArrayBuffer.getChannelData(0);
for (var i = 0; i < frameCount; i++) {
nowBuffering[i] =Math.sin(i**(1/1.8)/4)
}
var source = audioCtx.createBufferSource();
source.buffer = myArrayBuffer; source.connect(audioCtx.destination);
source.start();
}
iOS safari mobile – user7951676