demo · v136

setPreferredSinkId

Set the default audio output for the whole top-level frame (including iframes). Below: enumerate your audio outputs, pick one, then play tones and inspect sinkId on each element.

Probing…

standalone audio element

audio.sinkId (live)

WebAudio destination

ac.sinkId (live)
last action

Permission flow: the first enumerateDevices() call requires a microphone permission gesture before output labels are revealed.

the code

// Top-level frame — affects all child audio sinks too.
await navigator.mediaDevices.setPreferredSinkId(deviceId);

// Then every <audio>/<video> created afterwards inherits this default.
// Existing elements keep their explicit sinkId until reset.

see also