summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/static/music-player.js20
1 files changed, 16 insertions, 4 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/music-player.js b/packages/meshbay-hub/src/meshbay_hub/static/music-player.js
index 73cae27..7fdc74e 100644
--- a/packages/meshbay-hub/src/meshbay_hub/static/music-player.js
+++ b/packages/meshbay-hub/src/meshbay_hub/static/music-player.js
@@ -255,12 +255,24 @@ function MusicPlayerBar({ transportRef, gekRef, queue, onClose }) {
return url;
}, [transportRef, gekRef, evictOldBlobs]);
- // Silently warms the cache for the next track so pressing "next" doesn't
+ // Silently warms the cache for the next tracks so pressing "next" doesn't
// visibly wait (musicbay.md §2.2) — best-effort, never surfaces an error.
+ //
+ // Two ahead, not one: a screen lock can cost the transport several minutes
+ // (see the WebRTC auto-reconnect in transport.js — this is the other half
+ // of the same fix). A track already sitting in blobCacheRef needs no
+ // connection at all to play, so whatever got fetched *before* the lock
+ // started plays through it regardless of what the connection is doing —
+ // it just buys more of that runway than fetching only one track ahead did.
+ // MAX_CACHED_BLOBS is sized for exactly this: the one playing plus these two.
+ const PREFETCH_AHEAD = 2;
+
const prefetchNext = useCallback((fromPos) => {
- const nextEntry = tracks[order[fromPos + 1]];
- if (!nextEntry || blobCacheRef.current.has(nextEntry.id)) return;
- fetchTrackBlob(nextEntry).catch(() => {});
+ for (let ahead = 1; ahead <= PREFETCH_AHEAD; ahead++) {
+ const nextEntry = tracks[order[fromPos + ahead]];
+ if (!nextEntry || blobCacheRef.current.has(nextEntry.id)) continue;
+ fetchTrackBlob(nextEntry).catch(() => {});
+ }
}, [tracks, order, fetchTrackBlob]);
// (Re)initialize the queue whenever the shell hands over a new one.