disablePreload:'='
//ngAudio:'='
},
- controller: ['$scope', '$attrs', '$element', '$timeout', function($scope, $attrs, $element, $timeout) {
-
+ controller: function($scope, $attrs, $element, $timeout) {
+
/* Loads the sound from destination */
var audio;
function initSound(){
/* Remove watching features for improved performance */
audio.unbind();
- }
+ }
if (!$scope.disablePreload){
initSound();
- }
-
+ }
+
$element.on('click', function() {
if ($scope.clickPlay === false) {
return;
}
-
+
if ($scope.disablePreload){
initSound();
- }
+ }
/* iOS workaround: Call the play method directly in listener function */
audio.audio.play();
-
+
/* Set volume to $scope volume if it exists, or default to audio's current value */
audio.volume = $scope.volume || audio.volume;
audio.loop = $scope.loop;
audio.play();
}, 5);
});
-
+
$element.on('$destroy', function() {
audio.destroy();
});
- }]
+ }
};
}])
.directive('ngAudioHover', ['$compile', '$q', 'ngAudio', function($compile, $q, ngAudio) {
return {
restrict: 'AEC',
- controller: ['$scope', '$attrs', '$element', '$timeout', function($scope, $attrs, $element, $timeout) {
+ controller: function($scope, $attrs, $element, $timeout) {
var audio = ngAudio.load($attrs.ngAudioHover, $scope);
$element.on('mouseover rollover hover', function() {
-
+
/* iOS workaround: Call the play method directly in listener function */
audio.audio.play();
-
+
audio.volume = $attrs.volumeHover || audio.volume;
audio.loop = $attrs.loop;
audio.currentTime = $attrs.startHover || 0;
$element.on('$destroy', function() {
audio.destroy();
});
- }]
+ }
};
}])
.value('ngAudioGlobals', {
muting: false,
+ songmuting: false,
performance: 25,
- unlock: true,
- volume:1
+ unlock: true
})
.factory('NgAudioObject', ['cleverAudioFindingService', '$rootScope', '$interval', '$timeout', 'ngAudioGlobals', function(cleverAudioFindingService, $rootScope, $interval, $timeout, ngAudioGlobals) {
$willPlay = true;
return this;
};
-
+
var completeListeners = [];
this.complete = function(callback){
completeListeners.push(callback);
};
this.destroy = $destroy;
-
+
$scope.$on('$destroy', function() {
$destroy();
});
-
+
function $destroy() {
if (!$destroyed) {
if (interval) {
progress: audioObject.progress,
muting: audioObject.muting,
loop: audioObject.loop,
- playbackRate: audioObject.playbackRate,
- globalVolume: ngAudioGlobals.volume
+ playbackRate: audioObject.playbackRate
};
}, function(newValue, oldValue) {
//console.log("ngaudio watch callback for: " + audioObject.id);
audioObject.setPlaybackRate(newValue.playbackRate);
}
- if (newValue.globalVolume !== oldValue.globalVolume) {
- if (newValue.globalVolume === 0) {
- audioObject.setMuting(true);
- } else {
- audioObject.setMuting(false);
- audioObject.setVolume(newValue.globalVolume);
- }
- }
-
$looping = newValue.loop;
if (ngAudioGlobals.unlock) {
window.addEventListener("click", twiddle);
-
+
audio.addEventListener('playing', function() {
window.removeEventListener("click",twiddle);
});
$interval.cancel(interval);
interval = $interval(checkWatchers, ngAudioGlobals.performance);
})
-
+
function checkWatchers() {
if ($audioWatch) {
$audioWatch();
}
if (audio) {
- if ($isMuting || ngAudioGlobals.muting) {
+ if ($isMuting || ngAudioGlobals.isMuting) {
audio.volume = 0;
} else {
audio.volume = audioObject.volume !== undefined ? audioObject.volume : 1;
}
if ($willRestart) {
- audio.src = 'about:blank';
+ audio.pause();
+ audio.currentTime = 0;
$willRestart = false;
}
audioObject.currentTime = audio.currentTime;
audioObject.duration = audio.duration;
audioObject.remaining = audio.duration - audio.currentTime;
- audioObject.progress = 0; //We set initial value to 0
+ audioObject.progress = audio.currentTime / audio.duration;
audioObject.paused = audio.paused;
audioObject.src = audio.src;
-
- //After we check if progress is bigger than 0, and we set
- var tempProgress = (audio.currentTime / audio.duration);
- if(tempProgress > 0 ){
- audioObject.progress = tempProgress;
- }
-
+
if (audioObject.currentTime >= audioObject.duration) {
completeListeners.forEach(function(listener){
listener(audioObject);
}
}
- if (!$isMuting && !ngAudioGlobals.muting) {
+ if (!$isMuting && !ngAudioGlobals.isMuting) {
audioObject.volume = audio.volume;
}
this.setUnlock = function(unlock) {
ngAudioGlobals.unlock = unlock;
};
-
- this.setGlobalVolume = function(globalVolume) {
- ngAudioGlobals.volume = globalVolume;
- };
}])
.filter("trackTime", function(){
/* Conveniently takes a number and returns the track time */
-
+
return function(input){
var totalSec = Math.floor(input | 0);
hours = Math.floor(totalSec / 3600);
minutes = Math.floor((totalSec - (hours * 3600)) / 60);
- seconds = (totalSec - ((minutes * 60) + (hours * 3600)));
+ seconds = (totalSec - ((minutes * 60) + (hours * 3600)));
if (hours.toString().length == 1) {
hours = "0" + (Math.floor(totalSec / 3600)).toString();
- }
+ }
if (minutes.toString().length == 1) {
minutes = "0" + (Math.floor((totalSec - (hours * 3600)) / 60)).toString();
- }
+ }
if (seconds.toString().length == 1) {
- seconds = "0" + (totalSec - ((minutes * 60) + (hours * 3600))).toString();
- }
+ seconds = "0" + (totalSec - ((minutes * 60) + (hours * 3600))).toString();
+ }
output = hours + ":" + minutes + ":" + seconds;
output = totalSec + "s";
}
-
+
if (typeof Number.isNaN === "function" && Number.isNaN(output)){
debugger;
}
- return output;
+ return output;
}
});