--- title: AudioContext.onstatechange slug: Web/API/BaseAudioContext/statechange_event translation_of: Web/API/BaseAudioContext/onstatechange original_slug: Web/API/BaseAudioContext/onstatechange ---
{{ APIRef("Web Audio API") }}
{{ domxref("AudioContext") }}インターフェースのonstatechangeプロパティは、{{Event("statechange")}}イベントが発火した(これはオーディオコンテキストの状態が変わったとき発生します)とき呼ばれるイベントハンドラ関数を定義します。
var audioCtx = new AudioContext();
audioCtx.onstatechange = function() { ... };
次のスニペットはAudioContext states デモの一部です(すぐに実行)。{{domxref("AudioContext.onstatechange")}}ハンドラは、状態が変わるたびにコンソールにログを出力するために使われています。
audioCtx.onstatechange = function() {
console.log(audioCtx.state);
}
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('Web Audio API', '#widl-AudioContext-onstatechange', 'onstatechange')}} | {{Spec2('Web Audio API')}} |
{{Compat("api.BaseAudioContext.onstatechange")}}