-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
253 lines (239 loc) · 8.7 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
let is_playing_song = false;
let curr_audio = "";
let selected_user_song = "";
let is_newsong_selected = false;
let song_index = -1;
let step = 0;
let val = true;
let isDuration_jumped = false;
let step_during_jump = 0;
let entereed_into = false;
const song1 = new Audio("/songs/one call away.mp3");
const song2 = new Audio("/songs/chahu mein ya na.mp3");
const song3 = new Audio("/songs/mercy.mp3");
const song4 = new Audio("/songs/malhari.mp3");
const song5 = new Audio("/songs/act my age.mp3");
const song6 = new Audio("/songs/pi jaun.mp3");
const clickSound = new Audio("metallic-click.wav");
document.addEventListener("click", function(){
clickSound.play();
});
let arrayOfsongs = [song1, song2, song3, song4, song5, song6];
let durationOfsongs = ["03:12", "05:04", "02:42", "04:04", "03:18", "04:43"];
let seek = document.getElementById("seeker");
let startTimer = document.querySelector(".start");
let endTimer = document.querySelector(".music-dur");
let arr = startTimer.innerText.split(":");
seek.addEventListener("change", function () {
const clickpoint = seek.value / 100;
curr_audio.currentTime = (curr_audio.duration || 0) * clickpoint;
let songs_current_time = curr_audio.currentTime | 0;
switch(songs_current_time / 60 | 0){
case 0: step_during_jump = 0; break;
case 1: step_during_jump = 6; break;
case 2: step_during_jump = 12; break;
case 3: step_during_jump = 18; break;
case 4: step_during_jump = 24; break;
case 5: step_during_jump = 30; break;
case 6: step_during_jump = 36; break;
}
isDuration_jumped = true;
});
function range_slider(music) {
music.addEventListener("timeupdate", () => {
let curr_time_ofSong = music.currentTime | 0;
let min = (curr_time_ofSong / 10) | 0;
if (curr_time_ofSong != 0 && val == true && curr_time_ofSong % 60 == 0) {
step += 6;
val = false;
setTimeout(() => {
val = true;
}, 10000);
}
if(isDuration_jumped == true){
step = step_during_jump;
entereed_into = true;
}
startTimer.innerHTML =
`0${(curr_time_ofSong / 60) | 0}:${min - step}` +
`${curr_time_ofSong % 10}`;
if(entereed_into == true){
isDuration_jumped = false;
entereed_into = false;
}
seeker.value = (music.currentTime / music.duration) * 100;
if (music.currentTime == music.duration) {
seek.value = 0;
let div_to_be_remove = document.querySelector(".current-song");
div_to_be_remove.remove();
is_playing_song = false;
is_newsong_selected = false;
play_pause_element.classList.remove("fa-circle-pause");
play_pause_element.classList.add("fa-circle-play");
startTimer.style.visibility = "hidden";
endTimer.style.visibility = "hidden";
}
});
}
let backward_play_btn = document.querySelector(".play-backward");
let forward_play_btn = document.querySelector(".play-forward");
let arrayOf_songDivs = document.querySelectorAll(".songs");
backward_play_btn.addEventListener("click", function () {
step = 0;
val = true;
isDuration_jumped = false;
if (song_index == 0) {
let ele = document.querySelector(".current-song");
ele.innerHTML = "Pi jaun - Farhan Saeed";
curr_audio.pause();
curr_audio.currentTime = 0;
is_playing_song = false;
seeker.value = 0;
song_index = 5;
curr_audio = arrayOfsongs[arrayOfsongs.length - 1];
selected_user_song = arrayOfsongs[arrayOfsongs.length - 1];
play_pause_element.classList.remove("fa-circle-pause");
play_pause_element.classList.add("fa-circle-play");
endTimer.innerHTML = durationOfsongs[song_index];
} else {
let ele = document.querySelector(".current-song");
ele.innerHTML = arrayOf_songDivs[song_index - 1].innerHTML;
curr_audio.pause();
curr_audio.currentTime = 0;
is_playing_song = false;
seeker.value = 0;
curr_audio = arrayOfsongs[song_index - 1];
selected_user_song = arrayOfsongs[song_index - 1];
play_pause_element.classList.remove("fa-circle-pause");
play_pause_element.classList.add("fa-circle-play");
song_index = song_index - 1;
endTimer.innerHTML = durationOfsongs[song_index];
}
});
forward_play_btn.addEventListener("click", function(){
step = 0;
val = true;
isDuration_jumped = false;
if (song_index == 5) {
let ele = document.querySelector(".current-song");
ele.innerHTML = "One call away - By charlie puth";
curr_audio.pause();
curr_audio.currentTime = 0;
is_playing_song = false;
seeker.value = 0;
song_index = 0;
curr_audio = arrayOfsongs[0];
selected_user_song = arrayOfsongs[0];
play_pause_element.classList.remove("fa-circle-pause");
play_pause_element.classList.add("fa-circle-play");
endTimerl.innerHTML = durationOfsongs[song_index];
} else {
let ele = document.querySelector(".current-song");
ele.innerHTML = arrayOf_songDivs[song_index + 1].innerHTML;
curr_audio.pause();
curr_audio.currentTime = 0;
is_playing_song = false;
seeker.value = 0;
curr_audio = arrayOfsongs[song_index + 1];
selected_user_song = arrayOfsongs[song_index + 1];
play_pause_element.classList.remove("fa-circle-pause");
play_pause_element.classList.add("fa-circle-play");
song_index = song_index + 1;
endTimer.innerHTML = durationOfsongs[song_index];
}
});
const play_pause_element = document.querySelector(".playbtn");
play_pause_element.addEventListener("click", function () {
if (is_playing_song == true) {
curr_audio.pause();
play_pause_element.classList.remove("fa-circle-pause");
play_pause_element.classList.add("fa-circle-play");
is_playing_song = false;
} else {
selected_user_song.play();
play_pause_element.classList.remove("fa-circle-play");
play_pause_element.classList.add("fa-circle-pause");
range_slider(selected_user_song);
is_playing_song = true;
}
});
let song_elements = document.querySelectorAll(".songs");
for (i = 0; i < song_elements.length; i++) {
song_elements[i].addEventListener("click", function (event) {
startTimer.style.visibility = "visible";
endTimer.style.visibility = "visible";
step = 0;
val = true;
isDuration_jumped = false;
let data_recevied = event.target.textContent;
if (is_newsong_selected == true) {
startTimer.innerHTML = "00:00";
let ele = document.querySelector(".current-song");
ele.innerHTML = data_recevied;
curr_audio.pause();
curr_audio.currentTime = 0;
play_pause_element.classList.remove("fa-circle-pause");
play_pause_element.classList.add("fa-circle-play");
if (data_recevied == "One call away - By charlie puth") {
selected_user_song = song1;
curr_audio = song1;
song_index = 0;
} else if (data_recevied == "Chahun main ya na - Ashiqui 2") {
selected_user_song = song2;
curr_audio = song2;
song_index = 1;
} else if (data_recevied == "Mercy - By Badshah") {
selected_user_song = song3;
curr_audio = song3;
song_index = 2;
} else if (data_recevied == "Malhari - Bajirao Mastani") {
selected_user_song = song4;
curr_audio = song4;
song_index = 3;
} else if (data_recevied == "Act my age - By One direction") {
selected_user_song = song5;
curr_audio = song5;
song_index = 4;
} else if (data_recevied == "Pi jaun - Farhan Saeed") {
selected_user_song = song6;
curr_audio = song6;
song_index = 5;
}
endTimer.innerHTML = durationOfsongs[song_index];
} else {
let newdiv = document.createElement("div");
newdiv.classList.add("current-song");
newdiv.innerHTML = data_recevied;
const parentdiv = document.querySelector(".current");
startTimer.innerHTML = "00:00";
parentdiv.appendChild(newdiv);
is_newsong_selected = true;
if (data_recevied == "One call away - By charlie puth") {
selected_user_song = song1;
curr_audio = song1;
song_index = 0;
} else if (data_recevied == "Chahun main ya na - Ashiqui 2") {
selected_user_song = song2;
curr_audio = song2;
song_index = 1;
} else if (data_recevied == "Mercy - By Badshah") {
selected_user_song = song3;
curr_audio = song3;
song_index = 2;
} else if (data_recevied == "Malhari - Bajirao Mastani") {
selected_user_song = song4;
curr_audio = song4;
song_index = 3;
} else if (data_recevied == "Act my age - By One direction") {
selected_user_song = song5;
curr_audio = song5;
song_index = 4;
} else if (data_recevied == "Pi jaun - Farhan Saeed") {
selected_user_song = song6;
curr_audio = song6;
song_index = 5;
}
endTimer.innerHTML = durationOfsongs[song_index];
}
});
}