@eva/plugin-sound 1.2.7-fix.4 → 1.2.7-fix.6
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/EVA.plugin.sound.js +153 -16
- package/dist/EVA.plugin.sound.js.map +1 -0
- package/dist/EVA.plugin.sound.min.js +1 -1
- package/dist/miniprogram.js +104 -1
- package/dist/plugin-sound.cjs.js.map +1 -0
- package/dist/plugin-sound.cjs.prod.js +2 -2
- package/dist/plugin-sound.esm.js.map +1 -0
- package/package.json +2 -2
package/dist/EVA.plugin.sound.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
2
3
|
window.EVA = window.EVA || {};
|
|
3
4
|
window.EVA.plugin = window.EVA.plugin || {};
|
|
5
|
+
|
|
4
6
|
var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
5
7
|
'use strict';
|
|
6
8
|
|
|
@@ -14,30 +16,37 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
14
16
|
if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
15
17
|
}
|
|
16
18
|
};
|
|
19
|
+
|
|
17
20
|
return _extendStatics(d, b);
|
|
18
21
|
};
|
|
22
|
+
|
|
19
23
|
function __extends(d, b) {
|
|
20
24
|
_extendStatics(d, b);
|
|
25
|
+
|
|
21
26
|
function __() {
|
|
22
27
|
this.constructor = d;
|
|
23
28
|
}
|
|
29
|
+
|
|
24
30
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
25
31
|
}
|
|
32
|
+
|
|
26
33
|
function __decorate(decorators, target, key, desc) {
|
|
27
34
|
var c = arguments.length,
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
36
|
+
d;
|
|
30
37
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
|
|
31
38
|
if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
32
39
|
}
|
|
33
40
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
34
41
|
}
|
|
42
|
+
|
|
35
43
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
36
44
|
function adopt(value) {
|
|
37
45
|
return value instanceof P ? value : new P(function (resolve) {
|
|
38
46
|
resolve(value);
|
|
39
47
|
});
|
|
40
48
|
}
|
|
49
|
+
|
|
41
50
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
42
51
|
function fulfilled(value) {
|
|
43
52
|
try {
|
|
@@ -46,6 +55,7 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
46
55
|
reject(e);
|
|
47
56
|
}
|
|
48
57
|
}
|
|
58
|
+
|
|
49
59
|
function rejected(value) {
|
|
50
60
|
try {
|
|
51
61
|
step(generator["throw"](value));
|
|
@@ -53,26 +63,29 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
53
63
|
reject(e);
|
|
54
64
|
}
|
|
55
65
|
}
|
|
66
|
+
|
|
56
67
|
function step(result) {
|
|
57
68
|
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
58
69
|
}
|
|
70
|
+
|
|
59
71
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
60
72
|
});
|
|
61
73
|
}
|
|
74
|
+
|
|
62
75
|
function __generator(thisArg, body) {
|
|
63
76
|
var _ = {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
},
|
|
69
|
-
trys: [],
|
|
70
|
-
ops: []
|
|
77
|
+
label: 0,
|
|
78
|
+
sent: function sent() {
|
|
79
|
+
if (t[0] & 1) throw t[1];
|
|
80
|
+
return t[1];
|
|
71
81
|
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
82
|
+
trys: [],
|
|
83
|
+
ops: []
|
|
84
|
+
},
|
|
85
|
+
f,
|
|
86
|
+
y,
|
|
87
|
+
t,
|
|
88
|
+
g;
|
|
76
89
|
return g = {
|
|
77
90
|
next: verb(0),
|
|
78
91
|
"throw": verb(1),
|
|
@@ -80,60 +93,79 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
80
93
|
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
81
94
|
return this;
|
|
82
95
|
}), g;
|
|
96
|
+
|
|
83
97
|
function verb(n) {
|
|
84
98
|
return function (v) {
|
|
85
99
|
return step([n, v]);
|
|
86
100
|
};
|
|
87
101
|
}
|
|
102
|
+
|
|
88
103
|
function step(op) {
|
|
89
104
|
if (f) throw new TypeError("Generator is already executing.");
|
|
105
|
+
|
|
90
106
|
while (_) {
|
|
91
107
|
try {
|
|
92
108
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
93
109
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
110
|
+
|
|
94
111
|
switch (op[0]) {
|
|
95
112
|
case 0:
|
|
96
113
|
case 1:
|
|
97
114
|
t = op;
|
|
98
115
|
break;
|
|
116
|
+
|
|
99
117
|
case 4:
|
|
100
118
|
_.label++;
|
|
101
119
|
return {
|
|
102
120
|
value: op[1],
|
|
103
121
|
done: false
|
|
104
122
|
};
|
|
123
|
+
|
|
105
124
|
case 5:
|
|
106
125
|
_.label++;
|
|
107
126
|
y = op[1];
|
|
108
127
|
op = [0];
|
|
109
128
|
continue;
|
|
129
|
+
|
|
110
130
|
case 7:
|
|
111
131
|
op = _.ops.pop();
|
|
132
|
+
|
|
112
133
|
_.trys.pop();
|
|
134
|
+
|
|
113
135
|
continue;
|
|
136
|
+
|
|
114
137
|
default:
|
|
115
138
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
116
139
|
_ = 0;
|
|
117
140
|
continue;
|
|
118
141
|
}
|
|
142
|
+
|
|
119
143
|
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
120
144
|
_.label = op[1];
|
|
121
145
|
break;
|
|
122
146
|
}
|
|
147
|
+
|
|
123
148
|
if (op[0] === 6 && _.label < t[1]) {
|
|
124
149
|
_.label = t[1];
|
|
125
150
|
t = op;
|
|
126
151
|
break;
|
|
127
152
|
}
|
|
153
|
+
|
|
128
154
|
if (t && _.label < t[2]) {
|
|
129
155
|
_.label = t[2];
|
|
156
|
+
|
|
130
157
|
_.ops.push(op);
|
|
158
|
+
|
|
131
159
|
break;
|
|
132
160
|
}
|
|
161
|
+
|
|
133
162
|
if (t[2]) _.ops.pop();
|
|
163
|
+
|
|
134
164
|
_.trys.pop();
|
|
165
|
+
|
|
135
166
|
continue;
|
|
136
167
|
}
|
|
168
|
+
|
|
137
169
|
op = body.call(thisArg, _);
|
|
138
170
|
} catch (e) {
|
|
139
171
|
op = [6, e];
|
|
@@ -142,6 +174,7 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
142
174
|
f = t = 0;
|
|
143
175
|
}
|
|
144
176
|
}
|
|
177
|
+
|
|
145
178
|
if (op[0] & 5) throw op[1];
|
|
146
179
|
return {
|
|
147
180
|
value: op[0] ? op[1] : void 0,
|
|
@@ -149,10 +182,11 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
149
182
|
};
|
|
150
183
|
}
|
|
151
184
|
}
|
|
185
|
+
|
|
152
186
|
function __values(o) {
|
|
153
187
|
var s = typeof Symbol === "function" && Symbol.iterator,
|
|
154
|
-
|
|
155
|
-
|
|
188
|
+
m = s && o[s],
|
|
189
|
+
i = 0;
|
|
156
190
|
if (m) return m.call(o);
|
|
157
191
|
if (o && typeof o.length === "number") return {
|
|
158
192
|
next: function next() {
|
|
@@ -165,18 +199,24 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
165
199
|
};
|
|
166
200
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
167
201
|
}
|
|
202
|
+
|
|
168
203
|
var SoundSystem = function (_super) {
|
|
169
204
|
__extends(SoundSystem, _super);
|
|
205
|
+
|
|
170
206
|
function SoundSystem(obj) {
|
|
171
207
|
var _this = _super.call(this) || this;
|
|
208
|
+
|
|
172
209
|
_this.autoPauseAndStart = true;
|
|
173
210
|
_this.components = [];
|
|
174
211
|
_this.pausedComponents = [];
|
|
175
212
|
_this.audioBufferCache = {};
|
|
176
213
|
_this.decodeAudioPromiseMap = {};
|
|
214
|
+
|
|
177
215
|
_extends(_this, obj);
|
|
216
|
+
|
|
178
217
|
return _this;
|
|
179
218
|
}
|
|
219
|
+
|
|
180
220
|
Object.defineProperty(SoundSystem.prototype, "muted", {
|
|
181
221
|
get: function get() {
|
|
182
222
|
return this.gainNode ? this.gainNode.gain.value === 0 : false;
|
|
@@ -185,6 +225,7 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
185
225
|
if (!this.gainNode) {
|
|
186
226
|
return;
|
|
187
227
|
}
|
|
228
|
+
|
|
188
229
|
this.gainNode.gain.setValueAtTime(v ? 0 : 1, 0);
|
|
189
230
|
},
|
|
190
231
|
enumerable: false,
|
|
@@ -198,6 +239,7 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
198
239
|
if (!this.gainNode || typeof v !== 'number' || v < 0 || v > 1) {
|
|
199
240
|
return;
|
|
200
241
|
}
|
|
242
|
+
|
|
201
243
|
this.gainNode.gain.setValueAtTime(v, 0);
|
|
202
244
|
},
|
|
203
245
|
enumerable: false,
|
|
@@ -208,31 +250,40 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
208
250
|
if (!this.ctx) {
|
|
209
251
|
return true;
|
|
210
252
|
}
|
|
253
|
+
|
|
211
254
|
return this.ctx.state !== 'running';
|
|
212
255
|
},
|
|
213
256
|
enumerable: false,
|
|
214
257
|
configurable: true
|
|
215
258
|
});
|
|
259
|
+
|
|
216
260
|
SoundSystem.prototype.resumeAll = function () {
|
|
217
261
|
var _this = this;
|
|
262
|
+
|
|
218
263
|
var handleResume = function handleResume() {
|
|
219
264
|
_this.pausedComponents.forEach(function (component) {
|
|
220
265
|
component.play();
|
|
221
266
|
});
|
|
267
|
+
|
|
222
268
|
_this.pausedComponents = [];
|
|
223
269
|
};
|
|
270
|
+
|
|
224
271
|
this.ctx.resume().then(handleResume, handleResume);
|
|
225
272
|
};
|
|
273
|
+
|
|
226
274
|
SoundSystem.prototype.pauseAll = function () {
|
|
227
275
|
var _this = this;
|
|
276
|
+
|
|
228
277
|
this.components.forEach(function (component) {
|
|
229
278
|
if (component.playing) {
|
|
230
279
|
_this.pausedComponents.push(component);
|
|
280
|
+
|
|
231
281
|
component.pause();
|
|
232
282
|
}
|
|
233
283
|
});
|
|
234
284
|
this.ctx.suspend().then();
|
|
235
285
|
};
|
|
286
|
+
|
|
236
287
|
SoundSystem.prototype.stopAll = function () {
|
|
237
288
|
this.components.forEach(function (component) {
|
|
238
289
|
if (component.playing) {
|
|
@@ -242,12 +293,16 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
242
293
|
this.pausedComponents = [];
|
|
243
294
|
this.ctx.suspend().then();
|
|
244
295
|
};
|
|
296
|
+
|
|
245
297
|
SoundSystem.prototype.init = function () {
|
|
246
298
|
this.setupAudioContext();
|
|
247
299
|
};
|
|
300
|
+
|
|
248
301
|
SoundSystem.prototype.update = function () {
|
|
249
302
|
var e_1, _a;
|
|
303
|
+
|
|
250
304
|
var changes = this.componentObserver.clear();
|
|
305
|
+
|
|
251
306
|
try {
|
|
252
307
|
for (var changes_1 = __values(changes), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
|
|
253
308
|
var changed = changes_1_1.value;
|
|
@@ -265,23 +320,29 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
265
320
|
}
|
|
266
321
|
}
|
|
267
322
|
};
|
|
323
|
+
|
|
268
324
|
SoundSystem.prototype.onResume = function () {
|
|
269
325
|
if (!this.autoPauseAndStart) {
|
|
270
326
|
return;
|
|
271
327
|
}
|
|
328
|
+
|
|
272
329
|
this.resumeAll();
|
|
273
330
|
};
|
|
331
|
+
|
|
274
332
|
SoundSystem.prototype.onPause = function () {
|
|
275
333
|
if (!this.autoPauseAndStart) {
|
|
276
334
|
return;
|
|
277
335
|
}
|
|
336
|
+
|
|
278
337
|
this.pauseAll();
|
|
279
338
|
};
|
|
339
|
+
|
|
280
340
|
SoundSystem.prototype.onDestroy = function () {
|
|
281
341
|
this.components.forEach(function (component) {
|
|
282
342
|
component.onDestroy();
|
|
283
343
|
});
|
|
284
344
|
this.components = [];
|
|
345
|
+
|
|
285
346
|
if (this.ctx) {
|
|
286
347
|
this.gainNode.disconnect();
|
|
287
348
|
this.gainNode = null;
|
|
@@ -289,40 +350,50 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
289
350
|
this.ctx = null;
|
|
290
351
|
}
|
|
291
352
|
};
|
|
353
|
+
|
|
292
354
|
SoundSystem.prototype.componentChanged = function (changed) {
|
|
293
355
|
return __awaiter(this, void 0, void 0, function () {
|
|
294
356
|
return __generator(this, function (_a) {
|
|
295
357
|
if (changed.componentName !== 'Sound') return [2];
|
|
358
|
+
|
|
296
359
|
if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
|
|
297
360
|
this.add(changed);
|
|
298
361
|
}
|
|
362
|
+
|
|
299
363
|
return [2];
|
|
300
364
|
});
|
|
301
365
|
});
|
|
302
366
|
};
|
|
367
|
+
|
|
303
368
|
SoundSystem.prototype.setupAudioContext = function () {
|
|
304
369
|
try {
|
|
305
370
|
var AudioContext_1 = window.AudioContext || window.webkitAudioContext;
|
|
306
371
|
this.ctx = new AudioContext_1();
|
|
307
372
|
} catch (error) {
|
|
308
373
|
console.error(error);
|
|
374
|
+
|
|
309
375
|
if (this.onError) {
|
|
310
376
|
this.onError(error);
|
|
311
377
|
}
|
|
312
378
|
}
|
|
379
|
+
|
|
313
380
|
if (!this.ctx) {
|
|
314
381
|
return;
|
|
315
382
|
}
|
|
383
|
+
|
|
316
384
|
this.gainNode = typeof this.ctx.createGain === 'undefined' ? this.ctx.createGainNode() : this.ctx.createGain();
|
|
317
385
|
this.gainNode.gain.setValueAtTime(this.muted ? 0 : this.volume, this.ctx.currentTime);
|
|
318
386
|
this.gainNode.connect(this.ctx.destination);
|
|
319
387
|
this.unlockAudio();
|
|
320
388
|
};
|
|
389
|
+
|
|
321
390
|
SoundSystem.prototype.unlockAudio = function () {
|
|
322
391
|
var _this = this;
|
|
392
|
+
|
|
323
393
|
if (!this.ctx || !this.audioLocked) {
|
|
324
394
|
return;
|
|
325
395
|
}
|
|
396
|
+
|
|
326
397
|
var unlock = function unlock() {
|
|
327
398
|
if (_this.ctx) {
|
|
328
399
|
var removeListenerFn = function removeListenerFn() {
|
|
@@ -330,82 +401,106 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
330
401
|
document.body.removeEventListener('touchend', unlock);
|
|
331
402
|
document.body.removeEventListener('click', unlock);
|
|
332
403
|
};
|
|
404
|
+
|
|
333
405
|
_this.ctx.resume().then(removeListenerFn, removeListenerFn);
|
|
334
406
|
}
|
|
335
407
|
};
|
|
408
|
+
|
|
336
409
|
document.body.addEventListener('touchstart', unlock);
|
|
337
410
|
document.body.addEventListener('touchend', unlock);
|
|
338
411
|
document.body.addEventListener('click', unlock);
|
|
339
412
|
};
|
|
413
|
+
|
|
340
414
|
SoundSystem.prototype.add = function (changed) {
|
|
341
415
|
var _a;
|
|
416
|
+
|
|
342
417
|
return __awaiter(this, void 0, void 0, function () {
|
|
343
418
|
var component, config, audio, _b, _c, error_1;
|
|
419
|
+
|
|
344
420
|
return __generator(this, function (_d) {
|
|
345
421
|
switch (_d.label) {
|
|
346
422
|
case 0:
|
|
347
423
|
component = changed.component;
|
|
348
424
|
this.components.push(component);
|
|
349
425
|
_d.label = 1;
|
|
426
|
+
|
|
350
427
|
case 1:
|
|
351
428
|
_d.trys.push([1, 5,, 6]);
|
|
429
|
+
|
|
352
430
|
config = component.config;
|
|
353
431
|
component.state = 'loading';
|
|
354
432
|
return [4, eva_js.resource.getResource(config.resource)];
|
|
433
|
+
|
|
355
434
|
case 2:
|
|
356
435
|
audio = _d.sent();
|
|
357
436
|
if (!(!this.audioBufferCache[audio.name] && ((_a = audio === null || audio === void 0 ? void 0 : audio.data) === null || _a === void 0 ? void 0 : _a.audio))) return [3, 4];
|
|
358
437
|
_b = this.audioBufferCache;
|
|
359
438
|
_c = audio.name;
|
|
360
439
|
return [4, this.decodeAudioData(audio.data.audio, audio.name)];
|
|
440
|
+
|
|
361
441
|
case 3:
|
|
362
442
|
_b[_c] = _d.sent();
|
|
363
443
|
_d.label = 4;
|
|
444
|
+
|
|
364
445
|
case 4:
|
|
365
446
|
if (this.audioBufferCache[audio.name]) {
|
|
366
447
|
component.systemContext = this.ctx;
|
|
367
448
|
component.systemDestination = this.gainNode;
|
|
368
449
|
component.onload(this.audioBufferCache[audio.name]);
|
|
369
450
|
}
|
|
451
|
+
|
|
370
452
|
return [3, 6];
|
|
453
|
+
|
|
371
454
|
case 5:
|
|
372
455
|
error_1 = _d.sent();
|
|
456
|
+
|
|
373
457
|
if (this.onError) {
|
|
374
458
|
this.onError(error_1);
|
|
375
459
|
}
|
|
460
|
+
|
|
376
461
|
return [3, 6];
|
|
462
|
+
|
|
377
463
|
case 6:
|
|
378
464
|
return [2];
|
|
379
465
|
}
|
|
380
466
|
});
|
|
381
467
|
});
|
|
382
468
|
};
|
|
469
|
+
|
|
383
470
|
SoundSystem.prototype.decodeAudioData = function (arraybuffer, name) {
|
|
384
471
|
var _this = this;
|
|
472
|
+
|
|
385
473
|
if (this.decodeAudioPromiseMap[name]) {
|
|
386
474
|
return this.decodeAudioPromiseMap[name];
|
|
387
475
|
}
|
|
476
|
+
|
|
388
477
|
var promise = new Promise(function (resolve, reject) {
|
|
389
478
|
if (!_this.ctx) {
|
|
390
479
|
reject(new Error('No audio support'));
|
|
391
480
|
}
|
|
481
|
+
|
|
392
482
|
var success = function success(decodedData) {
|
|
393
483
|
if (_this.decodeAudioPromiseMap[name]) {
|
|
394
484
|
delete _this.decodeAudioPromiseMap[name];
|
|
395
485
|
}
|
|
486
|
+
|
|
396
487
|
if (decodedData) {
|
|
397
488
|
resolve(decodedData);
|
|
398
489
|
} else {
|
|
399
490
|
reject(new Error("Error decoding audio " + name));
|
|
400
491
|
}
|
|
401
492
|
};
|
|
493
|
+
|
|
402
494
|
var error = function error(err) {
|
|
403
495
|
if (_this.decodeAudioPromiseMap[name]) {
|
|
404
496
|
delete _this.decodeAudioPromiseMap[name];
|
|
405
497
|
}
|
|
498
|
+
|
|
406
499
|
reject(new Error(err + ". arrayBuffer byteLength: " + (arraybuffer ? arraybuffer.byteLength : 0)));
|
|
407
500
|
};
|
|
501
|
+
|
|
408
502
|
var promise = _this.ctx.decodeAudioData(arraybuffer, success, error);
|
|
503
|
+
|
|
409
504
|
if (promise instanceof Promise) {
|
|
410
505
|
promise.catch(function (err) {
|
|
411
506
|
reject(new Error("catch " + err + ", arrayBuffer byteLength: " + (arraybuffer ? arraybuffer.byteLength : 0)));
|
|
@@ -415,17 +510,22 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
415
510
|
this.decodeAudioPromiseMap[name] = promise;
|
|
416
511
|
return promise;
|
|
417
512
|
};
|
|
513
|
+
|
|
418
514
|
SoundSystem.systemName = 'SoundSystem';
|
|
419
515
|
SoundSystem = __decorate([eva_js.decorators.componentObserver({
|
|
420
516
|
Sound: []
|
|
421
517
|
})], SoundSystem);
|
|
422
518
|
return SoundSystem;
|
|
423
519
|
}(eva_js.System);
|
|
520
|
+
|
|
424
521
|
var SoundSystem$1 = SoundSystem;
|
|
522
|
+
|
|
425
523
|
var Sound = function (_super) {
|
|
426
524
|
__extends(Sound, _super);
|
|
525
|
+
|
|
427
526
|
function Sound() {
|
|
428
527
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
528
|
+
|
|
429
529
|
_this.state = 'unloaded';
|
|
430
530
|
_this.config = {
|
|
431
531
|
resource: '',
|
|
@@ -441,6 +541,7 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
441
541
|
_this.actionQueue = [];
|
|
442
542
|
return _this;
|
|
443
543
|
}
|
|
544
|
+
|
|
444
545
|
Object.defineProperty(Sound.prototype, "muted", {
|
|
445
546
|
get: function get() {
|
|
446
547
|
return this.gainNode ? this.gainNode.gain.value === 0 : false;
|
|
@@ -449,6 +550,7 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
449
550
|
if (!this.gainNode) {
|
|
450
551
|
return;
|
|
451
552
|
}
|
|
553
|
+
|
|
452
554
|
this.gainNode.gain.setValueAtTime(v ? 0 : this.config.volume, 0);
|
|
453
555
|
},
|
|
454
556
|
enumerable: false,
|
|
@@ -462,34 +564,45 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
462
564
|
if (typeof v !== 'number' || v < 0 || v > 1) {
|
|
463
565
|
return;
|
|
464
566
|
}
|
|
567
|
+
|
|
465
568
|
this.config.volume = v;
|
|
569
|
+
|
|
466
570
|
if (!this.gainNode) {
|
|
467
571
|
return;
|
|
468
572
|
}
|
|
573
|
+
|
|
469
574
|
this.gainNode.gain.setValueAtTime(v, 0);
|
|
470
575
|
},
|
|
471
576
|
enumerable: false,
|
|
472
577
|
configurable: true
|
|
473
578
|
});
|
|
579
|
+
|
|
474
580
|
Sound.prototype.init = function (obj) {
|
|
475
581
|
if (!obj) {
|
|
476
582
|
return;
|
|
477
583
|
}
|
|
584
|
+
|
|
478
585
|
_extends(this.config, obj);
|
|
586
|
+
|
|
479
587
|
if (this.config.autoplay) {
|
|
480
588
|
this.actionQueue.push(this.play.bind(this));
|
|
481
589
|
}
|
|
482
590
|
};
|
|
591
|
+
|
|
483
592
|
Sound.prototype.play = function () {
|
|
484
593
|
var _this = this;
|
|
594
|
+
|
|
485
595
|
if (this.state !== 'loaded') {
|
|
486
596
|
this.actionQueue.push(this.play.bind(this));
|
|
487
597
|
}
|
|
598
|
+
|
|
488
599
|
this.destroySource();
|
|
489
600
|
this.createSource();
|
|
601
|
+
|
|
490
602
|
if (!this.sourceNode) {
|
|
491
603
|
return;
|
|
492
604
|
}
|
|
605
|
+
|
|
493
606
|
var when = this.systemContext.currentTime;
|
|
494
607
|
var offset = this.config.seek;
|
|
495
608
|
var duration = this.config.duration;
|
|
@@ -499,43 +612,54 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
499
612
|
this.paused = false;
|
|
500
613
|
this.playing = true;
|
|
501
614
|
this.resetConfig();
|
|
615
|
+
|
|
502
616
|
this.endedListener = function () {
|
|
503
617
|
if (!_this.sourceNode) {
|
|
504
618
|
return;
|
|
505
619
|
}
|
|
620
|
+
|
|
506
621
|
if (_this.config.onEnd) {
|
|
507
622
|
_this.config.onEnd();
|
|
508
623
|
}
|
|
624
|
+
|
|
509
625
|
if (_this.playing) {
|
|
510
626
|
_this.destroySource();
|
|
511
627
|
}
|
|
512
628
|
};
|
|
629
|
+
|
|
513
630
|
this.sourceNode.addEventListener('ended', this.endedListener);
|
|
514
631
|
};
|
|
632
|
+
|
|
515
633
|
Sound.prototype.pause = function () {
|
|
516
634
|
if (this.state !== 'loaded') {
|
|
517
635
|
this.actionQueue.push(this.pause.bind(this));
|
|
518
636
|
}
|
|
637
|
+
|
|
519
638
|
if (this.paused || !this.playing) {
|
|
520
639
|
return;
|
|
521
640
|
}
|
|
641
|
+
|
|
522
642
|
this.paused = true;
|
|
523
643
|
this.playing = false;
|
|
524
644
|
this.config.seek = this.getCurrentTime();
|
|
525
645
|
this.destroySource();
|
|
526
646
|
};
|
|
647
|
+
|
|
527
648
|
Sound.prototype.stop = function () {
|
|
528
649
|
if (this.state !== 'loaded') {
|
|
529
650
|
this.actionQueue.push(this.stop.bind(this));
|
|
530
651
|
}
|
|
652
|
+
|
|
531
653
|
if (!this.paused && !this.playing) {
|
|
532
654
|
return;
|
|
533
655
|
}
|
|
656
|
+
|
|
534
657
|
this.playing = false;
|
|
535
658
|
this.paused = false;
|
|
536
659
|
this.destroySource();
|
|
537
660
|
this.resetConfig();
|
|
538
661
|
};
|
|
662
|
+
|
|
539
663
|
Sound.prototype.onload = function (buffer) {
|
|
540
664
|
this.state = 'loaded';
|
|
541
665
|
this.buffer = buffer;
|
|
@@ -545,33 +669,43 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
545
669
|
});
|
|
546
670
|
this.actionQueue.length = 0;
|
|
547
671
|
};
|
|
672
|
+
|
|
548
673
|
Sound.prototype.onDestroy = function () {
|
|
549
674
|
this.actionQueue.length = 0;
|
|
550
675
|
this.destroySource();
|
|
551
676
|
};
|
|
677
|
+
|
|
552
678
|
Sound.prototype.resetConfig = function () {
|
|
553
679
|
this.config.seek = 0;
|
|
554
680
|
};
|
|
681
|
+
|
|
555
682
|
Sound.prototype.getCurrentTime = function () {
|
|
556
683
|
if (this.config.loop && this.duration > 0) {
|
|
557
684
|
return (this.systemContext.currentTime - this.playTime) % this.duration;
|
|
558
685
|
}
|
|
686
|
+
|
|
559
687
|
return this.systemContext.currentTime - this.playTime;
|
|
560
688
|
};
|
|
689
|
+
|
|
561
690
|
Sound.prototype.createSource = function () {
|
|
562
691
|
if (!this.systemContext || this.state !== 'loaded') {
|
|
563
692
|
return;
|
|
564
693
|
}
|
|
694
|
+
|
|
565
695
|
this.sourceNode = this.systemContext.createBufferSource();
|
|
566
696
|
this.sourceNode.buffer = this.buffer;
|
|
567
697
|
this.sourceNode.loop = this.config.loop;
|
|
698
|
+
|
|
568
699
|
if (!this.gainNode) {
|
|
569
700
|
this.gainNode = this.systemContext.createGain();
|
|
570
701
|
this.gainNode.connect(this.systemDestination);
|
|
702
|
+
|
|
571
703
|
_extends(this, this.config);
|
|
572
704
|
}
|
|
705
|
+
|
|
573
706
|
this.sourceNode.connect(this.gainNode);
|
|
574
707
|
};
|
|
708
|
+
|
|
575
709
|
Sound.prototype.destroySource = function () {
|
|
576
710
|
if (!this.sourceNode) return;
|
|
577
711
|
this.sourceNode.removeEventListener('ended', this.endedListener);
|
|
@@ -582,9 +716,11 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
582
716
|
this.playTime = 0;
|
|
583
717
|
this.playing = false;
|
|
584
718
|
};
|
|
719
|
+
|
|
585
720
|
Sound.componentName = 'Sound';
|
|
586
721
|
return Sound;
|
|
587
722
|
}(eva_js.Component);
|
|
723
|
+
|
|
588
724
|
var Sound$1 = Sound;
|
|
589
725
|
exports.Sound = Sound$1;
|
|
590
726
|
exports.SoundSystem = SoundSystem$1;
|
|
@@ -593,4 +729,5 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
593
729
|
});
|
|
594
730
|
return exports;
|
|
595
731
|
}({}, EVA);
|
|
732
|
+
|
|
596
733
|
window.EVA.plugin.sound = window.EVA.plugin.sound || _EVA_IIFE_sound;
|