--- title: AudioContext.state slug: Web/API/BaseAudioContext/state translation_of: Web/API/BaseAudioContext/state original_slug: Web/API/AudioContext/state ---

{{ APIRef("Web Audio API") }}

{{ domxref("AudioContext") }}的state属性是只读的,返回AudioContext的当前状态。

语法

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

返回值

{{domxref("DOMString")}},可能的值如下:

例子

下面这段代码是AudioContext states demo (直接运行)中的,其中{{domxref("AudioContext.onstatechange")}}处理器会在每次当前状态发生变化时把它输出到控制台。

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

规范

Specification Status Comment
{{SpecName('Web Audio API', '#widl-AudioContext-state', 'state')}} {{Spec2('Web Audio API')}}  

浏览器兼容性

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatChrome(43.0)}} {{CompatGeckoDesktop(40.0)}}  {{CompatNo}} {{CompatUnknown}} {{CompatUnknown}}
Feature Android Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

另见