first stab at background audio

This commit is contained in:
Jeena 2014-11-16 01:22:58 +01:00
parent 1a71fa38f9
commit 1bdc798540
4 changed files with 46 additions and 2 deletions

View file

@ -0,0 +1,36 @@
define([
],
function () {
function AudioPlayer(path) {
this.audio = new Audio(path);
this.audio.loop = true;
this.audio.volume = 0.1;
this.audio.addEventListener('timeupdate', function(){
var buffer = 1
if(this.currentTime > this.duration - buffer) {
this.currentTime = 1
this.play()
}
}, false);
}
AudioPlayer.prototype.play = function() {
this.audio.play();
this.doPlay = true;
}
AudioPlayer.prototype.stop = function() {
this.audio.stop();
this.doPlay = false;
};
AudioPlayer.prototype.destroy = function() {
this.stop();
};
return AudioPlayer;
});