aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/audiocontext/close/index.html
blob: 68a219877606489eb879ee0b72b4d498d3bb7c46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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>