Hi guys,
I have a countdown timer in a view that lauch a sound when it ends. But if the screen is off, the countdown is paused. I have the view in cache = false but it’s not work.
I have this code : (at the end of countdown, i’m redirect on “finish.html”).
controller('TimerCtrl', function($scope,$timeout,$state) {
if (window.plugins !== undefined) {
window.plugins.insomnia.keepAwake();
window.plugins.backgroundMode.enable();
}
$scope.counter = parseFloat(window.localStorage['timer']); //oeufs à la coque basique
var mytimeout = null;
$scope.onTimeout = function() {
if($scope.counter === 0) {
$scope.$broadcast('timer-stopped', 0);
$timeout.cancel(mytimeout);
return;
}
$scope.counter--;
mytimeout = $timeout($scope.onTimeout, 1000);
};
mytimeout = $timeout($scope.onTimeout, 1000);
$scope.$on('timer-stopped', function(event, remaining) {
if(remaining === 0) {
$state.go('finish');
}
});
$scope.stop = function() {
$state.go('home');
}
})