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