The onended event handler for the AudioScheduledSourceNode interface specifies an event handler to be executed when the ended event occurs on the node. This event is sent to the node when the concrete interface (such as AudioBufferSourceNode, OscillatorNode, or ConstantSourceNode) determines that it has stopped playing.

Note: The ended event is only sent to a node configured to loop automatically when the node is stopped using its stop() method. This is the case, for example, when using an AudioBufferSourceNode with its loop property set to true.


AudioScheduledSourceNode.onended = EventHandler;


A function which is called by the browser when the ended event occurs on the AudioScheduledSourceNode. The function receives as input a single parameter, which is an object of type Event describing the event that occurred.


The following example shows basic usage of an AudioContext to create an oscillator node. For an applied example, check out our Violent Theremin demo (see app.js for relevant code).

// create web audio api context
  var audioCtx = new (window.AudioContext || window.webkitAudioContext)();

  // create Oscillator node
  var oscillator = audioCtx.createOscillator();

  oscillator.type = 'square';
  oscillator.frequency.value = 440; // value in hertz
  oscillator.start(); // start the tone playing

  oscillator.stop(5); // the tone will stop again in 5 seconds.

  oscillator.onended = function() {
    console.log('Your tone has now stopped playing!');


Web Audio API
# dom-audioscheduledsourcenode-onended

Browser compatibility

BCD tables only load in the browser

See also