-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
235 lines (210 loc) · 7.02 KB
/
Copy pathscript.js
File metadata and controls
235 lines (210 loc) · 7.02 KB
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
console.log("let start js");
let currentsong = new Audio();
let songs = [];
let currentfolder = "";
// All playlists hardcoded here
let playlists = {
"ncs": [
"HangoverSong.mp3",
"MurderAye.mp3",
"SanjuKARHAI.mp3"
],
"Angry_(mood)": [
"Haveli.mp3",
"thokar.mp3"
],
"Sidhu Moosewala": [
"0008sid.mp3",
"TakeNote.mp3"
],
"Chill_(mood)": [
"AZUL.mp3",
"ThodiSi.mp3"
],
"Dark_(mood)": [
"DardAurDava.mp3",
"MAUT.mp3"
],
"Diljit": [
"case.mp3",
"Goat.mp3"
],
"Tarna": [
"BlackBall.mp3",
"DayNight.mp3"
],
"karan aujla": [
"MFGABHRU.mp3",
"Peace.mp3"
],
"Love_(mood)": [
"JeeneLagaHoon.mp3",
"PehleBhiMain.mp3"
],
"Uplifting_(mood)": [
"Baari.mp3",
"Paarchanaa.mp3"
],
"cs": [
"COMPUTER.mp3",
"Topboy.mp3"
]
};
// Convert seconds to mm:ss
function secondsToMinutesSeconds(seconds) {
const minutes = Math.floor(seconds / 60);
const secondsRemaining = Math.floor(seconds % 60);
return `${minutes}:${secondsRemaining.toString().padStart(2, "0")}`;
}
// Render songs from playlist
function getSongs(folder) {
currentfolder = "songs/" + folder;
songs = playlists[folder];
let songUL = document.querySelector(".songlist ul");
songUL.innerHTML = "";
for (const song of songs) {
songUL.innerHTML += `
<li>
<img class="invert" src="img/music.svg" alt="music">
<div class="info"><div>${song}</div></div>
<div class="playnow">
<span>Play Now</span>
<img class="invert" src="img/play.svg" alt="play">
</div>
</li>`;
}
Array.from(songUL.getElementsByTagName("li")).forEach((e, index) => {
e.addEventListener("click", () => {
playMusic(songs[index]);
play.src = "img/pause.svg";
});
});
return songs;
}
// Play music
function playMusic(track, pause = false) {
currentsong.src = `${currentfolder}/${track}`;
if (!pause) {
currentsong.play();
}
play.src = "img/play.svg";
document.querySelector(".songinfo").innerHTML = decodeURI(track);
document.querySelector(".songtime").innerHTML = "00:00 / 00:00";
}
// Display album cards (hardcoded covers + descriptions)
function displayAlbums() {
let albums = [
{ folder: "ncs", title: "NCS Collection", description: "Non-copyrighted tracks", cover: "songs/ncs/cover.jpg" },
{ folder: "Angry_(mood)", title: "Angry Mood", description: "Energetic beats", cover: "songs/Angry_(mood)/cover.jpeg" },
{ folder: "Sidhu Moosewala", title: "Sidhu Moosewala Songs", description: "Sidhu Moosewala for you", cover: "songs/Sidhu Moosewala/cover.webp" },
{ folder: "Chill_(mood)", title: "Chill Mood", description: "Relax & enjoy", cover: "songs/Chill_(mood)/cover.jpg" },
{ folder: "Dark_(mood)", title: "Dark Mood", description: "Deep intense tracks", cover: "songs/Dark_(mood)/cover.jpg" },
{ folder: "Diljit", title: "Diljit Hits", description: "Punjabi Vibes", cover: "songs/Diljit/cover.jpg" },
{ folder: "Tarna", title: "Go Tarna", description: "Lets go Tarna", cover: "songs/Tarna/cover.webp" },
{ folder: "karan aujla", title: "Karan Aujla", description: "Best of Karan", cover: "songs/karan aujla/cover.jpg" },
{ folder: "Love_(mood)", title: "Love Mood", description: "Romantic tracks", cover: "songs/Love_(mood)/cover.jpg" },
{ folder: "Uplifting_(mood)", title: "Uplifting Mood", description: "Feel good songs", cover: "songs/Uplifting_(mood)/cover.jpg" },
{ folder: "cs", title: "Copyright Songs", description: "Cover Songs for you", cover: "songs/cs/cover.jpeg" }
];
let cardContainer = document.querySelector(".cardContainer");
cardContainer.innerHTML = "";
for (const album of albums) {
cardContainer.innerHTML += `
<div data-folder="${album.folder}" class="card">
<div class="play"><img src="img/play2.svg" alt="play"></div>
<img src="${album.cover}" alt="mood">
<h2>${album.title}</h2>
<p>${album.description}</p>
</div>`;
}
Array.from(document.getElementsByClassName("card")).forEach((e) => {
e.addEventListener("click", (item) => {
songs = getSongs(item.currentTarget.dataset.folder);
playMusic(songs[0]);
play.src = "img/pause.svg";
});
});
}
// Main app
function main() {
getSongs("ncs");
playMusic(songs[0], true);
displayAlbums();
// Play / Pause
play.addEventListener("click", () => {
if (currentsong.paused) {
currentsong.play();
play.src = "img/pause.svg";
} else {
currentsong.pause();
play.src = "img/play.svg";
}
});
// Progress bar
currentsong.addEventListener("timeupdate", () => {
document.querySelector(".songtime").innerHTML =
`${secondsToMinutesSeconds(currentsong.currentTime)} / ${secondsToMinutesSeconds(currentsong.duration)}`;
document.querySelector(".circle").style.left =
(currentsong.currentTime / currentsong.duration) * 100 + "%";
});
// Seek
document.querySelector(".seekbar").addEventListener("click", (e) => {
let percent = (e.offsetX / e.target.getBoundingClientRect().width) * 100;
document.querySelector(".circle").style.left = percent + "%";
currentsong.currentTime = (percent * currentsong.duration) / 100;
});
// Sidebar open/close
document.querySelector(".hamburger").addEventListener("click", () => {
document.querySelector(".left").style.left = "0px";
});
document.querySelector(".close").addEventListener("click", () => {
document.querySelector(".left").style.left = "-120%";
});
// Previous
previous.addEventListener("click", () => {
let index = songs.indexOf(currentsong.src.split("/").slice(-1)[0]);
if (index - 1 >= 0) {
playMusic(songs[index - 1]);
play.src = "img/pause.svg";
}
});
// Next
next.addEventListener("click", () => {
let index = songs.indexOf(currentsong.src.split("/").slice(-1)[0]);
if (index + 1 < songs.length) {
playMusic(songs[index + 1]);
} else {
playMusic(songs[0]);
}
play.src = "img/pause.svg";
});
// Volume slider
document.querySelector(".volume input").addEventListener("change", (e) => {
currentsong.volume = parseInt(e.target.value) / 100;
});
// Volume mute/unmute
document.querySelector(".volume > img").addEventListener("click", (e) => {
if (e.target.src.includes("img/volume.svg")) {
e.target.src = e.target.src.replace("img/volume.svg", "img/mute.svg");
currentsong.volume = 0;
document.querySelector(".volume input").value = 0;
} else {
e.target.src = e.target.src.replace("img/mute.svg", "img/volume.svg");
currentsong.volume = 0.5;
document.querySelector(".volume input").value = 50;
}
});
}
main();
let signupbtn=document.querySelector(".signupbtn");
signupbtn.addEventListener("click",()=>{
window.location.href="index.html";
})
let loginbtn=document.querySelector(".loginbtn");
loginbtn.addEventListener("click",()=>{
window.location.href="index.html";
})
let homebtn=document.querySelector(".home");
homebtn.addEventListener("click",()=>{
document.querySelector(".left").style.left = "-120%";
})