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
只读
"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. |
候选推荐 | 初始定义 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
MediaDeviceInfo
|
Chrome
55
注意事项
|
Edge ≤18 | Firefox 39 | IE 不支持 No |
Opera
不支持
No
注意事项
|
Safari 不支持 No |
WebView Android
55
注意事项
|
Chrome Android
55
注意事项
|
Firefox Android 39 |
Opera Android
不支持
No
注意事项
|
Safari iOS 不支持 No |
Samsung Internet Android
6.0
注意事项
|
deviceId
|
Chrome
55
注意事项
|
Edge 12 | Firefox 39 | IE 不支持 No |
Opera
不支持
No
注意事项
|
Safari 不支持 No |
WebView Android
55
注意事项
|
Chrome Android
55
注意事项
|
Firefox Android 39 |
Opera Android
不支持
No
注意事项
|
Safari iOS 不支持 No |
Samsung Internet Android
6.0
注意事项
|
groupId
|
Chrome
55
注意事项
|
Edge 12 |
Firefox
39
注意事项
|
IE 不支持 No |
Opera
不支持
No
注意事项
|
Safari 不支持 No |
WebView Android
55
注意事项
|
Chrome Android
55
注意事项
|
Firefox Android
39
注意事项
|
Opera Android
不支持
No
注意事项
|
Safari iOS 不支持 No |
Samsung Internet Android
6.0
注意事项
|
kind
|
Chrome
55
注意事项
|
Edge 12 | Firefox 39 | IE 不支持 No |
Opera
不支持
No
注意事项
|
Safari 不支持 No |
WebView Android
55
注意事项
|
Chrome Android
55
注意事项
|
Firefox Android 39 |
Opera Android
不支持
No
注意事项
|
Safari iOS 不支持 No |
Samsung Internet Android
6.0
注意事项
|
label
|
Chrome
55
注意事项
|
Edge 12 | Firefox 39 | IE 不支持 No |
Opera
不支持
No
注意事项
|
Safari 不支持 No |
WebView Android
55
注意事项
|
Chrome Android
55
注意事项
|
Firefox Android 39 |
Opera Android
不支持
No
注意事项
|
Safari iOS 不支持 No |
Samsung Internet Android
6.0
注意事项
|
toJSON()
|
Chrome Yes | Edge 18 | Firefox Yes | IE 不支持 No |
Opera
不支持
No
注意事项
|
Safari 不支持 No | WebView Android Yes | Chrome Android Yes | Firefox Android Yes |
Opera Android
不支持
No
注意事项
|
Safari iOS 不支持 No | Samsung Internet Android Yes |
完整支持
不支持
见实现注意事项。
MediaDeviceInfo
MediaDevices.getUserMedia()
Navigator.mediaDevices
RTCCertificate
RTCDTMFSender
RTCDTMFToneChangeEvent
RTCDataChannel
RTCDataChannelEvent
RTCDtlsTransport
RTCErrorEvent
RTCIceCandidate
RTCIceTransport
RTCPeerConnection
RTCPeerConnectionIceErrorEvent
RTCPeerConnectionIceEvent
RTCRtpReceiver
RTCRtpSender
RTCRtpTransceiver
RTCSctpTransport
RTCSessionDescription
RTCStatsReport
RTCTrackEvent