-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSound.js
48 lines (47 loc) · 1023 Bytes
/
Sound.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(Scratch => {
"use strict";
class Sound {
getInfo() {
return {
id: "notSound", // Intentional
name: "Sound",
blocks: [
{
opcode: 'play',
blockType: Scratch.BlockType.COMMAND,
text: "Play sound from url:[path]",
arguments: {
path: {
type: Scratch.ArgumentType.STRING,
defaultValue: "https://extensions.turbowarp.org/sound.mp3"
}
}
},
{
opcode: 'playUntilDone',
blockType: Scratch.BlockType.COMMAND,
text: "Play sound from url:[path] until done",
arguments: {
path: {
type: Scratch.ArgumentType.STRING,
defaultValue: "https://extensions.turbowarp.org/sound.mp3"
}
}
}
]
};
}
play({path}) {
let sound = new Audio(path);
sound.play();
}
playUntilDone({path}) {
return new Promise(resolve => {
let sound = new Audio(path);
sound.play();
sound.onended = resolve;
});
}
}
Scratch.extensions.register(new Sound());
})(Scratch);