playing audio in HTML5 after changing source with jQuery -


the strangest thing: have jquery function changes source of audio player. works if insert "alert()" in between. otherwise returns nan.

jquery:

$('.playpause').click(function(){    if (playmode==false){      audio = $('#player audio').get(0);     $(audio).attr('src','newurl.mp3');     playmode = true;     /*alert('wait minute!');*/     audio.play();   }    else {   audio.pause();   playmode = false;} }) 

i imagine has browser not having time load data? thoughts? thanks!

works me :>>

<script>         jquery(document).ready(function ($) {             $('.button').click(function(){                 var myaudio=$(".playpause");                      var audiosub = myaudio.get(0);                  var playmode=audiosub.paused;                   if (playmode){                           myaudio.attr('src','song.mp3');                     playmode = true;                          audiosub.play();                 }                  else {                     audiosub.pause();                     playmode = false;}             })         });     </script> 

html code :>>

 <button class="button" >next</button>             <audio controls  class="playpause">                 <source src="song0.mp3" type="audio/mp3"/>                 browser not support html5 audio.             </audio> 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -