stop() method on AudioScheduledSourceNode schedules a sound to cease playback at the specified time. If no time is specified, then the sound stops playing immediately.

每次调用 stop() on the same node, the specified time replaces any previously-scheduled stop time that hasn't occurred yet. If the node has already stopped, this method has no effect.

注意: If a scheduled stop time occurs before the node's scheduled start time, the node never starts to play.

句法

AudioScheduledSourceNode.stop([when]);
					

参数

可选
The time, in seconds, at which the sound should stop playing. This value is specified in the same time coordinate system as the AudioContext is using for its currentTime attribute. Omitting this parameter, specifying a value of 0, or passing a negative value causes the sound to stop playback immediately.

返回值

undefined

异常

InvalidStateNode
The node has not been started by calling start() .
RangeError
The value specified for 为负。

范例

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

规范

规范 状态 注释
Web 音频 API
The definition of 'stop()' 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
stop Chrome 14 Edge ≤79 Firefox 53 IE 不支持 No Opera 15 Safari ? WebView Android Yes Chrome Android 18 Firefox Android 25 Opera Android 14 Safari iOS ? Samsung Internet Android 1.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

另请参阅

元数据

  • 最后修改: