create-airjam 0.1.7 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +12 -4
- package/package.json +10 -8
- package/templates/pong/.env.example +7 -0
- package/templates/pong/{AI_INSTRUCTIONS.md → AGENTS.md} +9 -2
- package/templates/pong/README.md +38 -3
- package/templates/pong/airjam-docs/for-agents/page.md +27 -0
- package/templates/pong/airjam-docs/getting-started/architecture/page.md +4 -1
- package/templates/pong/airjam-docs/getting-started/introduction/page.md +56 -38
- package/templates/pong/airjam-docs/getting-started/quick-start/page.md +108 -0
- package/templates/pong/airjam-docs/how-it-works/architecture/page.md +168 -0
- package/templates/pong/airjam-docs/how-it-works/host-system/page.md +20 -10
- package/templates/pong/airjam-docs/sdk/hooks/page.md +13 -11
- package/templates/pong/airjam-docs/sdk/networked-state/page.md +1 -1
- package/templates/pong/package.json +6 -3
- package/templates/pong/scripts/dev-secure.mjs +177 -0
- package/templates/pong/scripts/secure-init.mjs +134 -0
- package/templates/pong/src/App.tsx +2 -0
- package/templates/pong/src/controller-view.tsx +78 -99
- package/templates/pong/src/host-view.tsx +3 -18
- package/templates/pong/src/vite-env.d.ts +1 -0
- package/templates/pong/vite.config.ts +9 -0
- package/templates/pong/dist/assets/index-BwJ4uU20.js +0 -269
- package/templates/pong/dist/assets/index-D42jDbB5.css +0 -1
- package/templates/pong/dist/index.html +0 -19
- package/templates/pong/node_modules/.bin/air-jam-server +0 -17
- package/templates/pong/node_modules/.bin/eslint +0 -17
- package/templates/pong/node_modules/.bin/eslint-config-prettier +0 -17
- package/templates/pong/node_modules/.bin/tsc +0 -17
- package/templates/pong/node_modules/.bin/tsserver +0 -17
- package/templates/pong/node_modules/.bin/vite +0 -17
- package/templates/pong/node_modules/.vite/deps/@radix-ui_react-dialog.js +0 -1680
- package/templates/pong/node_modules/.vite/deps/@radix-ui_react-dialog.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/@radix-ui_react-slider.js +0 -638
- package/templates/pong/node_modules/.vite/deps/@radix-ui_react-slider.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/@radix-ui_react-slot.js +0 -129
- package/templates/pong/node_modules/.vite/deps/@radix-ui_react-slot.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/@radix-ui_react-tabs.js +0 -434
- package/templates/pong/node_modules/.vite/deps/@radix-ui_react-tabs.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/_metadata.json +0 -163
- package/templates/pong/node_modules/.vite/deps/chunk-6G72RLJL.js +0 -1004
- package/templates/pong/node_modules/.vite/deps/chunk-6G72RLJL.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/chunk-BHOBIW4J.js +0 -99
- package/templates/pong/node_modules/.vite/deps/chunk-BHOBIW4J.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/chunk-E44IQKDY.js +0 -49
- package/templates/pong/node_modules/.vite/deps/chunk-E44IQKDY.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/chunk-E5X4SHYG.js +0 -21
- package/templates/pong/node_modules/.vite/deps/chunk-E5X4SHYG.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/chunk-G3PMV62Z.js +0 -35
- package/templates/pong/node_modules/.vite/deps/chunk-G3PMV62Z.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/chunk-LI6KBZ3D.js +0 -292
- package/templates/pong/node_modules/.vite/deps/chunk-LI6KBZ3D.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/chunk-MDNXVKSA.js +0 -337
- package/templates/pong/node_modules/.vite/deps/chunk-MDNXVKSA.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/chunk-METQ356G.js +0 -280
- package/templates/pong/node_modules/.vite/deps/chunk-METQ356G.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/chunk-NPTAWNEA.js +0 -171
- package/templates/pong/node_modules/.vite/deps/chunk-NPTAWNEA.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/class-variance-authority.js +0 -51
- package/templates/pong/node_modules/.vite/deps/class-variance-authority.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/clsx.js +0 -9
- package/templates/pong/node_modules/.vite/deps/clsx.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/howler.js +0 -2241
- package/templates/pong/node_modules/.vite/deps/howler.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/html5-qrcode.js +0 -29350
- package/templates/pong/node_modules/.vite/deps/html5-qrcode.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/lucide-react.js +0 -28662
- package/templates/pong/node_modules/.vite/deps/lucide-react.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/package.json +0 -3
- package/templates/pong/node_modules/.vite/deps/qrcode.js +0 -2083
- package/templates/pong/node_modules/.vite/deps/qrcode.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/react-dom.js +0 -6
- package/templates/pong/node_modules/.vite/deps/react-dom.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/react-dom_client.js +0 -20217
- package/templates/pong/node_modules/.vite/deps/react-dom_client.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/react-router-dom.js +0 -13900
- package/templates/pong/node_modules/.vite/deps/react-router-dom.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/react.js +0 -5
- package/templates/pong/node_modules/.vite/deps/react.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/react_jsx-dev-runtime.js +0 -278
- package/templates/pong/node_modules/.vite/deps/react_jsx-dev-runtime.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/react_jsx-runtime.js +0 -6
- package/templates/pong/node_modules/.vite/deps/react_jsx-runtime.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/socket__io-client.js +0 -3422
- package/templates/pong/node_modules/.vite/deps/socket__io-client.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/tailwind-merge.js +0 -2534
- package/templates/pong/node_modules/.vite/deps/tailwind-merge.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/zod.js +0 -13810
- package/templates/pong/node_modules/.vite/deps/zod.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/zustand.js +0 -56
- package/templates/pong/node_modules/.vite/deps/zustand.js.map +0 -7
- package/templates/pong/node_modules/.vite/deps/zustand_react_shallow.js +0 -77
- package/templates/pong/node_modules/.vite/deps/zustand_react_shallow.js.map +0 -7
|
@@ -1,2241 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__commonJS
|
|
3
|
-
} from "./chunk-G3PMV62Z.js";
|
|
4
|
-
|
|
5
|
-
// ../../../../node_modules/.pnpm/howler@2.2.4/node_modules/howler/dist/howler.js
|
|
6
|
-
var require_howler = __commonJS({
|
|
7
|
-
"../../../../node_modules/.pnpm/howler@2.2.4/node_modules/howler/dist/howler.js"(exports) {
|
|
8
|
-
(function() {
|
|
9
|
-
"use strict";
|
|
10
|
-
var HowlerGlobal2 = function() {
|
|
11
|
-
this.init();
|
|
12
|
-
};
|
|
13
|
-
HowlerGlobal2.prototype = {
|
|
14
|
-
/**
|
|
15
|
-
* Initialize the global Howler object.
|
|
16
|
-
* @return {Howler}
|
|
17
|
-
*/
|
|
18
|
-
init: function() {
|
|
19
|
-
var self = this || Howler2;
|
|
20
|
-
self._counter = 1e3;
|
|
21
|
-
self._html5AudioPool = [];
|
|
22
|
-
self.html5PoolSize = 10;
|
|
23
|
-
self._codecs = {};
|
|
24
|
-
self._howls = [];
|
|
25
|
-
self._muted = false;
|
|
26
|
-
self._volume = 1;
|
|
27
|
-
self._canPlayEvent = "canplaythrough";
|
|
28
|
-
self._navigator = typeof window !== "undefined" && window.navigator ? window.navigator : null;
|
|
29
|
-
self.masterGain = null;
|
|
30
|
-
self.noAudio = false;
|
|
31
|
-
self.usingWebAudio = true;
|
|
32
|
-
self.autoSuspend = true;
|
|
33
|
-
self.ctx = null;
|
|
34
|
-
self.autoUnlock = true;
|
|
35
|
-
self._setup();
|
|
36
|
-
return self;
|
|
37
|
-
},
|
|
38
|
-
/**
|
|
39
|
-
* Get/set the global volume for all sounds.
|
|
40
|
-
* @param {Float} vol Volume from 0.0 to 1.0.
|
|
41
|
-
* @return {Howler/Float} Returns self or current volume.
|
|
42
|
-
*/
|
|
43
|
-
volume: function(vol) {
|
|
44
|
-
var self = this || Howler2;
|
|
45
|
-
vol = parseFloat(vol);
|
|
46
|
-
if (!self.ctx) {
|
|
47
|
-
setupAudioContext();
|
|
48
|
-
}
|
|
49
|
-
if (typeof vol !== "undefined" && vol >= 0 && vol <= 1) {
|
|
50
|
-
self._volume = vol;
|
|
51
|
-
if (self._muted) {
|
|
52
|
-
return self;
|
|
53
|
-
}
|
|
54
|
-
if (self.usingWebAudio) {
|
|
55
|
-
self.masterGain.gain.setValueAtTime(vol, Howler2.ctx.currentTime);
|
|
56
|
-
}
|
|
57
|
-
for (var i = 0; i < self._howls.length; i++) {
|
|
58
|
-
if (!self._howls[i]._webAudio) {
|
|
59
|
-
var ids = self._howls[i]._getSoundIds();
|
|
60
|
-
for (var j = 0; j < ids.length; j++) {
|
|
61
|
-
var sound = self._howls[i]._soundById(ids[j]);
|
|
62
|
-
if (sound && sound._node) {
|
|
63
|
-
sound._node.volume = sound._volume * vol;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return self;
|
|
69
|
-
}
|
|
70
|
-
return self._volume;
|
|
71
|
-
},
|
|
72
|
-
/**
|
|
73
|
-
* Handle muting and unmuting globally.
|
|
74
|
-
* @param {Boolean} muted Is muted or not.
|
|
75
|
-
*/
|
|
76
|
-
mute: function(muted) {
|
|
77
|
-
var self = this || Howler2;
|
|
78
|
-
if (!self.ctx) {
|
|
79
|
-
setupAudioContext();
|
|
80
|
-
}
|
|
81
|
-
self._muted = muted;
|
|
82
|
-
if (self.usingWebAudio) {
|
|
83
|
-
self.masterGain.gain.setValueAtTime(muted ? 0 : self._volume, Howler2.ctx.currentTime);
|
|
84
|
-
}
|
|
85
|
-
for (var i = 0; i < self._howls.length; i++) {
|
|
86
|
-
if (!self._howls[i]._webAudio) {
|
|
87
|
-
var ids = self._howls[i]._getSoundIds();
|
|
88
|
-
for (var j = 0; j < ids.length; j++) {
|
|
89
|
-
var sound = self._howls[i]._soundById(ids[j]);
|
|
90
|
-
if (sound && sound._node) {
|
|
91
|
-
sound._node.muted = muted ? true : sound._muted;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return self;
|
|
97
|
-
},
|
|
98
|
-
/**
|
|
99
|
-
* Handle stopping all sounds globally.
|
|
100
|
-
*/
|
|
101
|
-
stop: function() {
|
|
102
|
-
var self = this || Howler2;
|
|
103
|
-
for (var i = 0; i < self._howls.length; i++) {
|
|
104
|
-
self._howls[i].stop();
|
|
105
|
-
}
|
|
106
|
-
return self;
|
|
107
|
-
},
|
|
108
|
-
/**
|
|
109
|
-
* Unload and destroy all currently loaded Howl objects.
|
|
110
|
-
* @return {Howler}
|
|
111
|
-
*/
|
|
112
|
-
unload: function() {
|
|
113
|
-
var self = this || Howler2;
|
|
114
|
-
for (var i = self._howls.length - 1; i >= 0; i--) {
|
|
115
|
-
self._howls[i].unload();
|
|
116
|
-
}
|
|
117
|
-
if (self.usingWebAudio && self.ctx && typeof self.ctx.close !== "undefined") {
|
|
118
|
-
self.ctx.close();
|
|
119
|
-
self.ctx = null;
|
|
120
|
-
setupAudioContext();
|
|
121
|
-
}
|
|
122
|
-
return self;
|
|
123
|
-
},
|
|
124
|
-
/**
|
|
125
|
-
* Check for codec support of specific extension.
|
|
126
|
-
* @param {String} ext Audio file extention.
|
|
127
|
-
* @return {Boolean}
|
|
128
|
-
*/
|
|
129
|
-
codecs: function(ext) {
|
|
130
|
-
return (this || Howler2)._codecs[ext.replace(/^x-/, "")];
|
|
131
|
-
},
|
|
132
|
-
/**
|
|
133
|
-
* Setup various state values for global tracking.
|
|
134
|
-
* @return {Howler}
|
|
135
|
-
*/
|
|
136
|
-
_setup: function() {
|
|
137
|
-
var self = this || Howler2;
|
|
138
|
-
self.state = self.ctx ? self.ctx.state || "suspended" : "suspended";
|
|
139
|
-
self._autoSuspend();
|
|
140
|
-
if (!self.usingWebAudio) {
|
|
141
|
-
if (typeof Audio !== "undefined") {
|
|
142
|
-
try {
|
|
143
|
-
var test = new Audio();
|
|
144
|
-
if (typeof test.oncanplaythrough === "undefined") {
|
|
145
|
-
self._canPlayEvent = "canplay";
|
|
146
|
-
}
|
|
147
|
-
} catch (e) {
|
|
148
|
-
self.noAudio = true;
|
|
149
|
-
}
|
|
150
|
-
} else {
|
|
151
|
-
self.noAudio = true;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
try {
|
|
155
|
-
var test = new Audio();
|
|
156
|
-
if (test.muted) {
|
|
157
|
-
self.noAudio = true;
|
|
158
|
-
}
|
|
159
|
-
} catch (e) {
|
|
160
|
-
}
|
|
161
|
-
if (!self.noAudio) {
|
|
162
|
-
self._setupCodecs();
|
|
163
|
-
}
|
|
164
|
-
return self;
|
|
165
|
-
},
|
|
166
|
-
/**
|
|
167
|
-
* Check for browser support for various codecs and cache the results.
|
|
168
|
-
* @return {Howler}
|
|
169
|
-
*/
|
|
170
|
-
_setupCodecs: function() {
|
|
171
|
-
var self = this || Howler2;
|
|
172
|
-
var audioTest = null;
|
|
173
|
-
try {
|
|
174
|
-
audioTest = typeof Audio !== "undefined" ? new Audio() : null;
|
|
175
|
-
} catch (err) {
|
|
176
|
-
return self;
|
|
177
|
-
}
|
|
178
|
-
if (!audioTest || typeof audioTest.canPlayType !== "function") {
|
|
179
|
-
return self;
|
|
180
|
-
}
|
|
181
|
-
var mpegTest = audioTest.canPlayType("audio/mpeg;").replace(/^no$/, "");
|
|
182
|
-
var ua = self._navigator ? self._navigator.userAgent : "";
|
|
183
|
-
var checkOpera = ua.match(/OPR\/(\d+)/g);
|
|
184
|
-
var isOldOpera = checkOpera && parseInt(checkOpera[0].split("/")[1], 10) < 33;
|
|
185
|
-
var checkSafari = ua.indexOf("Safari") !== -1 && ua.indexOf("Chrome") === -1;
|
|
186
|
-
var safariVersion = ua.match(/Version\/(.*?) /);
|
|
187
|
-
var isOldSafari = checkSafari && safariVersion && parseInt(safariVersion[1], 10) < 15;
|
|
188
|
-
self._codecs = {
|
|
189
|
-
mp3: !!(!isOldOpera && (mpegTest || audioTest.canPlayType("audio/mp3;").replace(/^no$/, ""))),
|
|
190
|
-
mpeg: !!mpegTest,
|
|
191
|
-
opus: !!audioTest.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, ""),
|
|
192
|
-
ogg: !!audioTest.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, ""),
|
|
193
|
-
oga: !!audioTest.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, ""),
|
|
194
|
-
wav: !!(audioTest.canPlayType('audio/wav; codecs="1"') || audioTest.canPlayType("audio/wav")).replace(/^no$/, ""),
|
|
195
|
-
aac: !!audioTest.canPlayType("audio/aac;").replace(/^no$/, ""),
|
|
196
|
-
caf: !!audioTest.canPlayType("audio/x-caf;").replace(/^no$/, ""),
|
|
197
|
-
m4a: !!(audioTest.canPlayType("audio/x-m4a;") || audioTest.canPlayType("audio/m4a;") || audioTest.canPlayType("audio/aac;")).replace(/^no$/, ""),
|
|
198
|
-
m4b: !!(audioTest.canPlayType("audio/x-m4b;") || audioTest.canPlayType("audio/m4b;") || audioTest.canPlayType("audio/aac;")).replace(/^no$/, ""),
|
|
199
|
-
mp4: !!(audioTest.canPlayType("audio/x-mp4;") || audioTest.canPlayType("audio/mp4;") || audioTest.canPlayType("audio/aac;")).replace(/^no$/, ""),
|
|
200
|
-
weba: !!(!isOldSafari && audioTest.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, "")),
|
|
201
|
-
webm: !!(!isOldSafari && audioTest.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, "")),
|
|
202
|
-
dolby: !!audioTest.canPlayType('audio/mp4; codecs="ec-3"').replace(/^no$/, ""),
|
|
203
|
-
flac: !!(audioTest.canPlayType("audio/x-flac;") || audioTest.canPlayType("audio/flac;")).replace(/^no$/, "")
|
|
204
|
-
};
|
|
205
|
-
return self;
|
|
206
|
-
},
|
|
207
|
-
/**
|
|
208
|
-
* Some browsers/devices will only allow audio to be played after a user interaction.
|
|
209
|
-
* Attempt to automatically unlock audio on the first user interaction.
|
|
210
|
-
* Concept from: http://paulbakaus.com/tutorials/html5/web-audio-on-ios/
|
|
211
|
-
* @return {Howler}
|
|
212
|
-
*/
|
|
213
|
-
_unlockAudio: function() {
|
|
214
|
-
var self = this || Howler2;
|
|
215
|
-
if (self._audioUnlocked || !self.ctx) {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
self._audioUnlocked = false;
|
|
219
|
-
self.autoUnlock = false;
|
|
220
|
-
if (!self._mobileUnloaded && self.ctx.sampleRate !== 44100) {
|
|
221
|
-
self._mobileUnloaded = true;
|
|
222
|
-
self.unload();
|
|
223
|
-
}
|
|
224
|
-
self._scratchBuffer = self.ctx.createBuffer(1, 1, 22050);
|
|
225
|
-
var unlock = function(e) {
|
|
226
|
-
while (self._html5AudioPool.length < self.html5PoolSize) {
|
|
227
|
-
try {
|
|
228
|
-
var audioNode = new Audio();
|
|
229
|
-
audioNode._unlocked = true;
|
|
230
|
-
self._releaseHtml5Audio(audioNode);
|
|
231
|
-
} catch (e2) {
|
|
232
|
-
self.noAudio = true;
|
|
233
|
-
break;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
for (var i = 0; i < self._howls.length; i++) {
|
|
237
|
-
if (!self._howls[i]._webAudio) {
|
|
238
|
-
var ids = self._howls[i]._getSoundIds();
|
|
239
|
-
for (var j = 0; j < ids.length; j++) {
|
|
240
|
-
var sound = self._howls[i]._soundById(ids[j]);
|
|
241
|
-
if (sound && sound._node && !sound._node._unlocked) {
|
|
242
|
-
sound._node._unlocked = true;
|
|
243
|
-
sound._node.load();
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
self._autoResume();
|
|
249
|
-
var source = self.ctx.createBufferSource();
|
|
250
|
-
source.buffer = self._scratchBuffer;
|
|
251
|
-
source.connect(self.ctx.destination);
|
|
252
|
-
if (typeof source.start === "undefined") {
|
|
253
|
-
source.noteOn(0);
|
|
254
|
-
} else {
|
|
255
|
-
source.start(0);
|
|
256
|
-
}
|
|
257
|
-
if (typeof self.ctx.resume === "function") {
|
|
258
|
-
self.ctx.resume();
|
|
259
|
-
}
|
|
260
|
-
source.onended = function() {
|
|
261
|
-
source.disconnect(0);
|
|
262
|
-
self._audioUnlocked = true;
|
|
263
|
-
document.removeEventListener("touchstart", unlock, true);
|
|
264
|
-
document.removeEventListener("touchend", unlock, true);
|
|
265
|
-
document.removeEventListener("click", unlock, true);
|
|
266
|
-
document.removeEventListener("keydown", unlock, true);
|
|
267
|
-
for (var i2 = 0; i2 < self._howls.length; i2++) {
|
|
268
|
-
self._howls[i2]._emit("unlock");
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
};
|
|
272
|
-
document.addEventListener("touchstart", unlock, true);
|
|
273
|
-
document.addEventListener("touchend", unlock, true);
|
|
274
|
-
document.addEventListener("click", unlock, true);
|
|
275
|
-
document.addEventListener("keydown", unlock, true);
|
|
276
|
-
return self;
|
|
277
|
-
},
|
|
278
|
-
/**
|
|
279
|
-
* Get an unlocked HTML5 Audio object from the pool. If none are left,
|
|
280
|
-
* return a new Audio object and throw a warning.
|
|
281
|
-
* @return {Audio} HTML5 Audio object.
|
|
282
|
-
*/
|
|
283
|
-
_obtainHtml5Audio: function() {
|
|
284
|
-
var self = this || Howler2;
|
|
285
|
-
if (self._html5AudioPool.length) {
|
|
286
|
-
return self._html5AudioPool.pop();
|
|
287
|
-
}
|
|
288
|
-
var testPlay = new Audio().play();
|
|
289
|
-
if (testPlay && typeof Promise !== "undefined" && (testPlay instanceof Promise || typeof testPlay.then === "function")) {
|
|
290
|
-
testPlay.catch(function() {
|
|
291
|
-
console.warn("HTML5 Audio pool exhausted, returning potentially locked audio object.");
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
return new Audio();
|
|
295
|
-
},
|
|
296
|
-
/**
|
|
297
|
-
* Return an activated HTML5 Audio object to the pool.
|
|
298
|
-
* @return {Howler}
|
|
299
|
-
*/
|
|
300
|
-
_releaseHtml5Audio: function(audio) {
|
|
301
|
-
var self = this || Howler2;
|
|
302
|
-
if (audio._unlocked) {
|
|
303
|
-
self._html5AudioPool.push(audio);
|
|
304
|
-
}
|
|
305
|
-
return self;
|
|
306
|
-
},
|
|
307
|
-
/**
|
|
308
|
-
* Automatically suspend the Web Audio AudioContext after no sound has played for 30 seconds.
|
|
309
|
-
* This saves processing/energy and fixes various browser-specific bugs with audio getting stuck.
|
|
310
|
-
* @return {Howler}
|
|
311
|
-
*/
|
|
312
|
-
_autoSuspend: function() {
|
|
313
|
-
var self = this;
|
|
314
|
-
if (!self.autoSuspend || !self.ctx || typeof self.ctx.suspend === "undefined" || !Howler2.usingWebAudio) {
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
for (var i = 0; i < self._howls.length; i++) {
|
|
318
|
-
if (self._howls[i]._webAudio) {
|
|
319
|
-
for (var j = 0; j < self._howls[i]._sounds.length; j++) {
|
|
320
|
-
if (!self._howls[i]._sounds[j]._paused) {
|
|
321
|
-
return self;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
if (self._suspendTimer) {
|
|
327
|
-
clearTimeout(self._suspendTimer);
|
|
328
|
-
}
|
|
329
|
-
self._suspendTimer = setTimeout(function() {
|
|
330
|
-
if (!self.autoSuspend) {
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
self._suspendTimer = null;
|
|
334
|
-
self.state = "suspending";
|
|
335
|
-
var handleSuspension = function() {
|
|
336
|
-
self.state = "suspended";
|
|
337
|
-
if (self._resumeAfterSuspend) {
|
|
338
|
-
delete self._resumeAfterSuspend;
|
|
339
|
-
self._autoResume();
|
|
340
|
-
}
|
|
341
|
-
};
|
|
342
|
-
self.ctx.suspend().then(handleSuspension, handleSuspension);
|
|
343
|
-
}, 3e4);
|
|
344
|
-
return self;
|
|
345
|
-
},
|
|
346
|
-
/**
|
|
347
|
-
* Automatically resume the Web Audio AudioContext when a new sound is played.
|
|
348
|
-
* @return {Howler}
|
|
349
|
-
*/
|
|
350
|
-
_autoResume: function() {
|
|
351
|
-
var self = this;
|
|
352
|
-
if (!self.ctx || typeof self.ctx.resume === "undefined" || !Howler2.usingWebAudio) {
|
|
353
|
-
return;
|
|
354
|
-
}
|
|
355
|
-
if (self.state === "running" && self.ctx.state !== "interrupted" && self._suspendTimer) {
|
|
356
|
-
clearTimeout(self._suspendTimer);
|
|
357
|
-
self._suspendTimer = null;
|
|
358
|
-
} else if (self.state === "suspended" || self.state === "running" && self.ctx.state === "interrupted") {
|
|
359
|
-
self.ctx.resume().then(function() {
|
|
360
|
-
self.state = "running";
|
|
361
|
-
for (var i = 0; i < self._howls.length; i++) {
|
|
362
|
-
self._howls[i]._emit("resume");
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
if (self._suspendTimer) {
|
|
366
|
-
clearTimeout(self._suspendTimer);
|
|
367
|
-
self._suspendTimer = null;
|
|
368
|
-
}
|
|
369
|
-
} else if (self.state === "suspending") {
|
|
370
|
-
self._resumeAfterSuspend = true;
|
|
371
|
-
}
|
|
372
|
-
return self;
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
var Howler2 = new HowlerGlobal2();
|
|
376
|
-
var Howl2 = function(o) {
|
|
377
|
-
var self = this;
|
|
378
|
-
if (!o.src || o.src.length === 0) {
|
|
379
|
-
console.error("An array of source files must be passed with any new Howl.");
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
self.init(o);
|
|
383
|
-
};
|
|
384
|
-
Howl2.prototype = {
|
|
385
|
-
/**
|
|
386
|
-
* Initialize a new Howl group object.
|
|
387
|
-
* @param {Object} o Passed in properties for this group.
|
|
388
|
-
* @return {Howl}
|
|
389
|
-
*/
|
|
390
|
-
init: function(o) {
|
|
391
|
-
var self = this;
|
|
392
|
-
if (!Howler2.ctx) {
|
|
393
|
-
setupAudioContext();
|
|
394
|
-
}
|
|
395
|
-
self._autoplay = o.autoplay || false;
|
|
396
|
-
self._format = typeof o.format !== "string" ? o.format : [o.format];
|
|
397
|
-
self._html5 = o.html5 || false;
|
|
398
|
-
self._muted = o.mute || false;
|
|
399
|
-
self._loop = o.loop || false;
|
|
400
|
-
self._pool = o.pool || 5;
|
|
401
|
-
self._preload = typeof o.preload === "boolean" || o.preload === "metadata" ? o.preload : true;
|
|
402
|
-
self._rate = o.rate || 1;
|
|
403
|
-
self._sprite = o.sprite || {};
|
|
404
|
-
self._src = typeof o.src !== "string" ? o.src : [o.src];
|
|
405
|
-
self._volume = o.volume !== void 0 ? o.volume : 1;
|
|
406
|
-
self._xhr = {
|
|
407
|
-
method: o.xhr && o.xhr.method ? o.xhr.method : "GET",
|
|
408
|
-
headers: o.xhr && o.xhr.headers ? o.xhr.headers : null,
|
|
409
|
-
withCredentials: o.xhr && o.xhr.withCredentials ? o.xhr.withCredentials : false
|
|
410
|
-
};
|
|
411
|
-
self._duration = 0;
|
|
412
|
-
self._state = "unloaded";
|
|
413
|
-
self._sounds = [];
|
|
414
|
-
self._endTimers = {};
|
|
415
|
-
self._queue = [];
|
|
416
|
-
self._playLock = false;
|
|
417
|
-
self._onend = o.onend ? [{ fn: o.onend }] : [];
|
|
418
|
-
self._onfade = o.onfade ? [{ fn: o.onfade }] : [];
|
|
419
|
-
self._onload = o.onload ? [{ fn: o.onload }] : [];
|
|
420
|
-
self._onloaderror = o.onloaderror ? [{ fn: o.onloaderror }] : [];
|
|
421
|
-
self._onplayerror = o.onplayerror ? [{ fn: o.onplayerror }] : [];
|
|
422
|
-
self._onpause = o.onpause ? [{ fn: o.onpause }] : [];
|
|
423
|
-
self._onplay = o.onplay ? [{ fn: o.onplay }] : [];
|
|
424
|
-
self._onstop = o.onstop ? [{ fn: o.onstop }] : [];
|
|
425
|
-
self._onmute = o.onmute ? [{ fn: o.onmute }] : [];
|
|
426
|
-
self._onvolume = o.onvolume ? [{ fn: o.onvolume }] : [];
|
|
427
|
-
self._onrate = o.onrate ? [{ fn: o.onrate }] : [];
|
|
428
|
-
self._onseek = o.onseek ? [{ fn: o.onseek }] : [];
|
|
429
|
-
self._onunlock = o.onunlock ? [{ fn: o.onunlock }] : [];
|
|
430
|
-
self._onresume = [];
|
|
431
|
-
self._webAudio = Howler2.usingWebAudio && !self._html5;
|
|
432
|
-
if (typeof Howler2.ctx !== "undefined" && Howler2.ctx && Howler2.autoUnlock) {
|
|
433
|
-
Howler2._unlockAudio();
|
|
434
|
-
}
|
|
435
|
-
Howler2._howls.push(self);
|
|
436
|
-
if (self._autoplay) {
|
|
437
|
-
self._queue.push({
|
|
438
|
-
event: "play",
|
|
439
|
-
action: function() {
|
|
440
|
-
self.play();
|
|
441
|
-
}
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
if (self._preload && self._preload !== "none") {
|
|
445
|
-
self.load();
|
|
446
|
-
}
|
|
447
|
-
return self;
|
|
448
|
-
},
|
|
449
|
-
/**
|
|
450
|
-
* Load the audio file.
|
|
451
|
-
* @return {Howler}
|
|
452
|
-
*/
|
|
453
|
-
load: function() {
|
|
454
|
-
var self = this;
|
|
455
|
-
var url = null;
|
|
456
|
-
if (Howler2.noAudio) {
|
|
457
|
-
self._emit("loaderror", null, "No audio support.");
|
|
458
|
-
return;
|
|
459
|
-
}
|
|
460
|
-
if (typeof self._src === "string") {
|
|
461
|
-
self._src = [self._src];
|
|
462
|
-
}
|
|
463
|
-
for (var i = 0; i < self._src.length; i++) {
|
|
464
|
-
var ext, str;
|
|
465
|
-
if (self._format && self._format[i]) {
|
|
466
|
-
ext = self._format[i];
|
|
467
|
-
} else {
|
|
468
|
-
str = self._src[i];
|
|
469
|
-
if (typeof str !== "string") {
|
|
470
|
-
self._emit("loaderror", null, "Non-string found in selected audio sources - ignoring.");
|
|
471
|
-
continue;
|
|
472
|
-
}
|
|
473
|
-
ext = /^data:audio\/([^;,]+);/i.exec(str);
|
|
474
|
-
if (!ext) {
|
|
475
|
-
ext = /\.([^.]+)$/.exec(str.split("?", 1)[0]);
|
|
476
|
-
}
|
|
477
|
-
if (ext) {
|
|
478
|
-
ext = ext[1].toLowerCase();
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
if (!ext) {
|
|
482
|
-
console.warn('No file extension was found. Consider using the "format" property or specify an extension.');
|
|
483
|
-
}
|
|
484
|
-
if (ext && Howler2.codecs(ext)) {
|
|
485
|
-
url = self._src[i];
|
|
486
|
-
break;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
if (!url) {
|
|
490
|
-
self._emit("loaderror", null, "No codec support for selected audio sources.");
|
|
491
|
-
return;
|
|
492
|
-
}
|
|
493
|
-
self._src = url;
|
|
494
|
-
self._state = "loading";
|
|
495
|
-
if (window.location.protocol === "https:" && url.slice(0, 5) === "http:") {
|
|
496
|
-
self._html5 = true;
|
|
497
|
-
self._webAudio = false;
|
|
498
|
-
}
|
|
499
|
-
new Sound2(self);
|
|
500
|
-
if (self._webAudio) {
|
|
501
|
-
loadBuffer(self);
|
|
502
|
-
}
|
|
503
|
-
return self;
|
|
504
|
-
},
|
|
505
|
-
/**
|
|
506
|
-
* Play a sound or resume previous playback.
|
|
507
|
-
* @param {String/Number} sprite Sprite name for sprite playback or sound id to continue previous.
|
|
508
|
-
* @param {Boolean} internal Internal Use: true prevents event firing.
|
|
509
|
-
* @return {Number} Sound ID.
|
|
510
|
-
*/
|
|
511
|
-
play: function(sprite, internal) {
|
|
512
|
-
var self = this;
|
|
513
|
-
var id = null;
|
|
514
|
-
if (typeof sprite === "number") {
|
|
515
|
-
id = sprite;
|
|
516
|
-
sprite = null;
|
|
517
|
-
} else if (typeof sprite === "string" && self._state === "loaded" && !self._sprite[sprite]) {
|
|
518
|
-
return null;
|
|
519
|
-
} else if (typeof sprite === "undefined") {
|
|
520
|
-
sprite = "__default";
|
|
521
|
-
if (!self._playLock) {
|
|
522
|
-
var num = 0;
|
|
523
|
-
for (var i = 0; i < self._sounds.length; i++) {
|
|
524
|
-
if (self._sounds[i]._paused && !self._sounds[i]._ended) {
|
|
525
|
-
num++;
|
|
526
|
-
id = self._sounds[i]._id;
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
if (num === 1) {
|
|
530
|
-
sprite = null;
|
|
531
|
-
} else {
|
|
532
|
-
id = null;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
var sound = id ? self._soundById(id) : self._inactiveSound();
|
|
537
|
-
if (!sound) {
|
|
538
|
-
return null;
|
|
539
|
-
}
|
|
540
|
-
if (id && !sprite) {
|
|
541
|
-
sprite = sound._sprite || "__default";
|
|
542
|
-
}
|
|
543
|
-
if (self._state !== "loaded") {
|
|
544
|
-
sound._sprite = sprite;
|
|
545
|
-
sound._ended = false;
|
|
546
|
-
var soundId = sound._id;
|
|
547
|
-
self._queue.push({
|
|
548
|
-
event: "play",
|
|
549
|
-
action: function() {
|
|
550
|
-
self.play(soundId);
|
|
551
|
-
}
|
|
552
|
-
});
|
|
553
|
-
return soundId;
|
|
554
|
-
}
|
|
555
|
-
if (id && !sound._paused) {
|
|
556
|
-
if (!internal) {
|
|
557
|
-
self._loadQueue("play");
|
|
558
|
-
}
|
|
559
|
-
return sound._id;
|
|
560
|
-
}
|
|
561
|
-
if (self._webAudio) {
|
|
562
|
-
Howler2._autoResume();
|
|
563
|
-
}
|
|
564
|
-
var seek = Math.max(0, sound._seek > 0 ? sound._seek : self._sprite[sprite][0] / 1e3);
|
|
565
|
-
var duration = Math.max(0, (self._sprite[sprite][0] + self._sprite[sprite][1]) / 1e3 - seek);
|
|
566
|
-
var timeout = duration * 1e3 / Math.abs(sound._rate);
|
|
567
|
-
var start = self._sprite[sprite][0] / 1e3;
|
|
568
|
-
var stop = (self._sprite[sprite][0] + self._sprite[sprite][1]) / 1e3;
|
|
569
|
-
sound._sprite = sprite;
|
|
570
|
-
sound._ended = false;
|
|
571
|
-
var setParams = function() {
|
|
572
|
-
sound._paused = false;
|
|
573
|
-
sound._seek = seek;
|
|
574
|
-
sound._start = start;
|
|
575
|
-
sound._stop = stop;
|
|
576
|
-
sound._loop = !!(sound._loop || self._sprite[sprite][2]);
|
|
577
|
-
};
|
|
578
|
-
if (seek >= stop) {
|
|
579
|
-
self._ended(sound);
|
|
580
|
-
return;
|
|
581
|
-
}
|
|
582
|
-
var node = sound._node;
|
|
583
|
-
if (self._webAudio) {
|
|
584
|
-
var playWebAudio = function() {
|
|
585
|
-
self._playLock = false;
|
|
586
|
-
setParams();
|
|
587
|
-
self._refreshBuffer(sound);
|
|
588
|
-
var vol = sound._muted || self._muted ? 0 : sound._volume;
|
|
589
|
-
node.gain.setValueAtTime(vol, Howler2.ctx.currentTime);
|
|
590
|
-
sound._playStart = Howler2.ctx.currentTime;
|
|
591
|
-
if (typeof node.bufferSource.start === "undefined") {
|
|
592
|
-
sound._loop ? node.bufferSource.noteGrainOn(0, seek, 86400) : node.bufferSource.noteGrainOn(0, seek, duration);
|
|
593
|
-
} else {
|
|
594
|
-
sound._loop ? node.bufferSource.start(0, seek, 86400) : node.bufferSource.start(0, seek, duration);
|
|
595
|
-
}
|
|
596
|
-
if (timeout !== Infinity) {
|
|
597
|
-
self._endTimers[sound._id] = setTimeout(self._ended.bind(self, sound), timeout);
|
|
598
|
-
}
|
|
599
|
-
if (!internal) {
|
|
600
|
-
setTimeout(function() {
|
|
601
|
-
self._emit("play", sound._id);
|
|
602
|
-
self._loadQueue();
|
|
603
|
-
}, 0);
|
|
604
|
-
}
|
|
605
|
-
};
|
|
606
|
-
if (Howler2.state === "running" && Howler2.ctx.state !== "interrupted") {
|
|
607
|
-
playWebAudio();
|
|
608
|
-
} else {
|
|
609
|
-
self._playLock = true;
|
|
610
|
-
self.once("resume", playWebAudio);
|
|
611
|
-
self._clearTimer(sound._id);
|
|
612
|
-
}
|
|
613
|
-
} else {
|
|
614
|
-
var playHtml5 = function() {
|
|
615
|
-
node.currentTime = seek;
|
|
616
|
-
node.muted = sound._muted || self._muted || Howler2._muted || node.muted;
|
|
617
|
-
node.volume = sound._volume * Howler2.volume();
|
|
618
|
-
node.playbackRate = sound._rate;
|
|
619
|
-
try {
|
|
620
|
-
var play = node.play();
|
|
621
|
-
if (play && typeof Promise !== "undefined" && (play instanceof Promise || typeof play.then === "function")) {
|
|
622
|
-
self._playLock = true;
|
|
623
|
-
setParams();
|
|
624
|
-
play.then(function() {
|
|
625
|
-
self._playLock = false;
|
|
626
|
-
node._unlocked = true;
|
|
627
|
-
if (!internal) {
|
|
628
|
-
self._emit("play", sound._id);
|
|
629
|
-
} else {
|
|
630
|
-
self._loadQueue();
|
|
631
|
-
}
|
|
632
|
-
}).catch(function() {
|
|
633
|
-
self._playLock = false;
|
|
634
|
-
self._emit("playerror", sound._id, "Playback was unable to start. This is most commonly an issue on mobile devices and Chrome where playback was not within a user interaction.");
|
|
635
|
-
sound._ended = true;
|
|
636
|
-
sound._paused = true;
|
|
637
|
-
});
|
|
638
|
-
} else if (!internal) {
|
|
639
|
-
self._playLock = false;
|
|
640
|
-
setParams();
|
|
641
|
-
self._emit("play", sound._id);
|
|
642
|
-
}
|
|
643
|
-
node.playbackRate = sound._rate;
|
|
644
|
-
if (node.paused) {
|
|
645
|
-
self._emit("playerror", sound._id, "Playback was unable to start. This is most commonly an issue on mobile devices and Chrome where playback was not within a user interaction.");
|
|
646
|
-
return;
|
|
647
|
-
}
|
|
648
|
-
if (sprite !== "__default" || sound._loop) {
|
|
649
|
-
self._endTimers[sound._id] = setTimeout(self._ended.bind(self, sound), timeout);
|
|
650
|
-
} else {
|
|
651
|
-
self._endTimers[sound._id] = function() {
|
|
652
|
-
self._ended(sound);
|
|
653
|
-
node.removeEventListener("ended", self._endTimers[sound._id], false);
|
|
654
|
-
};
|
|
655
|
-
node.addEventListener("ended", self._endTimers[sound._id], false);
|
|
656
|
-
}
|
|
657
|
-
} catch (err) {
|
|
658
|
-
self._emit("playerror", sound._id, err);
|
|
659
|
-
}
|
|
660
|
-
};
|
|
661
|
-
if (node.src === "data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA") {
|
|
662
|
-
node.src = self._src;
|
|
663
|
-
node.load();
|
|
664
|
-
}
|
|
665
|
-
var loadedNoReadyState = window && window.ejecta || !node.readyState && Howler2._navigator.isCocoonJS;
|
|
666
|
-
if (node.readyState >= 3 || loadedNoReadyState) {
|
|
667
|
-
playHtml5();
|
|
668
|
-
} else {
|
|
669
|
-
self._playLock = true;
|
|
670
|
-
self._state = "loading";
|
|
671
|
-
var listener = function() {
|
|
672
|
-
self._state = "loaded";
|
|
673
|
-
playHtml5();
|
|
674
|
-
node.removeEventListener(Howler2._canPlayEvent, listener, false);
|
|
675
|
-
};
|
|
676
|
-
node.addEventListener(Howler2._canPlayEvent, listener, false);
|
|
677
|
-
self._clearTimer(sound._id);
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
return sound._id;
|
|
681
|
-
},
|
|
682
|
-
/**
|
|
683
|
-
* Pause playback and save current position.
|
|
684
|
-
* @param {Number} id The sound ID (empty to pause all in group).
|
|
685
|
-
* @return {Howl}
|
|
686
|
-
*/
|
|
687
|
-
pause: function(id) {
|
|
688
|
-
var self = this;
|
|
689
|
-
if (self._state !== "loaded" || self._playLock) {
|
|
690
|
-
self._queue.push({
|
|
691
|
-
event: "pause",
|
|
692
|
-
action: function() {
|
|
693
|
-
self.pause(id);
|
|
694
|
-
}
|
|
695
|
-
});
|
|
696
|
-
return self;
|
|
697
|
-
}
|
|
698
|
-
var ids = self._getSoundIds(id);
|
|
699
|
-
for (var i = 0; i < ids.length; i++) {
|
|
700
|
-
self._clearTimer(ids[i]);
|
|
701
|
-
var sound = self._soundById(ids[i]);
|
|
702
|
-
if (sound && !sound._paused) {
|
|
703
|
-
sound._seek = self.seek(ids[i]);
|
|
704
|
-
sound._rateSeek = 0;
|
|
705
|
-
sound._paused = true;
|
|
706
|
-
self._stopFade(ids[i]);
|
|
707
|
-
if (sound._node) {
|
|
708
|
-
if (self._webAudio) {
|
|
709
|
-
if (!sound._node.bufferSource) {
|
|
710
|
-
continue;
|
|
711
|
-
}
|
|
712
|
-
if (typeof sound._node.bufferSource.stop === "undefined") {
|
|
713
|
-
sound._node.bufferSource.noteOff(0);
|
|
714
|
-
} else {
|
|
715
|
-
sound._node.bufferSource.stop(0);
|
|
716
|
-
}
|
|
717
|
-
self._cleanBuffer(sound._node);
|
|
718
|
-
} else if (!isNaN(sound._node.duration) || sound._node.duration === Infinity) {
|
|
719
|
-
sound._node.pause();
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
if (!arguments[1]) {
|
|
724
|
-
self._emit("pause", sound ? sound._id : null);
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
return self;
|
|
728
|
-
},
|
|
729
|
-
/**
|
|
730
|
-
* Stop playback and reset to start.
|
|
731
|
-
* @param {Number} id The sound ID (empty to stop all in group).
|
|
732
|
-
* @param {Boolean} internal Internal Use: true prevents event firing.
|
|
733
|
-
* @return {Howl}
|
|
734
|
-
*/
|
|
735
|
-
stop: function(id, internal) {
|
|
736
|
-
var self = this;
|
|
737
|
-
if (self._state !== "loaded" || self._playLock) {
|
|
738
|
-
self._queue.push({
|
|
739
|
-
event: "stop",
|
|
740
|
-
action: function() {
|
|
741
|
-
self.stop(id);
|
|
742
|
-
}
|
|
743
|
-
});
|
|
744
|
-
return self;
|
|
745
|
-
}
|
|
746
|
-
var ids = self._getSoundIds(id);
|
|
747
|
-
for (var i = 0; i < ids.length; i++) {
|
|
748
|
-
self._clearTimer(ids[i]);
|
|
749
|
-
var sound = self._soundById(ids[i]);
|
|
750
|
-
if (sound) {
|
|
751
|
-
sound._seek = sound._start || 0;
|
|
752
|
-
sound._rateSeek = 0;
|
|
753
|
-
sound._paused = true;
|
|
754
|
-
sound._ended = true;
|
|
755
|
-
self._stopFade(ids[i]);
|
|
756
|
-
if (sound._node) {
|
|
757
|
-
if (self._webAudio) {
|
|
758
|
-
if (sound._node.bufferSource) {
|
|
759
|
-
if (typeof sound._node.bufferSource.stop === "undefined") {
|
|
760
|
-
sound._node.bufferSource.noteOff(0);
|
|
761
|
-
} else {
|
|
762
|
-
sound._node.bufferSource.stop(0);
|
|
763
|
-
}
|
|
764
|
-
self._cleanBuffer(sound._node);
|
|
765
|
-
}
|
|
766
|
-
} else if (!isNaN(sound._node.duration) || sound._node.duration === Infinity) {
|
|
767
|
-
sound._node.currentTime = sound._start || 0;
|
|
768
|
-
sound._node.pause();
|
|
769
|
-
if (sound._node.duration === Infinity) {
|
|
770
|
-
self._clearSound(sound._node);
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
if (!internal) {
|
|
775
|
-
self._emit("stop", sound._id);
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
return self;
|
|
780
|
-
},
|
|
781
|
-
/**
|
|
782
|
-
* Mute/unmute a single sound or all sounds in this Howl group.
|
|
783
|
-
* @param {Boolean} muted Set to true to mute and false to unmute.
|
|
784
|
-
* @param {Number} id The sound ID to update (omit to mute/unmute all).
|
|
785
|
-
* @return {Howl}
|
|
786
|
-
*/
|
|
787
|
-
mute: function(muted, id) {
|
|
788
|
-
var self = this;
|
|
789
|
-
if (self._state !== "loaded" || self._playLock) {
|
|
790
|
-
self._queue.push({
|
|
791
|
-
event: "mute",
|
|
792
|
-
action: function() {
|
|
793
|
-
self.mute(muted, id);
|
|
794
|
-
}
|
|
795
|
-
});
|
|
796
|
-
return self;
|
|
797
|
-
}
|
|
798
|
-
if (typeof id === "undefined") {
|
|
799
|
-
if (typeof muted === "boolean") {
|
|
800
|
-
self._muted = muted;
|
|
801
|
-
} else {
|
|
802
|
-
return self._muted;
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
var ids = self._getSoundIds(id);
|
|
806
|
-
for (var i = 0; i < ids.length; i++) {
|
|
807
|
-
var sound = self._soundById(ids[i]);
|
|
808
|
-
if (sound) {
|
|
809
|
-
sound._muted = muted;
|
|
810
|
-
if (sound._interval) {
|
|
811
|
-
self._stopFade(sound._id);
|
|
812
|
-
}
|
|
813
|
-
if (self._webAudio && sound._node) {
|
|
814
|
-
sound._node.gain.setValueAtTime(muted ? 0 : sound._volume, Howler2.ctx.currentTime);
|
|
815
|
-
} else if (sound._node) {
|
|
816
|
-
sound._node.muted = Howler2._muted ? true : muted;
|
|
817
|
-
}
|
|
818
|
-
self._emit("mute", sound._id);
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
return self;
|
|
822
|
-
},
|
|
823
|
-
/**
|
|
824
|
-
* Get/set the volume of this sound or of the Howl group. This method can optionally take 0, 1 or 2 arguments.
|
|
825
|
-
* volume() -> Returns the group's volume value.
|
|
826
|
-
* volume(id) -> Returns the sound id's current volume.
|
|
827
|
-
* volume(vol) -> Sets the volume of all sounds in this Howl group.
|
|
828
|
-
* volume(vol, id) -> Sets the volume of passed sound id.
|
|
829
|
-
* @return {Howl/Number} Returns self or current volume.
|
|
830
|
-
*/
|
|
831
|
-
volume: function() {
|
|
832
|
-
var self = this;
|
|
833
|
-
var args = arguments;
|
|
834
|
-
var vol, id;
|
|
835
|
-
if (args.length === 0) {
|
|
836
|
-
return self._volume;
|
|
837
|
-
} else if (args.length === 1 || args.length === 2 && typeof args[1] === "undefined") {
|
|
838
|
-
var ids = self._getSoundIds();
|
|
839
|
-
var index = ids.indexOf(args[0]);
|
|
840
|
-
if (index >= 0) {
|
|
841
|
-
id = parseInt(args[0], 10);
|
|
842
|
-
} else {
|
|
843
|
-
vol = parseFloat(args[0]);
|
|
844
|
-
}
|
|
845
|
-
} else if (args.length >= 2) {
|
|
846
|
-
vol = parseFloat(args[0]);
|
|
847
|
-
id = parseInt(args[1], 10);
|
|
848
|
-
}
|
|
849
|
-
var sound;
|
|
850
|
-
if (typeof vol !== "undefined" && vol >= 0 && vol <= 1) {
|
|
851
|
-
if (self._state !== "loaded" || self._playLock) {
|
|
852
|
-
self._queue.push({
|
|
853
|
-
event: "volume",
|
|
854
|
-
action: function() {
|
|
855
|
-
self.volume.apply(self, args);
|
|
856
|
-
}
|
|
857
|
-
});
|
|
858
|
-
return self;
|
|
859
|
-
}
|
|
860
|
-
if (typeof id === "undefined") {
|
|
861
|
-
self._volume = vol;
|
|
862
|
-
}
|
|
863
|
-
id = self._getSoundIds(id);
|
|
864
|
-
for (var i = 0; i < id.length; i++) {
|
|
865
|
-
sound = self._soundById(id[i]);
|
|
866
|
-
if (sound) {
|
|
867
|
-
sound._volume = vol;
|
|
868
|
-
if (!args[2]) {
|
|
869
|
-
self._stopFade(id[i]);
|
|
870
|
-
}
|
|
871
|
-
if (self._webAudio && sound._node && !sound._muted) {
|
|
872
|
-
sound._node.gain.setValueAtTime(vol, Howler2.ctx.currentTime);
|
|
873
|
-
} else if (sound._node && !sound._muted) {
|
|
874
|
-
sound._node.volume = vol * Howler2.volume();
|
|
875
|
-
}
|
|
876
|
-
self._emit("volume", sound._id);
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
} else {
|
|
880
|
-
sound = id ? self._soundById(id) : self._sounds[0];
|
|
881
|
-
return sound ? sound._volume : 0;
|
|
882
|
-
}
|
|
883
|
-
return self;
|
|
884
|
-
},
|
|
885
|
-
/**
|
|
886
|
-
* Fade a currently playing sound between two volumes (if no id is passed, all sounds will fade).
|
|
887
|
-
* @param {Number} from The value to fade from (0.0 to 1.0).
|
|
888
|
-
* @param {Number} to The volume to fade to (0.0 to 1.0).
|
|
889
|
-
* @param {Number} len Time in milliseconds to fade.
|
|
890
|
-
* @param {Number} id The sound id (omit to fade all sounds).
|
|
891
|
-
* @return {Howl}
|
|
892
|
-
*/
|
|
893
|
-
fade: function(from, to, len, id) {
|
|
894
|
-
var self = this;
|
|
895
|
-
if (self._state !== "loaded" || self._playLock) {
|
|
896
|
-
self._queue.push({
|
|
897
|
-
event: "fade",
|
|
898
|
-
action: function() {
|
|
899
|
-
self.fade(from, to, len, id);
|
|
900
|
-
}
|
|
901
|
-
});
|
|
902
|
-
return self;
|
|
903
|
-
}
|
|
904
|
-
from = Math.min(Math.max(0, parseFloat(from)), 1);
|
|
905
|
-
to = Math.min(Math.max(0, parseFloat(to)), 1);
|
|
906
|
-
len = parseFloat(len);
|
|
907
|
-
self.volume(from, id);
|
|
908
|
-
var ids = self._getSoundIds(id);
|
|
909
|
-
for (var i = 0; i < ids.length; i++) {
|
|
910
|
-
var sound = self._soundById(ids[i]);
|
|
911
|
-
if (sound) {
|
|
912
|
-
if (!id) {
|
|
913
|
-
self._stopFade(ids[i]);
|
|
914
|
-
}
|
|
915
|
-
if (self._webAudio && !sound._muted) {
|
|
916
|
-
var currentTime = Howler2.ctx.currentTime;
|
|
917
|
-
var end = currentTime + len / 1e3;
|
|
918
|
-
sound._volume = from;
|
|
919
|
-
sound._node.gain.setValueAtTime(from, currentTime);
|
|
920
|
-
sound._node.gain.linearRampToValueAtTime(to, end);
|
|
921
|
-
}
|
|
922
|
-
self._startFadeInterval(sound, from, to, len, ids[i], typeof id === "undefined");
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
return self;
|
|
926
|
-
},
|
|
927
|
-
/**
|
|
928
|
-
* Starts the internal interval to fade a sound.
|
|
929
|
-
* @param {Object} sound Reference to sound to fade.
|
|
930
|
-
* @param {Number} from The value to fade from (0.0 to 1.0).
|
|
931
|
-
* @param {Number} to The volume to fade to (0.0 to 1.0).
|
|
932
|
-
* @param {Number} len Time in milliseconds to fade.
|
|
933
|
-
* @param {Number} id The sound id to fade.
|
|
934
|
-
* @param {Boolean} isGroup If true, set the volume on the group.
|
|
935
|
-
*/
|
|
936
|
-
_startFadeInterval: function(sound, from, to, len, id, isGroup) {
|
|
937
|
-
var self = this;
|
|
938
|
-
var vol = from;
|
|
939
|
-
var diff = to - from;
|
|
940
|
-
var steps = Math.abs(diff / 0.01);
|
|
941
|
-
var stepLen = Math.max(4, steps > 0 ? len / steps : len);
|
|
942
|
-
var lastTick = Date.now();
|
|
943
|
-
sound._fadeTo = to;
|
|
944
|
-
sound._interval = setInterval(function() {
|
|
945
|
-
var tick = (Date.now() - lastTick) / len;
|
|
946
|
-
lastTick = Date.now();
|
|
947
|
-
vol += diff * tick;
|
|
948
|
-
vol = Math.round(vol * 100) / 100;
|
|
949
|
-
if (diff < 0) {
|
|
950
|
-
vol = Math.max(to, vol);
|
|
951
|
-
} else {
|
|
952
|
-
vol = Math.min(to, vol);
|
|
953
|
-
}
|
|
954
|
-
if (self._webAudio) {
|
|
955
|
-
sound._volume = vol;
|
|
956
|
-
} else {
|
|
957
|
-
self.volume(vol, sound._id, true);
|
|
958
|
-
}
|
|
959
|
-
if (isGroup) {
|
|
960
|
-
self._volume = vol;
|
|
961
|
-
}
|
|
962
|
-
if (to < from && vol <= to || to > from && vol >= to) {
|
|
963
|
-
clearInterval(sound._interval);
|
|
964
|
-
sound._interval = null;
|
|
965
|
-
sound._fadeTo = null;
|
|
966
|
-
self.volume(to, sound._id);
|
|
967
|
-
self._emit("fade", sound._id);
|
|
968
|
-
}
|
|
969
|
-
}, stepLen);
|
|
970
|
-
},
|
|
971
|
-
/**
|
|
972
|
-
* Internal method that stops the currently playing fade when
|
|
973
|
-
* a new fade starts, volume is changed or the sound is stopped.
|
|
974
|
-
* @param {Number} id The sound id.
|
|
975
|
-
* @return {Howl}
|
|
976
|
-
*/
|
|
977
|
-
_stopFade: function(id) {
|
|
978
|
-
var self = this;
|
|
979
|
-
var sound = self._soundById(id);
|
|
980
|
-
if (sound && sound._interval) {
|
|
981
|
-
if (self._webAudio) {
|
|
982
|
-
sound._node.gain.cancelScheduledValues(Howler2.ctx.currentTime);
|
|
983
|
-
}
|
|
984
|
-
clearInterval(sound._interval);
|
|
985
|
-
sound._interval = null;
|
|
986
|
-
self.volume(sound._fadeTo, id);
|
|
987
|
-
sound._fadeTo = null;
|
|
988
|
-
self._emit("fade", id);
|
|
989
|
-
}
|
|
990
|
-
return self;
|
|
991
|
-
},
|
|
992
|
-
/**
|
|
993
|
-
* Get/set the loop parameter on a sound. This method can optionally take 0, 1 or 2 arguments.
|
|
994
|
-
* loop() -> Returns the group's loop value.
|
|
995
|
-
* loop(id) -> Returns the sound id's loop value.
|
|
996
|
-
* loop(loop) -> Sets the loop value for all sounds in this Howl group.
|
|
997
|
-
* loop(loop, id) -> Sets the loop value of passed sound id.
|
|
998
|
-
* @return {Howl/Boolean} Returns self or current loop value.
|
|
999
|
-
*/
|
|
1000
|
-
loop: function() {
|
|
1001
|
-
var self = this;
|
|
1002
|
-
var args = arguments;
|
|
1003
|
-
var loop, id, sound;
|
|
1004
|
-
if (args.length === 0) {
|
|
1005
|
-
return self._loop;
|
|
1006
|
-
} else if (args.length === 1) {
|
|
1007
|
-
if (typeof args[0] === "boolean") {
|
|
1008
|
-
loop = args[0];
|
|
1009
|
-
self._loop = loop;
|
|
1010
|
-
} else {
|
|
1011
|
-
sound = self._soundById(parseInt(args[0], 10));
|
|
1012
|
-
return sound ? sound._loop : false;
|
|
1013
|
-
}
|
|
1014
|
-
} else if (args.length === 2) {
|
|
1015
|
-
loop = args[0];
|
|
1016
|
-
id = parseInt(args[1], 10);
|
|
1017
|
-
}
|
|
1018
|
-
var ids = self._getSoundIds(id);
|
|
1019
|
-
for (var i = 0; i < ids.length; i++) {
|
|
1020
|
-
sound = self._soundById(ids[i]);
|
|
1021
|
-
if (sound) {
|
|
1022
|
-
sound._loop = loop;
|
|
1023
|
-
if (self._webAudio && sound._node && sound._node.bufferSource) {
|
|
1024
|
-
sound._node.bufferSource.loop = loop;
|
|
1025
|
-
if (loop) {
|
|
1026
|
-
sound._node.bufferSource.loopStart = sound._start || 0;
|
|
1027
|
-
sound._node.bufferSource.loopEnd = sound._stop;
|
|
1028
|
-
if (self.playing(ids[i])) {
|
|
1029
|
-
self.pause(ids[i], true);
|
|
1030
|
-
self.play(ids[i], true);
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
return self;
|
|
1037
|
-
},
|
|
1038
|
-
/**
|
|
1039
|
-
* Get/set the playback rate of a sound. This method can optionally take 0, 1 or 2 arguments.
|
|
1040
|
-
* rate() -> Returns the first sound node's current playback rate.
|
|
1041
|
-
* rate(id) -> Returns the sound id's current playback rate.
|
|
1042
|
-
* rate(rate) -> Sets the playback rate of all sounds in this Howl group.
|
|
1043
|
-
* rate(rate, id) -> Sets the playback rate of passed sound id.
|
|
1044
|
-
* @return {Howl/Number} Returns self or the current playback rate.
|
|
1045
|
-
*/
|
|
1046
|
-
rate: function() {
|
|
1047
|
-
var self = this;
|
|
1048
|
-
var args = arguments;
|
|
1049
|
-
var rate, id;
|
|
1050
|
-
if (args.length === 0) {
|
|
1051
|
-
id = self._sounds[0]._id;
|
|
1052
|
-
} else if (args.length === 1) {
|
|
1053
|
-
var ids = self._getSoundIds();
|
|
1054
|
-
var index = ids.indexOf(args[0]);
|
|
1055
|
-
if (index >= 0) {
|
|
1056
|
-
id = parseInt(args[0], 10);
|
|
1057
|
-
} else {
|
|
1058
|
-
rate = parseFloat(args[0]);
|
|
1059
|
-
}
|
|
1060
|
-
} else if (args.length === 2) {
|
|
1061
|
-
rate = parseFloat(args[0]);
|
|
1062
|
-
id = parseInt(args[1], 10);
|
|
1063
|
-
}
|
|
1064
|
-
var sound;
|
|
1065
|
-
if (typeof rate === "number") {
|
|
1066
|
-
if (self._state !== "loaded" || self._playLock) {
|
|
1067
|
-
self._queue.push({
|
|
1068
|
-
event: "rate",
|
|
1069
|
-
action: function() {
|
|
1070
|
-
self.rate.apply(self, args);
|
|
1071
|
-
}
|
|
1072
|
-
});
|
|
1073
|
-
return self;
|
|
1074
|
-
}
|
|
1075
|
-
if (typeof id === "undefined") {
|
|
1076
|
-
self._rate = rate;
|
|
1077
|
-
}
|
|
1078
|
-
id = self._getSoundIds(id);
|
|
1079
|
-
for (var i = 0; i < id.length; i++) {
|
|
1080
|
-
sound = self._soundById(id[i]);
|
|
1081
|
-
if (sound) {
|
|
1082
|
-
if (self.playing(id[i])) {
|
|
1083
|
-
sound._rateSeek = self.seek(id[i]);
|
|
1084
|
-
sound._playStart = self._webAudio ? Howler2.ctx.currentTime : sound._playStart;
|
|
1085
|
-
}
|
|
1086
|
-
sound._rate = rate;
|
|
1087
|
-
if (self._webAudio && sound._node && sound._node.bufferSource) {
|
|
1088
|
-
sound._node.bufferSource.playbackRate.setValueAtTime(rate, Howler2.ctx.currentTime);
|
|
1089
|
-
} else if (sound._node) {
|
|
1090
|
-
sound._node.playbackRate = rate;
|
|
1091
|
-
}
|
|
1092
|
-
var seek = self.seek(id[i]);
|
|
1093
|
-
var duration = (self._sprite[sound._sprite][0] + self._sprite[sound._sprite][1]) / 1e3 - seek;
|
|
1094
|
-
var timeout = duration * 1e3 / Math.abs(sound._rate);
|
|
1095
|
-
if (self._endTimers[id[i]] || !sound._paused) {
|
|
1096
|
-
self._clearTimer(id[i]);
|
|
1097
|
-
self._endTimers[id[i]] = setTimeout(self._ended.bind(self, sound), timeout);
|
|
1098
|
-
}
|
|
1099
|
-
self._emit("rate", sound._id);
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
} else {
|
|
1103
|
-
sound = self._soundById(id);
|
|
1104
|
-
return sound ? sound._rate : self._rate;
|
|
1105
|
-
}
|
|
1106
|
-
return self;
|
|
1107
|
-
},
|
|
1108
|
-
/**
|
|
1109
|
-
* Get/set the seek position of a sound. This method can optionally take 0, 1 or 2 arguments.
|
|
1110
|
-
* seek() -> Returns the first sound node's current seek position.
|
|
1111
|
-
* seek(id) -> Returns the sound id's current seek position.
|
|
1112
|
-
* seek(seek) -> Sets the seek position of the first sound node.
|
|
1113
|
-
* seek(seek, id) -> Sets the seek position of passed sound id.
|
|
1114
|
-
* @return {Howl/Number} Returns self or the current seek position.
|
|
1115
|
-
*/
|
|
1116
|
-
seek: function() {
|
|
1117
|
-
var self = this;
|
|
1118
|
-
var args = arguments;
|
|
1119
|
-
var seek, id;
|
|
1120
|
-
if (args.length === 0) {
|
|
1121
|
-
if (self._sounds.length) {
|
|
1122
|
-
id = self._sounds[0]._id;
|
|
1123
|
-
}
|
|
1124
|
-
} else if (args.length === 1) {
|
|
1125
|
-
var ids = self._getSoundIds();
|
|
1126
|
-
var index = ids.indexOf(args[0]);
|
|
1127
|
-
if (index >= 0) {
|
|
1128
|
-
id = parseInt(args[0], 10);
|
|
1129
|
-
} else if (self._sounds.length) {
|
|
1130
|
-
id = self._sounds[0]._id;
|
|
1131
|
-
seek = parseFloat(args[0]);
|
|
1132
|
-
}
|
|
1133
|
-
} else if (args.length === 2) {
|
|
1134
|
-
seek = parseFloat(args[0]);
|
|
1135
|
-
id = parseInt(args[1], 10);
|
|
1136
|
-
}
|
|
1137
|
-
if (typeof id === "undefined") {
|
|
1138
|
-
return 0;
|
|
1139
|
-
}
|
|
1140
|
-
if (typeof seek === "number" && (self._state !== "loaded" || self._playLock)) {
|
|
1141
|
-
self._queue.push({
|
|
1142
|
-
event: "seek",
|
|
1143
|
-
action: function() {
|
|
1144
|
-
self.seek.apply(self, args);
|
|
1145
|
-
}
|
|
1146
|
-
});
|
|
1147
|
-
return self;
|
|
1148
|
-
}
|
|
1149
|
-
var sound = self._soundById(id);
|
|
1150
|
-
if (sound) {
|
|
1151
|
-
if (typeof seek === "number" && seek >= 0) {
|
|
1152
|
-
var playing = self.playing(id);
|
|
1153
|
-
if (playing) {
|
|
1154
|
-
self.pause(id, true);
|
|
1155
|
-
}
|
|
1156
|
-
sound._seek = seek;
|
|
1157
|
-
sound._ended = false;
|
|
1158
|
-
self._clearTimer(id);
|
|
1159
|
-
if (!self._webAudio && sound._node && !isNaN(sound._node.duration)) {
|
|
1160
|
-
sound._node.currentTime = seek;
|
|
1161
|
-
}
|
|
1162
|
-
var seekAndEmit = function() {
|
|
1163
|
-
if (playing) {
|
|
1164
|
-
self.play(id, true);
|
|
1165
|
-
}
|
|
1166
|
-
self._emit("seek", id);
|
|
1167
|
-
};
|
|
1168
|
-
if (playing && !self._webAudio) {
|
|
1169
|
-
var emitSeek = function() {
|
|
1170
|
-
if (!self._playLock) {
|
|
1171
|
-
seekAndEmit();
|
|
1172
|
-
} else {
|
|
1173
|
-
setTimeout(emitSeek, 0);
|
|
1174
|
-
}
|
|
1175
|
-
};
|
|
1176
|
-
setTimeout(emitSeek, 0);
|
|
1177
|
-
} else {
|
|
1178
|
-
seekAndEmit();
|
|
1179
|
-
}
|
|
1180
|
-
} else {
|
|
1181
|
-
if (self._webAudio) {
|
|
1182
|
-
var realTime = self.playing(id) ? Howler2.ctx.currentTime - sound._playStart : 0;
|
|
1183
|
-
var rateSeek = sound._rateSeek ? sound._rateSeek - sound._seek : 0;
|
|
1184
|
-
return sound._seek + (rateSeek + realTime * Math.abs(sound._rate));
|
|
1185
|
-
} else {
|
|
1186
|
-
return sound._node.currentTime;
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
}
|
|
1190
|
-
return self;
|
|
1191
|
-
},
|
|
1192
|
-
/**
|
|
1193
|
-
* Check if a specific sound is currently playing or not (if id is provided), or check if at least one of the sounds in the group is playing or not.
|
|
1194
|
-
* @param {Number} id The sound id to check. If none is passed, the whole sound group is checked.
|
|
1195
|
-
* @return {Boolean} True if playing and false if not.
|
|
1196
|
-
*/
|
|
1197
|
-
playing: function(id) {
|
|
1198
|
-
var self = this;
|
|
1199
|
-
if (typeof id === "number") {
|
|
1200
|
-
var sound = self._soundById(id);
|
|
1201
|
-
return sound ? !sound._paused : false;
|
|
1202
|
-
}
|
|
1203
|
-
for (var i = 0; i < self._sounds.length; i++) {
|
|
1204
|
-
if (!self._sounds[i]._paused) {
|
|
1205
|
-
return true;
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
|
-
return false;
|
|
1209
|
-
},
|
|
1210
|
-
/**
|
|
1211
|
-
* Get the duration of this sound. Passing a sound id will return the sprite duration.
|
|
1212
|
-
* @param {Number} id The sound id to check. If none is passed, return full source duration.
|
|
1213
|
-
* @return {Number} Audio duration in seconds.
|
|
1214
|
-
*/
|
|
1215
|
-
duration: function(id) {
|
|
1216
|
-
var self = this;
|
|
1217
|
-
var duration = self._duration;
|
|
1218
|
-
var sound = self._soundById(id);
|
|
1219
|
-
if (sound) {
|
|
1220
|
-
duration = self._sprite[sound._sprite][1] / 1e3;
|
|
1221
|
-
}
|
|
1222
|
-
return duration;
|
|
1223
|
-
},
|
|
1224
|
-
/**
|
|
1225
|
-
* Returns the current loaded state of this Howl.
|
|
1226
|
-
* @return {String} 'unloaded', 'loading', 'loaded'
|
|
1227
|
-
*/
|
|
1228
|
-
state: function() {
|
|
1229
|
-
return this._state;
|
|
1230
|
-
},
|
|
1231
|
-
/**
|
|
1232
|
-
* Unload and destroy the current Howl object.
|
|
1233
|
-
* This will immediately stop all sound instances attached to this group.
|
|
1234
|
-
*/
|
|
1235
|
-
unload: function() {
|
|
1236
|
-
var self = this;
|
|
1237
|
-
var sounds = self._sounds;
|
|
1238
|
-
for (var i = 0; i < sounds.length; i++) {
|
|
1239
|
-
if (!sounds[i]._paused) {
|
|
1240
|
-
self.stop(sounds[i]._id);
|
|
1241
|
-
}
|
|
1242
|
-
if (!self._webAudio) {
|
|
1243
|
-
self._clearSound(sounds[i]._node);
|
|
1244
|
-
sounds[i]._node.removeEventListener("error", sounds[i]._errorFn, false);
|
|
1245
|
-
sounds[i]._node.removeEventListener(Howler2._canPlayEvent, sounds[i]._loadFn, false);
|
|
1246
|
-
sounds[i]._node.removeEventListener("ended", sounds[i]._endFn, false);
|
|
1247
|
-
Howler2._releaseHtml5Audio(sounds[i]._node);
|
|
1248
|
-
}
|
|
1249
|
-
delete sounds[i]._node;
|
|
1250
|
-
self._clearTimer(sounds[i]._id);
|
|
1251
|
-
}
|
|
1252
|
-
var index = Howler2._howls.indexOf(self);
|
|
1253
|
-
if (index >= 0) {
|
|
1254
|
-
Howler2._howls.splice(index, 1);
|
|
1255
|
-
}
|
|
1256
|
-
var remCache = true;
|
|
1257
|
-
for (i = 0; i < Howler2._howls.length; i++) {
|
|
1258
|
-
if (Howler2._howls[i]._src === self._src || self._src.indexOf(Howler2._howls[i]._src) >= 0) {
|
|
1259
|
-
remCache = false;
|
|
1260
|
-
break;
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
if (cache && remCache) {
|
|
1264
|
-
delete cache[self._src];
|
|
1265
|
-
}
|
|
1266
|
-
Howler2.noAudio = false;
|
|
1267
|
-
self._state = "unloaded";
|
|
1268
|
-
self._sounds = [];
|
|
1269
|
-
self = null;
|
|
1270
|
-
return null;
|
|
1271
|
-
},
|
|
1272
|
-
/**
|
|
1273
|
-
* Listen to a custom event.
|
|
1274
|
-
* @param {String} event Event name.
|
|
1275
|
-
* @param {Function} fn Listener to call.
|
|
1276
|
-
* @param {Number} id (optional) Only listen to events for this sound.
|
|
1277
|
-
* @param {Number} once (INTERNAL) Marks event to fire only once.
|
|
1278
|
-
* @return {Howl}
|
|
1279
|
-
*/
|
|
1280
|
-
on: function(event, fn, id, once) {
|
|
1281
|
-
var self = this;
|
|
1282
|
-
var events = self["_on" + event];
|
|
1283
|
-
if (typeof fn === "function") {
|
|
1284
|
-
events.push(once ? { id, fn, once } : { id, fn });
|
|
1285
|
-
}
|
|
1286
|
-
return self;
|
|
1287
|
-
},
|
|
1288
|
-
/**
|
|
1289
|
-
* Remove a custom event. Call without parameters to remove all events.
|
|
1290
|
-
* @param {String} event Event name.
|
|
1291
|
-
* @param {Function} fn Listener to remove. Leave empty to remove all.
|
|
1292
|
-
* @param {Number} id (optional) Only remove events for this sound.
|
|
1293
|
-
* @return {Howl}
|
|
1294
|
-
*/
|
|
1295
|
-
off: function(event, fn, id) {
|
|
1296
|
-
var self = this;
|
|
1297
|
-
var events = self["_on" + event];
|
|
1298
|
-
var i = 0;
|
|
1299
|
-
if (typeof fn === "number") {
|
|
1300
|
-
id = fn;
|
|
1301
|
-
fn = null;
|
|
1302
|
-
}
|
|
1303
|
-
if (fn || id) {
|
|
1304
|
-
for (i = 0; i < events.length; i++) {
|
|
1305
|
-
var isId = id === events[i].id;
|
|
1306
|
-
if (fn === events[i].fn && isId || !fn && isId) {
|
|
1307
|
-
events.splice(i, 1);
|
|
1308
|
-
break;
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
} else if (event) {
|
|
1312
|
-
self["_on" + event] = [];
|
|
1313
|
-
} else {
|
|
1314
|
-
var keys = Object.keys(self);
|
|
1315
|
-
for (i = 0; i < keys.length; i++) {
|
|
1316
|
-
if (keys[i].indexOf("_on") === 0 && Array.isArray(self[keys[i]])) {
|
|
1317
|
-
self[keys[i]] = [];
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
return self;
|
|
1322
|
-
},
|
|
1323
|
-
/**
|
|
1324
|
-
* Listen to a custom event and remove it once fired.
|
|
1325
|
-
* @param {String} event Event name.
|
|
1326
|
-
* @param {Function} fn Listener to call.
|
|
1327
|
-
* @param {Number} id (optional) Only listen to events for this sound.
|
|
1328
|
-
* @return {Howl}
|
|
1329
|
-
*/
|
|
1330
|
-
once: function(event, fn, id) {
|
|
1331
|
-
var self = this;
|
|
1332
|
-
self.on(event, fn, id, 1);
|
|
1333
|
-
return self;
|
|
1334
|
-
},
|
|
1335
|
-
/**
|
|
1336
|
-
* Emit all events of a specific type and pass the sound id.
|
|
1337
|
-
* @param {String} event Event name.
|
|
1338
|
-
* @param {Number} id Sound ID.
|
|
1339
|
-
* @param {Number} msg Message to go with event.
|
|
1340
|
-
* @return {Howl}
|
|
1341
|
-
*/
|
|
1342
|
-
_emit: function(event, id, msg) {
|
|
1343
|
-
var self = this;
|
|
1344
|
-
var events = self["_on" + event];
|
|
1345
|
-
for (var i = events.length - 1; i >= 0; i--) {
|
|
1346
|
-
if (!events[i].id || events[i].id === id || event === "load") {
|
|
1347
|
-
setTimeout((function(fn) {
|
|
1348
|
-
fn.call(this, id, msg);
|
|
1349
|
-
}).bind(self, events[i].fn), 0);
|
|
1350
|
-
if (events[i].once) {
|
|
1351
|
-
self.off(event, events[i].fn, events[i].id);
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
}
|
|
1355
|
-
self._loadQueue(event);
|
|
1356
|
-
return self;
|
|
1357
|
-
},
|
|
1358
|
-
/**
|
|
1359
|
-
* Queue of actions initiated before the sound has loaded.
|
|
1360
|
-
* These will be called in sequence, with the next only firing
|
|
1361
|
-
* after the previous has finished executing (even if async like play).
|
|
1362
|
-
* @return {Howl}
|
|
1363
|
-
*/
|
|
1364
|
-
_loadQueue: function(event) {
|
|
1365
|
-
var self = this;
|
|
1366
|
-
if (self._queue.length > 0) {
|
|
1367
|
-
var task = self._queue[0];
|
|
1368
|
-
if (task.event === event) {
|
|
1369
|
-
self._queue.shift();
|
|
1370
|
-
self._loadQueue();
|
|
1371
|
-
}
|
|
1372
|
-
if (!event) {
|
|
1373
|
-
task.action();
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
return self;
|
|
1377
|
-
},
|
|
1378
|
-
/**
|
|
1379
|
-
* Fired when playback ends at the end of the duration.
|
|
1380
|
-
* @param {Sound} sound The sound object to work with.
|
|
1381
|
-
* @return {Howl}
|
|
1382
|
-
*/
|
|
1383
|
-
_ended: function(sound) {
|
|
1384
|
-
var self = this;
|
|
1385
|
-
var sprite = sound._sprite;
|
|
1386
|
-
if (!self._webAudio && sound._node && !sound._node.paused && !sound._node.ended && sound._node.currentTime < sound._stop) {
|
|
1387
|
-
setTimeout(self._ended.bind(self, sound), 100);
|
|
1388
|
-
return self;
|
|
1389
|
-
}
|
|
1390
|
-
var loop = !!(sound._loop || self._sprite[sprite][2]);
|
|
1391
|
-
self._emit("end", sound._id);
|
|
1392
|
-
if (!self._webAudio && loop) {
|
|
1393
|
-
self.stop(sound._id, true).play(sound._id);
|
|
1394
|
-
}
|
|
1395
|
-
if (self._webAudio && loop) {
|
|
1396
|
-
self._emit("play", sound._id);
|
|
1397
|
-
sound._seek = sound._start || 0;
|
|
1398
|
-
sound._rateSeek = 0;
|
|
1399
|
-
sound._playStart = Howler2.ctx.currentTime;
|
|
1400
|
-
var timeout = (sound._stop - sound._start) * 1e3 / Math.abs(sound._rate);
|
|
1401
|
-
self._endTimers[sound._id] = setTimeout(self._ended.bind(self, sound), timeout);
|
|
1402
|
-
}
|
|
1403
|
-
if (self._webAudio && !loop) {
|
|
1404
|
-
sound._paused = true;
|
|
1405
|
-
sound._ended = true;
|
|
1406
|
-
sound._seek = sound._start || 0;
|
|
1407
|
-
sound._rateSeek = 0;
|
|
1408
|
-
self._clearTimer(sound._id);
|
|
1409
|
-
self._cleanBuffer(sound._node);
|
|
1410
|
-
Howler2._autoSuspend();
|
|
1411
|
-
}
|
|
1412
|
-
if (!self._webAudio && !loop) {
|
|
1413
|
-
self.stop(sound._id, true);
|
|
1414
|
-
}
|
|
1415
|
-
return self;
|
|
1416
|
-
},
|
|
1417
|
-
/**
|
|
1418
|
-
* Clear the end timer for a sound playback.
|
|
1419
|
-
* @param {Number} id The sound ID.
|
|
1420
|
-
* @return {Howl}
|
|
1421
|
-
*/
|
|
1422
|
-
_clearTimer: function(id) {
|
|
1423
|
-
var self = this;
|
|
1424
|
-
if (self._endTimers[id]) {
|
|
1425
|
-
if (typeof self._endTimers[id] !== "function") {
|
|
1426
|
-
clearTimeout(self._endTimers[id]);
|
|
1427
|
-
} else {
|
|
1428
|
-
var sound = self._soundById(id);
|
|
1429
|
-
if (sound && sound._node) {
|
|
1430
|
-
sound._node.removeEventListener("ended", self._endTimers[id], false);
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
delete self._endTimers[id];
|
|
1434
|
-
}
|
|
1435
|
-
return self;
|
|
1436
|
-
},
|
|
1437
|
-
/**
|
|
1438
|
-
* Return the sound identified by this ID, or return null.
|
|
1439
|
-
* @param {Number} id Sound ID
|
|
1440
|
-
* @return {Object} Sound object or null.
|
|
1441
|
-
*/
|
|
1442
|
-
_soundById: function(id) {
|
|
1443
|
-
var self = this;
|
|
1444
|
-
for (var i = 0; i < self._sounds.length; i++) {
|
|
1445
|
-
if (id === self._sounds[i]._id) {
|
|
1446
|
-
return self._sounds[i];
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
return null;
|
|
1450
|
-
},
|
|
1451
|
-
/**
|
|
1452
|
-
* Return an inactive sound from the pool or create a new one.
|
|
1453
|
-
* @return {Sound} Sound playback object.
|
|
1454
|
-
*/
|
|
1455
|
-
_inactiveSound: function() {
|
|
1456
|
-
var self = this;
|
|
1457
|
-
self._drain();
|
|
1458
|
-
for (var i = 0; i < self._sounds.length; i++) {
|
|
1459
|
-
if (self._sounds[i]._ended) {
|
|
1460
|
-
return self._sounds[i].reset();
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
return new Sound2(self);
|
|
1464
|
-
},
|
|
1465
|
-
/**
|
|
1466
|
-
* Drain excess inactive sounds from the pool.
|
|
1467
|
-
*/
|
|
1468
|
-
_drain: function() {
|
|
1469
|
-
var self = this;
|
|
1470
|
-
var limit = self._pool;
|
|
1471
|
-
var cnt = 0;
|
|
1472
|
-
var i = 0;
|
|
1473
|
-
if (self._sounds.length < limit) {
|
|
1474
|
-
return;
|
|
1475
|
-
}
|
|
1476
|
-
for (i = 0; i < self._sounds.length; i++) {
|
|
1477
|
-
if (self._sounds[i]._ended) {
|
|
1478
|
-
cnt++;
|
|
1479
|
-
}
|
|
1480
|
-
}
|
|
1481
|
-
for (i = self._sounds.length - 1; i >= 0; i--) {
|
|
1482
|
-
if (cnt <= limit) {
|
|
1483
|
-
return;
|
|
1484
|
-
}
|
|
1485
|
-
if (self._sounds[i]._ended) {
|
|
1486
|
-
if (self._webAudio && self._sounds[i]._node) {
|
|
1487
|
-
self._sounds[i]._node.disconnect(0);
|
|
1488
|
-
}
|
|
1489
|
-
self._sounds.splice(i, 1);
|
|
1490
|
-
cnt--;
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
},
|
|
1494
|
-
/**
|
|
1495
|
-
* Get all ID's from the sounds pool.
|
|
1496
|
-
* @param {Number} id Only return one ID if one is passed.
|
|
1497
|
-
* @return {Array} Array of IDs.
|
|
1498
|
-
*/
|
|
1499
|
-
_getSoundIds: function(id) {
|
|
1500
|
-
var self = this;
|
|
1501
|
-
if (typeof id === "undefined") {
|
|
1502
|
-
var ids = [];
|
|
1503
|
-
for (var i = 0; i < self._sounds.length; i++) {
|
|
1504
|
-
ids.push(self._sounds[i]._id);
|
|
1505
|
-
}
|
|
1506
|
-
return ids;
|
|
1507
|
-
} else {
|
|
1508
|
-
return [id];
|
|
1509
|
-
}
|
|
1510
|
-
},
|
|
1511
|
-
/**
|
|
1512
|
-
* Load the sound back into the buffer source.
|
|
1513
|
-
* @param {Sound} sound The sound object to work with.
|
|
1514
|
-
* @return {Howl}
|
|
1515
|
-
*/
|
|
1516
|
-
_refreshBuffer: function(sound) {
|
|
1517
|
-
var self = this;
|
|
1518
|
-
sound._node.bufferSource = Howler2.ctx.createBufferSource();
|
|
1519
|
-
sound._node.bufferSource.buffer = cache[self._src];
|
|
1520
|
-
if (sound._panner) {
|
|
1521
|
-
sound._node.bufferSource.connect(sound._panner);
|
|
1522
|
-
} else {
|
|
1523
|
-
sound._node.bufferSource.connect(sound._node);
|
|
1524
|
-
}
|
|
1525
|
-
sound._node.bufferSource.loop = sound._loop;
|
|
1526
|
-
if (sound._loop) {
|
|
1527
|
-
sound._node.bufferSource.loopStart = sound._start || 0;
|
|
1528
|
-
sound._node.bufferSource.loopEnd = sound._stop || 0;
|
|
1529
|
-
}
|
|
1530
|
-
sound._node.bufferSource.playbackRate.setValueAtTime(sound._rate, Howler2.ctx.currentTime);
|
|
1531
|
-
return self;
|
|
1532
|
-
},
|
|
1533
|
-
/**
|
|
1534
|
-
* Prevent memory leaks by cleaning up the buffer source after playback.
|
|
1535
|
-
* @param {Object} node Sound's audio node containing the buffer source.
|
|
1536
|
-
* @return {Howl}
|
|
1537
|
-
*/
|
|
1538
|
-
_cleanBuffer: function(node) {
|
|
1539
|
-
var self = this;
|
|
1540
|
-
var isIOS = Howler2._navigator && Howler2._navigator.vendor.indexOf("Apple") >= 0;
|
|
1541
|
-
if (!node.bufferSource) {
|
|
1542
|
-
return self;
|
|
1543
|
-
}
|
|
1544
|
-
if (Howler2._scratchBuffer && node.bufferSource) {
|
|
1545
|
-
node.bufferSource.onended = null;
|
|
1546
|
-
node.bufferSource.disconnect(0);
|
|
1547
|
-
if (isIOS) {
|
|
1548
|
-
try {
|
|
1549
|
-
node.bufferSource.buffer = Howler2._scratchBuffer;
|
|
1550
|
-
} catch (e) {
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
node.bufferSource = null;
|
|
1555
|
-
return self;
|
|
1556
|
-
},
|
|
1557
|
-
/**
|
|
1558
|
-
* Set the source to a 0-second silence to stop any downloading (except in IE).
|
|
1559
|
-
* @param {Object} node Audio node to clear.
|
|
1560
|
-
*/
|
|
1561
|
-
_clearSound: function(node) {
|
|
1562
|
-
var checkIE = /MSIE |Trident\//.test(Howler2._navigator && Howler2._navigator.userAgent);
|
|
1563
|
-
if (!checkIE) {
|
|
1564
|
-
node.src = "data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA";
|
|
1565
|
-
}
|
|
1566
|
-
}
|
|
1567
|
-
};
|
|
1568
|
-
var Sound2 = function(howl) {
|
|
1569
|
-
this._parent = howl;
|
|
1570
|
-
this.init();
|
|
1571
|
-
};
|
|
1572
|
-
Sound2.prototype = {
|
|
1573
|
-
/**
|
|
1574
|
-
* Initialize a new Sound object.
|
|
1575
|
-
* @return {Sound}
|
|
1576
|
-
*/
|
|
1577
|
-
init: function() {
|
|
1578
|
-
var self = this;
|
|
1579
|
-
var parent = self._parent;
|
|
1580
|
-
self._muted = parent._muted;
|
|
1581
|
-
self._loop = parent._loop;
|
|
1582
|
-
self._volume = parent._volume;
|
|
1583
|
-
self._rate = parent._rate;
|
|
1584
|
-
self._seek = 0;
|
|
1585
|
-
self._paused = true;
|
|
1586
|
-
self._ended = true;
|
|
1587
|
-
self._sprite = "__default";
|
|
1588
|
-
self._id = ++Howler2._counter;
|
|
1589
|
-
parent._sounds.push(self);
|
|
1590
|
-
self.create();
|
|
1591
|
-
return self;
|
|
1592
|
-
},
|
|
1593
|
-
/**
|
|
1594
|
-
* Create and setup a new sound object, whether HTML5 Audio or Web Audio.
|
|
1595
|
-
* @return {Sound}
|
|
1596
|
-
*/
|
|
1597
|
-
create: function() {
|
|
1598
|
-
var self = this;
|
|
1599
|
-
var parent = self._parent;
|
|
1600
|
-
var volume = Howler2._muted || self._muted || self._parent._muted ? 0 : self._volume;
|
|
1601
|
-
if (parent._webAudio) {
|
|
1602
|
-
self._node = typeof Howler2.ctx.createGain === "undefined" ? Howler2.ctx.createGainNode() : Howler2.ctx.createGain();
|
|
1603
|
-
self._node.gain.setValueAtTime(volume, Howler2.ctx.currentTime);
|
|
1604
|
-
self._node.paused = true;
|
|
1605
|
-
self._node.connect(Howler2.masterGain);
|
|
1606
|
-
} else if (!Howler2.noAudio) {
|
|
1607
|
-
self._node = Howler2._obtainHtml5Audio();
|
|
1608
|
-
self._errorFn = self._errorListener.bind(self);
|
|
1609
|
-
self._node.addEventListener("error", self._errorFn, false);
|
|
1610
|
-
self._loadFn = self._loadListener.bind(self);
|
|
1611
|
-
self._node.addEventListener(Howler2._canPlayEvent, self._loadFn, false);
|
|
1612
|
-
self._endFn = self._endListener.bind(self);
|
|
1613
|
-
self._node.addEventListener("ended", self._endFn, false);
|
|
1614
|
-
self._node.src = parent._src;
|
|
1615
|
-
self._node.preload = parent._preload === true ? "auto" : parent._preload;
|
|
1616
|
-
self._node.volume = volume * Howler2.volume();
|
|
1617
|
-
self._node.load();
|
|
1618
|
-
}
|
|
1619
|
-
return self;
|
|
1620
|
-
},
|
|
1621
|
-
/**
|
|
1622
|
-
* Reset the parameters of this sound to the original state (for recycle).
|
|
1623
|
-
* @return {Sound}
|
|
1624
|
-
*/
|
|
1625
|
-
reset: function() {
|
|
1626
|
-
var self = this;
|
|
1627
|
-
var parent = self._parent;
|
|
1628
|
-
self._muted = parent._muted;
|
|
1629
|
-
self._loop = parent._loop;
|
|
1630
|
-
self._volume = parent._volume;
|
|
1631
|
-
self._rate = parent._rate;
|
|
1632
|
-
self._seek = 0;
|
|
1633
|
-
self._rateSeek = 0;
|
|
1634
|
-
self._paused = true;
|
|
1635
|
-
self._ended = true;
|
|
1636
|
-
self._sprite = "__default";
|
|
1637
|
-
self._id = ++Howler2._counter;
|
|
1638
|
-
return self;
|
|
1639
|
-
},
|
|
1640
|
-
/**
|
|
1641
|
-
* HTML5 Audio error listener callback.
|
|
1642
|
-
*/
|
|
1643
|
-
_errorListener: function() {
|
|
1644
|
-
var self = this;
|
|
1645
|
-
self._parent._emit("loaderror", self._id, self._node.error ? self._node.error.code : 0);
|
|
1646
|
-
self._node.removeEventListener("error", self._errorFn, false);
|
|
1647
|
-
},
|
|
1648
|
-
/**
|
|
1649
|
-
* HTML5 Audio canplaythrough listener callback.
|
|
1650
|
-
*/
|
|
1651
|
-
_loadListener: function() {
|
|
1652
|
-
var self = this;
|
|
1653
|
-
var parent = self._parent;
|
|
1654
|
-
parent._duration = Math.ceil(self._node.duration * 10) / 10;
|
|
1655
|
-
if (Object.keys(parent._sprite).length === 0) {
|
|
1656
|
-
parent._sprite = { __default: [0, parent._duration * 1e3] };
|
|
1657
|
-
}
|
|
1658
|
-
if (parent._state !== "loaded") {
|
|
1659
|
-
parent._state = "loaded";
|
|
1660
|
-
parent._emit("load");
|
|
1661
|
-
parent._loadQueue();
|
|
1662
|
-
}
|
|
1663
|
-
self._node.removeEventListener(Howler2._canPlayEvent, self._loadFn, false);
|
|
1664
|
-
},
|
|
1665
|
-
/**
|
|
1666
|
-
* HTML5 Audio ended listener callback.
|
|
1667
|
-
*/
|
|
1668
|
-
_endListener: function() {
|
|
1669
|
-
var self = this;
|
|
1670
|
-
var parent = self._parent;
|
|
1671
|
-
if (parent._duration === Infinity) {
|
|
1672
|
-
parent._duration = Math.ceil(self._node.duration * 10) / 10;
|
|
1673
|
-
if (parent._sprite.__default[1] === Infinity) {
|
|
1674
|
-
parent._sprite.__default[1] = parent._duration * 1e3;
|
|
1675
|
-
}
|
|
1676
|
-
parent._ended(self);
|
|
1677
|
-
}
|
|
1678
|
-
self._node.removeEventListener("ended", self._endFn, false);
|
|
1679
|
-
}
|
|
1680
|
-
};
|
|
1681
|
-
var cache = {};
|
|
1682
|
-
var loadBuffer = function(self) {
|
|
1683
|
-
var url = self._src;
|
|
1684
|
-
if (cache[url]) {
|
|
1685
|
-
self._duration = cache[url].duration;
|
|
1686
|
-
loadSound(self);
|
|
1687
|
-
return;
|
|
1688
|
-
}
|
|
1689
|
-
if (/^data:[^;]+;base64,/.test(url)) {
|
|
1690
|
-
var data = atob(url.split(",")[1]);
|
|
1691
|
-
var dataView = new Uint8Array(data.length);
|
|
1692
|
-
for (var i = 0; i < data.length; ++i) {
|
|
1693
|
-
dataView[i] = data.charCodeAt(i);
|
|
1694
|
-
}
|
|
1695
|
-
decodeAudioData(dataView.buffer, self);
|
|
1696
|
-
} else {
|
|
1697
|
-
var xhr = new XMLHttpRequest();
|
|
1698
|
-
xhr.open(self._xhr.method, url, true);
|
|
1699
|
-
xhr.withCredentials = self._xhr.withCredentials;
|
|
1700
|
-
xhr.responseType = "arraybuffer";
|
|
1701
|
-
if (self._xhr.headers) {
|
|
1702
|
-
Object.keys(self._xhr.headers).forEach(function(key) {
|
|
1703
|
-
xhr.setRequestHeader(key, self._xhr.headers[key]);
|
|
1704
|
-
});
|
|
1705
|
-
}
|
|
1706
|
-
xhr.onload = function() {
|
|
1707
|
-
var code = (xhr.status + "")[0];
|
|
1708
|
-
if (code !== "0" && code !== "2" && code !== "3") {
|
|
1709
|
-
self._emit("loaderror", null, "Failed loading audio file with status: " + xhr.status + ".");
|
|
1710
|
-
return;
|
|
1711
|
-
}
|
|
1712
|
-
decodeAudioData(xhr.response, self);
|
|
1713
|
-
};
|
|
1714
|
-
xhr.onerror = function() {
|
|
1715
|
-
if (self._webAudio) {
|
|
1716
|
-
self._html5 = true;
|
|
1717
|
-
self._webAudio = false;
|
|
1718
|
-
self._sounds = [];
|
|
1719
|
-
delete cache[url];
|
|
1720
|
-
self.load();
|
|
1721
|
-
}
|
|
1722
|
-
};
|
|
1723
|
-
safeXhrSend(xhr);
|
|
1724
|
-
}
|
|
1725
|
-
};
|
|
1726
|
-
var safeXhrSend = function(xhr) {
|
|
1727
|
-
try {
|
|
1728
|
-
xhr.send();
|
|
1729
|
-
} catch (e) {
|
|
1730
|
-
xhr.onerror();
|
|
1731
|
-
}
|
|
1732
|
-
};
|
|
1733
|
-
var decodeAudioData = function(arraybuffer, self) {
|
|
1734
|
-
var error = function() {
|
|
1735
|
-
self._emit("loaderror", null, "Decoding audio data failed.");
|
|
1736
|
-
};
|
|
1737
|
-
var success = function(buffer) {
|
|
1738
|
-
if (buffer && self._sounds.length > 0) {
|
|
1739
|
-
cache[self._src] = buffer;
|
|
1740
|
-
loadSound(self, buffer);
|
|
1741
|
-
} else {
|
|
1742
|
-
error();
|
|
1743
|
-
}
|
|
1744
|
-
};
|
|
1745
|
-
if (typeof Promise !== "undefined" && Howler2.ctx.decodeAudioData.length === 1) {
|
|
1746
|
-
Howler2.ctx.decodeAudioData(arraybuffer).then(success).catch(error);
|
|
1747
|
-
} else {
|
|
1748
|
-
Howler2.ctx.decodeAudioData(arraybuffer, success, error);
|
|
1749
|
-
}
|
|
1750
|
-
};
|
|
1751
|
-
var loadSound = function(self, buffer) {
|
|
1752
|
-
if (buffer && !self._duration) {
|
|
1753
|
-
self._duration = buffer.duration;
|
|
1754
|
-
}
|
|
1755
|
-
if (Object.keys(self._sprite).length === 0) {
|
|
1756
|
-
self._sprite = { __default: [0, self._duration * 1e3] };
|
|
1757
|
-
}
|
|
1758
|
-
if (self._state !== "loaded") {
|
|
1759
|
-
self._state = "loaded";
|
|
1760
|
-
self._emit("load");
|
|
1761
|
-
self._loadQueue();
|
|
1762
|
-
}
|
|
1763
|
-
};
|
|
1764
|
-
var setupAudioContext = function() {
|
|
1765
|
-
if (!Howler2.usingWebAudio) {
|
|
1766
|
-
return;
|
|
1767
|
-
}
|
|
1768
|
-
try {
|
|
1769
|
-
if (typeof AudioContext !== "undefined") {
|
|
1770
|
-
Howler2.ctx = new AudioContext();
|
|
1771
|
-
} else if (typeof webkitAudioContext !== "undefined") {
|
|
1772
|
-
Howler2.ctx = new webkitAudioContext();
|
|
1773
|
-
} else {
|
|
1774
|
-
Howler2.usingWebAudio = false;
|
|
1775
|
-
}
|
|
1776
|
-
} catch (e) {
|
|
1777
|
-
Howler2.usingWebAudio = false;
|
|
1778
|
-
}
|
|
1779
|
-
if (!Howler2.ctx) {
|
|
1780
|
-
Howler2.usingWebAudio = false;
|
|
1781
|
-
}
|
|
1782
|
-
var iOS = /iP(hone|od|ad)/.test(Howler2._navigator && Howler2._navigator.platform);
|
|
1783
|
-
var appVersion = Howler2._navigator && Howler2._navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);
|
|
1784
|
-
var version = appVersion ? parseInt(appVersion[1], 10) : null;
|
|
1785
|
-
if (iOS && version && version < 9) {
|
|
1786
|
-
var safari = /safari/.test(Howler2._navigator && Howler2._navigator.userAgent.toLowerCase());
|
|
1787
|
-
if (Howler2._navigator && !safari) {
|
|
1788
|
-
Howler2.usingWebAudio = false;
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1791
|
-
if (Howler2.usingWebAudio) {
|
|
1792
|
-
Howler2.masterGain = typeof Howler2.ctx.createGain === "undefined" ? Howler2.ctx.createGainNode() : Howler2.ctx.createGain();
|
|
1793
|
-
Howler2.masterGain.gain.setValueAtTime(Howler2._muted ? 0 : Howler2._volume, Howler2.ctx.currentTime);
|
|
1794
|
-
Howler2.masterGain.connect(Howler2.ctx.destination);
|
|
1795
|
-
}
|
|
1796
|
-
Howler2._setup();
|
|
1797
|
-
};
|
|
1798
|
-
if (typeof define === "function" && define.amd) {
|
|
1799
|
-
define([], function() {
|
|
1800
|
-
return {
|
|
1801
|
-
Howler: Howler2,
|
|
1802
|
-
Howl: Howl2
|
|
1803
|
-
};
|
|
1804
|
-
});
|
|
1805
|
-
}
|
|
1806
|
-
if (typeof exports !== "undefined") {
|
|
1807
|
-
exports.Howler = Howler2;
|
|
1808
|
-
exports.Howl = Howl2;
|
|
1809
|
-
}
|
|
1810
|
-
if (typeof global !== "undefined") {
|
|
1811
|
-
global.HowlerGlobal = HowlerGlobal2;
|
|
1812
|
-
global.Howler = Howler2;
|
|
1813
|
-
global.Howl = Howl2;
|
|
1814
|
-
global.Sound = Sound2;
|
|
1815
|
-
} else if (typeof window !== "undefined") {
|
|
1816
|
-
window.HowlerGlobal = HowlerGlobal2;
|
|
1817
|
-
window.Howler = Howler2;
|
|
1818
|
-
window.Howl = Howl2;
|
|
1819
|
-
window.Sound = Sound2;
|
|
1820
|
-
}
|
|
1821
|
-
})();
|
|
1822
|
-
(function() {
|
|
1823
|
-
"use strict";
|
|
1824
|
-
HowlerGlobal.prototype._pos = [0, 0, 0];
|
|
1825
|
-
HowlerGlobal.prototype._orientation = [0, 0, -1, 0, 1, 0];
|
|
1826
|
-
HowlerGlobal.prototype.stereo = function(pan) {
|
|
1827
|
-
var self = this;
|
|
1828
|
-
if (!self.ctx || !self.ctx.listener) {
|
|
1829
|
-
return self;
|
|
1830
|
-
}
|
|
1831
|
-
for (var i = self._howls.length - 1; i >= 0; i--) {
|
|
1832
|
-
self._howls[i].stereo(pan);
|
|
1833
|
-
}
|
|
1834
|
-
return self;
|
|
1835
|
-
};
|
|
1836
|
-
HowlerGlobal.prototype.pos = function(x, y, z) {
|
|
1837
|
-
var self = this;
|
|
1838
|
-
if (!self.ctx || !self.ctx.listener) {
|
|
1839
|
-
return self;
|
|
1840
|
-
}
|
|
1841
|
-
y = typeof y !== "number" ? self._pos[1] : y;
|
|
1842
|
-
z = typeof z !== "number" ? self._pos[2] : z;
|
|
1843
|
-
if (typeof x === "number") {
|
|
1844
|
-
self._pos = [x, y, z];
|
|
1845
|
-
if (typeof self.ctx.listener.positionX !== "undefined") {
|
|
1846
|
-
self.ctx.listener.positionX.setTargetAtTime(self._pos[0], Howler.ctx.currentTime, 0.1);
|
|
1847
|
-
self.ctx.listener.positionY.setTargetAtTime(self._pos[1], Howler.ctx.currentTime, 0.1);
|
|
1848
|
-
self.ctx.listener.positionZ.setTargetAtTime(self._pos[2], Howler.ctx.currentTime, 0.1);
|
|
1849
|
-
} else {
|
|
1850
|
-
self.ctx.listener.setPosition(self._pos[0], self._pos[1], self._pos[2]);
|
|
1851
|
-
}
|
|
1852
|
-
} else {
|
|
1853
|
-
return self._pos;
|
|
1854
|
-
}
|
|
1855
|
-
return self;
|
|
1856
|
-
};
|
|
1857
|
-
HowlerGlobal.prototype.orientation = function(x, y, z, xUp, yUp, zUp) {
|
|
1858
|
-
var self = this;
|
|
1859
|
-
if (!self.ctx || !self.ctx.listener) {
|
|
1860
|
-
return self;
|
|
1861
|
-
}
|
|
1862
|
-
var or = self._orientation;
|
|
1863
|
-
y = typeof y !== "number" ? or[1] : y;
|
|
1864
|
-
z = typeof z !== "number" ? or[2] : z;
|
|
1865
|
-
xUp = typeof xUp !== "number" ? or[3] : xUp;
|
|
1866
|
-
yUp = typeof yUp !== "number" ? or[4] : yUp;
|
|
1867
|
-
zUp = typeof zUp !== "number" ? or[5] : zUp;
|
|
1868
|
-
if (typeof x === "number") {
|
|
1869
|
-
self._orientation = [x, y, z, xUp, yUp, zUp];
|
|
1870
|
-
if (typeof self.ctx.listener.forwardX !== "undefined") {
|
|
1871
|
-
self.ctx.listener.forwardX.setTargetAtTime(x, Howler.ctx.currentTime, 0.1);
|
|
1872
|
-
self.ctx.listener.forwardY.setTargetAtTime(y, Howler.ctx.currentTime, 0.1);
|
|
1873
|
-
self.ctx.listener.forwardZ.setTargetAtTime(z, Howler.ctx.currentTime, 0.1);
|
|
1874
|
-
self.ctx.listener.upX.setTargetAtTime(xUp, Howler.ctx.currentTime, 0.1);
|
|
1875
|
-
self.ctx.listener.upY.setTargetAtTime(yUp, Howler.ctx.currentTime, 0.1);
|
|
1876
|
-
self.ctx.listener.upZ.setTargetAtTime(zUp, Howler.ctx.currentTime, 0.1);
|
|
1877
|
-
} else {
|
|
1878
|
-
self.ctx.listener.setOrientation(x, y, z, xUp, yUp, zUp);
|
|
1879
|
-
}
|
|
1880
|
-
} else {
|
|
1881
|
-
return or;
|
|
1882
|
-
}
|
|
1883
|
-
return self;
|
|
1884
|
-
};
|
|
1885
|
-
Howl.prototype.init = /* @__PURE__ */ (function(_super) {
|
|
1886
|
-
return function(o) {
|
|
1887
|
-
var self = this;
|
|
1888
|
-
self._orientation = o.orientation || [1, 0, 0];
|
|
1889
|
-
self._stereo = o.stereo || null;
|
|
1890
|
-
self._pos = o.pos || null;
|
|
1891
|
-
self._pannerAttr = {
|
|
1892
|
-
coneInnerAngle: typeof o.coneInnerAngle !== "undefined" ? o.coneInnerAngle : 360,
|
|
1893
|
-
coneOuterAngle: typeof o.coneOuterAngle !== "undefined" ? o.coneOuterAngle : 360,
|
|
1894
|
-
coneOuterGain: typeof o.coneOuterGain !== "undefined" ? o.coneOuterGain : 0,
|
|
1895
|
-
distanceModel: typeof o.distanceModel !== "undefined" ? o.distanceModel : "inverse",
|
|
1896
|
-
maxDistance: typeof o.maxDistance !== "undefined" ? o.maxDistance : 1e4,
|
|
1897
|
-
panningModel: typeof o.panningModel !== "undefined" ? o.panningModel : "HRTF",
|
|
1898
|
-
refDistance: typeof o.refDistance !== "undefined" ? o.refDistance : 1,
|
|
1899
|
-
rolloffFactor: typeof o.rolloffFactor !== "undefined" ? o.rolloffFactor : 1
|
|
1900
|
-
};
|
|
1901
|
-
self._onstereo = o.onstereo ? [{ fn: o.onstereo }] : [];
|
|
1902
|
-
self._onpos = o.onpos ? [{ fn: o.onpos }] : [];
|
|
1903
|
-
self._onorientation = o.onorientation ? [{ fn: o.onorientation }] : [];
|
|
1904
|
-
return _super.call(this, o);
|
|
1905
|
-
};
|
|
1906
|
-
})(Howl.prototype.init);
|
|
1907
|
-
Howl.prototype.stereo = function(pan, id) {
|
|
1908
|
-
var self = this;
|
|
1909
|
-
if (!self._webAudio) {
|
|
1910
|
-
return self;
|
|
1911
|
-
}
|
|
1912
|
-
if (self._state !== "loaded") {
|
|
1913
|
-
self._queue.push({
|
|
1914
|
-
event: "stereo",
|
|
1915
|
-
action: function() {
|
|
1916
|
-
self.stereo(pan, id);
|
|
1917
|
-
}
|
|
1918
|
-
});
|
|
1919
|
-
return self;
|
|
1920
|
-
}
|
|
1921
|
-
var pannerType = typeof Howler.ctx.createStereoPanner === "undefined" ? "spatial" : "stereo";
|
|
1922
|
-
if (typeof id === "undefined") {
|
|
1923
|
-
if (typeof pan === "number") {
|
|
1924
|
-
self._stereo = pan;
|
|
1925
|
-
self._pos = [pan, 0, 0];
|
|
1926
|
-
} else {
|
|
1927
|
-
return self._stereo;
|
|
1928
|
-
}
|
|
1929
|
-
}
|
|
1930
|
-
var ids = self._getSoundIds(id);
|
|
1931
|
-
for (var i = 0; i < ids.length; i++) {
|
|
1932
|
-
var sound = self._soundById(ids[i]);
|
|
1933
|
-
if (sound) {
|
|
1934
|
-
if (typeof pan === "number") {
|
|
1935
|
-
sound._stereo = pan;
|
|
1936
|
-
sound._pos = [pan, 0, 0];
|
|
1937
|
-
if (sound._node) {
|
|
1938
|
-
sound._pannerAttr.panningModel = "equalpower";
|
|
1939
|
-
if (!sound._panner || !sound._panner.pan) {
|
|
1940
|
-
setupPanner(sound, pannerType);
|
|
1941
|
-
}
|
|
1942
|
-
if (pannerType === "spatial") {
|
|
1943
|
-
if (typeof sound._panner.positionX !== "undefined") {
|
|
1944
|
-
sound._panner.positionX.setValueAtTime(pan, Howler.ctx.currentTime);
|
|
1945
|
-
sound._panner.positionY.setValueAtTime(0, Howler.ctx.currentTime);
|
|
1946
|
-
sound._panner.positionZ.setValueAtTime(0, Howler.ctx.currentTime);
|
|
1947
|
-
} else {
|
|
1948
|
-
sound._panner.setPosition(pan, 0, 0);
|
|
1949
|
-
}
|
|
1950
|
-
} else {
|
|
1951
|
-
sound._panner.pan.setValueAtTime(pan, Howler.ctx.currentTime);
|
|
1952
|
-
}
|
|
1953
|
-
}
|
|
1954
|
-
self._emit("stereo", sound._id);
|
|
1955
|
-
} else {
|
|
1956
|
-
return sound._stereo;
|
|
1957
|
-
}
|
|
1958
|
-
}
|
|
1959
|
-
}
|
|
1960
|
-
return self;
|
|
1961
|
-
};
|
|
1962
|
-
Howl.prototype.pos = function(x, y, z, id) {
|
|
1963
|
-
var self = this;
|
|
1964
|
-
if (!self._webAudio) {
|
|
1965
|
-
return self;
|
|
1966
|
-
}
|
|
1967
|
-
if (self._state !== "loaded") {
|
|
1968
|
-
self._queue.push({
|
|
1969
|
-
event: "pos",
|
|
1970
|
-
action: function() {
|
|
1971
|
-
self.pos(x, y, z, id);
|
|
1972
|
-
}
|
|
1973
|
-
});
|
|
1974
|
-
return self;
|
|
1975
|
-
}
|
|
1976
|
-
y = typeof y !== "number" ? 0 : y;
|
|
1977
|
-
z = typeof z !== "number" ? -0.5 : z;
|
|
1978
|
-
if (typeof id === "undefined") {
|
|
1979
|
-
if (typeof x === "number") {
|
|
1980
|
-
self._pos = [x, y, z];
|
|
1981
|
-
} else {
|
|
1982
|
-
return self._pos;
|
|
1983
|
-
}
|
|
1984
|
-
}
|
|
1985
|
-
var ids = self._getSoundIds(id);
|
|
1986
|
-
for (var i = 0; i < ids.length; i++) {
|
|
1987
|
-
var sound = self._soundById(ids[i]);
|
|
1988
|
-
if (sound) {
|
|
1989
|
-
if (typeof x === "number") {
|
|
1990
|
-
sound._pos = [x, y, z];
|
|
1991
|
-
if (sound._node) {
|
|
1992
|
-
if (!sound._panner || sound._panner.pan) {
|
|
1993
|
-
setupPanner(sound, "spatial");
|
|
1994
|
-
}
|
|
1995
|
-
if (typeof sound._panner.positionX !== "undefined") {
|
|
1996
|
-
sound._panner.positionX.setValueAtTime(x, Howler.ctx.currentTime);
|
|
1997
|
-
sound._panner.positionY.setValueAtTime(y, Howler.ctx.currentTime);
|
|
1998
|
-
sound._panner.positionZ.setValueAtTime(z, Howler.ctx.currentTime);
|
|
1999
|
-
} else {
|
|
2000
|
-
sound._panner.setPosition(x, y, z);
|
|
2001
|
-
}
|
|
2002
|
-
}
|
|
2003
|
-
self._emit("pos", sound._id);
|
|
2004
|
-
} else {
|
|
2005
|
-
return sound._pos;
|
|
2006
|
-
}
|
|
2007
|
-
}
|
|
2008
|
-
}
|
|
2009
|
-
return self;
|
|
2010
|
-
};
|
|
2011
|
-
Howl.prototype.orientation = function(x, y, z, id) {
|
|
2012
|
-
var self = this;
|
|
2013
|
-
if (!self._webAudio) {
|
|
2014
|
-
return self;
|
|
2015
|
-
}
|
|
2016
|
-
if (self._state !== "loaded") {
|
|
2017
|
-
self._queue.push({
|
|
2018
|
-
event: "orientation",
|
|
2019
|
-
action: function() {
|
|
2020
|
-
self.orientation(x, y, z, id);
|
|
2021
|
-
}
|
|
2022
|
-
});
|
|
2023
|
-
return self;
|
|
2024
|
-
}
|
|
2025
|
-
y = typeof y !== "number" ? self._orientation[1] : y;
|
|
2026
|
-
z = typeof z !== "number" ? self._orientation[2] : z;
|
|
2027
|
-
if (typeof id === "undefined") {
|
|
2028
|
-
if (typeof x === "number") {
|
|
2029
|
-
self._orientation = [x, y, z];
|
|
2030
|
-
} else {
|
|
2031
|
-
return self._orientation;
|
|
2032
|
-
}
|
|
2033
|
-
}
|
|
2034
|
-
var ids = self._getSoundIds(id);
|
|
2035
|
-
for (var i = 0; i < ids.length; i++) {
|
|
2036
|
-
var sound = self._soundById(ids[i]);
|
|
2037
|
-
if (sound) {
|
|
2038
|
-
if (typeof x === "number") {
|
|
2039
|
-
sound._orientation = [x, y, z];
|
|
2040
|
-
if (sound._node) {
|
|
2041
|
-
if (!sound._panner) {
|
|
2042
|
-
if (!sound._pos) {
|
|
2043
|
-
sound._pos = self._pos || [0, 0, -0.5];
|
|
2044
|
-
}
|
|
2045
|
-
setupPanner(sound, "spatial");
|
|
2046
|
-
}
|
|
2047
|
-
if (typeof sound._panner.orientationX !== "undefined") {
|
|
2048
|
-
sound._panner.orientationX.setValueAtTime(x, Howler.ctx.currentTime);
|
|
2049
|
-
sound._panner.orientationY.setValueAtTime(y, Howler.ctx.currentTime);
|
|
2050
|
-
sound._panner.orientationZ.setValueAtTime(z, Howler.ctx.currentTime);
|
|
2051
|
-
} else {
|
|
2052
|
-
sound._panner.setOrientation(x, y, z);
|
|
2053
|
-
}
|
|
2054
|
-
}
|
|
2055
|
-
self._emit("orientation", sound._id);
|
|
2056
|
-
} else {
|
|
2057
|
-
return sound._orientation;
|
|
2058
|
-
}
|
|
2059
|
-
}
|
|
2060
|
-
}
|
|
2061
|
-
return self;
|
|
2062
|
-
};
|
|
2063
|
-
Howl.prototype.pannerAttr = function() {
|
|
2064
|
-
var self = this;
|
|
2065
|
-
var args = arguments;
|
|
2066
|
-
var o, id, sound;
|
|
2067
|
-
if (!self._webAudio) {
|
|
2068
|
-
return self;
|
|
2069
|
-
}
|
|
2070
|
-
if (args.length === 0) {
|
|
2071
|
-
return self._pannerAttr;
|
|
2072
|
-
} else if (args.length === 1) {
|
|
2073
|
-
if (typeof args[0] === "object") {
|
|
2074
|
-
o = args[0];
|
|
2075
|
-
if (typeof id === "undefined") {
|
|
2076
|
-
if (!o.pannerAttr) {
|
|
2077
|
-
o.pannerAttr = {
|
|
2078
|
-
coneInnerAngle: o.coneInnerAngle,
|
|
2079
|
-
coneOuterAngle: o.coneOuterAngle,
|
|
2080
|
-
coneOuterGain: o.coneOuterGain,
|
|
2081
|
-
distanceModel: o.distanceModel,
|
|
2082
|
-
maxDistance: o.maxDistance,
|
|
2083
|
-
refDistance: o.refDistance,
|
|
2084
|
-
rolloffFactor: o.rolloffFactor,
|
|
2085
|
-
panningModel: o.panningModel
|
|
2086
|
-
};
|
|
2087
|
-
}
|
|
2088
|
-
self._pannerAttr = {
|
|
2089
|
-
coneInnerAngle: typeof o.pannerAttr.coneInnerAngle !== "undefined" ? o.pannerAttr.coneInnerAngle : self._coneInnerAngle,
|
|
2090
|
-
coneOuterAngle: typeof o.pannerAttr.coneOuterAngle !== "undefined" ? o.pannerAttr.coneOuterAngle : self._coneOuterAngle,
|
|
2091
|
-
coneOuterGain: typeof o.pannerAttr.coneOuterGain !== "undefined" ? o.pannerAttr.coneOuterGain : self._coneOuterGain,
|
|
2092
|
-
distanceModel: typeof o.pannerAttr.distanceModel !== "undefined" ? o.pannerAttr.distanceModel : self._distanceModel,
|
|
2093
|
-
maxDistance: typeof o.pannerAttr.maxDistance !== "undefined" ? o.pannerAttr.maxDistance : self._maxDistance,
|
|
2094
|
-
refDistance: typeof o.pannerAttr.refDistance !== "undefined" ? o.pannerAttr.refDistance : self._refDistance,
|
|
2095
|
-
rolloffFactor: typeof o.pannerAttr.rolloffFactor !== "undefined" ? o.pannerAttr.rolloffFactor : self._rolloffFactor,
|
|
2096
|
-
panningModel: typeof o.pannerAttr.panningModel !== "undefined" ? o.pannerAttr.panningModel : self._panningModel
|
|
2097
|
-
};
|
|
2098
|
-
}
|
|
2099
|
-
} else {
|
|
2100
|
-
sound = self._soundById(parseInt(args[0], 10));
|
|
2101
|
-
return sound ? sound._pannerAttr : self._pannerAttr;
|
|
2102
|
-
}
|
|
2103
|
-
} else if (args.length === 2) {
|
|
2104
|
-
o = args[0];
|
|
2105
|
-
id = parseInt(args[1], 10);
|
|
2106
|
-
}
|
|
2107
|
-
var ids = self._getSoundIds(id);
|
|
2108
|
-
for (var i = 0; i < ids.length; i++) {
|
|
2109
|
-
sound = self._soundById(ids[i]);
|
|
2110
|
-
if (sound) {
|
|
2111
|
-
var pa = sound._pannerAttr;
|
|
2112
|
-
pa = {
|
|
2113
|
-
coneInnerAngle: typeof o.coneInnerAngle !== "undefined" ? o.coneInnerAngle : pa.coneInnerAngle,
|
|
2114
|
-
coneOuterAngle: typeof o.coneOuterAngle !== "undefined" ? o.coneOuterAngle : pa.coneOuterAngle,
|
|
2115
|
-
coneOuterGain: typeof o.coneOuterGain !== "undefined" ? o.coneOuterGain : pa.coneOuterGain,
|
|
2116
|
-
distanceModel: typeof o.distanceModel !== "undefined" ? o.distanceModel : pa.distanceModel,
|
|
2117
|
-
maxDistance: typeof o.maxDistance !== "undefined" ? o.maxDistance : pa.maxDistance,
|
|
2118
|
-
refDistance: typeof o.refDistance !== "undefined" ? o.refDistance : pa.refDistance,
|
|
2119
|
-
rolloffFactor: typeof o.rolloffFactor !== "undefined" ? o.rolloffFactor : pa.rolloffFactor,
|
|
2120
|
-
panningModel: typeof o.panningModel !== "undefined" ? o.panningModel : pa.panningModel
|
|
2121
|
-
};
|
|
2122
|
-
var panner = sound._panner;
|
|
2123
|
-
if (!panner) {
|
|
2124
|
-
if (!sound._pos) {
|
|
2125
|
-
sound._pos = self._pos || [0, 0, -0.5];
|
|
2126
|
-
}
|
|
2127
|
-
setupPanner(sound, "spatial");
|
|
2128
|
-
panner = sound._panner;
|
|
2129
|
-
}
|
|
2130
|
-
panner.coneInnerAngle = pa.coneInnerAngle;
|
|
2131
|
-
panner.coneOuterAngle = pa.coneOuterAngle;
|
|
2132
|
-
panner.coneOuterGain = pa.coneOuterGain;
|
|
2133
|
-
panner.distanceModel = pa.distanceModel;
|
|
2134
|
-
panner.maxDistance = pa.maxDistance;
|
|
2135
|
-
panner.refDistance = pa.refDistance;
|
|
2136
|
-
panner.rolloffFactor = pa.rolloffFactor;
|
|
2137
|
-
panner.panningModel = pa.panningModel;
|
|
2138
|
-
}
|
|
2139
|
-
}
|
|
2140
|
-
return self;
|
|
2141
|
-
};
|
|
2142
|
-
Sound.prototype.init = /* @__PURE__ */ (function(_super) {
|
|
2143
|
-
return function() {
|
|
2144
|
-
var self = this;
|
|
2145
|
-
var parent = self._parent;
|
|
2146
|
-
self._orientation = parent._orientation;
|
|
2147
|
-
self._stereo = parent._stereo;
|
|
2148
|
-
self._pos = parent._pos;
|
|
2149
|
-
self._pannerAttr = parent._pannerAttr;
|
|
2150
|
-
_super.call(this);
|
|
2151
|
-
if (self._stereo) {
|
|
2152
|
-
parent.stereo(self._stereo);
|
|
2153
|
-
} else if (self._pos) {
|
|
2154
|
-
parent.pos(self._pos[0], self._pos[1], self._pos[2], self._id);
|
|
2155
|
-
}
|
|
2156
|
-
};
|
|
2157
|
-
})(Sound.prototype.init);
|
|
2158
|
-
Sound.prototype.reset = /* @__PURE__ */ (function(_super) {
|
|
2159
|
-
return function() {
|
|
2160
|
-
var self = this;
|
|
2161
|
-
var parent = self._parent;
|
|
2162
|
-
self._orientation = parent._orientation;
|
|
2163
|
-
self._stereo = parent._stereo;
|
|
2164
|
-
self._pos = parent._pos;
|
|
2165
|
-
self._pannerAttr = parent._pannerAttr;
|
|
2166
|
-
if (self._stereo) {
|
|
2167
|
-
parent.stereo(self._stereo);
|
|
2168
|
-
} else if (self._pos) {
|
|
2169
|
-
parent.pos(self._pos[0], self._pos[1], self._pos[2], self._id);
|
|
2170
|
-
} else if (self._panner) {
|
|
2171
|
-
self._panner.disconnect(0);
|
|
2172
|
-
self._panner = void 0;
|
|
2173
|
-
parent._refreshBuffer(self);
|
|
2174
|
-
}
|
|
2175
|
-
return _super.call(this);
|
|
2176
|
-
};
|
|
2177
|
-
})(Sound.prototype.reset);
|
|
2178
|
-
var setupPanner = function(sound, type) {
|
|
2179
|
-
type = type || "spatial";
|
|
2180
|
-
if (type === "spatial") {
|
|
2181
|
-
sound._panner = Howler.ctx.createPanner();
|
|
2182
|
-
sound._panner.coneInnerAngle = sound._pannerAttr.coneInnerAngle;
|
|
2183
|
-
sound._panner.coneOuterAngle = sound._pannerAttr.coneOuterAngle;
|
|
2184
|
-
sound._panner.coneOuterGain = sound._pannerAttr.coneOuterGain;
|
|
2185
|
-
sound._panner.distanceModel = sound._pannerAttr.distanceModel;
|
|
2186
|
-
sound._panner.maxDistance = sound._pannerAttr.maxDistance;
|
|
2187
|
-
sound._panner.refDistance = sound._pannerAttr.refDistance;
|
|
2188
|
-
sound._panner.rolloffFactor = sound._pannerAttr.rolloffFactor;
|
|
2189
|
-
sound._panner.panningModel = sound._pannerAttr.panningModel;
|
|
2190
|
-
if (typeof sound._panner.positionX !== "undefined") {
|
|
2191
|
-
sound._panner.positionX.setValueAtTime(sound._pos[0], Howler.ctx.currentTime);
|
|
2192
|
-
sound._panner.positionY.setValueAtTime(sound._pos[1], Howler.ctx.currentTime);
|
|
2193
|
-
sound._panner.positionZ.setValueAtTime(sound._pos[2], Howler.ctx.currentTime);
|
|
2194
|
-
} else {
|
|
2195
|
-
sound._panner.setPosition(sound._pos[0], sound._pos[1], sound._pos[2]);
|
|
2196
|
-
}
|
|
2197
|
-
if (typeof sound._panner.orientationX !== "undefined") {
|
|
2198
|
-
sound._panner.orientationX.setValueAtTime(sound._orientation[0], Howler.ctx.currentTime);
|
|
2199
|
-
sound._panner.orientationY.setValueAtTime(sound._orientation[1], Howler.ctx.currentTime);
|
|
2200
|
-
sound._panner.orientationZ.setValueAtTime(sound._orientation[2], Howler.ctx.currentTime);
|
|
2201
|
-
} else {
|
|
2202
|
-
sound._panner.setOrientation(sound._orientation[0], sound._orientation[1], sound._orientation[2]);
|
|
2203
|
-
}
|
|
2204
|
-
} else {
|
|
2205
|
-
sound._panner = Howler.ctx.createStereoPanner();
|
|
2206
|
-
sound._panner.pan.setValueAtTime(sound._stereo, Howler.ctx.currentTime);
|
|
2207
|
-
}
|
|
2208
|
-
sound._panner.connect(sound._node);
|
|
2209
|
-
if (!sound._paused) {
|
|
2210
|
-
sound._parent.pause(sound._id, true).play(sound._id, true);
|
|
2211
|
-
}
|
|
2212
|
-
};
|
|
2213
|
-
})();
|
|
2214
|
-
}
|
|
2215
|
-
});
|
|
2216
|
-
export default require_howler();
|
|
2217
|
-
/*! Bundled license information:
|
|
2218
|
-
|
|
2219
|
-
howler/dist/howler.js:
|
|
2220
|
-
(*!
|
|
2221
|
-
* howler.js v2.2.4
|
|
2222
|
-
* howlerjs.com
|
|
2223
|
-
*
|
|
2224
|
-
* (c) 2013-2020, James Simpson of GoldFire Studios
|
|
2225
|
-
* goldfirestudios.com
|
|
2226
|
-
*
|
|
2227
|
-
* MIT License
|
|
2228
|
-
*)
|
|
2229
|
-
(*!
|
|
2230
|
-
* Spatial Plugin - Adds support for stereo and 3D audio where Web Audio is supported.
|
|
2231
|
-
*
|
|
2232
|
-
* howler.js v2.2.4
|
|
2233
|
-
* howlerjs.com
|
|
2234
|
-
*
|
|
2235
|
-
* (c) 2013-2020, James Simpson of GoldFire Studios
|
|
2236
|
-
* goldfirestudios.com
|
|
2237
|
-
*
|
|
2238
|
-
* MIT License
|
|
2239
|
-
*)
|
|
2240
|
-
*/
|
|
2241
|
-
//# sourceMappingURL=howler.js.map
|