qadenza
qadenza

Reputation: 9293

How to preload mp3 files

I have about 50 sentences on each page and clicking on each of them a specific short mp3 (200-300KB) is playing.

<p class='sent' id='01/01.mp3'>some text</p>
<p class='sent' id='01/02.mp3'>some text</p>
<p class='sent' id='01/03.mp3'>some text</p>
....

js

$(".sent").click(function() {
abc=$(this).attr('id');
$('#player').html("<embed src=\""+abc+"\" hidden=\"true\" autostart=\"true\" loop=\"" + loop +"\" />");
});

I prefer this solution over html5 audio tag because of firefox/chrome compatibility, i.e. I don't need to convert a lot of files from mp3 to ogg, but downside is that mp3 files are not preloaded, so there is a huge silence between clicking and playing.

Any solution to preload mp3 files ?
Or, maybe a better complete solution ?

Upvotes: 0

Views: 496

Answers (1)

MentalRay
MentalRay

Reputation: 344

It seems that your jquery script, uses html5 audio tag properties. you can try the preload property. preload = auto;

EDIT : By the way, this property says to start loading the file as soon as page starts to load If you want to check if the file has loaded first and then play it, you can use the on event.

Upvotes: 1

Related Questions