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.
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
Specification |
---|
Web Audio API # dom-baseaudiocontext-onstatechange |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
statechange event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.