AudioScheduledSourceNode: stop() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2020.
Thestop() method onAudioScheduledSourceNode schedules asound to cease playback at the specified time. If no time is specified, then the soundstops playing immediately.
Each time you callstop() on the same node, the specified time replacesany previously-scheduled stop time that hasn't occurred yet. If the node has alreadystopped, this method has no effect.
Note:If a scheduled stop time occurs before the node's scheduledstart time, the node never starts to play.
In this article
Syntax
stop()stop(when)Parameters
whenOptionalThe time, in seconds, at which the sound should stop playing. This value isspecified in the same time coordinate system as the
AudioContextisusing for itscurrentTimeattribute.Omitting this parameter, specifying a value of 0, or passing a negative value causesthe sound to stop playback immediately.
Return value
None (undefined).
Exceptions
InvalidStateNodeDOMExceptionThrown if the node has not been started by calling
start().RangeErrorThrown if the value specified for
whenis negative.
Examples
This example demonstrates starting an oscillator node, scheduled to begin playing atonce and to stop playing in one second. The stop time is determined by taking the audiocontext's current time fromAudioContext.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 |
|---|
| Web Audio API> # dom-audioscheduledsourcenode-stop> |