AudioContext.onstatechange
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.
AudioContext
的 onstatechange
属性定义了一个事件处理器函数,触发 statechange
会被调用,也就是说 audio context 的状态发生变化时会执行。
语法
js
var audioCtx = new AudioContext();
audioCtx.onstatechange = function() { ... };
例子
下面这段代码是AudioContext states DEMO (直接运行) 中的,其中 onstatechange
处理器会在每次当前 state
发生变化时把它输出到控制台。
js
audioCtx.onstatechange = function () {
console.log(audioCtx.state);
};
规范
Specification |
---|
Web Audio API # dom-baseaudiocontext-onstatechange |
浏览器兼容性
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.