--- 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")}},可能的值如下:
suspended
: audio context被阻塞了(用{{domxref("AudioContext.suspend()")}} 方法)running
: audio context正常运行closed
: audio context被关闭了(用{{domxref("AudioContext.close()")}}方法)下面这段代码是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')}} |
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}} |