HTMLMediaElement.setSinkId()

Experimental: 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.

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

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
setSinkId
49
17
64
No
36
No
No
Not availabe due to a limitation in Android.
No
Not availabe due to a limitation in Android.
64
36
No
No
Not availabe due to a limitation in Android.

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/setSinkId