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
|
---
title: AudioBufferSourceNode.start()
slug: Web/API/AudioBufferSourceNode/start
translation_of: Web/API/AudioBufferSourceNode/start
---
<p>{{ APIRef("Web Audio API") }}</p>
<div>
<p> {{ domxref("AudioBufferSourceNode") }} 接口的<code>start()</code>方法用于计划对缓冲区中包含的音频数据的回放,或者立即开始回放。</p>
</div>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><em>AudioBufferSourceNode</em>.start([<em>when</em>][, <em>offset</em>][, <em>duration</em>]);
</pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>when</code> {{optional_inline}}</dt>
<dd>The time声音开始播放的时间,单位是秒,与 {{domxref("AudioContext")}}使用相同的时间坐标系统. 如果 <code>when</code> 小于 ({{domxref("AudioContext.currentTime")}}, 或者是0,声音立即被播放。 <strong>默认值是0。</strong></dd>
<dt><code>offset</code> {{optional_inline}}</dt>
<dd>An offset, specified as the number of seconds in the same time coordinate system as the <code>AudioContext</code>, to the time within the audio buffer that playback should begin. For example, to start playback halfway through a 10-second audio clip, <code>offset</code> should be 5. The default value, 0, will begin playback at the beginning of the audio buffer, and offsets past the end of the audio which will be played (based on the audio buffer's {{domxref("AudioBuffer.duration", "duration")}} and/or the {{domxref("AudioBufferSourceNode.loopEnd", "loopEnd")}} property) are silently clamped to the maximum value allowed. The computation of the offset into the sound is performed using the sound buffer's natural sample rate, rather than the current playback rate, so even if the sound is playing at twice its normal speed, the midway point through a 10-second audio buffer is still 5.</dd>
<dt><code>duration</code> {{optional_inline}}</dt>
<dd>将要播放的声音的持续时间,指定单位为秒。如果这个参数没有被指定,声音播放到自然结束或者使用{{domxref("AudioScheduledSourceNode.stop", "stop()")}} 方法结束。使用这个参数的功能与调用 <code>start(when, offset)</code> 和调用 <code>stop(when+duration)</code>完全相同。</dd>
</dl>
<h3 id="返回值">返回值</h3>
<p>{{jsxref("undefined")}}.</p>
<h3 id="异常">异常</h3>
<dl>
<dt><code>TypeError</code></dt>
<dd>A negative value was specified for one or more of the three time parameters. Please don't attempt to tamper with the laws of temporal physics.</dd>
<dt><code>InvalidStateError</code></dt>
<dd><code>start()</code> 已经被调用。在一个<code>AudioBufferSourceNode</code>的生命周期内只能调用一次这个函数。</dd>
</dl>
<h2 id="例子">例子</h2>
<p>The most simple example just starts the audio buffer playing from the beginning — you don't need to specify any parameters in this case:</p>
<pre class="brush: js">source.start();</pre>
<p>The following more complex example will, 1 second from now, start playing 10 seconds worth of sound starting 3 seconds into the audio buffer.</p>
<pre class="brush: js">source.start(audioCtx.currentTime + 1,3,10);</pre>
<div class="note">
<p>For a more complete example showing <code>start()</code> in use, check out our {{domxref("AudioContext.decodeAudioData()")}} example, You can also <a class="external external-icon" href="http://mdn.github.io/decode-audio-data/">run the code example live</a>, or <a class="external external-icon" href="https://github.com/mdn/decode-audio-data">view the source</a>.</p>
</div>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('Web Audio API', '#widl-AudioBufferSourceNode-start-void-double-when-double-offset-double-duration', 'start()')}}</td>
<td>{{Spec2('Web Audio API')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>
<p>{{Compat("api.AudioBufferSourceNode.start")}}</p>
</div>
<h2 id="See_also">See also</h2>
<ul>
<li><a href="/en-US/docs/Web/API/Web_Audio_API/Using_Web_Audio_API">Using the Web Audio API</a></li>
</ul>
|