MediaDeviceInfo interface contains information that describes a single media input or output device. The list of devices obtained by calling navigator.mediaDevices.enumerateDevices() 是数组化的 MediaDeviceInfo objects, one per media device.

特性

MediaDeviceInfo.deviceId 只读
返回 DOMString that is an identifier for the represented device that is persisted across sessions. It is un-guessable by other applications and unique to the origin of the calling application. It is reset when the user clears cookies (for Private Browsing, a different identifier is used that is not persisted across sessions).
MediaDeviceInfo.groupId 只读
返回 DOMString that is a group identifier. Two devices have the same group identifier if they belong to the same physical device — for example a monitor with both a built-in camera and a microphone.
MediaDeviceInfo.kind 只读
Returns an enumerated value that is either "videoinput" , "audioinput" or "audiooutput" .
MediaDeviceInfo.label 只读
返回 DOMString that is a label describing this device (for example "External USB Webcam").

For security reasons, the label field is always blank unless an active media stream exists or the user has granted persistent permission for media device access. The set of device labels could otherwise be used as part of a fingerprinting mechanism to identify a user.

方法

None.

范例

这里的范例是使用 enumerateDevices() to get a list of devices.

if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
  console.log("enumerateDevices() not supported.");
  return;
}
// List cameras and microphones.
navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
  devices.forEach(function(device) {
    console.log(device.kind + ": " + device.label +
                " id = " + device.deviceId);
  });
})
.catch(function(err) {
  console.log(err.name + ": " + err.message);
});
					

This might produce:

videoinput: id = csO9c0YpAf274OuCPUA53CNE0YHlIr2yXCi+SqfBZZ8=
audioinput: id = RKxXByjnabbADGQNNZqLVLdmXlS0YkETYCIbg+XxnvM=
audioinput: id = r2/xw1xUPIyZunfV1lGrKOma5wTOvCkWfZ368XCndm0=
					

or if one or more media streams are active, or if persistent permissions have been granted:

videoinput: FaceTime HD Camera (Built-in) id=csO9c0YpAf274OuCPUA53CNE0YHlIr2yXCi+SqfBZZ8=
audioinput: default (Built-in Microphone) id=RKxXByjnabbADGQNNZqLVLdmXlS0YkETYCIbg+XxnvM=
audioinput: Built-in Microphone id=r2/xw1xUPIyZunfV1lGrKOma5wTOvCkWfZ368XCndm0=
					

规范

规范 状态 注释
媒体捕获和流
The definition of 'MediaDevicesInfo' 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
MediaDeviceInfo Chrome 55 注意事项
55 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
Edge ≤18 Firefox 39 IE 不支持 No Opera 不支持 No 注意事项
No 注意事项
This interface can be used in Opera by using the adapter.js polyfill.
Safari 不支持 No WebView Android 55 注意事项
55 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
Chrome Android 55 注意事项
55 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
Firefox Android 39 Opera Android 不支持 No 注意事项
No 注意事项
This interface can be used in Opera by using the adapter.js polyfill.
Safari iOS 不支持 No Samsung Internet Android 6.0 注意事项
6.0 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
deviceId Chrome 55 注意事项
55 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
Edge 12 Firefox 39 IE 不支持 No Opera 不支持 No 注意事项
No 注意事项
This property can be used in Opera by using the adapter.js polyfill.
Safari 不支持 No WebView Android 55 注意事项
55 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
Chrome Android 55 注意事项
55 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
Firefox Android 39 Opera Android 不支持 No 注意事项
No 注意事项
This property can be used in Opera by using the adapter.js polyfill.
Safari iOS 不支持 No Samsung Internet Android 6.0 注意事项
6.0 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
groupId Chrome 55 注意事项
55 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
Edge 12 Firefox 39 注意事项
39 注意事项
Prior to Firefox 67, related devices are not actually grouped together by groupId .
IE 不支持 No Opera 不支持 No 注意事项
No 注意事项
This property can be used in Opera by using the adapter.js polyfill.
Safari 不支持 No WebView Android 55 注意事项
55 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
Chrome Android 55 注意事项
55 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
Firefox Android 39 注意事项
39 注意事项
Prior to Firefox 67, related devices are not actually grouped together by groupId .
Opera Android 不支持 No 注意事项
No 注意事项
This property can be used in Opera by using the adapter.js polyfill.
Safari iOS 不支持 No Samsung Internet Android 6.0 注意事项
6.0 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
kind Chrome 55 注意事项
55 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
Edge 12 Firefox 39 IE 不支持 No Opera 不支持 No 注意事项
No 注意事项
This property can be used in Opera by using the adapter.js polyfill.
Safari 不支持 No WebView Android 55 注意事项
55 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
Chrome Android 55 注意事项
55 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
Firefox Android 39 Opera Android 不支持 No 注意事项
No 注意事项
This property can be used in Opera by using the adapter.js polyfill.
Safari iOS 不支持 No Samsung Internet Android 6.0 注意事项
6.0 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
label Chrome 55 注意事项
55 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
Edge 12 Firefox 39 IE 不支持 No Opera 不支持 No 注意事项
No 注意事项
This property can be used in Opera by using the adapter.js polyfill.
Safari 不支持 No WebView Android 55 注意事项
55 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
Chrome Android 55 注意事项
55 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
Firefox Android 39 Opera Android 不支持 No 注意事项
No 注意事项
This property can be used in Opera by using the adapter.js polyfill.
Safari iOS 不支持 No Samsung Internet Android 6.0 注意事项
6.0 注意事项
For earlier versions, this interface is available through the adapter.js polyfill
toJSON() Chrome Yes Edge 18 Firefox Yes IE 不支持 No Opera 不支持 No 注意事项
No 注意事项
For earlier versions, this method is available through the adapter.js polyfill
Safari 不支持 No WebView Android Yes Chrome Android Yes Firefox Android Yes Opera Android 不支持 No 注意事项
No 注意事项
For earlier versions, this method is available through the adapter.js polyfill
Safari iOS 不支持 No Samsung Internet Android Yes

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

另请参阅

元数据

  • 最后修改: