How to preload a sound in Javascript?

Your problem is that Audio objects don’t support the ‘load’ event.

Instead, there’s an event called ‘canplaythrough’ that doesn’t mean it’s fully loaded, but enough of it is loaded that at the current download rate, it will finish by the time the track has had enough time to play through.

So instead of

audio.onload = isAppLoaded;

try

audio.oncanplaythrough = isAppLoaded;

Or better yet.. 😉

audio.addEventListener('canplaythrough', isAppLoaded, false);

Leave a Comment