Closed frastlin closed 5 years ago
I just tested the MDN loop example and it works fine on Firefox. The AudioBufferSourceNode.loop should just be passed the Boolean passed to the Wad context. It sounds like this is happening actually. This means the sound is being stopped by something that is not related to the AudioBufferSourceNode.loop. The first places I would look are to the hold in the env object (sound.env.hold), and the return of the promise when the sound stops. The reason why I would look at both of these is because when I tried rolling my own loop functionality using these two options, both gave a significant delay before looping the sound again, about the same amount of delay as the sound plays in the current loop before stopping. I also believe that Wad is doing something with either the env.delay value or the Promise that stops sound playback.
The issue here is that the default env.hold
parameter is about 3 seconds, and this default value can override various other features in wad, such as looping. To play a sound that really loops forever, you'd have to manually set the hold time to be a really large value: sound.play({env:{hold:999999}})
.
Apparently this behavior is unintuitive for many users. I'll probably change it at some point.
Thank you for telling me this! It's not intuitive at all. Because loop only works on sound files, it would be advantageous to remove the hold function from the env for sound files, or if the hold is important for sound files, have hold be the length of the sound by default and loop just play the sound after the hold value has finished.
I was playing around with the hold length and -1 seems to play the sound infinitely. Maybe the default hold length for sound files can be -1 and that would solve this problem.
Ok, so in version 4.4.0, Wad.js is a little smarter about using the default hold parameter. If you play an audio clip with loop
set to true, then the default hold duration is 999 seconds (the same as passing in -1).
Note that if you want, you can still explicitly set a hold duration on a looping sound to make it loop for a specific amount of time.
999 seconds is only 16 minutes. For games, this is not that long for the background sounds. I think, if there should be a max limit, 999999 would be acceptable as that is 277 hours, which is way longer than anyone should be having a game open. Also, this may be a different feature, but it would be very useful if we could specify 10 loops or 100 loops rather than do duration, although with the new .duration attribute, the code to do this would be a little easier, but it is not obvious that the env.hold time and loop are connected.
Hello, The loop:true attribute doesn't loop the sound correctly in the latest version of Firefox or Chrome.
Plays the file 1.5 times with no errors in the console. I'm using Wad 4.2.3 (the latest version).