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!'); }
Specification |
---|
Web Audio API # dom-audioscheduledsourcenode-onended |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
onended |
30 |
12 |
25 |
No |
17 |
7 |
≤37 |
30 |
25 |
18 |
7 |
2.0 |
ended
event and its type, Event
. AudioScheduledSourceNode
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/AudioScheduledSourceNode/onended