-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplaySong.js
More file actions
32 lines (30 loc) · 803 Bytes
/
playSong.js
File metadata and controls
32 lines (30 loc) · 803 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
function sound(src) {
this.sound = document.createElement("audio");
this.sound.src = src;
this.sound.setAttribute("preload", "auto");
this.sound.setAttribute("controls", "none");
this.sound.style.display = "none";
document.body.appendChild(this.sound);
this.play = function(){
this.sound.play();
}
this.stop = function(){
this.sound.pause();
}
}
localStorage.clear();
changeBgSound = new sound("sounds/changeBg.mp3");
clickOpSound = new sound("sounds/clickOp.mp3");
finishSound = new sound("sounds/finish.mp3");
themeSong = new sound("sounds/themeSong.mp3");
let playing = false;
function playSong() {
if (playing == true) {
themeSong.stop();
playing = false;
}
else {
themeSong.play()
playing = true;
}
}