AudioBufferSourceNode.onended

The onended event handler of the AudioBufferSourceNode contains the callback associated with the ended event: this allows you to run code in response to the audio track finishing playback.

Note: The onended handler won't have any effect if the loop property is set to true, as the audio won't stop playing. To see the effect in this case you'd have to use AudioBufferSourceNode.stop().

Syntax

js;highlight[20]
var source = audioCtx.createBufferSource();
source.onended = function() { ... };

Example

JavaScript
source.start();
source.onended = function() {
  console.log('Your audio has finished playing');
}

Properties

None.

Specification

Specification Status Comment
Web Audio API
The definition of 'onended' in that specification.
Working Draft  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 14 webkit 23 Not supported 15 webkit
22 (unprefixed)
6 webkit
Feature Android Chrome Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support Not supported 28 webkit 25 1.2 Not supported Not supported webkit

See also

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/audiobuffersourcenode/onended

API AudioBufferSourceNode onended Property Reference Référence Web Audio API