-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
258 lines (227 loc) · 7.53 KB
/
index.html
File metadata and controls
258 lines (227 loc) · 7.53 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Music Player with Lyrics</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.player {
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
text-align: center;
width: 400px;
}
.playlist-button {
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
.playlist-button:hover {
background-color: #0056b3;
}
.playlist {
margin-top: 20px;
text-align: left;
}
.playlist ul {
list-style-type: none;
padding: 0;
}
.playlist li {
padding: 10px;
border-bottom: 1px solid #ddd;
cursor: pointer;
}
.playlist li:hover {
background-color: #f9f9f9;
}
.audio-controls {
margin-top: 20px;
display: none; /* Hidden by default */
}
.album-art {
width: 150px;
height: 150px;
background-color: #ddd;
margin: 0 auto 10px;
border-radius: 10px;
overflow: hidden;
}
.album-art img {
width: 100%;
height: 100%;
object-fit: cover;
}
.controls {
display: flex;
justify-content: center;
gap: 10px;
margin-top: 10px;
}
.controls button {
background: none;
border: none;
cursor: pointer;
font-size: 20px;
}
.controls button:hover {
color: #007bff;
}
.lyrics {
margin-top: 20px;
text-align: left;
max-height: 200px;
overflow-y: auto;
border: 1px solid #ddd;
padding: 10px;
border-radius: 5px;
}
.lyrics p {
margin: 5px 0;
opacity: 0.5;
transition: opacity 0.3s, font-weight 0.3s;
}
.lyrics p.active {
opacity: 1;
font-weight: bold;
}
</style>
</head>
<body>
<div class="player">
<h1>Music Player</h1>
<button class="playlist-button" id="playlistButton">Show Playlist</button>
<div class="playlist" id="playlist" style="display: none;">
<h2>Playlist</h2>
<ul id="playlistList"></ul>
</div>
<div class="audio-controls" id="audioControls">
<div class="album-art">
<img src="default-album.jpg" alt="Album Art">
</div>
<audio id="audio" controls></audio>
<div class="controls">
<button onclick="playPrevious()">⏮️</button>
<button onclick="playNext()">⏭️</button>
</div>
<div class="lyrics" id="lyrics"></div>
</div>
</div>
<script>
const playlistButton = document.getElementById("playlistButton");
const playlist = document.getElementById("playlist");
const playlistList = document.getElementById("playlistList");
const audioControls = document.getElementById("audioControls");
const audio = document.getElementById("audio");
const lyricsElement = document.getElementById("lyrics");
// Mock list of songs (replace with actual file names from your folder)
const songs = [
{ name: "Song 1", file: "songs/song1.mp3", lyrics: "lyrics/song1.lrc" },
{ name: "Song 2", file: "songs/song2.mp3", lyrics: "lyrics/song2.lrc" }
];
let currentSongIndex = 0;
let lyricsData = [];
// Show playlist when button is clicked
playlistButton.addEventListener("click", () => {
playlist.style.display = "block";
playlistButton.style.display = "none";
renderPlaylist();
});
// Render playlist
function renderPlaylist() {
songs.forEach((song, index) => {
const li = document.createElement("li");
li.textContent = song.name;
li.addEventListener("click", () => playSong(index));
playlistList.appendChild(li);
});
}
// Play selected song
function playSong(index) {
currentSongIndex = index;
const song = songs[index];
audio.src = song.file;
audioControls.style.display = "block";
fetchLyrics(song.lyrics);
audio.play();
}
// Fetch lyrics from LRC file
function fetchLyrics(lyricsFile) {
fetch(lyricsFile)
.then(response => response.text())
.then(text => {
lyricsData = parseLRC(text);
renderLyrics();
})
.catch(error => {
console.error("Error loading lyrics:", error);
lyricsElement.innerHTML = "<p>Lyrics not available.</p>";
});
}
// Parse LRC file
function parseLRC(lrcText) {
const lines = lrcText.split("\n");
const parsedLyrics = [];
lines.forEach(line => {
const match = line.match(/^\[(\d{2}):(\d{2}\.\d{2})\](.*)/);
if (match) {
const minutes = parseFloat(match[1]);
const seconds = parseFloat(match[2]);
const time = minutes * 60 + seconds;
const text = match[3].trim();
parsedLyrics.push({ time, text });
}
});
return parsedLyrics;
}
// Render lyrics
function renderLyrics() {
lyricsElement.innerHTML = "";
lyricsData.forEach(line => {
const p = document.createElement("p");
p.textContent = line.text;
lyricsElement.appendChild(p);
});
}
// Highlight current line of lyrics
audio.addEventListener("timeupdate", () => {
const currentTime = audio.currentTime;
const lines = lyricsElement.querySelectorAll("p");
lines.forEach((line, index) => {
const nextLineTime = index < lyricsData.length - 1 ? lyricsData[index + 1].time : Infinity;
if (currentTime >= lyricsData[index].time && currentTime < nextLineTime) {
line.classList.add("active");
} else {
line.classList.remove("active");
}
});
});
// Play next song
function playNext() {
currentSongIndex = (currentSongIndex + 1) % songs.length;
playSong(currentSongIndex);
}
// Play previous song
function playPrevious() {
currentSongIndex = (currentSongIndex - 1 + songs.length) % songs.length;
playSong(currentSongIndex);
}
</script>
</body>
</html>