简体   繁体   中英

JavaScript - Uncaught TypeError: Cannot set property of undefined

I keep getting Uncaught TypeError: Cannot set property 'onaudioprocess' of undefined at (index):144. Every time when I use the setTimeout I get the error.

 setTimeout(function(){
  setupAudioNodes();
  loadSound("lecture10.mp3");
}, 3000);



javascriptNode.onaudioprocess = function() {

    //get input as web param.
    var param = window.location.search.substring(1);
    //console.log(param);
    var res = param.split("%20");

    // get the average for the first channel
    var array =  new Uint8Array(analyser.frequencyBinCount);
    analyser.getByteFrequencyData(array);
    var average = getAverageVolume(array);

    if(average < 25.0){
      if(n > res.length-1){return;}
      console.log("First Channel : " + average);
      console.log(context.currentTime);
      //document.write(parseInt(context.currentTime));
      document.write(res[n++] + " ");
      //document.getElementById('title').innerHTML = "ssss " ;
    }

}

我认为您可能在 setupAudioNodes() 中定义了 javascriptNode [意味着该节点仅在超时时间 3 秒后可用,直到该时间节点未定义],如果是这样,在 setupAudioNodes() 中移动以下行应该可以解决问题。

javascriptNode.onaudioprocess = function() { //... }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM