1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Audio = function(target, id){
this.id = id;
this._soundObj = new Sound(target);
this._soundObj.attachSound(this.id);
this._soundObj._parent = this;
this._soundObj.onSoundComplete = function(){
this._parent.isPlaying = false;
}
this.duration = this._soundObj.duration;
this.position = 0;
this.isPlaying = false;
}
Audio.prototype.play = function(){
this.isPlaying = true;
this._soundObj.stop(this.id);
this._soundObj.start(this.position/1000, 0);
}
Audio.prototype.pause = function(){
this.isPlaying = false;
this._soundObj.stop(this.id);
}
Audio.prototype.stop = function(){
this.pause();
this.position = 0;
}
Audio.prototype.setPosition = function(milliseconds){
this.position = milliseconds;
if (this.isPlaying) this.play();
}
Audio.prototype.update = function(){
if (this.isPlaying) this.position = this._soundObj.position;
}