Web Audio API, events?

javascript, web-audio-api

Solution

var isFinished = false;
var source = context.createBufferSource();
source.onended = onEnded;
function onEnded() {
    isFinished = true;
    console.log('playback finished');
}

Check this out

Problem

Is it possible to add event listeners to web audio api sounds? I've been looking for an event or trigger for when a sounds completes but can't find anything. Here is how I imagine it would work: ``` soundSource = context.createBufferSource(); soundBuffer = context.createBuffer(audioData, true); soundSource.buffer = soundBuffer; soundSource.connect(volumeNode); soundSource.addEventListener('ended', function(e){ console.log("ended", "", e); }, false); soundSource.noteOn(context.currentTime); ```

Original source