This is an experimental technology
Check 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.
HTMLMediaElement.setSinkId(sinkId).then(function() { ... })
A Promise
that resolves to undefined
.
MediaDeviceInfo.deviceId
of the audio output device.Exception | Explanation |
---|---|
DOMException | No permission to use the requested device |
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);
Specification | Status | Comment |
---|---|---|
Audio Output Devices API The definition of 'sinkId' in that specification. | Candidate Recommendation | Initial definition. Older versions of this spec were called "Media Capture Output". |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 49 | 17 | ? | ? | ? | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | 49 | 49 | 17 | ? | ? | ? | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/setSinkId