MediaTrackSupportedConstraints: sampleRate 屬性

可用性有限

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

MediaTrackSupportedConstraints 字典的 sampleRate 屬性是一個只讀的布林值。當且僅當使用者代理支援 sampleRate 約束時,它才會出現在由 MediaDevices.getSupportedConstraints() 返回的物件中(並設定為 true)。如果該約束不受支援,則它不會包含在列表中,因此此值永遠不會是 false

您可以透過呼叫 navigator.mediaDevices.getSupportedConstraints() 來訪問支援的約束字典。

如果使用者代理支援 sampleRate 約束,則此屬性會出現在字典中(其值始終為 true)。如果該屬性不存在,則表示它從支援的約束字典中缺失,嘗試檢視其值時將得到 undefined

示例

js
const result = document.getElementById("result");
const supported = navigator.mediaDevices.getSupportedConstraints().sampleRate;
result.textContent = supported ? "Supported!" : "Not supported!";

結果

規範

規範
媒體捕獲和流
# dom-mediatrackconstraintset-samplerate

瀏覽器相容性

另見