Skip to main content

AudioScheduledSourceNode

The AudioScheduledSourceNode interface is an AudioNode which serves as a parent interface for several types of audio source nodes. It provides ability to start and stop audio playback.

Methods

start

The above method schedules the node to start audio playback at specified time, if no time is given, it starts immediately. You can invoke this method only once in node's life.

ParametersTypeDescription
whennumberThe time, in seconds, at which the node will start to play.

Errors:

Error typeDescription
RangeErrorwhen is negative number.
InvalidStateErrorIf node has already been started once.

Returns undefined.

stop

The above method schedules the node to stop audio playback at specified time, if no time is given, it stops immediately. If you invoke this method multiple times on the same node before the designated stop time, the most recent call overwrites previous one.

ParametersTypeDescription
whennumberThe time, in seconds, at which the node will stop playing.

Errors:

Error typeDescription
RangeErrorwhen is negative number.
InvalidStateErrorIf node has not been started yet.

Returns undefined.

Events

onended
Experimental

Above callback is fired when source node has stopped playing. By setting this callback you can achieve pause functionality.

const [offset, setOffset] = useState(0);

/* ... */

audioBufferSourceNode.onended = (stopTime?: number) => {
setOffset((_prev) => stopTime || 0);
};

source.start(context.currentTime, offset)
caution

Tested only on Android and iOS.