diff options
Diffstat (limited to 'files/zh-cn/web/api/audiocontext/close/index.html')
-rw-r--r-- | files/zh-cn/web/api/audiocontext/close/index.html | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/audiocontext/close/index.html b/files/zh-cn/web/api/audiocontext/close/index.html new file mode 100644 index 0000000000..68a2198776 --- /dev/null +++ b/files/zh-cn/web/api/audiocontext/close/index.html @@ -0,0 +1,115 @@ +--- +title: AudioContext.close() +slug: Web/API/AudioContext/close +translation_of: Web/API/AudioContext/close +--- +<p>{{ APIRef("Web Audio API") }}</p> + +<p>{{ domxref("AudioContext") }}的<code>close()</code>方法可以关闭audio context,同时释放占用的所有系统资源。</p> + +<p>关闭的context不能用来创建新节点,但可以解码音频数据,创建buffer等等</p> + +<p>该函数不会自动释放所有用<code>AudioContext创建的对象</code>,除非其他引用也都已经解除了。但是,它会强制释放所有可能阻止其它<code style="font-style: normal;">AudioContexts被创建或使用</code>的系统音频资源。挂起audio context中音频时间的进度,并停止对音频数据的处理。<span title="The returned 'Promise' resolves when all AudioContext-creation-blocking resources have been released.">所有的<span style="font-family: courier,andale mono,monospace;">AudioContext创建/阻塞资源都被释放后,</span>返回的{{jsxref("Promise")}}才会被释放。</span>如果在一个{{domxref("OfflineAudioContext")}}上调用该方法,则会抛出<code>INVALID_STATE_ERR</code> 异常。</p> + +<h2 id="语法">语法</h2> + +<pre class="brush: js">var audioCtx = new AudioContext(); +audioCtx.close().then(function() { ... }); +</pre> + +<h3 id="返回值">返回值</h3> + +<p>一个 resolve void值得 {{jsxref("Promise")}}。 </p> + +<h2 id="例子">例子</h2> + +<p>下面这段代码是<a href="https://github.com/mdn/audiocontext-states/settings">AudioContext states demo</a> (<a href="http://mdn.github.io/audiocontext-states/">直接运行</a>)中的,点击停止按钮调用<code>close()</code>。promise释放后,回到初始状态。</p> + +<pre class="brush: js">stopBtn.onclick = function() { + audioCtx.close().then(function() { + startBtn.removeAttribute('disabled'); + susresBtn.setAttribute('disabled','disabled'); + stopBtn.setAttribute('disabled','disabled'); + }); +} +</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">规范</th> + <th scope="col">状态</th> + <th scope="col">注释</th> + </tr> + <tr> + <td>{{SpecName('Web Audio API', '#widl-AudioContext-close-Promise-void', 'close()')}}</td> + <td>{{Spec2('Web Audio API')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome(43.0)}}</td> + <td>{{CompatGeckoDesktop(40.0)}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Android Webview</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + <th>Chrome for Android</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="另见">另见</h2> + +<ul> + <li><a href="/en-US/docs/Web_Audio_API/Using_Web_Audio_API">Using the Web Audio API</a></li> + <li><a href="/en-US/docs/Web/API/Web_Audio_API">Web Audio API</a></li> +</ul> |