W3cubDocs

/Web APIs

BaseAudioContext: statechange event

A statechange event is fired at a BaseAudioContext object when its state member changes.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

js

addEventListener("statechange", (event) => { })

onstatechange = (event) => { }

Event type

A generic 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 state to the console every time it changes.

js

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

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
statechange_event 41 14 40 No 28 9 41 41 40 28 9 4.0

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/statechange_event