files/en-us/web/api/audiobuffersourcenode/start/index.md
{{ APIRef("Web Audio API") }}
The start() method of the {{ domxref("AudioBufferSourceNode") }}
Interface is used to schedule playback of the audio data contained in the buffer, or
to begin playback immediately.
start(when)
start(when, offset)
start(when, offset, duration)
when {{optional_inline}}
when is
less than ({{domxref("BaseAudioContext/currentTime", "AudioContext.currentTime")}}, or if it's 0, the sound begins to
play at once. The default value is 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}}
duration of 2 seconds with a playbackRate of 2 will play 2 seconds of the source,
producing a 1 second audio output.None ({{jsxref("undefined")}}).
InvalidStateError {{domxref("DOMException")}}
start() has already been called. You can only call this function once
during the lifetime of an 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);
[!NOTE] For a more complete example showing
start()in use, check out our {{domxref("BaseAudioContext/decodeAudioData", "AudioContext.decodeAudioData()")}} example. You can also try the example live, and have a look at the example source.
{{Specifications}}
{{Compat}}