Instantiating and running jPlayer directly one after the other doesn't work -- why?

Instantiating and running jPlayer directly one after the other doesn't work -- why?

Hi everybody,
I want to initialize the jPlayer plugin and directly play an audio file one after the other, however it somehow doesn't work. I've found a workaround, that if I wait aout 750ms (setTimeout) then playing the audio file works.

Example code of what doesn't work:
  1. // initialization
    var jp = $('<div id="jplayer"></div>');
    $('body').append(jp);
    jp.jPlayer( { swfPath: "javascript" });
           




  2. jp.jPlayer('setFile', 'somefile.mp3').jPlayer('play');
That code would be called after a user clicks on a button.
If I put the second part in a setTimeout() and run it after about 750ms, then it works. This is strange, any idea how we can get this to work?

Thanks!







    • Topic Participants

    • salim