AudioContext.state
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
的 state
属性是只读的,返回 AudioContext
的当前状态。
语法
js
var audioCtx = new AudioContext();
var myState = audioCtx.state;
返回值
DOMString
,可能的值如下:
suspended
: audio context 被阻塞了 (用AudioContext.suspend()
方法)running
: audio context 正常运行closed
: audio context 被关闭了 (用AudioContext.close()
方法)
例子
下面这段代码是AudioContext states demo (直接运行) 中的,其中AudioContext.onstatechange
处理器会在每次当前状态发生变化时把它输出到控制台。
js
audioCtx.onstatechange = function () {
console.log(audioCtx.state);
};
规范
Specification |
---|
Web Audio API # dom-baseaudiocontext-state |
浏览器兼容性
BCD tables only load in the browser