This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.
The state read-only property of the BaseAudioContext interface returns the current state of the AudioContext.
A string. Possible values are:
closedThe audio context has been closed (with the AudioContext.close() method.)
interruptedThe audio context has been interrupted by an occurrence outside the control of the web app.
runningThe audio context is running normally.
suspendedThe audio context has been suspended (with the AudioContext.suspend() method.)
The state property of an audio context is used to expose its current operational state. This is normally done by querying the state inside a statechange event handler so that changes in state can be responded to appropriately.
The running and closed values are self-explanatory — they indicate that the audio context is either running normally, or closed (via the AudioContext.close() method).
The interrupted and suspended states both represent a "paused" state that can later be resumed, but they differ in terms of what they signify:
suspended state indicates that the audio context was paused in response to a user action inside the web app, by running the AudioContext.suspend() method inside a click (or similar) event handler. In this case, the context would be unpaused by running the AudioContext.resume() method.interrupted state indicates that the audio context was paused in response to an interruption outside the control of the web app. In this case, the browser decides when to pause and unpause the app. The web app can then handle the interrupted state appropriately, for example by pausing an audio stream to avoid wasting resources while an app is not being used.Interruptions that may trigger the interrupted state can include:
Note: How the interrupted state is triggered may vary between browsers.
Note also the potential for transitions between the interrupted and suspended states:
suspend() is called on an audio context during an interruption (state is interrupted), the state will transition to suspended immediately.resume() is called on a suspended audio context during an interruption, the state will transition to interrupted immediately.suspended, the context will not transition to interrupted. This transition won't happen unless resume() is called on the context (as outlined by the previous point). This choice was made to avoid exposing too much device information to web pages - for example, logging every time the laptop is closed could be a privacy issue.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);
};
In iOS Safari, when a user leaves the page (e.g., switches tabs, minimizes the browser, or turns off the screen) the audio context's state changes to "interrupted" and needs to be resumed. For example:
function play() {
if (audioCtx.state === "interrupted") {
audioCtx.resume().then(() => play());
return;
}
// rest of the play() function
}
| Specification |
|---|
| Web Audio API> # dom-baseaudiocontext-state> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
state |
41 | 14 | 40 | 28 | 9 | 41 | 40 | 28 | 9 | 4.0 | 41 | 9 |
interrupted |
136 | 136 | No | 121 | 9 | 136 | No | 90 | 9 | No | 136 | 9 |
© 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/state