-
Notifications
You must be signed in to change notification settings - Fork 0
/
index3.js
89 lines (80 loc) · 2.58 KB
/
index3.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var index = 0;
var audio = new Audio("Songs2/song1.mp3");
var allSongs = ["song1.mp3", "song2.mp3", "song3.mp3", "song4.mp3", "song5.mp3"]
var SongsName = {
music: ["Khaab- Akhil", "Lehanga: Jass Manak", "Wakhra Swag", "Mann Bharrya: B.Praak", "Pasoori"]
}
$(".song").click(function() {
if (this.id === "song1") {
index = 0;
} else if (this.id === "song2") {
index = 1;
} else if (this.id === "song3") {
index = 2;
} else if (this.id === "song4") {
index = 3;
} else if (this.id === "song5") {
index = 4;
}
animate = ("#" + this.id);
$(animate).fadeIn(100).fadeOut(100).fadeIn(100);
audio.src = ("Songs2/" + this.id + ".mp3");
audio.play();
$(".GIF").css("opacity", "1");
document.getElementById("toggleMusic").innerText = SongsName.music[index];
});
document.getElementById("mainButt").addEventListener('click', () => {
if (audio.paused) {
audio.play();
$("#mainButt").removeClass("icon fa-regular fa-2x fa-circle-play");
$("#mainButt").addClass("icon fa-regular fa-2x fa-circle-pause");
$(".GIF").css("opacity", "1");
document.getElementById("toggleMusic").innerText = SongsName.music[index];
} else {
audio.pause();
$("#mainButt").removeClass("icon fa-regular fa-2x fa-circle-pause");
$("#mainButt").addClass("icon fa-regular fa-2x fa-circle-play");
$(".GIF").css("opacity", "0");
}
})
document.getElementById("forw").addEventListener('click', () => {
index++;
if (index > 5) {
index = 0;
audio.src = ("Songs2/" + allSongs[index]);
audio.play();
} else {
audio.src = ("Songs2/" + allSongs[index]);
audio.play();
}
document.getElementById("toggleMusic").innerText = SongsName.music[index];
})
document.getElementById("prev").addEventListener('click', () => {
index--;
if (index < 1) {
index = 5;
audio.src = ("Songs2/" + allSongs[index]);
audio.play();
} else {
audio.src = ("Songs2/" + allSongs[index]);
audio.play();
}
document.getElementById("toggleMusic").innerText = SongsName.music[index];
})
audio.addEventListener('timeupdate', () => {
progress = parseInt((audio.currentTime / audio.duration) * 100);
myRange.value = progress;
if (progress === 100) {
if (index >= 5) {
index = 1;
} else {
index++;
}
audio.src = ("Songs2/" + allSongs[index]);
audio.play();
document.getElementById("toggleMusic").innerText = SongsName.music[index];
}
})
myRange.addEventListener('change', () => {
audio.currentTime = myRange.value * audio.duration / 100;
})