Spaces:
Running
Running
prasanth.thangavel
commited on
Commit
Β·
466bb96
1
Parent(s):
2f0eefe
Minor improvements
Browse files- README.md +8 -2
- templates/index.html +76 -5
README.md
CHANGED
@@ -12,8 +12,14 @@ short_description: My personal music player
|
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
13 |
|
14 |
# Todo
|
15 |
-
|
|
|
16 |
```
|
17 |
docker build -t musicplayer .
|
18 |
docker run -p 7860:7860 musicplayer
|
19 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
13 |
|
14 |
# Todo
|
15 |
+
## Testing
|
16 |
+
- [ ] Test docker locally for faster iterative testing.
|
17 |
```
|
18 |
docker build -t musicplayer .
|
19 |
docker run -p 7860:7860 musicplayer
|
20 |
+
```
|
21 |
+
## Enhancements
|
22 |
+
- [ ] Add a aesthetically beautiful background theme/color/design.
|
23 |
+
- [ ] Improve the icons/buttons and overall design
|
24 |
+
- [ ] The loop feature is not working as intended
|
25 |
+
- [ ] Add persistent memory, especially for creating playlists (it get's overwritten once the changes are deployed)
|
templates/index.html
CHANGED
@@ -74,8 +74,11 @@
|
|
74 |
transition: transform 0.2s;
|
75 |
}
|
76 |
|
77 |
-
.sw-btn
|
78 |
transform: scale(0.96);
|
|
|
|
|
|
|
79 |
}
|
80 |
|
81 |
.sw-dropdown {
|
@@ -97,6 +100,7 @@
|
|
97 |
border-radius: 12px;
|
98 |
background: #f5f5f5;
|
99 |
transition: background 0.2s;
|
|
|
100 |
}
|
101 |
|
102 |
.sw-track.active {
|
@@ -163,6 +167,9 @@
|
|
163 |
.sw-btn:hover {
|
164 |
background: #7722ff;
|
165 |
}
|
|
|
|
|
|
|
166 |
.sw-track {
|
167 |
padding: 20px;
|
168 |
}
|
@@ -171,7 +178,7 @@
|
|
171 |
<body>
|
172 |
<div class="sw-container">
|
173 |
<div class="sw-player">
|
174 |
-
<h1 class="sw-header"
|
175 |
<div class="sw-now-playing"><span id="swCurrentSong">No song selected</span></div>
|
176 |
<audio id="swAudio" class="sw-audio" controls preload="none" autoplay="false">
|
177 |
Your browser does not support audio playback.
|
@@ -180,6 +187,8 @@
|
|
180 |
<div class="sw-btn-group">
|
181 |
<button class="sw-btn" onclick="swPrevious()">Previous</button>
|
182 |
<button class="sw-btn" onclick="swNext()">Next</button>
|
|
|
|
|
183 |
</div>
|
184 |
|
185 |
<select class="sw-dropdown" id="swPlaylistSelect" onchange="swChangePlaylist()">
|
@@ -230,9 +239,24 @@
|
|
230 |
|
231 |
function swNext() {
|
232 |
const currentPlaylistTracks = swGetCurrentTracks();
|
233 |
-
if (
|
234 |
-
swCurrentIndex
|
235 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
}
|
237 |
}
|
238 |
|
@@ -285,6 +309,9 @@
|
|
285 |
function swChangePlaylist() {
|
286 |
swCurrentPlaylist = document.getElementById('swPlaylistSelect').value;
|
287 |
swCurrentIndex = 0;
|
|
|
|
|
|
|
288 |
swUpdateTracks();
|
289 |
if (swGetCurrentTracks().length > 0) {
|
290 |
swPlay(swGetCurrentTracks()[0]);
|
@@ -333,6 +360,50 @@
|
|
333 |
audio.currentTime = 0;
|
334 |
}
|
335 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
336 |
</script>
|
337 |
</body>
|
338 |
</html>
|
|
|
74 |
transition: transform 0.2s;
|
75 |
}
|
76 |
|
77 |
+
.sw-btn.active {
|
78 |
transform: scale(0.96);
|
79 |
+
background: #7722ff;
|
80 |
+
position: relative;
|
81 |
+
order: 2px solid var(--primary);
|
82 |
}
|
83 |
|
84 |
.sw-dropdown {
|
|
|
100 |
border-radius: 12px;
|
101 |
background: #f5f5f5;
|
102 |
transition: background 0.2s;
|
103 |
+
font-size: 0.85rem; /* Added this line to reduce font size */
|
104 |
}
|
105 |
|
106 |
.sw-track.active {
|
|
|
167 |
.sw-btn:hover {
|
168 |
background: #7722ff;
|
169 |
}
|
170 |
+
.sw-btn.active:hover {
|
171 |
+
background: #6200ee;
|
172 |
+
}
|
173 |
.sw-track {
|
174 |
padding: 20px;
|
175 |
}
|
|
|
178 |
<body>
|
179 |
<div class="sw-container">
|
180 |
<div class="sw-player">
|
181 |
+
<h1 class="sw-header">π΅ Music Player</h1>
|
182 |
<div class="sw-now-playing"><span id="swCurrentSong">No song selected</span></div>
|
183 |
<audio id="swAudio" class="sw-audio" controls preload="none" autoplay="false">
|
184 |
Your browser does not support audio playback.
|
|
|
187 |
<div class="sw-btn-group">
|
188 |
<button class="sw-btn" onclick="swPrevious()">Previous</button>
|
189 |
<button class="sw-btn" onclick="swNext()">Next</button>
|
190 |
+
<button class="sw-btn" id="swLoopBtn" onclick="swToggleLoop()">π Loop</button>
|
191 |
+
<button class="sw-btn" id="swShuffleBtn" onclick="swToggleShuffle()">π Shuffle</button>
|
192 |
</div>
|
193 |
|
194 |
<select class="sw-dropdown" id="swPlaylistSelect" onchange="swChangePlaylist()">
|
|
|
239 |
|
240 |
function swNext() {
|
241 |
const currentPlaylistTracks = swGetCurrentTracks();
|
242 |
+
if (swIsShuffling) {
|
243 |
+
const currentShuffleIndex = swShuffledIndices.indexOf(swCurrentIndex);
|
244 |
+
if (currentShuffleIndex < swShuffledIndices.length - 1) {
|
245 |
+
swCurrentIndex = swShuffledIndices[currentShuffleIndex + 1];
|
246 |
+
swPlay(currentPlaylistTracks[swCurrentIndex]);
|
247 |
+
} else if (swIsLooping) {
|
248 |
+
generateShuffledIndices();
|
249 |
+
swCurrentIndex = swShuffledIndices[0];
|
250 |
+
swPlay(currentPlaylistTracks[swCurrentIndex]);
|
251 |
+
}
|
252 |
+
} else {
|
253 |
+
if (swCurrentIndex < currentPlaylistTracks.length - 1) {
|
254 |
+
swCurrentIndex++;
|
255 |
+
swPlay(currentPlaylistTracks[swCurrentIndex]);
|
256 |
+
} else if (swIsLooping) {
|
257 |
+
swCurrentIndex = 0;
|
258 |
+
swPlay(currentPlaylistTracks[swCurrentIndex]);
|
259 |
+
}
|
260 |
}
|
261 |
}
|
262 |
|
|
|
309 |
function swChangePlaylist() {
|
310 |
swCurrentPlaylist = document.getElementById('swPlaylistSelect').value;
|
311 |
swCurrentIndex = 0;
|
312 |
+
if (swIsShuffling) {
|
313 |
+
generateShuffledIndices();
|
314 |
+
}
|
315 |
swUpdateTracks();
|
316 |
if (swGetCurrentTracks().length > 0) {
|
317 |
swPlay(swGetCurrentTracks()[0]);
|
|
|
360 |
audio.currentTime = 0;
|
361 |
}
|
362 |
});
|
363 |
+
|
364 |
+
// State variables
|
365 |
+
let swIsLooping = false;
|
366 |
+
let swIsShuffling = false;
|
367 |
+
let swShuffledIndices = [];
|
368 |
+
|
369 |
+
// Load saved preferences
|
370 |
+
document.addEventListener('DOMContentLoaded', function() {
|
371 |
+
// ... existing code ...
|
372 |
+
swIsLooping = JSON.parse(localStorage.getItem('swIsLooping') || 'false');
|
373 |
+
swIsShuffling = JSON.parse(localStorage.getItem('swIsShuffling') || 'false');
|
374 |
+
updateControlButtons();
|
375 |
+
});
|
376 |
+
|
377 |
+
function swToggleLoop() {
|
378 |
+
swIsLooping = !swIsLooping;
|
379 |
+
localStorage.setItem('swIsLooping', swIsLooping);
|
380 |
+
updateControlButtons();
|
381 |
+
}
|
382 |
+
|
383 |
+
function swToggleShuffle() {
|
384 |
+
swIsShuffling = !swIsShuffling;
|
385 |
+
localStorage.setItem('swIsShuffling', swIsShuffling);
|
386 |
+
if (swIsShuffling) {
|
387 |
+
generateShuffledIndices();
|
388 |
+
}
|
389 |
+
updateControlButtons();
|
390 |
+
}
|
391 |
+
|
392 |
+
function updateControlButtons() {
|
393 |
+
document.getElementById('swLoopBtn').classList.toggle('active', swIsLooping);
|
394 |
+
document.getElementById('swShuffleBtn').classList.toggle('active', swIsShuffling);
|
395 |
+
}
|
396 |
+
|
397 |
+
function generateShuffledIndices() {
|
398 |
+
const tracks = swGetCurrentTracks();
|
399 |
+
swShuffledIndices = Array.from({length: tracks.length}, (_, i) => i);
|
400 |
+
// Fisher-Yates shuffle
|
401 |
+
for (let i = swShuffledIndices.length - 1; i > 0; i--) {
|
402 |
+
const j = Math.floor(Math.random() * (i + 1));
|
403 |
+
[swShuffledIndices[i], swShuffledIndices[j]] = [swShuffledIndices[j], swShuffledIndices[i]];
|
404 |
+
}
|
405 |
+
}
|
406 |
+
|
407 |
</script>
|
408 |
</body>
|
409 |
</html>
|