Web/API/BaseAudioContext/onstatechange

From Get docs

The onstatechange property of the BaseAudioContext interface defines an event handler function to be called when the statechange event fires: this occurs when the audio context's state changes.


Syntax

baseAudioContext.onstatechange = function() { ... };

Example

The following snippet is taken from our AudioContext states demo ([[../../../../../../../mdn.github.io/webaudio-examples/audiocontext-states/index|see it running live]].) The onstatechange hander is used to log the current state to the console every time it changes.

audioCtx.onstatechange = function() {
  console.log(audioCtx.state);
}

Specifications

Specification Status Comment
Web Audio APIThe definition of 'onstatechange' in that specification. Working Draft

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
onstatechange Chrome

Full support 43

Edge

Full support ≤79

Firefox Full support 53

Notes'

Full support 53

Notes'

Notes' Originally implemented on AudioContext in Firefox 40.

IE

No support No

Opera

Full support Yes

Safari Full support 9

Prefixed'

Full support 9

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android Full support 53

Notes'

Full support 53

Notes'

Notes' Originally implemented on AudioContext in Firefox Android 40.

Opera Android

Full support Yes

Safari iOS Full support 9

Prefixed'

Full support 9

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

Samsung Internet Android

Full support Yes

Legend

Full support  
Full support
No support  
No support
See implementation notes.'
See implementation notes.
Requires a vendor prefix or different name for use.'
Requires a vendor prefix or different name for use.


See also