-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
61 lines (48 loc) · 1.38 KB
/
script.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
49
50
51
52
53
54
55
56
57
58
59
60
61
const btnPlayPause = document.querySelector(".play-pause");
const audioCurrent = document.querySelector(".audio");
const btnNext = document.querySelector(".after");
const btnBefore = document.querySelector(".before");
const txtNumCapCurrent = document.querySelector(".num-cap");
const numMaxCap = 10;
let isPlaying = false;
let capCurrent = 1;
const playTrack = () => {
audioCurrent.play();
isPlaying = true;
btnPlayPause.classList.remove("bi-play-circle-fill");
btnPlayPause.classList.add("bi-pause-circle-fill");
};
const pauseTrack = () => {
audioCurrent.pause();
isPlaying = false;
btnPlayPause.classList.add("bi-play-circle-fill");
btnPlayPause.classList.remove("bi-pause-circle-fill");
};
const playOrPause = () => {
if (isPlaying) {
pauseTrack();
} else {
playTrack();
}
};
const nextTrack = () => {
capCurrent++;
if (capCurrent > 10) {
capCurrent = 1;
}
txtNumCapCurrent.innerText = capCurrent;
audioCurrent.src = `./books/dom-casmurro/${capCurrent}.mp3`;
playTrack();
};
const beforeTrack = () => {
capCurrent--;
if (capCurrent === 0) {
capCurrent = 10;
}
txtNumCapCurrent.innerText = capCurrent;
audioCurrent.src = `./books/dom-casmurro/${capCurrent}.mp3`;
playTrack();
};
btnPlayPause.addEventListener("click", playOrPause);
btnNext.addEventListener("click", nextTrack);
btnBefore.addEventListener("click", beforeTrack);