Crafty icon indicating copy to clipboard operation
Crafty copied to clipboard

Let users specify a minimum threshold for an audio asset to be considered loaded

Open starwed opened this issue 9 years ago • 2 comments

Browsers don't give you an event when an audio item has completely loaded, but we can still manually compare the loaded time against what the user expects.

The upside is that you can then force Crafty.load to only continue when the full audio has been fetched.

The downside is that the user has to specify the expected audio length, and keep it up to date if the audio asset changes.

starwed avatar Dec 11 '16 22:12 starwed

I realized that there's also a loadedmetadata event that fires when metadata, including the audio length, is available.

That means we could use a slightly more reasonable strategy: wait until both canplaythrough and length >= threshold || length >= duration are true. The threshold value would have a global default that's quite small, but a user could specify something much larger, both globally or for individual assets.

starwed avatar Dec 30 '16 15:12 starwed

Good find!

The threshold value would have a global default that's quite small

Wouldn't it make sense to make the threshold = Infinity? Wait for it to be completely loaded, but have an option for advanced users, who understand the risk of starting the game too soon.

mucaho avatar Apr 23 '17 02:04 mucaho