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.

AudioContextstate 属性是只读的,返回 AudioContext 的当前状态。

语法

js
var audioCtx = new AudioContext();
var myState = audioCtx.state;

返回值

DOMString,可能的值如下:

例子

下面这段代码是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

参见