--- title: AudioBufferSourceNode.start() slug: Web/API/AudioBufferSourceNode/start translation_of: Web/API/AudioBufferSourceNode/start ---
{{ APIRef("Web Audio API") }}
{{ domxref("AudioBufferSourceNode") }} 接口的start()
方法用于计划对缓冲区中包含的音频数据的回放,或者立即开始回放。
AudioBufferSourceNode.start([when][, offset][, duration]);
when
{{optional_inline}}when
小于 ({{domxref("AudioContext.currentTime")}}, 或者是0,声音立即被播放。 默认值是0。offset
{{optional_inline}}AudioContext
, to the time within the audio buffer that playback should begin. For example, to start playback halfway through a 10-second audio clip, offset
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.duration
{{optional_inline}}start(when, offset)
和调用 stop(when+duration)
完全相同。{{jsxref("undefined")}}.
TypeError
InvalidStateError
start()
已经被调用。在一个AudioBufferSourceNode
的生命周期内只能调用一次这个函数。The most simple example just starts the audio buffer playing from the beginning — you don't need to specify any parameters in this case:
source.start();
The following more complex example will, 1 second from now, start playing 10 seconds worth of sound starting 3 seconds into the audio buffer.
source.start(audioCtx.currentTime + 1,3,10);
For a more complete example showing start()
in use, check out our {{domxref("AudioContext.decodeAudioData()")}} example, You can also run the code example live, or view the source.
Specification | Status | Comment |
---|---|---|
{{SpecName('Web Audio API', '#widl-AudioBufferSourceNode-start-void-double-when-double-offset-double-duration', 'start()')}} | {{Spec2('Web Audio API')}} |
{{Compat("api.AudioBufferSourceNode.start")}}