var AVPlayer = require('plask').AVPlayer;
Simple audio playback for Plask
var audio = new Audio("assets/test.mp3");
audio.play();
audio.volume = 0.5;
var AVPlayer = require('plask').AVPlayer;
function Audio(file) {
this.audio = new AVPlayer();
this.audio.appendFile(file);
this._playing = false;
this._loops = false;
Object.defineProperty(this, 'volume', {
set: function(value) {
this.audio.setVolume(value);
},
get: function() {
return this.audio.volume();
}
});
returns true if audio is currently playing, false otherwise { Boolean } FIXME: this is currently not reliable as we don’t have a method to detect if file stopped playing
Object.defineProperty(this, 'isPlaying', {
get: function() {
return this._playing;
}
});
Object.defineProperty(this, 'currentTime', {
get: function() {
return this.audio.currentTime();
},
set: function(time) {
this.audio.seekToTime(time);
}
});
Object.defineProperty(this, 'duration', {
get: function() {
return this.audio.duration() || 0;
}
});
Object.defineProperty(this, 'loop', {
get: function() {
return this._loops;
},
set: function(value) {
this._loops = value;
this.audio.setLoops(value);
}
});
}
Audio.prototype.play = function() {
this._playing = true;
this.audio.setRate(1);
}
Audio.prototype.pause = function() {
this._playing = false;
this.audio.setRate(0);
}
module.exports = Audio;