MDN self-hosted library · e01.org

BaseAudioContext: statechange event

Web Audio API

Web Audio API

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

Syntax

Use the event name in addEventListener():

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

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

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

See also