[英]AudioWorkletProcessor and Polymer 3.4.1 and 'window' not defined
嘗試使用 lit element/Polymer Web 組件和 Audioworklet/AudioWorklet 處理器時,出現此錯誤:
boot-c9e09360.js:20 Uncaught ReferenceError: window is not defined
at boot-c9e09360.js:20:1
在我的代碼中的這一行:
await aw.audioContext.audioWorklet.addModule("micSpkrAwp.js") //micSpkrAwp is the audio-worklet-processor running in different process.
boot-c9e09360.js 是一個 polymer 文件,其中包含:
/**
@license 版權所有 (c) 2017 Polymer 項目作者。 版權所有。 ... */
/* eslint-disable no-unused-vars // *
我一直在使用 lit element/Polymer web 組件,效果很好。 我刪除了 polymer 組件,AudioWorkletProcessor 運行良好。 我認為問題是 Polymer 假設定義了 window(因為 polymer 使用 DOM),但是當遇到 javascript 文件時 - 沒有引用 DOM 的 AudioWorkletProcessor(只是一個提供音頻處理接口的文件)發生這個錯誤. 有什么建議么? micSpkrAwp.js 代碼:
從“./queue.js”導入{frameBufferQBRes} 從“./config.js”導入{config}
class MicSpkrProcessor 擴展 AudioWorkletProcessor {
constructor() {
super()
/** ..**/
process (inputs, outputs, parameters){
console.log(`micSpkrAws - this.stopImmediateFlag ${this.stopImmediateFlag}`)
if (this.stopImmediateFlag) return false
const retVal=this.processFromQueue(inputs,outputs,parameters)
return retVal
}
}
registerProcessor('mic-spkr-processor', MicSpkrProcessor)
感謝 Kaiido 的解決方案:答案:Polymer 腳本由於導入而被注入到 AudioWorkletProcessor 代碼中:
import { calculateSplices } from '@polymer/polymer/lib/utils/array-splice';
這不是立即可見的,因為它是嵌套導入(導入的文件包含此導入語句)。 此導入已刪除,問題已解決!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.