registerProcessor 方法在 AudioWorkletGlobalScope interface registers a class constructor derived from AudioWorkletProcessor interface under a specified name .

句法

AudioWorkletGlobalScope.registerProcessor(name, processorCtor);
					

参数

名称

A string representing the name under which the processor will be registered.

processorCtor
The constructor of a class derived from AudioWorkletProcessor .

注意 : A key-value pair { 名称: constructor } is saved internally in the AudioWorkletGlobalScope once  the processor is registered. The name is to be referred to when creating an AudioWorkletNode based on the registered processor. A new processor by the given name is internally created and associated with the new node.

返回值

undefined

异常

NotSupportedError
  • name is an empty string, or
  • a constructor under the given name is already registered. Registering the same name twice is not allowed.
TypeError

范例

In this example we create a custom AudioWorkletNode that outputs silence.

First, we need to define a custom AudioWorkletProcessor and register it. Note that this should be done in a separate file.

// test-processor.js
class TestProcessor extends AudioWorkletProcessor {
  process (inputs, outputs, parameters) {
    return true
  }
}
registerProcessor('test-processor', TestProcessor)
					

Next, in our main script file we'll load the processor, create an instance of AudioWorkletNode — passing it the processor name that we used when calling registerProcessor — and connect it to an audio graph.

const audioContext = new AudioContext()
await audioContext.audioWorklet.addModule('test-processor.js')
const node = new AudioWorkletNode(audioContext, 'test-processor')
node.connect(audioContext.destination)
					

规范

规范 状态 注释
Web 音频 API
The definition of 'registerProcessor()' in that specification.
工作草案

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
registerProcessor Chrome 66 Edge 79 Firefox 76 IE 不支持 No Opera 53 Safari 不支持 No WebView Android 66 Chrome Android 66 Firefox Android 不支持 No Opera Android 47 Safari iOS 不支持 No Samsung Internet Android 9.0

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: