function Audio(url) {
this.audio = new window.Audio();
this.audio.src = url;
this.audio.onended = function() {
this.playing = false;
}.bind(this);
Simple audio playback for the browser
var audio = new Audio("assets/test.mp3");
audio.play();
audio.volume = 0.5;
function Audio(url) {
this.audio = new window.Audio();
this.audio.src = url;
this.audio.onended = function() {
this.playing = false;
}.bind(this);
Object.defineProperty(this, 'volume', {
get: function() {
return this.audio.volume;
},
set: function(value) {
this.audio.volume = value;
}
});
Object.defineProperty(this, 'isPlaying', {
get: function() {
return this.playing;
}
});
Object.defineProperty(this, 'currentTime', {
get: function() {
return this.audio.currentTime;
},
set: function(time) {
this.audio.currentTime = time;
}
});
Object.defineProperty(this, 'duration', {
get: function() {
return this.audio.duration || 0;
}
});
Object.defineProperty(this, 'loop', {
get: function() {
return this.audio.loop;
},
set: function(value) {
this.audio.loop = value;
}
});
}
Audio.prototype.play = function() {
this.audio.play();
this.playing = true;
}
Audio.prototype.pause = function() {
this.audio.pause();
this.playing = false;
}
module.exports = Audio;