W3cubDocs

/Web APIs

BaseAudioContext: statechange event

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨April 2021⁩.

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.

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.

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

Specifications

Browser compatibility

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

See also

© 2005–2025 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