javascript - Preloading my audio file in html -


i'm using below way play sound effect on website. need sound play out everytime received protocol slave device:

<script> function rxprotocol() {     playsound('audio123.wav'); }  function playsound(soundfile)  {     document.getelementbyid("dummy").innerhtml=     "<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />"; } </script>  <body> <span id="dummy"></span> </body> 

but seems way audio played delayed everytime. after received protocol 2 seconds, audio played.

is because did not preload audio? guys teach me how modify code , make preload enable?

you can try preload attribute of html5 audio tag

like preload="auto"

also read http://webdesignledger.com/tips/audio-and-video-with-html5 , http://code.google.com/p/html5-preloader/


Comments