BaseAudioContext: statechange event

فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

{{APIRef("Web Audio API")}}

A statechange event is fired at a {{DOMxRef("BaseAudioContext")}} object when its {{domxref("BaseAudioContext.state", "state")}} member changes.

Syntax

Use the event name in {{domxref("EventTarget/addEventListener", "addEventListener()")}}:

js-nolint
addEventListener("statechange", (event) => { })

Alternatively, assign to the event handler property of the interface:

js-nolint
onstatechange = (event) => { }

Event type

A generic {{domxref("Event")}}.

Examples

The following snippet is taken from our AudioContext states demo (see it running live.) The onstatechange handler is used to log the current {{domxref("BaseAudioContext.state", "state")}} to the console every time it changes.

js
audioCtx.onstatechange = () => {
  console.log(audioCtx.state);
};

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • Using the Web Audio API