I’m using the jQuery audio player ‘jPlayer’, I have a loop which creates a number of jPlayer unique instances then assigns an on click ‘jPlayer play’ to another part of the document for each instance.. The problem is jPlayer uses an internal ready: function() {} to assign the audio path and load the file.. I need to wait for this function to finish before continuing the loop.
The pseudocode is something like this:
for loop{
create jPlayer div;
instantiate jPlayer and assign audio file in the ready(); // need to wait before continuing
assign an on click event to play file;
}
I’m convinced it’s about using queues but I wouldn’t know how to implement it? Any help would be most appreciated!
You might try something like this:
Basically we get rid of the explicit loop and instead use the ready function itself to advance the build iteration via the
initPlayerfunction. By usin an array we can usepop()which will get us that last element of the array while also removing it from the array. We wait to invokeinitPlayeruntil after we get a load percent of 100 by polling the load percent of the player every 500 ms.This is only a suggestion and may need a lot of work… ive never used jPlayer and am flying blind from the documentation so dont expect it to work out of the box :-).