MDN Web Docs

Syntax

js

stop()
stop(when)

Parameters

when Optional

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.

Return value

None (undefined).

Exceptions

InvalidStateNode DOMException

Thrown if the node has not been started by calling start().

RangeError

Thrown if the value specified for when is 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

Browser compatibility

See also

Help improve MDN

Yes No

Learn how to contribute

This page was last modified on by MDN contributors.

Read the original on developer.mozilla.org ↗