-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.md
57 lines (38 loc) · 1.95 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
title: "AudioContext: sinkchange イベント"
slug: Web/API/AudioContext/sinkchange_event
l10n:
sourceCommit: bca8d1ab2bc4f5a1ef6b39c454b0229539178e98
---
{{APIRef("Web Audio API")}}{{SeeCompatTable}}
{{domxref("AudioContext")}} インターフェイスの **`sinkchange`** イベントは、出力音声デバイスが変更された (そしてその結果 {{domxref("AudioContext.sinkId")}} が変更された) 時発火します。
## 構文
{{domxref("EventTarget.addEventListener", "addEventListener()")}} のようなメソッドでイベント名を用いるか、イベントハンドラープロパティを設定します。
```js
addEventListener("sinkchange", (event) => {});
onsinkchange = (event) => {};
```
## イベント型
{{domxref("Event")}} です。
{{InheritanceDiagram("Event")}}
## 例
`sinkchange` イベントのリスナーは、音声出力デバイスの変更を報告するのに利用できます。{{domxref("AudioContext.sinkId", "sinkId")}} に {{domxref("AudioSinkInfo")}} オブジェクトが入っている場合、音声がどの出力デバイスでも再生されないようになったことを表すことに注意してください。
```js
audioCtx.addEventListener("sinkchange", () => {
if (typeof audioCtx.sinkId === "object" && audioCtx.sinkId.type === "none") {
console.log("音声がどのデバイスでも再生されなくなりました");
} else {
console.log(`音声出力デバイスが ${audioCtx.sinkId} に変更されました`);
}
});
```
動くコードは、[SetSinkId test example](https://set-sink-id.glitch.me/) を参照してください。
## 仕様書
{{Specifications}}
## ブラウザーの互換性
{{Compat}}
## 関連情報
- [SetSinkId test example](https://set-sink-id.glitch.me/)
- [Change the destination output device in Web Audio](https://developer.chrome.com/blog/audiocontext-setsinkid/)
- {{domxref("AudioContext.setSinkId()")}}
- {{domxref("AudioContext.sinkId")}}