files/en-us/web/api/audiocontext/sinkchange_event/index.md
{{APIRef("Web Audio API")}}{{SeeCompatTable}}
The sinkchange event of the {{domxref("AudioContext")}} interface is fired when the output audio device (and therefore, the {{domxref("AudioContext.sinkId")}}) has changed.
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
addEventListener("sinkchange", (event) => { })
onsinkchange = (event) => { }
{{domxref("Event")}}.
{{InheritanceDiagram("Event")}}
A sinkchange event listener can be used to report a change of audio output device. Note that if {{domxref("AudioContext.sinkId", "sinkId")}} contains an {{domxref("AudioSinkInfo")}} object, it indicates that the audio has been changed to not play on any output device.
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}`);
}
});
See our SetSinkId test example for working code (also check out the source code).
{{Specifications}}
{{Compat}}