feat: implement preloading of next track in queue

- Add a hidden `preloadAudio` element to buffer the next song in the queue
- Automatically preload the next track after the current one starts playing
- Update service worker cache version to v6 to ensure fresh assets are fetched
This commit is contained in:
Brian Fertig 2026-04-18 16:08:54 -06:00
parent a4954dfaa8
commit 569c432fb5
2 changed files with 16 additions and 1 deletions

View File

@ -123,10 +123,12 @@
highlightNowPlaying(cur.id);
updateMediaSession();
showPlayNotification(cur);
preloadNext();
}
function playOne(song) {
requestNotificationPermission();
preloadAudio.src = '';
state.queue = [song];
state.index = 0;
playCurrent();
@ -159,6 +161,19 @@
// event fired by src reassignment doesn't mislead iOS into thinking playback stopped.
let transitioning = false;
// Hidden audio element used to buffer the next track in the queue.
const preloadAudio = new Audio();
preloadAudio.preload = 'auto';
function preloadNext() {
const next = state.queue[state.index + 1];
if (next) {
preloadAudio.src = `/stream/${next.id}`;
} else {
preloadAudio.src = '';
}
}
audio.addEventListener('ended', next);
audio.addEventListener('play', () => {
transitioning = false;

View File

@ -1,4 +1,4 @@
const CACHE = 'bri-tunes-v5';
const CACHE = 'bri-tunes-v6';
const STATIC_PRECACHE = [
'/',
'/static/css/app.css',