javascript - whats the best idea to play several music in same html5 audio player? -


i want make player winamp html5 audio player. when click javascript button('play' button used onclick event call functions change audio source , play music) source doesn't load in time. code is:

<script type="text/javascript"> function play(src){ document.getelementbyid('new').currentsrc=src+".ogg"; document.getelementbyid('new').play(); } </script>          <audio id="new">             <source src="m.ogg" type="audio/ogg" />             browser not support html5 audio. please upgrade browser.                         </audio>  <button onclick="play('source');">play next song</button> 

and problem there initial src need keep there(like m.ogg).otherwise new source doesn't load. if change innerhtml of 'new' audio player problem doesn't happen little slow load.

so whats best practice ? changing current source or changing innerhtml of audio player?

-thanks.

try calling

document.getelementbyid('new').load(); 

before calling play().

iirc attempt play enough data has buffered.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

visual studio - TFS will not accept changes I've made to a Java project -