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.
Astatechange event is fired at aBaseAudioContext object when itsstate member changes.
In this article
Syntax
Use the event name in methods likeaddEventListener(), or set an event handler property.
js
addEventListener("statechange", (event) => { })onstatechange = (event) => { }Event type
A genericEvent.
Examples
The following snippet is taken from ourAudioContext states demo (see it running live.) Theonstatechange handler is used to log the currentstate to the console every time it changes.
js
audioCtx.onstatechange = () => { console.log(audioCtx.state);};Specifications
| Specification |
|---|
| Web Audio API> # dom-baseaudiocontext-onstatechange> |