@urso/core 0.8.3 → 0.8.5-dev
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/package.json
CHANGED
package/src/js/extra/main.js
CHANGED
|
@@ -3,7 +3,6 @@ class SoundManagerController {
|
|
|
3
3
|
this._systemVolume = 1;
|
|
4
4
|
this._globalVolume = 0;
|
|
5
5
|
|
|
6
|
-
this._howler = null;
|
|
7
6
|
this._codecsToCheck = ['ogg', 'm4a', 'mp3', 'wav'];
|
|
8
7
|
this._selectedCodec = null;
|
|
9
8
|
this._sounds = {};
|
|
@@ -16,7 +15,7 @@ class SoundManagerController {
|
|
|
16
15
|
|
|
17
16
|
_setCodec() {
|
|
18
17
|
for (const codec of this._codecsToCheck) {
|
|
19
|
-
if (Howler.Howler.codecs(codec)) {
|
|
18
|
+
if (UrsoUtils.Howler.Howler.codecs(codec)) {
|
|
20
19
|
this._selectedCodec = codec;
|
|
21
20
|
return;
|
|
22
21
|
}
|
|
@@ -36,7 +35,8 @@ class SoundManagerController {
|
|
|
36
35
|
const soundSptite = this.getInstance('SoundSprite', {
|
|
37
36
|
sprite: json.sprite,
|
|
38
37
|
name: soundKey,
|
|
39
|
-
audiosprite
|
|
38
|
+
audiosprite,
|
|
39
|
+
codec: this._selectedCodec
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
this._sounds[soundKey] = soundSptite;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
const DUMMY_SOUND_DELAY = 500; // ms
|
|
2
2
|
class SoundSprite {
|
|
3
|
-
constructor({ name, sprite, audiosprite }) {
|
|
3
|
+
constructor({ name, sprite, audiosprite, codec }) {
|
|
4
4
|
this._player = null;
|
|
5
5
|
this._totalVolume = 0;
|
|
6
6
|
this._makePlayer(sprite, audiosprite);
|
|
7
7
|
|
|
8
8
|
this._name = name;
|
|
9
9
|
this._sprite = sprite;
|
|
10
|
+
this._codec = codec;
|
|
10
11
|
|
|
11
12
|
this._soundsState = this._initSoundsState();
|
|
12
13
|
|
|
@@ -14,9 +15,11 @@ class SoundSprite {
|
|
|
14
15
|
this._fadeTweens = {};
|
|
15
16
|
this._eventsQueue = [];
|
|
16
17
|
this._isAudioUnlocked = false;
|
|
17
|
-
this._reactToEvent = this._reactToEvent.bind(this);
|
|
18
18
|
this._timeout = null;
|
|
19
19
|
this._dummy = null;
|
|
20
|
+
|
|
21
|
+
this._reactToEvent = this._reactToEvent.bind(this);
|
|
22
|
+
this._audioUnlockHandler = this._audioUnlockHandler.bind(this);
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
|
|
@@ -37,7 +40,7 @@ class SoundSprite {
|
|
|
37
40
|
return soundsStateObj;
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
|
|
43
|
+
_makePlayer_Bak(sprite, audiosprite) {
|
|
41
44
|
var reader = new FileReader();
|
|
42
45
|
reader.readAsDataURL(audiosprite);
|
|
43
46
|
reader.onloadend = () => {
|
|
@@ -50,12 +53,39 @@ class SoundSprite {
|
|
|
50
53
|
}
|
|
51
54
|
};
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
this.
|
|
55
|
-
|
|
56
|
+
_makePlayer(sprite, audiosprite) {
|
|
57
|
+
if (!this._codec) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const reader = new FileReader();
|
|
62
|
+
const blob = new Blob([audiosprite], { type: `audio/${this._codec}` });
|
|
63
|
+
|
|
64
|
+
reader.onloadend = () => {
|
|
65
|
+
var { result: src } = reader;
|
|
66
|
+
this._player = new Howl({ src, sprite });
|
|
67
|
+
this._subscribePlayerEvents();
|
|
68
|
+
|
|
56
69
|
this._onUnlock();
|
|
57
|
-
|
|
58
|
-
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
reader.readAsDataURL(blob);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
_audioUnlockHandler() {
|
|
76
|
+
this._isAudioUnlocked = true;
|
|
77
|
+
this._onUnlock();
|
|
78
|
+
this.emit(Urso.events.MODULES_SOUND_MANAGER_CONTEXT_UNLOCKED);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
_subscribePlayerEvents() {
|
|
82
|
+
if (UrsoUtils.Howler.Howler._audioUnlocked) {
|
|
83
|
+
this._audioUnlockHandler();
|
|
84
|
+
} else {
|
|
85
|
+
this._player.on('unlock', () => setTimeout(() => {
|
|
86
|
+
this._audioUnlockHandler();
|
|
87
|
+
}, 1000));
|
|
88
|
+
}
|
|
59
89
|
|
|
60
90
|
this._player.on('end', id => {
|
|
61
91
|
const soundState = this._getSoundStateById(id);
|