Spaces:
Running
Running
My music player stopped working after I tried to add an audio visualizer. The Play button does nothing now.
Browse filesPlease do the following:
Revert script.js to the most recent previous version where:
the MySpace-style music player worked,
the playlist and seek bar worked,
and the music autoplayed on page load.
DO NOT add any Web Audio / visualizer code. I just want the plain, original working music player back.
DO NOT change index.html or styles.css.
Make sure script.js has:
the const playlist = [...] definition,
the event listeners for play/pause/next/prev/seek bar,
and the big if (audioEl && titleEl && artistEl && playPauseBtn && prevBtn && nextBtn && seekBar) { ... } block properly closed with a final }.
In short: please restore script.js to the last known working version before any visualizer changes, so the music player works and autoplay works again.
script.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
| 1 |
-
=== MySpace-style music player ==========
|
| 2 |
-
|
| 3 |
-
// 1) Playlist: add as many tracks as you like here.
|
| 4 |
-
=======
|
| 5 |
-
// ========== MySpace-style music player ==========
|
| 6 |
|
| 7 |
// Audio analyzer setup
|
| 8 |
let audioContext;
|
|
@@ -57,77 +53,76 @@ function animateEqualizer() {
|
|
| 57 |
}
|
| 58 |
|
| 59 |
// 1) Playlist: add as many tracks as you like here.
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
// Initialize tooltips
|
| 63 |
-
const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
|
| 64 |
-
tooltipTriggerList.map(function (tooltipTriggerEl) {
|
| 65 |
-
return new bootstrap.Tooltip(tooltipTriggerEl);
|
| 66 |
-
});
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
friendList.setAttribute('loading', 'false');
|
| 73 |
-
}
|
| 74 |
-
}, 1500);
|
| 75 |
-
|
| 76 |
-
// Handle post submission
|
| 77 |
-
const postForm = document.querySelector('.post-form');
|
| 78 |
-
if (postForm) {
|
| 79 |
-
postForm.addEventListener('submit', function(e) {
|
| 80 |
-
e.preventDefault();
|
| 81 |
-
alert('Post submitted! (This is a demo)');
|
| 82 |
-
this.reset();
|
| 83 |
-
});
|
| 84 |
-
}
|
| 85 |
-
});
|
| 86 |
-
// Theme switcher for retro mode
|
| 87 |
-
function toggleRetroMode() {
|
| 88 |
-
document.body.classList.toggle('retro-mode');
|
| 89 |
-
localStorage.setItem('retroMode', document.body.classList.contains('retro-mode'));
|
| 90 |
-
updateThemeIcon();
|
| 91 |
-
}
|
| 92 |
|
| 93 |
-
//
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
| 97 |
|
| 98 |
-
function
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
}
|
| 110 |
-
|
| 111 |
-
function
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
}
|
| 118 |
|
| 119 |
-
//
|
| 120 |
-
document.addEventListener('DOMContentLoaded', function() {
|
| 121 |
-
updateThemeIcon();
|
| 122 |
-
|
| 123 |
-
// Auto-play music on page load
|
| 124 |
-
const audio = document.querySelector('audio');
|
| 125 |
-
if (audio) {
|
| 126 |
-
audio.volume = 0.5; // Set default volume to 50%
|
| 127 |
-
}
|
| 128 |
-
});
|
| 129 |
|
| 130 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
// 1) Playlist: add as many tracks as you like here.
|
| 133 |
// For now these point to files like "songs/amber.mp3".
|
|
@@ -136,11 +131,10 @@ const playlist = [
|
|
| 136 |
{
|
| 137 |
title: "The Ocean",
|
| 138 |
artist: "Super Fuzz",
|
| 139 |
-
src: "https://cdn-uploads.huggingface.co/production/uploads/693f06e4c231c8267144eb68/WwdKDnPZAW9q7tXWomfSY.mpga",
|
| 140 |
},
|
| 141 |
];
|
| 142 |
|
| 143 |
-
|
| 144 |
// 2) Grab all the player elements from the page
|
| 145 |
const audioEl = document.getElementById("audio-player");
|
| 146 |
const titleEl = document.getElementById("track-title");
|
|
@@ -234,19 +228,12 @@ if (
|
|
| 234 |
loadTrack(currentTrackIndex);
|
| 235 |
playTrack();
|
| 236 |
});
|
|
|
|
| 237 |
// Load first track + try to autoplay like old MySpace
|
| 238 |
window.addEventListener("load", () => {
|
| 239 |
loadTrack(currentTrackIndex);
|
| 240 |
// Browsers might block this until the visitor clicks somewhere,
|
| 241 |
// but we'll *try* to autoplay for that true 2005 chaos.
|
| 242 |
playTrack();
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
|
|
|
| 1 |
+
=== MySpace-style music player ============= MySpace-style music player ==========
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
// Audio analyzer setup
|
| 4 |
let audioContext;
|
|
|
|
| 53 |
}
|
| 54 |
|
| 55 |
// 1) Playlist: add as many tracks as you like here.
|
| 56 |
+
=======
|
| 57 |
+
// ========== MySpace-style music player ==========
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
// 1) Playlist: add as many tracks as you like here.
|
| 60 |
+
1) Playlist: add as many tracks as you like here.
|
| 61 |
+
=======
|
| 62 |
+
// ========== MySpace-style music player ==========
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
+
// Audio analyzer setup
|
| 65 |
+
let audioContext;
|
| 66 |
+
let analyser;
|
| 67 |
+
let dataArray;
|
| 68 |
+
let animationId;
|
| 69 |
+
const eqBars = document.querySelectorAll('.eq-bar');
|
| 70 |
|
| 71 |
+
function setupAudioAnalyzer(audioElement) {
|
| 72 |
+
try {
|
| 73 |
+
if (!audioContext) {
|
| 74 |
+
audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
if (analyser) {
|
| 78 |
+
analyser.disconnect();
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
analyser = audioContext.createAnalyser();
|
| 82 |
+
analyser.fftSize = 32;
|
| 83 |
+
|
| 84 |
+
const source = audioContext.createMediaElementSource(audioElement);
|
| 85 |
+
source.connect(analyser);
|
| 86 |
+
analyser.connect(audioContext.destination);
|
| 87 |
+
|
| 88 |
+
dataArray = new Uint8Array(analyser.frequencyBinCount);
|
| 89 |
+
|
| 90 |
+
if (animationId) {
|
| 91 |
+
cancelAnimationFrame(animationId);
|
| 92 |
+
}
|
| 93 |
+
animateEqualizer();
|
| 94 |
+
} catch (e) {
|
| 95 |
+
console.error('Audio analyzer setup failed:', e);
|
| 96 |
+
}
|
| 97 |
}
|
| 98 |
+
|
| 99 |
+
function animateEqualizer() {
|
| 100 |
+
if (!analyser || !dataArray || eqBars.length === 0) return;
|
| 101 |
+
|
| 102 |
+
analyser.getByteFrequencyData(dataArray);
|
| 103 |
+
|
| 104 |
+
// Scale the frequency data to match our EQ bars
|
| 105 |
+
for (let i = 0; i < eqBars.length; i++) {
|
| 106 |
+
const barIndex = Math.floor(i * (dataArray.length / eqBars.length));
|
| 107 |
+
const value = dataArray[barIndex] / 255;
|
| 108 |
+
const height = value * 100;
|
| 109 |
+
eqBars[i].style.height = `${height}%`;
|
| 110 |
+
eqBars[i].style.opacity = 0.3 + (value * 0.7);
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
animationId = requestAnimationFrame(animateEqualizer);
|
| 114 |
}
|
| 115 |
|
| 116 |
+
// 1) Playlist: add as many tracks as you like here.=== MySpace-style music player ==========
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
+
// 1) Playlist: add as many tracks as you like here.
|
| 119 |
+
// For now these point to files like "songs/amber.mp3".
|
| 120 |
+
// We'll talk about uploading those right after this.
|
| 121 |
+
=======
|
| 122 |
+
// 1) Playlist: add as many tracks as you like here.
|
| 123 |
+
// For now these point to files like "songs/amber.mp3".
|
| 124 |
+
// We'll talk about uploading those right after this.
|
| 125 |
+
========== MySpace-style music player ==========
|
| 126 |
|
| 127 |
// 1) Playlist: add as many tracks as you like here.
|
| 128 |
// For now these point to files like "songs/amber.mp3".
|
|
|
|
| 131 |
{
|
| 132 |
title: "The Ocean",
|
| 133 |
artist: "Super Fuzz",
|
| 134 |
+
src: "https://cdn-uploads.huggingface.co/production/uploads/693f06e4c231c8267144eb68/WwdKDnPZAW9q7tXWomfSY.mpga",
|
| 135 |
},
|
| 136 |
];
|
| 137 |
|
|
|
|
| 138 |
// 2) Grab all the player elements from the page
|
| 139 |
const audioEl = document.getElementById("audio-player");
|
| 140 |
const titleEl = document.getElementById("track-title");
|
|
|
|
| 228 |
loadTrack(currentTrackIndex);
|
| 229 |
playTrack();
|
| 230 |
});
|
| 231 |
+
|
| 232 |
// Load first track + try to autoplay like old MySpace
|
| 233 |
window.addEventListener("load", () => {
|
| 234 |
loadTrack(currentTrackIndex);
|
| 235 |
// Browsers might block this until the visitor clicks somewhere,
|
| 236 |
// but we'll *try* to autoplay for that true 2005 chaos.
|
| 237 |
playTrack();
|
| 238 |
+
});
|
| 239 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|