mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
first stab at background audio
This commit is contained in:
parent
1a71fa38f9
commit
1bdc798540
4 changed files with 46 additions and 2 deletions
36
app/Game/Client/AudioPlayer.js
Normal file
36
app/Game/Client/AudioPlayer.js
Normal 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;
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue