大网数据广告活动
Web 标准与前端开发

AudioBufferSourceNode.start()

· 52CE 我爱测

AudioBufferSourceNode 接口的`start()`方法用于计划对缓冲区中包含的音频数据的回放,或者立即开始回放。

Web Audio API

AudioBufferSourceNode 接口的start()方法用于计划对缓冲区中包含的音频数据的回放,或者立即开始回放。

语法

start(when)
start(when, offset)
start(when, offset, duration)

参数

  • when
    • : The time 声音开始播放的时间,单位是秒,与 AudioContext使用相同的时间坐标系统。如果 when 小于 (AudioContext.currentTime, 或者是 0,声音立即被播放。 默认值是 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 AudioBuffer.duration and/or the AudioBufferSourceNode.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
    • : 将要播放的声音的持续时间,指定单位为秒。如果这个参数没有被指定,声音播放到自然结束或者使用AudioScheduledSourceNode.stop 方法结束。使用这个参数的功能与调用 start(when, offset) 和调用 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() 已经被调用。在一个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 AudioContext.decodeAudioData() example, You can also run the code example live, or view the source.

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。