forked from WhatPumpkin/Sburb-Legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAudio.js
86 lines (62 loc) · 1.6 KB
/
Audio.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var Sburb = (function(Sburb){
Sburb.globalVolume = 1;
///////////////////////////////////////
//Sound Class
///////////////////////////////////////
//Constructor
Sburb.Sound = function(asset){
this.asset = asset;
}
//play this sound
Sburb.Sound.prototype.play = function() {
this.fixVolume();
this.asset.play();
}
//pause this sound
Sburb.Sound.prototype.pause = function() {
this.asset.pause();
}
//stop this sound
Sburb.Sound.prototype.stop = function() {
this.pause();
this.asset.currentTime = 0;
}
//has the sound stopped
Sburb.Sound.prototype.ended = function() {
return this.asset.ended;
}
//ensure the sound is playing at the global volume
Sburb.Sound.prototype.fixVolume = function(){
this.asset.volume = Sburb.globalVolume;
this.asset.pause();
this.asset.play();
}
/////////////////////////////////////
//BGM Class (inherits Sound)
/////////////////////////////////////
//constructor
Sburb.BGM = function(asset, startLoop, priority) {
Sburb.Sound.call(this,asset);
this.startLoop;
this.endLoop;
this.setLoopPoints(startLoop?startLoop:0);
}
Sburb.BGM.prototype = new Sburb.Sound();
//set the points in the sound to loop
Sburb.BGM.prototype.setLoopPoints = function(start, end) {
tmpAsset = this.asset
tmpAsset.addEventListener('ended', function() {
tmpAsset.currentTime = start;
tmpAsset.play();
},false);
this.startLoop = start;
this.endLoop = end;
// do we need to have an end point? does that even make sense
}
//loop the sound
Sburb.BGM.prototype.loop = function() {
this.asset.currentTime = this.startLoop;
this.asset.play();
}
return Sburb;
})(Sburb || {});