start() 方法在 AudioBufferSourceNode Interface is used to schedule playback of the audio data contained in the buffer, or to begin playback immediately.

句法

AudioBufferSourceNode.start([when][, offset][, duration]);
					

参数

可选
The time, in seconds, at which the sound should begin to play, in the same time coordinate system used by the AudioContext 。若 is less than ( AudioContext.currentTime , or if it's 0, the sound begins to play at once. 默认值为 0。
offset 可选
An offset, specified as the number of seconds in the same time coordinate system as the 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 duration and/or the 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 可选
The duration of the sound to be played, specified in seconds. If this parameter isn't specified, the sound plays until it reaches its natural conclusion or is stopped using the stop() method. Using this parameter is functionally identical to calling start(when, offset) and then calling stop(when+duration) .

返回值

undefined .

异常

TypeError

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.

InvalidStateError
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);
					

For a more complete example showing start() in use, check out our AudioContext.decodeAudioData() example, You can also run the code example live ,或 view the source .

规范

规范 状态 注释
Web 音频 API
The definition of 'start()' in that specification.
工作草案

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
start Chrome 不支持 14 — 57 Edge 不支持 12 — 79 Firefox 25 IE 不支持 No Opera 15 Safari 6 WebView Android Yes Chrome Android 18 Firefox Android 26 Opera Android 14 Safari iOS Yes Samsung Internet Android 1.0

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: