MediaDevices
接口的getSupportedConstraints
()
方法返回一个基于MediaTrackSupportedConstraints
的对象, 其成员字段都是客户端(user agent)所支持的约束属性(如帧率,窗口大小)。
语法
var supportedConstraints = navigator.mediaDevices.getSupportedConstraints();
参数
无
返回值
一个新的基于MediaTrackSupportedConstraints
的对象用来监视客户端所支持的约束属性.因为只有客户端所支持的约束属性才能被展示在这个列表中 , 这些布尔值(Boolean)属性的每一个都为true。
示例
这个示例展示了你的客户端所支持的约束属性的列表。
let constraintList = document.getElementById("constraintList");
let supportedConstraints = navigator.mediaDevices.getSupportedConstraints();
for (let constraint in supportedConstraints) {
if (supportedConstraints.hasOwnProperty(constraint)) {
let elem = document.createElement("li");
elem.innerHTML = "<code>" + constraint + "</code>";
constraintList.appendChild(elem);
}
}
结果
规范
规范 | 状态 | 备注 |
---|---|---|
Media Capture and Streams getSupportedConstraints() |
Candidate Recommendation | Initial definition. |
浏览器支持情况
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Microsoft Edge | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | (Yes) | 50 (50) | ? | ? | ? | ? |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Basic support | ? | 48.0 (48) | 50.0 (50) | ? | ? | ? | (Yes) |