diff --git a/public/music/psshvec.flac b/public/music/psshvec.flac new file mode 100644 index 0000000..36059c9 Binary files /dev/null and b/public/music/psshvec.flac differ diff --git a/public/music/zimaooes.flac b/public/music/zimaooes.flac new file mode 100644 index 0000000..3712474 Binary files /dev/null and b/public/music/zimaooes.flac differ diff --git a/src/lib/AudioPlayer.svelte b/src/lib/AudioPlayer.svelte index 05e5912..8997465 100644 --- a/src/lib/AudioPlayer.svelte +++ b/src/lib/AudioPlayer.svelte @@ -18,6 +18,31 @@ let currentTrackIndex = 0; let currentTrack = null; + function getSecureRandomIntExclusive(max) { + if (!max || max <= 0) return 0; + const cryptoObj = typeof window !== 'undefined' && (window.crypto || window.msCrypto); + if (cryptoObj && cryptoObj.getRandomValues) { + const maxUint32 = 4294967296; + const threshold = maxUint32 - (maxUint32 % max); + const buf = new Uint32Array(1); + for (;;) { + cryptoObj.getRandomValues(buf); + const r = buf[0]; + if (r < threshold) return r % max; + } + } + return Math.floor(Math.random() * max); + } + + function shuffleInPlace(arr) { + for (let i = arr.length - 1; i > 0; i--) { + const j = getSecureRandomIntExclusive(i + 1); + const tmp = arr[i]; + arr[i] = arr[j]; + arr[j] = tmp; + } + } + onMount(async () => { await loadTracks(); }); @@ -33,7 +58,8 @@ try { loadingProgress = 10; - const trackFiles = ['mgxleepe.flac', 'jifmachinecd.flac']; + const trackFiles = ['mgxleepe.flac', 'jifmachinecd.flac', 'psshvec.flac', 'zimaooes.flac']; + shuffleInPlace(trackFiles); tracks = []; for (let i = 0; i < trackFiles.length; i++) { @@ -41,7 +67,8 @@ loadingProgress = 20 + (i * 60 / trackFiles.length); try { - const response = await fetch(`/music/${filename}`); + const url = `/music/${filename}`; + const response = await fetch(url, { cache: 'force-cache' }); if (!response.ok) continue; const arrayBuffer = await response.arrayBuffer(); @@ -49,7 +76,7 @@ tracks.push({ filename, - src: `/music/${filename}`, + src: url, metadata, title: metadata.common.title || filename.replace('.flac', ''), artist: metadata.common.artist || 'Unknown Artist', @@ -67,7 +94,8 @@ } loadingProgress = 90; - currentTrack = tracks[0]; + currentTrackIndex = getSecureRandomIntExclusive(tracks.length); + currentTrack = tracks[currentTrackIndex]; loadingProgress = 100; setTimeout(() => { @@ -166,6 +194,7 @@ on:timeupdate={updateTime} on:loadedmetadata={updateTime} on:ended={nextTrack} + preload="auto" > {#if loading}