Asperger Asperger - 4 years ago 292
Javascript Question

Webaudio: createMediaElementSource faster than XMLHttpRequest

Whenever I play music using XMLHttpRequest I must wait at least 10 seconds or so until I hear the sound.


  • Short sounds load instantly.

  • The larger sound (3 minutes) takes at least 10 seconds before it plays.



What are some factors that play a role in loading time? I mean im doing this in a localhost. Sound should play back instantly as im not downloading anything. Obviously the time for the script running though is equal for large and small sounds.

I did notice that using createMediaElementSource considerably speeds it up and sounds play instantly.

So what is going on?

Answer Source

How big is the audio file in question? If it's large, you're probably paying a big price for decodeAudioData.

With createMediaElementSource(), you get to decode the audio file in chunks. It'll start playing back as soon as it thinks it has enough of a buffer to play through to the end.

But with decodeAudioData, you have to wait until the whole file gets decoded.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download