Yoy can use an asynchronous library. Thus, I solve every problem with asynchrony. In this case, you can use the "every" sentence:
async.each( // List of item audioFiles, // Function to apply to each item function(index, callback){ PlayAudio(audioFiles[index], function(){ callback() }); }, // Function callback function(err,results){ alert("Process finished"); } );
And if you want to avoid parallelism, you can use "eachSeries" instead of "each"
async.eachSeries( // List of item audioFiles, // Function to apply to each item function(index, callback){ PlayAudio(audioFiles[index], function(){ callback() }); }, // Function callback function(err,results){ alert("Process finished"); } );
https://github.com/caolan/async
source share