AudioDecoder: isConfigSupported() 靜態方法
注意:此功能在 專用 Web Workers 中可用。
isConfigSupported() 是 AudioDecoder 介面的一個靜態方法,它檢查給定的配置是否受支援(即是否可以使用給定的配置成功配置 AudioDecoder 物件)。
語法
js
AudioDecoder.isConfigSupported(config)
引數
config-
被
AudioDecoder.configure接受的字典物件。
返回值
一個 Promise,它會解析為一個包含以下成員的物件:
異常
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 AudioDecoder.isConfigSupported(config);
console.log(
`AudioDecoder's config ${JSON.stringify(support.config)} support: ${
support.supported
}`,
);
}
規範
| 規範 |
|---|
| WebCodecs # dom-audiodecoder-isconfigsupported |
瀏覽器相容性
載入中…