-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
208 lines (189 loc) · 7.64 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
console.log("Welcome to Música");
let songIndex = 0;
let audioElement = new Audio('songs/1.mp3');
let masterPlay = document.getElementById('masterPlay');
let myProgressBar = document.getElementById('myProgressBar');
let songItems = Array.from(document.getElementsByClassName('songItem'));
let songs = [{
songName: "Yaad Aati Nahin - Pawan Singh",
filePath: "songs/Yaad Aati Nahin Pawan Singh.mp3",
coverPath: "cover/Yaad Aati Nahin Pawan Singh.jpg",
songDuration: "03:34"
},
{
songName: "Aa jaiha Pach ke - Pawan Singh",
filePath: "songs/Aa jaiha Pach ke - Pawan Singh.mp3",
coverPath: "cover/Aa Jaiha 5 ke pawan singh.jpg",
songDuration: "04:15"
}, {
songName: "Baarish Ban Jaana ( Bhojpuri ) - Pawan Singh",
filePath: "songs/Baarish Ban Jaana ( Bhojpuri ) - Pawan Singh.mp3",
coverPath: "cover/Baarish Ban jaana Pawan singh.jpg",
songDuration: "03:24"
}, {
songName: "Saari Se Tadi - Pawan Singh",
filePath: "songs/Saari Se Tadi - Pawan Singh.mp3",
coverPath: "cover/Saari se tadi Pawan singh.jpg",
songDuration: "03:20"
}, {
songName: "Tumsa Koi Pyaara - PAWAN SINGH & PRIYANKA SINGH ",
filePath: "songs/Tumsa Koi Pyaara - PAWAN SINGH & PRIYANKA SINGH .mp3",
coverPath: "cover/Tumsa Koi Pyaara Pawan singh.jpg",
songDuration: "03:29"
}, {
songName: "Zindagi 2 Mulaqaat Pawan Singh",
filePath: "songs/Zindagi 2 Mulaqaat Pawan Singh.mp3",
coverPath: "cover/Zindagi 2 Mulaqaat Pawan Singh.jpg",
songDuration: "03:44"
}, {
songName: "Zindagi - Pawan Singh",
filePath: "songs/7.mp3",
coverPath: "cover/Zindagi Pawan Singh.jpg",
songDuration: "03:59"
}, {
songName: "Najariya Na Lage - Pawan Singh",
filePath: "songs/8.mp3",
coverPath: "cover/najariya na laage.jpg",
songDuration: "03:22"
}, {
songName: "Mohobat Ab Bechata - Pawan Singh",
filePath: "songs/9.mp3",
coverPath: "cover/Mohobat ab bechata Pawan Singh.jpg",
songDuration: "03:14"
}, {
songName: "Lut gaye Bhojpuri - Pawan Singh",
filePath: "songs/10.mp3",
coverPath: "cover/Lut gaye Bhojpuri Pawan Singh.jpg",
songDuration: "03:39"
},
]
songItems.forEach((element, i) => {
element.getElementsByTagName("img")[0].src = songs[i].coverPath;
element.getElementsByClassName("songName")[0].innerText = songs[i].songName;
element.getElementsByClassName("timestamp")[0].innerHTML = songs[i].songDuration;
});
// audioElement.play();//listen to events
//handle play/pause click
masterPlay.addEventListener('click', () => {
if (audioElement.paused || audioElement.currentTime <= 0) {
audioElement.play();
masterPlay.classList.remove('fa-circle-play');
masterPlay.classList.add('fa-circle-pause');
} else {
audioElement.pause();
masterPlay.classList.remove('fa-circle-pause');
masterPlay.classList.add('fa-circle-play');
makeAllPlays();
}
})
audioElement.addEventListener('timeupdate', () => {
//update seekbar
progress = parseInt((audioElement.currentTime / audioElement.duration) * 100);
myProgressBar.value = progress;
if (myProgressBar.value == 100) {
if (songIndex >= 9) {
songIndex = 0
} else {
songIndex += 1;
}
makeAllPlays();
audioElement.src = `songs/${songIndex+1}.mp3`;
audioElement.currentTime = 0;
audioElement.play();
masterPlay.classList.remove('fa-circle-play');
masterPlay.classList.add('fa-circle-pause');
document.getElementById('songInfoBottom').innerText = songs[songIndex].songName;
document.getElementById("cover").src = songs[songIndex].coverPath;
document.getElementById("cover1").src = songs[songIndex].coverPath;
document.getElementById("coverImg").src = songs[songIndex].coverPath;
}
});
myProgressBar.addEventListener('change', () => {
audioElement.currentTime = (myProgressBar.value * audioElement.duration) / 100;
if (myProgressBar.value == 100) {
if (songIndex >= 9) {
songIndex = 0;
} else {
songIndex += 1;
}
makeAllPlays();
audioElement.src = `songs/${songIndex+1}.mp3`;
audioElement.currentTime = 0;
audioElement.play();
masterPlay.classList.remove('fa-circle-play');
masterPlay.classList.add('fa-circle-pause');
document.getElementById('songInfoBottom').innerText = songs[songIndex].songName;
document.getElementById("cover").src = songs[songIndex].coverPath;
document.getElementById("cover1").src = songs[songIndex].coverPath;
document.getElementById("coverImg").src = songs[songIndex].coverPath;
}
})
var minutes = 0;
var seconds = 0;
function timestamp() {
let time = parseInt(audioElement.currentTime);
minutes = Math.floor(time / 60);
seconds = time - minutes * 60;
if (seconds < 10) {
document.getElementById('time').innerText = "0" + minutes + ":0" + seconds;
} else {
document.getElementById('time').innerText = "0" + minutes + ":" + seconds;
}
}
setInterval(timestamp, 1000);
const makeAllPlays = () => {
Array.from(document.getElementsByClassName('songItemPlay')).forEach((element) => {
element.classList.add('fa-circle-play');
element.classList.remove('fa-circle-pause');
})
}
Array.from(document.getElementsByClassName('songItemPlay')).forEach((element) => {
element.addEventListener('click', (e) => {
makeAllPlays();
songIndex = parseInt(e.target.id)
e.target.classList.remove('fa-circle-play');
e.target.classList.add('fa-circle-pause');
audioElement.src = `songs/${songIndex+1}.mp3`;
audioElement.currentTime = 0;
audioElement.play();
masterPlay.classList.remove('fa-circle-play');
masterPlay.classList.add('fa-circle-pause');
document.getElementById('songInfoBottom').innerText = songs[songIndex].songName;
document.getElementById("cover").src = songs[songIndex].coverPath;
document.getElementById("cover1").src = songs[songIndex].coverPath;
document.getElementById("coverImg").src = songs[songIndex].coverPath;
})
})
document.getElementById('next').addEventListener('click', () => {
if (songIndex >= 9) {
songIndex = 0
} else {
songIndex += 1;
}
makeAllPlays();
audioElement.src = `songs/${songIndex+1}.mp3`;
audioElement.currentTime = 0;
audioElement.play();
masterPlay.classList.remove('fa-circle-play');
masterPlay.classList.add('fa-circle-pause');
document.getElementById('songInfoBottom').innerText = songs[songIndex].songName;
document.getElementById("cover").src = songs[songIndex].coverPath;
document.getElementById("cover1").src = songs[songIndex].coverPath;
document.getElementById("coverImg").src = songs[songIndex].coverPath;
})
document.getElementById('previous').addEventListener('click', () => {
if (songIndex <= 0) {
songIndex = 9;
} else {
songIndex -= 1;
}
audioElement.src = `songs/${songIndex+1}.mp3`;
audioElement.currentTime = 0;
audioElement.play();
masterPlay.classList.remove('fa-circle-play');
masterPlay.classList.add('fa-circle-pause');
document.getElementById('songInfoBottom').innerText = songs[songIndex].songName;
document.getElementById("cover").src = songs[songIndex].coverPath;
document.getElementById("cover1").src = songs[songIndex].coverPath;
document.getElementById("coverImg").src = songs[songIndex].coverPath;
})