@momo2555/koppeliajs 0.0.138 → 0.0.139
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.
|
@@ -2,40 +2,68 @@ import { writable } from 'svelte/store';
|
|
|
2
2
|
class AudioInstance {
|
|
3
3
|
audio;
|
|
4
4
|
id;
|
|
5
|
+
path;
|
|
6
|
+
loop;
|
|
5
7
|
constructor(id, loop = false) {
|
|
6
8
|
this.id = id;
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
9
|
+
this.path = `/audios/${id}.mp3`;
|
|
10
|
+
this.loop = loop;
|
|
11
|
+
}
|
|
12
|
+
fetch() {
|
|
13
|
+
this.audio = new Audio(this.path);
|
|
14
|
+
this.audio.loop = this.loop;
|
|
9
15
|
}
|
|
10
16
|
play() {
|
|
11
|
-
this.audio
|
|
17
|
+
if (this.audio != undefined) {
|
|
18
|
+
this.audio.play().catch(err => console.error(`Error playing ${this.id}:`, err));
|
|
19
|
+
}
|
|
12
20
|
}
|
|
13
21
|
pause() {
|
|
14
|
-
this.audio
|
|
22
|
+
if (this.audio != undefined) {
|
|
23
|
+
this.audio.pause();
|
|
24
|
+
}
|
|
15
25
|
}
|
|
16
26
|
stop() {
|
|
17
|
-
this.audio
|
|
18
|
-
|
|
27
|
+
if (this.audio != undefined) {
|
|
28
|
+
this.audio.pause();
|
|
29
|
+
this.audio.currentTime = 0;
|
|
30
|
+
}
|
|
19
31
|
}
|
|
20
32
|
setLoop(loop) {
|
|
21
|
-
this.audio
|
|
33
|
+
if (this.audio != undefined) {
|
|
34
|
+
this.audio.loop = loop;
|
|
35
|
+
}
|
|
22
36
|
}
|
|
23
37
|
isPlaying() {
|
|
24
|
-
|
|
38
|
+
if (this.audio != undefined) {
|
|
39
|
+
return !this.audio.paused;
|
|
40
|
+
}
|
|
25
41
|
}
|
|
26
42
|
getId() {
|
|
27
43
|
return this.id;
|
|
28
44
|
}
|
|
29
45
|
}
|
|
46
|
+
class AudioUrlInstance extends AudioInstance {
|
|
47
|
+
constructor(id, url, loop) {
|
|
48
|
+
super(id, loop);
|
|
49
|
+
this.path = url;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
30
52
|
export class AudioManager {
|
|
31
53
|
players = new Map();
|
|
32
54
|
/**
|
|
33
55
|
* Play an audio by id (creates it if doesn't exist)
|
|
34
56
|
*/
|
|
35
|
-
play(id, loop = false) {
|
|
57
|
+
play(id, loop = false, url) {
|
|
36
58
|
let player = this.players.get(id);
|
|
37
59
|
if (!player) {
|
|
38
|
-
|
|
60
|
+
if (url !== undefined) {
|
|
61
|
+
player = new AudioUrlInstance(id, url, loop);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
player = new AudioInstance(id, loop);
|
|
65
|
+
}
|
|
66
|
+
player.fetch();
|
|
39
67
|
this.players.set(id, player);
|
|
40
68
|
}
|
|
41
69
|
else {
|
package/package.json
CHANGED