Spaces:
Runtime error
Runtime error
Update public/script.js
Browse files- public/script.js +14 -10
public/script.js
CHANGED
|
@@ -158,36 +158,40 @@ function playMusic(fileName) {
|
|
| 158 |
return;
|
| 159 |
}
|
| 160 |
|
|
|
|
|
|
|
| 161 |
isLoadingMusic = true;
|
| 162 |
currentPlaying = fileName;
|
| 163 |
|
| 164 |
updatePlayingIndicator();
|
| 165 |
|
| 166 |
-
const loaderContainer = document.getElementById('loader-container');
|
| 167 |
-
loaderContainer.innerHTML = '';
|
| 168 |
const player = document.getElementById('audio-player');
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
loaderContainer.appendChild(loaderElement);
|
| 172 |
-
|
| 173 |
-
player.src = `/music/${fileName}`;
|
| 174 |
player.load();
|
| 175 |
|
| 176 |
player.oncanplaythrough = () => {
|
|
|
|
| 177 |
isLoadingMusic = false;
|
| 178 |
-
|
| 179 |
player.play();
|
| 180 |
player.loop = isLooping;
|
| 181 |
updateDuration();
|
| 182 |
document.getElementById('play-pause-btn').textContent = 'Pause'; // Update button label
|
| 183 |
};
|
| 184 |
|
| 185 |
-
player.onerror = () => {
|
|
|
|
| 186 |
isLoadingMusic = false;
|
| 187 |
-
|
| 188 |
alert(`Error loading the music: ${fileName}`);
|
| 189 |
currentPlaying = '';
|
| 190 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
}
|
| 192 |
|
| 193 |
// Add functions to manage the custom controls
|
|
|
|
| 158 |
return;
|
| 159 |
}
|
| 160 |
|
| 161 |
+
console.log("Trying to play: ", fileName);
|
| 162 |
+
|
| 163 |
isLoadingMusic = true;
|
| 164 |
currentPlaying = fileName;
|
| 165 |
|
| 166 |
updatePlayingIndicator();
|
| 167 |
|
|
|
|
|
|
|
| 168 |
const player = document.getElementById('audio-player');
|
| 169 |
+
player.src = `/music/${fileName}`; // Make sure this path is correct
|
| 170 |
+
console.log("Set audio source to: ", player.src);
|
|
|
|
|
|
|
|
|
|
| 171 |
player.load();
|
| 172 |
|
| 173 |
player.oncanplaythrough = () => {
|
| 174 |
+
console.log("Audio can play through, starting playback...");
|
| 175 |
isLoadingMusic = false;
|
| 176 |
+
document.getElementById('loader-container').innerHTML = ''; // Remove the loader element
|
| 177 |
player.play();
|
| 178 |
player.loop = isLooping;
|
| 179 |
updateDuration();
|
| 180 |
document.getElementById('play-pause-btn').textContent = 'Pause'; // Update button label
|
| 181 |
};
|
| 182 |
|
| 183 |
+
player.onerror = (e) => {
|
| 184 |
+
console.error("Error loading the audio: ", e);
|
| 185 |
isLoadingMusic = false;
|
| 186 |
+
document.getElementById('loader-container').innerHTML = ''; // Clear out the loader element
|
| 187 |
alert(`Error loading the music: ${fileName}`);
|
| 188 |
currentPlaying = '';
|
| 189 |
};
|
| 190 |
+
|
| 191 |
+
// Add an alternative event listener as a test
|
| 192 |
+
player.onloadeddata = () => {
|
| 193 |
+
console.log("Audio data loaded, src: ", player.src);
|
| 194 |
+
};
|
| 195 |
}
|
| 196 |
|
| 197 |
// Add functions to manage the custom controls
|