In HTML5 WebAudio how to know whether sound was stopped or finished playing?
<p>I'm trying to create a very simple music player using Web Audio API. One of the requirement is a function that when one track is finished - next one starts automatically.</p>

<p>Currently I'm subscribing for the 'ended' event. Something along the lines with</p>

<pre><code>nodeSource.onEnded = function () {}
nodeSource.start(0, offset, duration);
</code></pre>

<p>The problem comes from the fact that 'onended' is triggered in two cases:</p>

<ul>
<li>sound finished playing (exactly what's needed)</li>
<li>someone actually stopped the sound (not needed at all)</li>
</ul>

<p>I need a way to separate these two cases. Currently I wasn't able to find a value of current position inside the sound buffer, so I could compare it to the time when sound should end.</p>

<p>I understand that it's possible to create a separate timer at the start of the playback and then check whether the sound is still playing right before it should stop, but that is a really weird way to do it.</p>

<p>Is there a way to get what I need with Web Audio itself? Or, maybe, any other, less weird way?</p>