AudioContext: sinkchange イベント
Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。
AudioContext
インターフェイスの sinkchange
イベントは、出力音声デバイスが変更された (そしてその結果 AudioContext.sinkId
が変更された) 時発火します。
構文
addEventListener()
のようなメソッドでイベント名を用いるか、イベントハンドラープロパティを設定します。
js
addEventListener("sinkchange", (event) => {});
onsinkchange = (event) => {};
イベント型
Event
です。
例
sinkchange
イベントのリスナーは、音声出力デバイスの変更を報告するのに利用できます。sinkId
に AudioSinkInfo
オブジェクトが入っている場合、音声がどの出力デバイスでも再生されないようになったことを表すことに注意してください。
js
audioCtx.addEventListener("sinkchange", () => {
if (typeof audioCtx.sinkId === "object" && audioCtx.sinkId.type === "none") {
console.log("音声がどのデバイスでも再生されなくなりました");
} else {
console.log(`音声出力デバイスが ${audioCtx.sinkId} に変更されました`);
}
});
動くコードは、SetSinkId test example を参照してください。
仕様書
Specification |
---|
Web Audio API # eventdef-audiocontext-sinkchange |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
sinkchange event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.