I have this code:
$scope.play = function (audio) {
var deferred = $q.defer();
api.play(audio).then(function () {
deferred.resolve();
}, function (err) {
deferred.reject();
console.log(err);
});
return deferred.promise;
};
I have a array of audio that i use inside my controller and pass to $scope.play. However, using the below:
var playIndex = 0;
$scope.play(audios[playIndex]).then(function () {
playIndex++;
$scope.play(audios[playIndex]);
});
This works for the first two audios i have in the array of course since I am not checking the return of the second .play. How can i make this loop through all the audios array successfully?
Thanks in advance.
$scope.play = function (audio) { return api.play(audio); }. That's it, really.