{{APIRef("WebRTC")}}{{SeeCompatTable}}
The MediaDevicesInfo
interface contains information on the available media input and output devices.
Properties
- {{domxref("MediaDeviceInfo.deviceId")}}{{readonlyinline}}
- Returns a {{domxref("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).
- {{domxref("MediaDeviceInfo.groupId")}}{{readonlyinline}}
- Returns a {{domxref("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 microphone.
- {{domxref("MediaDeviceInfo.kind")}}{{readonlyinline}}
- Returns an enumerated value that is either
"videoinput"
,"audioinput"
or"audiooutput"
. - {{domxref("MediaDeviceInfo.label")}}{{readonlyinline}}
- Returns a {{domxref("DOMString")}} that is a label describing this device (for example "External USB Webcam"). Only available during active MediaStream use or when persistent permissions have been granted.
Methods
None.
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName('Media Capture', '#idl-def-MediaDeviceInfo', 'MediaDevicesInfo')}} | {{Spec2('Media Capture')}} | Initial definition |
Example
Here's an example of using mediaDevices.enumerateDevices()
.
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 + ": " + error.message); });
This might produce:
videoinput: id = csO9c0YpAf274OuCPUA53CNE0YHlIr2yXCi+SqfBZZ8= audioinput: id = RKxXByjnabbADGQNNZqLVLdmXlS0YkETYCIbg+XxnvM= audioinput: id = r2/xw1xUPIyZunfV1lGrKOma5wTOvCkWfZ368XCndm0=
or if one or more MediaStreams are active or persistent permissions are 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=
Browser compatibility
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | {{CompatChrome(45.0)}}[1] | 39 | {{CompatNo}} | {{CompatNo}}[2] | {{CompatNo}} |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | Firefox OS (Gecko) | IE Phone | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatNo}} | 39 | 2.5 | {{CompatNo}} | {{CompatNo}}[2] | {{CompatNo}} | {{CompatNo}} |
[1] Behind a flag. This interface is also available in Chrome through the adapter.js polyfill.
[2] This interface is available in Opera through the adapter.js polyfill.
See also
- WebRTC - the introductory page to the API