demo · v136

Multi-track Sink Switcher

A mixing-desk metaphor for setPreferredSinkId(): one click on a frame-wide sink choice routes every audio element on the page to the chosen output device. Each track also exposes its per-element setSinkId() so you can see when a per-element override beats the frame default.

0 sinks
state: not initialised

what the demo is testing

the code

// 1. Get device IDs (requires a prior getUserMedia grant to see labels).
const devs = await navigator.mediaDevices.enumerateDevices();
const sinks = devs.filter(d => d.kind === 'audiooutput');

// 2. Set the frame default. Applies to every <audio>/<video> and AudioContext
//    in this top-level frame AND its child iframes.
await navigator.mediaDevices.setPreferredSinkId(sinks[1].deviceId);

// 3. Per-element override still beats the frame default.
await audio.setSinkId(sinks[2].deviceId);
console.log(audio.sinkId); // sinks[2].deviceId

see also