-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (27 loc) · 832 Bytes
/
index.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
//created a wave and if song is played then progress wave will covered
var audioTrack = WaveSurfer.create({
container: ".audio",
waveColor: "gray",
progressColor: "crimson",
barWidth: 2,
});
//importing audio track
audioTrack.load("./bensound-funkyelement.mp3");
//Getting element using querySelector to control the play and pause the song
const playBtn = document.querySelector(".play-btn");
const stopBtn = document.querySelector(".stop-btn");
const canvas = document.querySelector(".canvas");
//play function
playBtn.addEventListener("click", () => {
audioTrack.playPause();
if (audioTrack.isPlaying()) {
playBtn.classList.add("playing");
} else {
playBtn.classList.remove("playing");
}
});
//stop function
stopBtn.addEventListener("click", () => {
audioTrack.stop();
playBtn.classList.remove("playing");
});