audioCtx.addEventListener("sinkchange", () => {
if (typeof audioCtx.sinkId === "object" && audioCtx.sinkId.type === "none") {
console.log("Audio changed to not play on any device");
} else {
console.log(`Audio output device changed to ${audioCtx.sinkId}`);
}
});AudioContext: sinkchange event / notebook
AudioContext: sinkchange event
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.