Syntax
js
stop()
stop(when)
Parameters
whenOptional-
The time, in seconds, at which the sound should stop playing. This value is specified in the same time coordinate system as the
AudioContextis using for itscurrentTimeattribute. Omitting this parameter, specifying a value of 0, or passing a negative value causes the sound to stop playback immediately.
Return value
None (undefined).
Exceptions
InvalidStateNodeDOMException-
Thrown if the node has not been started by calling
start(). RangeError-
Thrown if the value specified for
whenis negative.
Examples
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.
js
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 |
|---|
| Web Audio API # dom-audioscheduledsourcenode-stop |