-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsounds.js
More file actions
31 lines (27 loc) · 1.11 KB
/
Copy pathsounds.js
File metadata and controls
31 lines (27 loc) · 1.11 KB
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
// All possible sounds
var sounds = new Map();
// Audio on/off
// Note: we start with audio off for cross-browser integration
var canPlay = false;
// Get all sounds initialized
function initSounds() {
sounds.set('background_music', new Audio(document.getElementById("background_music").src));
sounds.set('shorter_drill', new Audio(document.getElementById("shorter_drill").src));
sounds.set('short_drill', new Audio(document.getElementById("short_drill").src));
sounds.set('med_drill', new Audio(document.getElementById("med_drill").src));
sounds.set('long_drill', new Audio(document.getElementById("long_drill").src));
sounds.set('scale_b', new Audio(document.getElementById("scale01").src));
sounds.set('scale_t', new Audio(document.getElementById("scale02").src));
}
// Reproduce a sound
function playSound(sound, repeat = false, volume = 0.2) {
var audio = sounds.get(sound);
audio.loop = repeat;
audio.volume = volume;
if (canPlay) audio.play();
}
// Stop an active sound
function stopSound(sound) {
var audio = sounds.get(sound);
audio.pause();
}