A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/state below:

BaseAudioContext: state property - Web APIs

BaseAudioContext: state property

Baseline Widely available

The state read-only property of the BaseAudioContext interface returns the current state of the AudioContext.

Value

A string. Possible values are:

closed

The audio context has been closed (with the AudioContext.close() method.)

interrupted

The audio context has been interrupted by an occurrence outside the control of the web app.

running

The audio context is running normally.

suspended

The audio context has been suspended (with the AudioContext.suspend() method.)

Description

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:

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:

Examples Handling state changes

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);
};
Resuming interrupted play states in iOS Safari

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
}
Specifications Browser compatibility See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4