Heyo! Not sure if this is a bug or “working as intended”, but it definitely surprised me and made me go on a bug hunt throughout my own code, and then the BJS code afterwards.
Because BJS seems to request files from disk (via XHR) every time a new Sound is created with a file URL parameter, I decided to use my own caching system. This loads the file once and stores it as an ArrayBuffer, which I then passed to the Sound constructor to avoid repeated and unnecessary disk I/O.
The first time, it’s playing the audio as expected, but the second it just did nothing. Upon looking into this, I found that the ArrayBuffer was emptied so there would be no data to play on the second attempt. I’ve traced it back to this call, which appears to be a WebAudio builtin.
Once my buffer reaches that call it is decoded and then emptied, which is unfortunate since my caching system doesn’t expect any user of the resources to irrevocably consume them (all operations should be idempotent to ensure the same resource buffer can be re-used until evicted from the resource cache).
Is this just a limitation of WebAudio and I have to copy the buffer before passing it to BJS or should this be something BJS takes precautions against? Either way, it likely should be documented. If it already is, my apologies, but I didn’t find anything.
As always, thank you for your time and your amazing work!