diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-08-26 13:38:04 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-08-26 13:38:04 +0200 |
| commit | 5ebebb8748453323709136d86f3b027cee309d4d (patch) | |
| tree | 33f2d19ae4e5083573f9cb84ae17d50e01e02b51 /packages | |
| parent | 5dcf3066a2be83d5422ea176e39b413c4769bcf8 (diff) | |
| download | meshbay-5ebebb8748453323709136d86f3b027cee309d4d.tar.gz | |
feat(music): prefetch 2 tracks ahead instead of 1
Complements the WebRTC auto-reconnect: a track already sitting in
blobCacheRef needs no live connection to play, so whatever was fetched
before a screen lock started plays through it regardless of what the
transport is doing during the lock. One track of runway was often shorter
than the lock itself; two buys more of it. MAX_CACHED_BLOBS (3) already
covers the currently-playing track plus these two, so no cache-size change
needed.
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/static/music-player.js | 20 |
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. |