chuck.js/app/Game/Client/AudioPlayer.js
2014-11-16 01:22:58 +01:00

36 lines
No EOL
670 B
JavaScript

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;
});