From 652465910dcdcc761aa2e078ff1a82625e2a0aa5 Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Sun, 4 Oct 2026 22:46:00 +0200 Subject: feat(android): music keeps playing with the screen off While a track plays, the page asks the shell to stay awake (playback:keep-alive): on Android the cast's foreground service and visible WebView, with a notification; on desktop a power save blocker. Co-Authored-By: Claude Opus 5.5 --- packages/meshbay-hub/src/meshbay_hub/static/music-player.js | 10 ++++++++++ packages/meshbay-hub/src/meshbay_hub/static/platform.js | 10 ++++++++++ 2 files changed, 20 insertions(+) (limited to 'packages/meshbay-hub/src/meshbay_hub/static') 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 f0f7c47..500f518 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/music-player.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/music-player.js @@ -6,6 +6,7 @@ import { t } from './i18n.js'; import { Icon } from './icon.js'; import { useStickyBand } from './sticky.js'; import { CHUNK_SIZE, pipelinedDownload } from './file-utils.js'; +import { playback } from './platform.js'; /** * The Music app's persistent player bar (docs/MESHBAY_DESIGN.md §9.8). @@ -279,6 +280,15 @@ 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. + useEffect(() => { + if (!playing) return; + playback.keepAlive(true); + return () => playback.keepAlive(false); + }, [playing]); + // 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 // expectation, matching Spotify/Deezer, is that the phone locks on its own diff --git a/packages/meshbay-hub/src/meshbay_hub/static/platform.js b/packages/meshbay-hub/src/meshbay_hub/static/platform.js index c131495..0174edc 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/platform.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/platform.js @@ -204,6 +204,16 @@ export const folder = { async forget() { return bridge && bridge.folder ? bridge.folder.forget() : false; }, }; +/** + * Music is playing: the shell keeps what playback needs awake (on a phone, the + * page itself with the screen off). A no-op in a browser. + */ +export const playback = { + keepAlive(on) { + if (bridge && bridge.playback) bridge.playback.keepAlive(on).catch(() => {}); + }, +}; + /** Pick a directory to add as a group root. Returns { path, name } or null. */ export const rootPicker = { available: Boolean(bridge && bridge.rootPicker), -- cgit v1.2.3