v133 · 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

    Persist the chosen audio output device for the origin.

  2. Cross-origin iframe

    The motivating use case: route audio for a cross-origin iframe from the top frame — no postMessage handshake, no per-element setSinkId in the child.

  3. Device picker with capability probe

    Detect setPreferredSinkId, legacy per-element setSinkId, and the unprompted selectAudioOutput picker. Enumerate sinks and apply the user's choice through the best available API.

  4. WebAudio + media element routing

    An oscillator, a sample player, and a media element all routed through one document-wide preferred sink. Switch device once, every renderer follows — no per-source rewiring.

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