HTMLMediaElement: setSinkId() method

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The setSinkId() method of the HTMLMediaElement interface sets the ID of the audio device to use for output and returns a Promise.

This only works when the application is permitted to use the specified device. For more information see the security requirements below.

Syntax

js
setSinkId(sinkId)

Parameters

sinkId

The MediaDeviceInfo.deviceId of the audio output device.

Return value

A Promise that resolves to undefined.

Exceptions

NotAllowedError DOMException

Returned if a speaker-selection Permissions Policy is used to block use of audio outputs.

NotFoundError DOMException

Returned if the deviceId does not match any audio output device.

AbortError DOMException

Returned if switching the audio output device to the new audio device failed.

Security requirements

Access to the API is subject to the following constraints:

Examples

This example shows how to select an audio output device from the array returned by MediaDevices.enumerateDevices(), and set it as the sink for audio. Note that the result of enumerateDevices() only includes devices for which user permission is not required or has already been granted.

js
const devices = await navigator.mediaDevices.enumerateDevices();
const audioDevice = devices.find((device) => device.kind === "audiooutput");
const audio = document.createElement("audio");
await audio.setSinkId(audioDevice.deviceId);
console.log(`Audio is being output on ${audio.sinkId}`);

Specifications

Specification
Audio Output Devices API
# dom-htmlmediaelement-setsinkid

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
setSinkId
Chrome – Full support
Chrome 49 (Release date: 2016-03-02)
footnote Full support
Edge – Full support
Edge 17 (Release date: 2018-04-30)
footnote Full support
Firefox – Full support
Firefox 116 (Release date: 2023-08-01)
footnote Full support
Opera – Full support
Opera 36 (Release date: 2016-03-15)
footnote Full support
Safari – Full support
Safari 18.4 (Release date: 2025-03-31)
footnote
footnote See bug 216641
Chrome Android – No support
Chrome Android
footnote
footnote Not available due to a limitation in Android, see bug 41276355.
Firefox for Android – No support
Firefox for Android
footnote
footnote Not available due to a limitation in Android, see bug 1473346.
Opera Android – No support
Opera Android
footnote
footnote Not available due to a limitation in Android, see bug 41276355.
Safari on iOS – Full support
Safari on iOS 18.4 (Release date: 2025-03-31)
footnote
footnote See bug 216641
Samsung Internet – No support
Samsung Internet
footnote
footnote Not available due to a limitation in Android, see bug 41276355.
WebView Android – No support
WebView Android
footnote
footnote Not available due to a limitation in Android, see bug 41276355.
WebView on iOS – Full support
WebView on iOS 18.4 (Release date: 2025-03-31)
footnote
footnote See bug 216641

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

See also