AudioScheduledSourceNode.stop()

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

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

注意: 如果计划的停止时间发生在节点计划的开始时间之前,则节点永远不会开始运行。

语法

AudioScheduledSourceNode.stop([when]);

参数

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

Return value

undefined

Exceptions

InvalidStateNode
节点还没有通过调用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

Specification Status Comment
Web Audio API
stop()
Working Draft  

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
stopChrome Full support 14Edge ? Firefox Full support 53IE No support NoOpera Full support 15Safari ? WebView Android Full support YesChrome Android Full support 18Firefox Android Full support 25Opera Android Full support 14Safari iOS ? Samsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

See also