Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. HTMLMediaElement
  4. setSinkId()

HTMLMediaElement: setSinkId() method

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

ThesetSinkId() method of theHTMLMediaElement interface sets the ID of the audio device to use for output and returns aPromise.

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

Syntax

js
setSinkId(sinkId)

Parameters

sinkId

TheMediaDeviceInfo.deviceId of the audio output device.

Return value

APromise that resolves toundefined.

Exceptions

NotAllowedErrorDOMException

Returned if aspeaker-selectionPermissions Policy is used to block use of audio outputs.

NotFoundErrorDOMException

Returned if thedeviceId does not match any audio output device.

AbortErrorDOMException

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 byMediaDevices.enumerateDevices(), and set it as the sink for audio.Note that the result ofenumerateDevices() 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

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp