add optional shuffle flag
Hunter
Saturday, November 1st, 2025 at 7:49 PM
8 const audio = document.getElementById('audioPlayer');
9 audio.controls = true; // Enable controls for iOS media session
10
11 +const shuffle = false;
12 +
13 +function shuffleArray(array) {
14 + const shuffled = [...array];
15 + for (let i = shuffled.length - 1; i > 0; i--) {
16 + const j = Math.floor(Math.random() * (i + 1));
17 + [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
18 + }
19 + return shuffled;
20 +}
21 +
22 let currentSongIndex = 0;
23 let isPlaying = false;
24 let progressInterval;
40 return response.json();
41 })
42 .then(data => {
- songs = data;
43 + songs = shuffle ? shuffleArray(data) : data;
44 if (songs.length > 0) {
45 playerReady = true;
46 updateCurrentSongDisplay(`Ready to play: ${songs[0].artist} – ${songs[0].title}`);