Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. AudioScheduledSourceNode
  4. stop()

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.

Syntax

js
stop()stop(when)

Parameters

whenOptional

The time, in seconds, at which the sound should stop playing. This value isspecified in the same time coordinate system as theAudioContext isusing for itscurrentTime attribute.Omitting this parameter, specifying a value of 0, or passing a negative value causesthe sound to stop playback immediately.

Return value

None (undefined).

Exceptions

InvalidStateNodeDOMException

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

RangeError

Thrown if the value specified forwhen is 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.

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

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp