This is an experimental technologyCheck the Browser compatibility table carefully before using this in production.
The HTMLMediaElement.setSinkId()
method sets the ID of the audio device to use for output and returns a Promise
. This only works when the application is authorized to use the specified device.
Syntax
HTMLMediaElement.setSinkId(sinkId).then(function() { ... })
Returns
A Promise
that resolves to undefined
.
Parameters
- sinkId
- The
MediaDeviceInfo.deviceId
of the audio output device.
Exceptions
Exception | Explanation |
---|---|
DOMException
|
No permission to use the requested device |
Examples
const devices = await navigator.mediaDevices.enumerateDevices(); const audioDevices = devices.filter(device => device.kind === 'audiooutput'); const audio = document.createElement('audio'); await audio.setSinkId(audioDevices[0].deviceId); console.log('Audio is being played on ' + audio.sinkId);
Specifications
Specification | Status | Comment |
Audio Output Devices APIThe definition of 'sinkId' in that specification. | Candidate Recommendation | Initial definition. Older versions of this spec were called "Media Capture Output". |
Browser compatibility
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.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
setSinkId
|
Chrome
Full support 49 |
Edge
Full support 17 |
Firefox Full support 64 Full support 64 Disabled' From version 64: this feature is behind the |
IE
No support No |
Opera
Full support 36 |
Safari
? |
WebView Android No support No No support No Notes' Not availabe due to a limitation in Android. |
Chrome Android No support No No support No Notes' Not availabe due to a limitation in Android. |
Firefox Android Full support 64 Full support 64 Disabled' From version 64: this feature is behind the |
Opera Android
Full support 36 |
Safari iOS
? |
Samsung Internet Android No support No No support No Notes' Not availabe due to a limitation in Android. |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- See implementation notes.'
- See implementation notes.
- User must explicitly enable this feature.'
- User must explicitly enable this feature.
HTMLMediaElement.setSinkId() by Mozilla Contributors is licensed under CC-BY-SA 2.5.