AudioEncoder:isConfigSupported() 靜態方法

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

安全上下文: 此功能僅在安全上下文(HTTPS)中可用,且支援此功能的瀏覽器數量有限。

注意:此功能在 專用 Web Workers 中可用。

AudioEncoder 介面的 isConfigSupported() 靜態方法用於檢查給定配置是否受支援(即,是否可以使用給定配置成功配置 AudioEncoder 物件)。

語法

js
AudioEncoder.isConfigSupported(config)

引數

config

AudioEncoder.configure 接受的字典物件

返回值

一個 Promise,它會解析為一個包含以下成員的物件:

supported

如果給定配置受編碼器支援,則返回布林值 true

config

給定配置的副本,其中包含編碼器識別的所有欄位。

異常

TypeError

如果提供的 config 無效,則丟擲此異常;即,如果它缺少必需的值(如空的 codec 欄位)或具有無效的值(如負數的 sampleRate)。

示例

以下示例測試瀏覽器是否支援多種音訊編解碼器。

js
const codecs = ["mp4a.40.2", "mp3", "alaw", "ulaw"];
const configs = [];
for (const codec of codecs) {
  configs.push({
    codec,
    sampleRate: 48000,
    numberOfChannels: 1,
    not_supported_field: 123,
  });
}
for (const config of configs) {
  const support = await AudioEncoder.isConfigSupported(config);
  console.log(
    `AudioEncoder's config ${JSON.stringify(support.config)} support: ${
      support.supported
    }`,
  );
}

規範

規範
WebCodecs
# dom-audioencoder-isconfigsupported

瀏覽器相容性