v136 · webrtc

Audio Output Devices API: setPreferredSinkId()

Adds setPreferredSinkId() to MediaDevices, which enables a top-level frame to override the default audio output device for all audio renderers in the top-level frame and its child frames, including cross-origin child frames. Audio renderers include HTML <media> elements and web audio contexts.

concepts

  1. setPreferredSinkId

    setPreferredSinkId persists a user's chosen audio output for the origin. Saves the per-session re-selection that setSinkId required.

  2. Iframe inherits sink

    The motivating use case: a parent frame's preferred-sink choice flows into child iframes' audio elements without postMessage. Pick a sink in the parent — the iframe's audio.sinkId updates live.

  3. Multi-track Sink Switcher

    Two synthesised tones, one frame-default sink, and per-element overrides. Watch the frame default route every audio element — then watch audio.setSinkId() beat the default for one track.

  4. Sink permission flow

    Walk the full permission pipeline: enumerate devices (IDs hidden without permission) → request getUserMedia audio → re-enumerate (IDs now visible) → call setPreferredSinkId. Explains why deviceId: "" appears before permission is granted.

why it shipped

Without setPreferredSinkId(), a top-level frame has no mechanism to change the default audio output device in its cross-origin child frames. A top-level frame cannot use setSinkId() in a cross-origin child frame due to security boundaries. Instead, the top-level frame and cross-origin child frame must collaborate using postMessage() to change the audio output device.

references