Asperger
Asperger

Reputation: 3222

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.

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?

Upvotes: 0

Views: 262

Answers (1)

Kevin Ennis
Kevin Ennis

Reputation: 14456

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.

Upvotes: 2

Related Questions