If howler receives a call to pause() before the audio is loaded it puts the command into the internal queue to be run after loading has completed. The issue is that autoplay is checked and acted upon after the queue has been unloaded. This means that the audio will be paused (even though it hasn't started yet) then it will be played.
Here's a jsbin that will show it. I picked a pretty big audio file from WikiCommons. It takes about 2.5 seconds for it to load on my unthrottled network connection. When I call pause() while it's loading it will not pause. When I call pause() after the file has loaded (5 seconds in my case) it does pause correctly.
// Fire the loaded event.
if (self._state !== 'loaded') {
self._state = 'loaded';
self._emit('load');
self._loadQueue(); // <-- Going to call pause() in here...
}
// Begin playback if specified.
if (self._autoplay) {
self.play(); // <-- Then autoplay
}
Is it intentional to check autoplay after the queue is unloaded? One benefit I can think of is that your volume, position, etc. will be set before playing but I think you can accomplish all of this on initial load with options.
If this is not intentional, I'd be happy to open a pull request that checks autoplay before going through the queue. Alternatively, maybe autoplay should just add a play action to the front(?) of the queue?
Thanks for catching this! It wasn't intentional, it was overlooked when the queue system was added. It probably makes most sense to add it to the start of the queue, which I'll get added into v2.0.2.
If howler receives a call to
pause()
before the audio is loaded it puts the command into the internal queue to be run after loading has completed. The issue is that autoplay is checked and acted upon after the queue has been unloaded. This means that the audio will be paused (even though it hasn't started yet) then it will be played.Here's a jsbin that will show it. I picked a pretty big audio file from WikiCommons. It takes about 2.5 seconds for it to load on my unthrottled network connection. When I call
pause()
while it's loading it will not pause. When I callpause()
after the file has loaded (5 seconds in my case) it does pause correctly.There are two places in the howler.js core source that have the following pattern.
Is it intentional to check autoplay after the queue is unloaded? One benefit I can think of is that your volume, position, etc. will be set before playing but I think you can accomplish all of this on initial load with options.
If this is not intentional, I'd be happy to open a pull request that checks autoplay before going through the queue. Alternatively, maybe autoplay should just add a
play
action to the front(?) of the queue?