cordova-plugin-nativeaudio icon indicating copy to clipboard operation
cordova-plugin-nativeaudio copied to clipboard

Play an array sound list

Open LautaroRiveiro opened this issue 7 years ago • 1 comments

Hi! I have an array with some .mp3's id, for example:

$scope.list = ['bass', 'bass', 'bongo'];

And I want to play that sequence with a general form. I tried a forEach, like this:

angular.forEach($scope.list, function(value, key) { window.plugins.NativeAudio.play(value); });

But that plays all the audios at the same time. I tried using completeCallback and worked, but I had to put manually each element of the array. Is there any function or method to play one by one?

Sorry my bad english. Thanks!!

LautaroRiveiro avatar Sep 17 '16 18:09 LautaroRiveiro

Finally a friend helped me. If it helps someone the solution is inserting the function "play" into a $timeout, and asigning an incremental variable at delay. Like this:

var delay = 0; angular.forEach($scope.list, function(value, key) { $timeout(function() { window.plugins.NativeAudio.play(value); }, delay); delay += 1000; //1s });

Sorry my bad english!!

LautaroRiveiro avatar Sep 24 '16 22:09 LautaroRiveiro