Fixed audio not looping occasionally #1225
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Finally upgrade to the latest Howler after sitting on a version from early 2018 for ages!
I can across a bug in games where the background audio would sometimes not loop. Sometimes it did, and I couldn't work out why and when it sometimes did work and sometimes didn't. When setting a breakpoint around this area, the background looping always worked, which made things even more infuriating.
Eventually I came to this simple change. If you play a sound, and it doesn't have the looping property set, but then set it straight after playing; well, it appears there's this tiny race condition. It's something like this:
You play the audio, and when getting the id back, you set the audio to pause. But web audio isn't ready yet; so when it finally IS ready setParams is called later on than usual, and resets the loop property to it's original value of false.