Spaces:
Runtime error
Runtime error
Update public/script.js
Browse files- public/script.js +17 -0
public/script.js
CHANGED
|
@@ -215,6 +215,7 @@ function playMusic(fileName) {
|
|
| 215 |
}
|
| 216 |
|
| 217 |
isLoadingMusic = true;
|
|
|
|
| 218 |
currentPlaying = fileName;
|
| 219 |
|
| 220 |
updatePlayingIndicator();
|
|
@@ -227,12 +228,28 @@ function playMusic(fileName) {
|
|
| 227 |
|
| 228 |
audio.oncanplaythrough = () => {
|
| 229 |
isLoadingMusic = false;
|
|
|
|
| 230 |
document.getElementById('play-pause-btn').textContent = 'Pause'; // Update play/pause button
|
| 231 |
audio.play(); // Start playback
|
| 232 |
};
|
| 233 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
audio.onerror = () => {
|
| 235 |
isLoadingMusic = false;
|
|
|
|
| 236 |
alert(`Error loading the music: ${fileName}`);
|
| 237 |
currentPlaying = ''; // Reset the current playing track
|
| 238 |
};
|
|
|
|
| 215 |
}
|
| 216 |
|
| 217 |
isLoadingMusic = true;
|
| 218 |
+
showLoader(true); // Show loader when starting to load a new song
|
| 219 |
currentPlaying = fileName;
|
| 220 |
|
| 221 |
updatePlayingIndicator();
|
|
|
|
| 228 |
|
| 229 |
audio.oncanplaythrough = () => {
|
| 230 |
isLoadingMusic = false;
|
| 231 |
+
showLoader(false); // Hide loader when song is ready
|
| 232 |
document.getElementById('play-pause-btn').textContent = 'Pause'; // Update play/pause button
|
| 233 |
audio.play(); // Start playback
|
| 234 |
};
|
| 235 |
|
| 236 |
+
// Updated onended event handler within playMusic function
|
| 237 |
+
audio.onended = () => {
|
| 238 |
+
if (isLooping) {
|
| 239 |
+
// Replay the current song
|
| 240 |
+
audio.currentTime = 0;
|
| 241 |
+
audio.play();
|
| 242 |
+
} else {
|
| 243 |
+
const currentIndex = trackList.indexOf(currentPlaying);
|
| 244 |
+
if (currentIndex !== -1 && currentIndex < trackList.length - 1) {
|
| 245 |
+
playMusic(trackList[currentIndex + 1]);
|
| 246 |
+
}
|
| 247 |
+
}
|
| 248 |
+
};
|
| 249 |
+
|
| 250 |
audio.onerror = () => {
|
| 251 |
isLoadingMusic = false;
|
| 252 |
+
showLoader(false); // Hide loader on error
|
| 253 |
alert(`Error loading the music: ${fileName}`);
|
| 254 |
currentPlaying = ''; // Reset the current playing track
|
| 255 |
};
|