@eva/plugin-sound 2.0.0-beta.1 → 2.0.0-beta.2
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 +180 -368
- package/dist/EVA.plugin.sound.min.js +1 -1
- package/dist/plugin-sound.cjs.js +186 -301
- package/dist/plugin-sound.cjs.prod.js +2 -2
- package/dist/plugin-sound.esm.js +187 -302
- package/package.json +2 -2
package/dist/EVA.plugin.sound.js
CHANGED
|
@@ -3,23 +3,6 @@ window.EVA = window.EVA || {};
|
|
|
3
3
|
window.EVA.plugin = window.EVA.plugin || {};
|
|
4
4
|
var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
5
5
|
'use strict';
|
|
6
|
-
var extendStatics = function (d, b) {
|
|
7
|
-
extendStatics = Object.setPrototypeOf || {
|
|
8
|
-
__proto__: []
|
|
9
|
-
} instanceof Array && function (d, b) {
|
|
10
|
-
d.__proto__ = b;
|
|
11
|
-
} || function (d, b) {
|
|
12
|
-
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
13
|
-
};
|
|
14
|
-
return extendStatics(d, b);
|
|
15
|
-
};
|
|
16
|
-
function __extends(d, b) {
|
|
17
|
-
extendStatics(d, b);
|
|
18
|
-
function __() {
|
|
19
|
-
this.constructor = d;
|
|
20
|
-
}
|
|
21
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
22
|
-
}
|
|
23
6
|
function __decorate(decorators, target, key, desc) {
|
|
24
7
|
var c = arguments.length,
|
|
25
8
|
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
@@ -54,224 +37,90 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
54
37
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
55
38
|
});
|
|
56
39
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
},
|
|
67
|
-
f,
|
|
68
|
-
y,
|
|
69
|
-
t,
|
|
70
|
-
g;
|
|
71
|
-
return g = {
|
|
72
|
-
next: verb(0),
|
|
73
|
-
"throw": verb(1),
|
|
74
|
-
"return": verb(2)
|
|
75
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
76
|
-
return this;
|
|
77
|
-
}), g;
|
|
78
|
-
function verb(n) {
|
|
79
|
-
return function (v) {
|
|
80
|
-
return step([n, v]);
|
|
81
|
-
};
|
|
40
|
+
let SoundSystem = class SoundSystem extends eva_js.System {
|
|
41
|
+
constructor(obj) {
|
|
42
|
+
super();
|
|
43
|
+
this.autoPauseAndStart = true;
|
|
44
|
+
this.components = [];
|
|
45
|
+
this.pausedComponents = [];
|
|
46
|
+
this.audioBufferCache = {};
|
|
47
|
+
this.decodeAudioPromiseMap = {};
|
|
48
|
+
_extends(this, obj);
|
|
82
49
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
case 0:
|
|
90
|
-
case 1:
|
|
91
|
-
t = op;
|
|
92
|
-
break;
|
|
93
|
-
case 4:
|
|
94
|
-
_.label++;
|
|
95
|
-
return {
|
|
96
|
-
value: op[1],
|
|
97
|
-
done: false
|
|
98
|
-
};
|
|
99
|
-
case 5:
|
|
100
|
-
_.label++;
|
|
101
|
-
y = op[1];
|
|
102
|
-
op = [0];
|
|
103
|
-
continue;
|
|
104
|
-
case 7:
|
|
105
|
-
op = _.ops.pop();
|
|
106
|
-
_.trys.pop();
|
|
107
|
-
continue;
|
|
108
|
-
default:
|
|
109
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
110
|
-
_ = 0;
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
114
|
-
_.label = op[1];
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
118
|
-
_.label = t[1];
|
|
119
|
-
t = op;
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
if (t && _.label < t[2]) {
|
|
123
|
-
_.label = t[2];
|
|
124
|
-
_.ops.push(op);
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
if (t[2]) _.ops.pop();
|
|
128
|
-
_.trys.pop();
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
op = body.call(thisArg, _);
|
|
132
|
-
} catch (e) {
|
|
133
|
-
op = [6, e];
|
|
134
|
-
y = 0;
|
|
135
|
-
} finally {
|
|
136
|
-
f = t = 0;
|
|
50
|
+
get muted() {
|
|
51
|
+
return this.gainNode ? this.gainNode.gain.value === 0 : false;
|
|
52
|
+
}
|
|
53
|
+
set muted(v) {
|
|
54
|
+
if (!this.gainNode) {
|
|
55
|
+
return;
|
|
137
56
|
}
|
|
138
|
-
|
|
139
|
-
return {
|
|
140
|
-
value: op[0] ? op[1] : void 0,
|
|
141
|
-
done: true
|
|
142
|
-
};
|
|
57
|
+
this.gainNode.gain.setValueAtTime(v ? 0 : 1, 0);
|
|
143
58
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (o && typeof o.length === "number") return {
|
|
151
|
-
next: function () {
|
|
152
|
-
if (o && i >= o.length) o = void 0;
|
|
153
|
-
return {
|
|
154
|
-
value: o && o[i++],
|
|
155
|
-
done: !o
|
|
156
|
-
};
|
|
59
|
+
get volume() {
|
|
60
|
+
return this.gainNode ? this.gainNode.gain.value : 1;
|
|
61
|
+
}
|
|
62
|
+
set volume(v) {
|
|
63
|
+
if (!this.gainNode || typeof v !== 'number' || v < 0 || v > 1) {
|
|
64
|
+
return;
|
|
157
65
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
_this.decodeAudioPromiseMap = {};
|
|
170
|
-
_extends(_this, obj);
|
|
171
|
-
return _this;
|
|
172
|
-
}
|
|
173
|
-
Object.defineProperty(SoundSystem.prototype, "muted", {
|
|
174
|
-
get: function () {
|
|
175
|
-
return this.gainNode ? this.gainNode.gain.value === 0 : false;
|
|
176
|
-
},
|
|
177
|
-
set: function (v) {
|
|
178
|
-
if (!this.gainNode) {
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
this.gainNode.gain.setValueAtTime(v ? 0 : 1, 0);
|
|
182
|
-
},
|
|
183
|
-
enumerable: false,
|
|
184
|
-
configurable: true
|
|
185
|
-
});
|
|
186
|
-
Object.defineProperty(SoundSystem.prototype, "volume", {
|
|
187
|
-
get: function () {
|
|
188
|
-
return this.gainNode ? this.gainNode.gain.value : 1;
|
|
189
|
-
},
|
|
190
|
-
set: function (v) {
|
|
191
|
-
if (!this.gainNode || typeof v !== 'number' || v < 0 || v > 1) {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
this.gainNode.gain.setValueAtTime(v, 0);
|
|
195
|
-
},
|
|
196
|
-
enumerable: false,
|
|
197
|
-
configurable: true
|
|
198
|
-
});
|
|
199
|
-
Object.defineProperty(SoundSystem.prototype, "audioLocked", {
|
|
200
|
-
get: function () {
|
|
201
|
-
if (!this.ctx) {
|
|
202
|
-
return true;
|
|
203
|
-
}
|
|
204
|
-
return this.ctx.state !== 'running';
|
|
205
|
-
},
|
|
206
|
-
enumerable: false,
|
|
207
|
-
configurable: true
|
|
208
|
-
});
|
|
209
|
-
SoundSystem.prototype.resumeAll = function () {
|
|
210
|
-
var _this = this;
|
|
211
|
-
var handleResume = function () {
|
|
212
|
-
_this.pausedComponents.forEach(function (component) {
|
|
66
|
+
this.gainNode.gain.setValueAtTime(v, 0);
|
|
67
|
+
}
|
|
68
|
+
get audioLocked() {
|
|
69
|
+
if (!this.ctx) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
return this.ctx.state !== 'running';
|
|
73
|
+
}
|
|
74
|
+
resumeAll() {
|
|
75
|
+
const handleResume = () => {
|
|
76
|
+
this.pausedComponents.forEach(component => {
|
|
213
77
|
component.play();
|
|
214
78
|
});
|
|
215
|
-
|
|
79
|
+
this.pausedComponents = [];
|
|
216
80
|
};
|
|
217
81
|
this.ctx.resume().then(handleResume, handleResume);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
this.components.forEach(function (component) {
|
|
82
|
+
}
|
|
83
|
+
pauseAll() {
|
|
84
|
+
this.components.forEach(component => {
|
|
222
85
|
if (component.playing) {
|
|
223
|
-
|
|
86
|
+
this.pausedComponents.push(component);
|
|
224
87
|
component.pause();
|
|
225
88
|
}
|
|
226
89
|
});
|
|
227
90
|
this.ctx.suspend().then();
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
this.components.forEach(
|
|
91
|
+
}
|
|
92
|
+
stopAll() {
|
|
93
|
+
this.components.forEach(component => {
|
|
231
94
|
if (component.playing) {
|
|
232
95
|
component.stop();
|
|
233
96
|
}
|
|
234
97
|
});
|
|
235
98
|
this.pausedComponents = [];
|
|
236
99
|
this.ctx.suspend().then();
|
|
237
|
-
}
|
|
238
|
-
|
|
100
|
+
}
|
|
101
|
+
init() {
|
|
239
102
|
this.setupAudioContext();
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
for (var changes_1 = __values(changes), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
|
|
246
|
-
var changed = changes_1_1.value;
|
|
247
|
-
this.componentChanged(changed);
|
|
248
|
-
}
|
|
249
|
-
} catch (e_1_1) {
|
|
250
|
-
e_1 = {
|
|
251
|
-
error: e_1_1
|
|
252
|
-
};
|
|
253
|
-
} finally {
|
|
254
|
-
try {
|
|
255
|
-
if (changes_1_1 && !changes_1_1.done && (_a = changes_1.return)) _a.call(changes_1);
|
|
256
|
-
} finally {
|
|
257
|
-
if (e_1) throw e_1.error;
|
|
258
|
-
}
|
|
103
|
+
}
|
|
104
|
+
update() {
|
|
105
|
+
const changes = this.componentObserver.clear();
|
|
106
|
+
for (const changed of changes) {
|
|
107
|
+
this.componentChanged(changed);
|
|
259
108
|
}
|
|
260
|
-
}
|
|
261
|
-
|
|
109
|
+
}
|
|
110
|
+
onResume() {
|
|
262
111
|
if (!this.autoPauseAndStart) {
|
|
263
112
|
return;
|
|
264
113
|
}
|
|
265
114
|
this.resumeAll();
|
|
266
|
-
}
|
|
267
|
-
|
|
115
|
+
}
|
|
116
|
+
onPause() {
|
|
268
117
|
if (!this.autoPauseAndStart) {
|
|
269
118
|
return;
|
|
270
119
|
}
|
|
271
120
|
this.pauseAll();
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
this.components.forEach(
|
|
121
|
+
}
|
|
122
|
+
onDestroy() {
|
|
123
|
+
this.components.forEach(component => {
|
|
275
124
|
component.onDestroy();
|
|
276
125
|
});
|
|
277
126
|
this.components = [];
|
|
@@ -281,22 +130,19 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
281
130
|
this.ctx.close();
|
|
282
131
|
this.ctx = null;
|
|
283
132
|
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
return [2];
|
|
293
|
-
});
|
|
133
|
+
}
|
|
134
|
+
componentChanged(changed) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
if (changed.componentName !== 'Sound') return;
|
|
137
|
+
if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
|
|
138
|
+
this.add(changed);
|
|
139
|
+
}
|
|
294
140
|
});
|
|
295
|
-
}
|
|
296
|
-
|
|
141
|
+
}
|
|
142
|
+
setupAudioContext() {
|
|
297
143
|
try {
|
|
298
|
-
|
|
299
|
-
this.ctx = new
|
|
144
|
+
const AudioContext = window.AudioContext || window.webkitAudioContext;
|
|
145
|
+
this.ctx = new AudioContext();
|
|
300
146
|
} catch (error) {
|
|
301
147
|
console.error(error);
|
|
302
148
|
if (this.onError) {
|
|
@@ -310,117 +156,96 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
310
156
|
this.gainNode.gain.setValueAtTime(this.muted ? 0 : this.volume, this.ctx.currentTime);
|
|
311
157
|
this.gainNode.connect(this.ctx.destination);
|
|
312
158
|
this.unlockAudio();
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
var _this = this;
|
|
159
|
+
}
|
|
160
|
+
unlockAudio() {
|
|
316
161
|
if (!this.ctx || !this.audioLocked) {
|
|
317
162
|
return;
|
|
318
163
|
}
|
|
319
|
-
|
|
320
|
-
if (
|
|
321
|
-
|
|
164
|
+
const unlock = () => {
|
|
165
|
+
if (this.ctx) {
|
|
166
|
+
const removeListenerFn = () => {
|
|
322
167
|
document.body.removeEventListener('touchstart', unlock);
|
|
323
168
|
document.body.removeEventListener('touchend', unlock);
|
|
324
169
|
document.body.removeEventListener('click', unlock);
|
|
325
170
|
};
|
|
326
|
-
|
|
171
|
+
this.ctx.resume().then(removeListenerFn, removeListenerFn);
|
|
327
172
|
}
|
|
328
173
|
};
|
|
329
174
|
document.body.addEventListener('touchstart', unlock);
|
|
330
175
|
document.body.addEventListener('touchend', unlock);
|
|
331
176
|
document.body.addEventListener('click', unlock);
|
|
332
|
-
}
|
|
333
|
-
|
|
177
|
+
}
|
|
178
|
+
add(changed) {
|
|
334
179
|
var _a;
|
|
335
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
component.state = 'loading';
|
|
347
|
-
return [4, eva_js.resource.getResource(config.resource)];
|
|
348
|
-
case 2:
|
|
349
|
-
audio = _d.sent();
|
|
350
|
-
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];
|
|
351
|
-
_b = this.audioBufferCache;
|
|
352
|
-
_c = audio.name;
|
|
353
|
-
return [4, this.decodeAudioData(audio.data.audio, audio.name)];
|
|
354
|
-
case 3:
|
|
355
|
-
_b[_c] = _d.sent();
|
|
356
|
-
_d.label = 4;
|
|
357
|
-
case 4:
|
|
358
|
-
if (this.audioBufferCache[audio.name]) {
|
|
359
|
-
component.systemContext = this.ctx;
|
|
360
|
-
component.systemDestination = this.gainNode;
|
|
361
|
-
component.onload(this.audioBufferCache[audio.name]);
|
|
362
|
-
}
|
|
363
|
-
return [3, 6];
|
|
364
|
-
case 5:
|
|
365
|
-
error_1 = _d.sent();
|
|
366
|
-
if (this.onError) {
|
|
367
|
-
this.onError(error_1);
|
|
368
|
-
}
|
|
369
|
-
return [3, 6];
|
|
370
|
-
case 6:
|
|
371
|
-
return [2];
|
|
180
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
const component = changed.component;
|
|
182
|
+
this.components.push(component);
|
|
183
|
+
try {
|
|
184
|
+
const {
|
|
185
|
+
config
|
|
186
|
+
} = component;
|
|
187
|
+
component.state = 'loading';
|
|
188
|
+
const audio = yield eva_js.resource.getResource(config.resource);
|
|
189
|
+
if (!this.audioBufferCache[audio.name] && ((_a = audio === null || audio === void 0 ? void 0 : audio.data) === null || _a === void 0 ? void 0 : _a.audio)) {
|
|
190
|
+
this.audioBufferCache[audio.name] = yield this.decodeAudioData(audio.data.audio, audio.name);
|
|
372
191
|
}
|
|
373
|
-
|
|
192
|
+
if (this.audioBufferCache[audio.name]) {
|
|
193
|
+
component.systemContext = this.ctx;
|
|
194
|
+
component.systemDestination = this.gainNode;
|
|
195
|
+
component.onload(this.audioBufferCache[audio.name]);
|
|
196
|
+
}
|
|
197
|
+
} catch (error) {
|
|
198
|
+
if (this.onError) {
|
|
199
|
+
this.onError(error);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
374
202
|
});
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
var _this = this;
|
|
203
|
+
}
|
|
204
|
+
decodeAudioData(arraybuffer, name) {
|
|
378
205
|
if (this.decodeAudioPromiseMap[name]) {
|
|
379
206
|
return this.decodeAudioPromiseMap[name];
|
|
380
207
|
}
|
|
381
|
-
|
|
382
|
-
if (!
|
|
208
|
+
const promise = new Promise((resolve, reject) => {
|
|
209
|
+
if (!this.ctx) {
|
|
383
210
|
reject(new Error('No audio support'));
|
|
384
211
|
}
|
|
385
|
-
|
|
386
|
-
if (
|
|
387
|
-
delete
|
|
212
|
+
const success = decodedData => {
|
|
213
|
+
if (this.decodeAudioPromiseMap[name]) {
|
|
214
|
+
delete this.decodeAudioPromiseMap[name];
|
|
388
215
|
}
|
|
389
216
|
if (decodedData) {
|
|
390
217
|
resolve(decodedData);
|
|
391
218
|
} else {
|
|
392
|
-
reject(new Error(
|
|
219
|
+
reject(new Error(`Error decoding audio ${name}`));
|
|
393
220
|
}
|
|
394
221
|
};
|
|
395
|
-
|
|
396
|
-
if (
|
|
397
|
-
delete
|
|
222
|
+
const error = err => {
|
|
223
|
+
if (this.decodeAudioPromiseMap[name]) {
|
|
224
|
+
delete this.decodeAudioPromiseMap[name];
|
|
398
225
|
}
|
|
399
|
-
reject(new Error(err
|
|
226
|
+
reject(new Error(`${err}. arrayBuffer byteLength: ${arraybuffer ? arraybuffer.byteLength : 0}`));
|
|
400
227
|
};
|
|
401
|
-
|
|
228
|
+
const promise = this.ctx.decodeAudioData(arraybuffer, success, error);
|
|
402
229
|
if (promise instanceof Promise) {
|
|
403
|
-
promise.catch(
|
|
404
|
-
reject(new Error(
|
|
230
|
+
promise.catch(err => {
|
|
231
|
+
reject(new Error(`catch ${err}, arrayBuffer byteLength: ${arraybuffer ? arraybuffer.byteLength : 0}`));
|
|
405
232
|
});
|
|
406
233
|
}
|
|
407
234
|
});
|
|
408
235
|
this.decodeAudioPromiseMap[name] = promise;
|
|
409
236
|
return promise;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
}(eva_js.System);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
SoundSystem.systemName = 'SoundSystem';
|
|
240
|
+
SoundSystem = __decorate([eva_js.decorators.componentObserver({
|
|
241
|
+
Sound: []
|
|
242
|
+
})], SoundSystem);
|
|
417
243
|
var SoundSystem$1 = SoundSystem;
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
_this.config = {
|
|
244
|
+
class Sound extends eva_js.Component {
|
|
245
|
+
constructor() {
|
|
246
|
+
super(...arguments);
|
|
247
|
+
this.state = 'unloaded';
|
|
248
|
+
this.config = {
|
|
424
249
|
resource: '',
|
|
425
250
|
autoplay: false,
|
|
426
251
|
muted: false,
|
|
@@ -428,43 +253,34 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
428
253
|
loop: false,
|
|
429
254
|
seek: 0
|
|
430
255
|
};
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
if (!this.gainNode) {
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
this.gainNode.gain.setValueAtTime(v, 0);
|
|
463
|
-
},
|
|
464
|
-
enumerable: false,
|
|
465
|
-
configurable: true
|
|
466
|
-
});
|
|
467
|
-
Sound.prototype.init = function (obj) {
|
|
256
|
+
this.playTime = 0;
|
|
257
|
+
this.startTime = 0;
|
|
258
|
+
this.duration = 0;
|
|
259
|
+
this.actionQueue = [];
|
|
260
|
+
}
|
|
261
|
+
get muted() {
|
|
262
|
+
return this.gainNode ? this.gainNode.gain.value === 0 : false;
|
|
263
|
+
}
|
|
264
|
+
set muted(v) {
|
|
265
|
+
if (!this.gainNode) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
this.gainNode.gain.setValueAtTime(v ? 0 : this.config.volume, 0);
|
|
269
|
+
}
|
|
270
|
+
get volume() {
|
|
271
|
+
return this.gainNode ? this.gainNode.gain.value : 1;
|
|
272
|
+
}
|
|
273
|
+
set volume(v) {
|
|
274
|
+
if (typeof v !== 'number' || v < 0 || v > 1) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
this.config.volume = v;
|
|
278
|
+
if (!this.gainNode) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
this.gainNode.gain.setValueAtTime(v, 0);
|
|
282
|
+
}
|
|
283
|
+
init(obj) {
|
|
468
284
|
if (!obj) {
|
|
469
285
|
return;
|
|
470
286
|
}
|
|
@@ -472,9 +288,8 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
472
288
|
if (this.config.autoplay) {
|
|
473
289
|
this.actionQueue.push(this.play.bind(this));
|
|
474
290
|
}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
var _this = this;
|
|
291
|
+
}
|
|
292
|
+
play() {
|
|
478
293
|
if (this.state !== 'loaded') {
|
|
479
294
|
this.actionQueue.push(this.play.bind(this));
|
|
480
295
|
}
|
|
@@ -483,29 +298,29 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
483
298
|
if (!this.sourceNode) {
|
|
484
299
|
return;
|
|
485
300
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
301
|
+
const when = this.systemContext.currentTime;
|
|
302
|
+
const offset = this.config.seek;
|
|
303
|
+
const duration = this.config.duration;
|
|
489
304
|
this.sourceNode.start(0, offset, duration);
|
|
490
305
|
this.startTime = when;
|
|
491
306
|
this.playTime = when - offset;
|
|
492
307
|
this.paused = false;
|
|
493
308
|
this.playing = true;
|
|
494
309
|
this.resetConfig();
|
|
495
|
-
this.endedListener =
|
|
496
|
-
if (!
|
|
310
|
+
this.endedListener = () => {
|
|
311
|
+
if (!this.sourceNode) {
|
|
497
312
|
return;
|
|
498
313
|
}
|
|
499
|
-
if (
|
|
500
|
-
|
|
314
|
+
if (this.config.onEnd) {
|
|
315
|
+
this.config.onEnd();
|
|
501
316
|
}
|
|
502
|
-
if (
|
|
503
|
-
|
|
317
|
+
if (this.playing) {
|
|
318
|
+
this.destroySource();
|
|
504
319
|
}
|
|
505
320
|
};
|
|
506
321
|
this.sourceNode.addEventListener('ended', this.endedListener);
|
|
507
|
-
}
|
|
508
|
-
|
|
322
|
+
}
|
|
323
|
+
pause() {
|
|
509
324
|
if (this.state !== 'loaded') {
|
|
510
325
|
this.actionQueue.push(this.pause.bind(this));
|
|
511
326
|
}
|
|
@@ -516,8 +331,8 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
516
331
|
this.playing = false;
|
|
517
332
|
this.config.seek = this.getCurrentTime();
|
|
518
333
|
this.destroySource();
|
|
519
|
-
}
|
|
520
|
-
|
|
334
|
+
}
|
|
335
|
+
stop() {
|
|
521
336
|
if (this.state !== 'loaded') {
|
|
522
337
|
this.actionQueue.push(this.stop.bind(this));
|
|
523
338
|
}
|
|
@@ -528,30 +343,28 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
528
343
|
this.paused = false;
|
|
529
344
|
this.destroySource();
|
|
530
345
|
this.resetConfig();
|
|
531
|
-
}
|
|
532
|
-
|
|
346
|
+
}
|
|
347
|
+
onload(buffer) {
|
|
533
348
|
this.state = 'loaded';
|
|
534
349
|
this.buffer = buffer;
|
|
535
350
|
this.duration = this.buffer.duration;
|
|
536
|
-
this.actionQueue.forEach(
|
|
537
|
-
return action();
|
|
538
|
-
});
|
|
351
|
+
this.actionQueue.forEach(action => action());
|
|
539
352
|
this.actionQueue.length = 0;
|
|
540
|
-
}
|
|
541
|
-
|
|
353
|
+
}
|
|
354
|
+
onDestroy() {
|
|
542
355
|
this.actionQueue.length = 0;
|
|
543
356
|
this.destroySource();
|
|
544
|
-
}
|
|
545
|
-
|
|
357
|
+
}
|
|
358
|
+
resetConfig() {
|
|
546
359
|
this.config.seek = 0;
|
|
547
|
-
}
|
|
548
|
-
|
|
360
|
+
}
|
|
361
|
+
getCurrentTime() {
|
|
549
362
|
if (this.config.loop && this.duration > 0) {
|
|
550
363
|
return (this.systemContext.currentTime - this.playTime) % this.duration;
|
|
551
364
|
}
|
|
552
365
|
return this.systemContext.currentTime - this.playTime;
|
|
553
|
-
}
|
|
554
|
-
|
|
366
|
+
}
|
|
367
|
+
createSource() {
|
|
555
368
|
if (!this.systemContext || this.state !== 'loaded') {
|
|
556
369
|
return;
|
|
557
370
|
}
|
|
@@ -564,8 +377,8 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
564
377
|
_extends(this, this.config);
|
|
565
378
|
}
|
|
566
379
|
this.sourceNode.connect(this.gainNode);
|
|
567
|
-
}
|
|
568
|
-
|
|
380
|
+
}
|
|
381
|
+
destroySource() {
|
|
569
382
|
if (!this.sourceNode) return;
|
|
570
383
|
this.sourceNode.removeEventListener('ended', this.endedListener);
|
|
571
384
|
this.sourceNode.stop();
|
|
@@ -574,10 +387,9 @@ var _EVA_IIFE_sound = function (exports, eva_js) {
|
|
|
574
387
|
this.startTime = 0;
|
|
575
388
|
this.playTime = 0;
|
|
576
389
|
this.playing = false;
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
}(eva_js.Component);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
Sound.componentName = 'Sound';
|
|
581
393
|
var Sound$1 = Sound;
|
|
582
394
|
exports.Sound = Sound$1;
|
|
583
395
|
exports.SoundSystem = SoundSystem$1;
|