-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
392 lines (334 loc) · 13.9 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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
console.log("Javascript Let's Go");
let songs;
let currFolder;
let currentSong = new Audio();
function convertSecondsToTime1(seconds) {
// Ensure the input is a positive integer
if (seconds < 0 || isNaN(seconds)) {
throw new Error("Input must be a non-negative number");
}
//Calculate minutes and remaining seconds
const minutes = Math.floor(seconds / 60);
const remainingSeconds = Math.floor(seconds % 60);
// Format minutes and seconds to ensure two-digit seconds
const formattedMinutes = String(minutes).padStart(2,'0');
const formattedSeconds = String(remainingSeconds).padStart(2, '0');
// Return the formatted time string
return `${formattedMinutes}:${formattedSeconds}`;
}
function convertSecondsToTime(seconds) {
// Calculate hours, minutes, and seconds
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
const remainingSeconds = seconds % 60;
// Format minutes and seconds to always show two digits
const formattedMinutes = String(minutes).padStart(2, '0');
const formattedSeconds = String(remainingSeconds).padStart(2, '0');
// If hours are more than 0, include hours in the output
if (hours > 0) {
const formattedHours = String(hours).padStart(2, '0');
return `${formattedHours}:${formattedMinutes}:${formattedSeconds}`;
} else {
// Otherwise, just return minutes and seconds
return `${formattedMinutes}:${formattedSeconds}`;
}
}
// Hardcoded list of songs and albums (replace with actual file names)
const albums = [
{
folder: 'kishore',
cover: './Songs/kishore/cover.jpg',
songs: [
"Jai%20Jai%20Shiv%20Shankar.mp3",
"Neele%20Neele%20Ambar.mp3",
"Samne%20wali%20Khidki.mp3",
"Zindagi%20Ek%20Safar.mp3"
],
title: 'Kishore Kumar - Hits',
description: 'Songs for you',
},
{
folder: 'kum_Sanu',
cover: './Songs/kum_Sanu/cover.jpg',
songs: ['01%20-%20Meri%20Mehbooba-BarmanMusic.Com.mp3', '02%20-%20Pyaar%20Nahin%20Karna%20Jahan-BarmanMusic.Com.mp3', '03%20-%20Baadalon%20Mein%20Chup%20Raha%20Chand-BarmanMusic.Com.mp3', '04%20-%20Tumse%20Milne%20Ko%20Dil-BarmanMusic.Com.mp3', '06%20-%20Aankhon%20Mein%20Neendein%20Na%20Dil-BarmanMusic.Com.mp3', '10%20-%20Aankhon%20Se%20Tune%20Kya%20Keh%20Diya-BarmanMusic.Com.mp3', '13%20-%20Mere%20Khwabon%20Mein%20Tu-BarmanMusic.Com.mp3'],
title: 'Kumar Sanu - Top Hits',
description: 'Songs for you',
},
{
folder: 'lata_mam',
cover: './Songs/lata_mam/cover.jpg',
songs:
['bollywood_VZ%202004%20-%20Tere%20Liye.mp3', 'Dekha%20Ek%20Khwab%20To.mp3', 'Dil%20To%20Pagal%20Hai%20-%20DTPH%201997.mp3', 'Kya%20Yehi%20Pyar%20Hai.mp3', 'Tuujhe%20Dekha%20To%20Jana%20-%20DDLJ%20(1995).mp3'],
title: 'Lata Mangeshkar - Top Hits',
description: 'Songs for you',
},
{
folder: 'rajesh_kh',
cover: './Songs/rajesh_kh/cover.jpg',
songs: ['Dilwale%202015%20-%20Janam%20Janam.mp3', 'Hamari%20Adhuri%20Kahani.mp3', 'MSDhoni%20-%20Phir%20Kabhi.mp3', 'Nashe%20Si%20Chadh%20Gayi.mp3', 'Sanam%20Re.mp3', 'Tum%20Hi%20Ho%20-%20PagalSongs.com.mp3'],
title: 'Arjist Singth - Top Hits',
description: 'Songs for you',
},
{
folder: 'y_udit',
cover: './Songs/y_udit/cover.jpg',
songs: ['Aaja%20Mahiya%20.mp3', 'Dil%20To%20Pagal%20Hai%20-%20DTPH%201997.mp3', 'Kuch%20Kuch%20Hota%20Hai%20-%20PagalSongs.com.mp3', 'Mere%20Mehboob.mp3', 'tere%20Naam%20-.com.mp3'],
title: 'Udit Kumar - Top Hits',
description: 'Songs for you',
},
{
folder: 'z_ghoshal',
cover: './Songs/z_ghoshal/cover.jpg',
songs: ['Deewani%20Mastani.mp3', 'Kar%20Har%20Maidaan%20Fateh.mp3', 'Manwa%20Lage.mp3', 'Saathiyaa.mp3', 'Teri%20Meri.mp3'],
title: 'Shreya Ghoshal - Top Hits',
description: 'Songs for you',
}
];
const albums2 = [
{
folder: 'acs',
cover: './Songs1/acs/cover.jpg',
songs: ['Bajrangdal%20Song%20Dj%202023.mp3', 'Bharat%20Ka%20Baccha%20Baccha.mp3', 'Keejo%20Kesari%20Ke%20Laal.mp3', 'Mangal%20Bhavan%20Amangal%20Hari.mp3', 'old_gulaal-Aarambh.mp3', 'Ram%20Darshan(PagalWorld).mp3', 'Ram%20Siya%20Ram.mp3'],
title: 'Bhakti Geet',
description: 'No Depression, No Daydreaming- Only Sanatani',
},
{
folder: 'Calm',
cover: './Songs1/Calm/cover.jpg',
songs: ['Alan-walker-faded.mp3', 'Alan-walker-united.mp3', 'Alone-Drill-remix-2024.mp3', 'On%20My%20Way-(PagalSongs.Com.IN).mp3'],
title: 'Calm',
description: 'Ganapati Bapa Mourya',
},
{
folder: 'Hot Pick',
cover: './Songs1/Hot Pick/cover.jpg',
songs:
['Lose%20yourself.mp3', 'mockingbird%20(1).mp3', 'till%20i%20collapse.mp3'],
title: 'Hot Picks',
description: 'Songs for you',
},
{
folder: 'ncs',
cover: './Songs1/ncs/cover.jpg',
songs: ['Cartoon%2C%20J%C3%A9ja%20-%20On%20%26%20On%20(feat.%20Daniel%20Levi)%20%5BNCS%20Release%5D.mp3', 'Egzod%2C%20Maestro%20Chives%2C%20Neoni%20-%20Royalty%20%5BNCS%20Release%5D.mp3', 'Jay%20Eskar%2C%20ESCARGOT%2C%20SNAILS%20-%20Earthq…%20Justin%20J.%20Moore)%20%5BNCS%20Release%5D.mp3', 'Tobu%20-%20Faster%20%5BNCS%20Release%5D.mp3', 'Warriyo%20-%20Mortals%20(feat.%20Laura%20Brehm)%20%5BNCS%20Release%5D.mp3'],
title: 'Non Copyrighted Songs',
description: 'Songs for you',
},
{
folder: 'Trending',
cover: './Songs1/Trending/cover.jpg',
songs:
['Frente%20Frente%20Phonk(PagalWorld.com.so).mp3', 'My%20Way.mp3'],
title: 'Trending Once',
description: 'Songs for you',
},
{
folder: 'Zzzz',
cover: './Songs1/Zzzz/cover.jpg',
songs: ['Jay%20Eskar%2C%20ESCARGOT%2C%20SNAILS%20-%20Earthq…%20Justin%20J.%20Moore)%20%5BNCS%20Release%5D.mp3', 'Tobu%20-%20Faster%20%5BNCS%20Release%5D.mp3', 'Warriyo%20-%20Mortals%20(feat.%20Laura%20Brehm)%20%5BNCS%20Release%5D.mp3'],
title: 'Zzzz',
description: 'Songs for you',
}
];
function get_songs(folder) {
currFolder = folder;
// Find the selected album based on the folder name
let album = albums.find(a => a.folder === folder);
if (!album) {
console.error("Album not found!");
return;
}
// Extract the songs from the album
songs = album.songs;
// Display the list of songs in the playlist
let sul = document.querySelector(".songlist ul");
sul.innerHTML = ""; // Clear previous song list
songs.forEach(song => {
sul.innerHTML += `
<li>
<img class="invert" id="close" src="./images/musicclose.svg" alt="not playing">
<div class="songinfo">
<div class="songname">${song.replaceAll("%20", " ")}</div>
<div> Prayag </div>
</div>
<div class="playnow">
<span>Play</span>
<img class="invert resize" src="./images/play1.svg" alt="playnow">
</div>
</li>`;
});
// Add click event to play the selected song
Array.from(document.querySelector(".songlist ul").getElementsByTagName("li")).forEach(e => {
e.addEventListener("click", () => {
let songName = e.querySelector(".songinfo").firstElementChild.innerHTML.trim();
let songPath = `./Songs/${folder}/${songName}`;
playMusic(songPath);
});
});
console.log(songs);
}
get_songs("kishore");
playMusic(songs[0],true);
function displayAlbums() {
let cardContainer = document.querySelector(".cardContainer");
cardContainer.innerHTML = "";
albums.forEach(album => {
cardContainer.innerHTML += `
<div data-folder="${album.folder}" class="card">
<div class="play">
<svg xmlns="http://www.w3.org/2000/svg" width="35px" height="35px" viewBox="0 0 28 28">
<path d="M14 0C6.268 0 0 6.268 0 14s6.268 14 14 14 14-6.268 14-14S21.732 0 14 0z" fill="#00FF00" />
<path d="M11 8.5v11l7.5-5.5-7.5-5.5z" fill="#000000" />
</svg>
</div>
<img src="${album.cover}" alt="Album Cover" />
<h3>${album.title}</h3>
<p>${album.description}</p>
</div>
`;
});
document.querySelectorAll(".card").forEach(card => {
card.addEventListener("click", event => {
let folder = event.currentTarget.dataset.folder;
let album = albums.find(a => a.folder === folder);
songs = album.songs.map(song => `./Songs/${folder}/${song}`);
playMusic(songs[0], true);
get_songs(`${folder}`)
});
});
}
function displayAlbums2() {
let cardContainer = document.querySelector(".cardContainer2");
cardContainer.innerHTML = "";
albums2.forEach(album1 => {
cardContainer.innerHTML += `
<div data-folder="${album1.folder}" class="card">
<div class="play">
<svg xmlns="http://www.w3.org/2000/svg" width="35px" height="35px" viewBox="0 0 28 28">
<path d="M14 0C6.268 0 0 6.268 0 14s6.268 14 14 14 14-6.268 14-14S21.732 0 14 0z" fill="#00FF00" />
<path d="M11 8.5v11l7.5-5.5-7.5-5.5z" fill="#000000" />
</svg>
</div>
<img src="${album1.cover}" alt="Album Cover" />
<h3>${album1.title}</h3>
<p>${album1.description}</p>
</div>
`;
});
document.querySelectorAll(".card").forEach(card => {
card.addEventListener("click", event => {
let folder = event.currentTarget.dataset.folder;
let album = albums2.find(a => a.folder === folder);
songs = album.songs.map(song => `./Songs1/${folder}/${song}`);
playMusic(songs[0]);
get_songs(`${folder}`);
});
});
}
let currentSongIndex = 0;
function playMusic(track, pause = false) {
currentSong.src = track;
if (!pause) {
currentSong.play();
play.src = "./images/pause.svg";
}
document.querySelector(".songinfo1").innerHTML = decodeURI(track.split('/').pop());
document.querySelector(".songtime").innerHTML = "00:00 / 00:00";
}
document.addEventListener("DOMContentLoaded", function() {
displayAlbums();
displayAlbums2();
// Event listeners for play/pause and time update
const play = document.querySelector("#play");
play.addEventListener("click", () => {
if (currentSong.paused) {
currentSong.play();
play.src = "./images/pause.svg";
} else {
currentSong.pause();
play.src = "./images/play1.svg";
}
});
currentSong.addEventListener("timeupdate", () => {
document.querySelector(".songtime").innerHTML = `${convertSecondsToTime1(currentSong.currentTime)} / ${convertSecondsToTime1(currentSong.duration)}`;
});
const prev = document.querySelector("#prev");
prev.addEventListener("click", () => {
if (currentSongIndex > 0) {
currentSongIndex--;
} else {
currentSongIndex = songs.length - 1; // Loop to the last song
}
playMusic(songs[currentSongIndex]);
});
const next = document.querySelector("#next");
next.addEventListener("click", () => {
if (currentSongIndex < songs.length - 1) {
currentSongIndex++;
} else {
currentSongIndex = 0; // Loop back to the first song
}
playMusic(songs[currentSongIndex]);
});
// Volume control
const volumeIcon = document.querySelector(".volume");
const volumeRange = document.querySelector(".range");
let isMuted = false;
function toggleVolume() {
if (isMuted) {
volumeRange.value = 60;
volumeIcon.src = './images/voume.svg';
currentSong.volume = 0.6;
} else {
volumeRange.value = 0;
volumeIcon.src = './images/mute.svg';
}
isMuted = !isMuted;
}
volumeIcon.addEventListener("click", toggleVolume);
volumeRange.addEventListener("input", function () {
currentSong.volume = volumeRange.value / 100;
});
// Seekbar functionality
// const seekbar = document.querySelector(".seekbar");
// seekbar.addEventListener("click", (e) => {
// let percent = (e.offsetX / seekbar.offsetWidth);
// currentSong.currentTime = percent * currentSong.duration;
// });
document.querySelector(".seekbar").addEventListener("click", e => {
let percent = (e.offsetX/e.target.getBoundingClientRect().width) * 100;
document.querySelector(".circle").style.left = percent + "%";
currentSong.currentTime = ((currentSong.duration) * percent) /100;
}
)
// Time update on seekbar
currentSong.addEventListener("timeupdate", () => {
let progress = (currentSong.currentTime / currentSong.duration) * 100;
// document.querySelector(".circle").style.width = `${progress}%`;
document.querySelector(".circle").style.left = (currentSong.currentTime/currentSong.duration) * 100 + "%";
});
// Mute/unmute button functionality
document.querySelector(".volume > img").addEventListener("click", () => {
if (currentSong.muted) {
currentSong.muted = false;
document.querySelector(".volume > img").src = "images/voume.svg";
} else {
currentSong.muted = true;
document.querySelector(".volume > img").src = "images/mute.svg";
}
});
document.querySelector(".range").getElementsByTagName("input")[0].addEventListener("change",(e) => {
currentSong.volume = parseInt(e.target.value)/100;
}
)
// Hamburger menu toggle
const hamburger = document.querySelector(".hamburger");
const closeBtn = document.querySelector(".close");
const leftMenu = document.querySelector(".left");
hamburger.addEventListener("click", () => {
leftMenu.style.left = "0";
});
closeBtn.addEventListener("click", () => {
leftMenu.style.left = "-100%";
leftMenu.style.transition = "0.4s";
});});