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:
parent
a4954dfaa8
commit
569c432fb5
|
|
@ -123,10 +123,12 @@
|
||||||
highlightNowPlaying(cur.id);
|
highlightNowPlaying(cur.id);
|
||||||
updateMediaSession();
|
updateMediaSession();
|
||||||
showPlayNotification(cur);
|
showPlayNotification(cur);
|
||||||
|
preloadNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
function playOne(song) {
|
function playOne(song) {
|
||||||
requestNotificationPermission();
|
requestNotificationPermission();
|
||||||
|
preloadAudio.src = '';
|
||||||
state.queue = [song];
|
state.queue = [song];
|
||||||
state.index = 0;
|
state.index = 0;
|
||||||
playCurrent();
|
playCurrent();
|
||||||
|
|
@ -159,6 +161,19 @@
|
||||||
// event fired by src reassignment doesn't mislead iOS into thinking playback stopped.
|
// event fired by src reassignment doesn't mislead iOS into thinking playback stopped.
|
||||||
let transitioning = false;
|
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('ended', next);
|
||||||
audio.addEventListener('play', () => {
|
audio.addEventListener('play', () => {
|
||||||
transitioning = false;
|
transitioning = false;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
const CACHE = 'bri-tunes-v5';
|
const CACHE = 'bri-tunes-v6';
|
||||||
const STATIC_PRECACHE = [
|
const STATIC_PRECACHE = [
|
||||||
'/',
|
'/',
|
||||||
'/static/css/app.css',
|
'/static/css/app.css',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue