diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-10-04 23:07:46 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-10-04 23:07:46 +0200 |
| commit | ac8ed437659d765120d1b0cc9f83e942549b479f (patch) | |
| tree | 7ebb9d5fa4b8868dfb0f5e95221c4d1a4321d2e7 /packages | |
| parent | 652465910dcdcc761aa2e078ff1a82625e2a0aa5 (diff) | |
| download | meshbay-ac8ed437659d765120d1b0cc9f83e942549b479f.tar.gz | |
fix(hub): music keep-alive outlasts a skipped track
Held while a track plays or loads and released 5 s late, so skipping a
bad file with the screen off no longer drops the Android foreground
service, which cannot be taken back from the background.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/static/music-player.js | 22 |
1 files changed, 15 insertions, 7 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 500f518..e97ce00 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/music-player.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/music-player.js @@ -280,14 +280,22 @@ function MusicPlayerBar({ getConnection, queue, onClose, userPrefs, onSaveQueue for (const { url } of blobCacheRef.current.values()) URL.revokeObjectURL(url); }, []); - // Held for as long as a track plays, through the advance to the next one: - // without it a phone freezes the page a minute after the screen goes off, - // and the next track never loads. + // Held for as long as a track plays or loads: without it a phone freezes the + // page a minute after the screen goes off, and the next track never loads. + // Let go a few seconds late, because skipping a track that failed passes + // through "not playing", and Android refuses to take the hold back from the + // background: a playlist would stop at its first bad file. + const keepAliveRef = useRef({ held: false, timer: null }); + const active = playing || loading; useEffect(() => { - if (!playing) return; - playback.keepAlive(true); - return () => playback.keepAlive(false); - }, [playing]); + const k = keepAliveRef.current; + if (!active) return; + clearTimeout(k.timer); + if (!k.held) { k.held = true; playback.keepAlive(true); } + return () => { + k.timer = setTimeout(() => { k.held = false; playback.keepAlive(false); }, 5000); + }; + }, [active]); // Screen Wake Lock, opt-in only (Settings → music_keep_screen_on) and only // while a track is actually playing — off by default because the ordinary |