-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsound.js
More file actions
36 lines (32 loc) · 804 Bytes
/
sound.js
File metadata and controls
36 lines (32 loc) · 804 Bytes
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
function playSound(sound) {
sound.play();
}
function pauseSound(sound) {
sound.pause();
}
function playMusic(music) {
if(music.currentTime > 0 || !music.paused) {
return;
}
music.volume = 0.5;
music.loop = true;
music.muted = false;
var resp = music.play();
// Odd workaround for basic autoplay in browser.
if (resp !== undefined) {
resp.then(_ => {
// autoplay starts!
}).catch(err => {
console.error(err);
window.addEventListener("click", function() {
music.play();
});
window.addEventListener("touchend", function() {
music.play();
});
});
}
}
function pauseMusic(music) {
music.pause();
}