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

AudioScheduledSourceNode.stop()

· 52CE 我爱测

AudioScheduledSourceNode 上的`stop()`方法将声音安排在指定的时间停止播放。如果没有指定时间,声音将立即停止播放。

Web Audio API

AudioScheduledSourceNode 上的stop()方法将声音安排在指定的时间停止播放。如果没有指定时间,声音将立即停止播放。

每次在同一个节点上调用 stop() 时,指定的时间将替换任何未发生的计划停止时间。如果节点已经停止,则此方法无效。

[!NOTE] 如果计划的停止时间发生在节点计划的开始时间之前,则节点永远不会开始运行。

语法

stop()
stop(when)

参数

  • when
    • : 声音停止播放的时间,单位为秒。这个值在 AudioContext 用于其 AudioContext.currentTime 属性的同一时间坐标系统中指定。省略这个参数,设置为 0 或者负值都会立即停止播放。

Return value

undefined

Exceptions

  • InvalidStateNode
    • : 节点还没有通过调用AudioScheduledSourceNode.start方法被播放。
  • RangeError
    • : 当 when 指定为负值时。

Example

This example demonstrates starting an oscillator node, scheduled to begin playing at once and to stop playing in one second. The stop time is determined by taking the audio context's current time from AudioContext.currentTime and adding 1 second.

context = new AudioContext();
osc = context.createOscillator();
osc.connect(context.destination);

/* Let's play a sine wave for one second. */

osc.start();
osc.stop(context.currentTime + 1);

Specifications

Browser compatibility

See also

  • Using the Web Audio API
  • AudioScheduledSourceNode.start
  • AudioScheduledSourceNode
  • AudioBufferSourceNode
  • ConstantSourceNode
  • OscillatorNode

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

资料来源与适用范围

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

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

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