From f6181162dd22264b4454a2119c042b963f72e895 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 5 Nov 2026 22:25:08 +0000 Subject: [PATCH] Restore lock-screen release navigation without timeline reporting Co-authored-by: stephan.terning --- app/components/media-session.ts | 25 ++++++++++++--- app/components/release-player.tsx | 8 +++++ docs/testing.md | 2 +- docs/wavecase-specification.md | 2 +- tests/media-session.test.ts | 51 +++++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 6 deletions(-) diff --git a/app/components/media-session.ts b/app/components/media-session.ts index 560a83c..ca7f79a 100644 --- a/app/components/media-session.ts +++ b/app/components/media-session.ts @@ -1,12 +1,18 @@ import type { PlaybackMedia } from "./playback-audio"; import { useEffect, useEffectEvent } from "react"; +type QueueControls = { + previousTrack?: () => void; + nextTrack?: () => void; +}; + export function attachMediaSession( media: PlaybackMedia, metadata: MediaMetadataInit, onError: () => void, onPlay: () => Promise = () => media.play(), onPause: () => void = () => media.pause(), + { previousTrack, nextTrack }: QueueControls = {}, ) { if (!("mediaSession" in navigator)) return () => {}; const session = navigator.mediaSession; @@ -27,8 +33,8 @@ export function attachMediaSession( seekto: null, seekbackward: null, seekforward: null, - previoustrack: null, - nexttrack: null, + previoustrack: previousTrack ?? null, + nexttrack: nextTrack ?? null, }; const setHandlers = (clear = false) => { for (const [action, handler] of Object.entries(handlers)) { @@ -46,7 +52,9 @@ export function attachMediaSession( clearPosition(); setHandlers(); const updateState = () => { - session.metadata = media.error ? null : description; + // Reassigning unchanged metadata can make WebKit reload the artwork. + const current = media.error ? null : description; + if (session.metadata !== current) session.metadata = current; session.playbackState = media.error ? "none" : !media.paused && !media.ended @@ -84,10 +92,15 @@ export function useMediaSession( onError: () => void, onPlay: () => Promise, onPause?: () => void, + { previousTrack, nextTrack }: QueueControls = {}, ) { const fail = useEffectEvent(onError); const play = useEffectEvent(onPlay); const pause = useEffectEvent(() => (onPause ? onPause() : media?.pause())); + const previous = useEffectEvent(() => previousTrack?.()); + const next = useEffectEvent(() => nextTrack?.()); + const canPrevious = !!previousTrack; + const canNext = !!nextTrack; const { src, sizes, type } = artwork ?? {}; useEffect(() => { if (!media || title === undefined) return; @@ -97,6 +110,10 @@ export function useMediaSession( () => fail(), () => play(), () => pause(), + { + previousTrack: canPrevious ? () => previous() : undefined, + nextTrack: canNext ? () => next() : undefined, + }, ); - }, [media, title, artist, album, src, sizes, type]); + }, [media, title, artist, album, src, sizes, type, canPrevious, canNext]); } diff --git a/app/components/release-player.tsx b/app/components/release-player.tsx index 24dcdfb..b3cbc6e 100644 --- a/app/components/release-player.tsx +++ b/app/components/release-player.tsx @@ -70,6 +70,14 @@ function ReleasePlayer() { }, () => playback.fail(), playback.play, + undefined, + { + previousTrack: playback.previousTrack, + nextTrack: + queue && index + 1 < queue.tracks.length + ? playback.nextTrack + : undefined, + }, ); if (!queue && !error) return null; return ( diff --git a/docs/testing.md b/docs/testing.md index c663c99..e46086d 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -85,7 +85,7 @@ Use synthetic media and disposable accounts. Test listeners in a separate/privat On a physical iPhone with HTTPS and the configured `APP_URL`, check uploads, actual audio, repeat pinch/pan/hold gestures, narrow layouts, downloads, background playback, interruptions, automatic release progression, and lock-screen resume. Verify title/artist/artwork updates, a demo without artwork, release cover replacement, and metadata cleanup after errors or leaving the player. Public navigation keeps the media session; private covers still require authorization. Browser automation cannot replace these device checks. -For lock-screen controls, verify title/artist/artwork and play/pause on the physical iPhone. The worklet player should have no reported elapsed time or progress timeline and no seek/previous/next commands. Check pause/resume after app switches, lock/unlock, track changes, repeat boundaries, production/stage navigation, interruptions and reaching the queue end. In-app waveform and slider seeking, repeat and automatic release progression must continue to work with the production worklet engine. Confirm that a previous player's timeline is cleared and errors, revocation and player exit clear metadata/handlers. `media-session` tests cover metadata, play/pause, position clearing and the absence of time reports and seeking actions. iOS controls the actual layout; native fallback elements may still expose a browser-owned timeline. +For lock-screen controls, verify title/artist/artwork and play/pause on the physical iPhone. The worklet player should have no reported elapsed time or progress timeline and no seek commands. Release Previous restarts after three seconds or goes to the preceding queued track near the start; Next is unavailable at the queue end; demos show no track navigation. Check pause/resume after app switches, lock/unlock, track changes, repeat boundaries, production/stage navigation, interruptions and reaching the queue end. In-app waveform and slider seeking, repeat and automatic release progression must continue to work with the production worklet engine. Confirm that a previous player's timeline is cleared and errors, revocation and player exit clear metadata/handlers. `media-session` tests cover metadata, play/pause, queue navigation, position clearing and the absence of time reports and seeking actions. iOS controls the actual layout; native fallback elements may still expose a browser-owned timeline. On macOS Safari, verify the shared media-stream output with built-in speakers: audible pause and forward/backward seeks, repeat, source changes, playback across navigation, several minutes in a background tab, and interruption/resume. Normalization remains upstream of this output. Mobile Safari (including iPad desktop identity) and other browsers retain the direct Web Audio destination. Check their existing playback journeys too. diff --git a/docs/wavecase-specification.md b/docs/wavecase-specification.md index 3ea7325..177baf2 100644 --- a/docs/wavecase-specification.md +++ b/docs/wavecase-specification.md @@ -131,7 +131,7 @@ The 220-pixel waveform may normalize visual amplitude. Click/tap seeks, wheel zo Comment time fields use minutes:seconds with optional hundredths, converted to numeric seconds on submission. Comment/reply/download dialogs trap focus, support Escape/close, and return focus to their trigger. A comment retains its selected version/thread while open and closes after successful submission. -Media Session provides title, artist, available artwork and play/pause only. Clear any previously published position state when attaching or leaving a player. Do not publish duration, position, playback rate, artificial rates or playback-state re-announcements. Do not register seek or previous/next track handlers. In-app waveform/slider seeking, repeat, automatic release progression, sample-accurate worklet playback, normalization and existing analytics remain available. Update metadata when tracks change; clear metadata and handlers on exit, failure or learned revocation. Private artwork keeps its access checks. The platform controls the final lock-screen layout: verify that the worklet path shows play/pause without a progress timeline on the physical iPhone; native fallback elements may expose their own browser-owned timeline. +Media Session provides title, artist, available artwork, play/pause and, for releases, previous/next track. Clear any previously published position state when attaching or leaving a player. Do not publish duration, position, playback rate, artificial rates or playback-state re-announcements. Do not register seek handlers. Release controls use the existing queue: Next selects the following queued track and is unavailable at the end; Previous restarts after three seconds or selects the preceding queued track near the beginning. Navigation preserves playing/paused state and never wraps or extends the queue. Demos register no track navigation. In-app waveform/slider seeking, repeat, automatic release progression, sample-accurate worklet playback, normalization and existing analytics remain available. Update metadata when tracks change; clear metadata and handlers on exit, failure or learned revocation. Private artwork keeps its access checks. The platform controls the final lock-screen layout: verify that the worklet path shows play/pause without a progress timeline on the physical iPhone; native fallback elements may expose their own browser-owned timeline. ### Analytics diff --git a/tests/media-session.test.ts b/tests/media-session.test.ts index c358756..6dbe27b 100644 --- a/tests/media-session.test.ts +++ b/tests/media-session.test.ts @@ -152,6 +152,57 @@ test("lock-screen controls publish metadata and play/pause without track time or ); }); +test("release queue controls use the shared player and disable next at the queue end", async (t) => { + const { session, handlers } = browserSession(t); + let assignments = 0; + let current = session.metadata; + Object.defineProperty(session, "metadata", { + get: () => current, + set: (value: MediaMetadataInit | null) => { + assignments++; + current = value; + }, + }); + const media = new Media(); + let previous = 0; + let next = 0; + const attach = (canNext: boolean) => + attachMediaSession( + media as unknown as HTMLAudioElement, + { title: "Release track" }, + () => {}, + () => media.play(), + undefined, + { + previousTrack: () => { + previous++; + }, + nextTrack: canNext + ? () => { + next++; + } + : undefined, + }, + ); + const stop = attach(true); + handlers.get("previoustrack")!({ action: "previoustrack" }); + handlers.get("nexttrack")!({ action: "nexttrack" }); + assert.equal(previous, 1); + assert.equal(next, 1); + for (const action of ["seekto", "seekbackward", "seekforward"]) + assert.equal(handlers.get(action), null); + assignments = 0; + await media.play(); + media.pause(); + assert.equal(assignments, 0, "unchanged metadata is not reassigned"); + stop(); + const stopLast = attach(false); + assert.equal(handlers.get("nexttrack"), null); + assert.ok(handlers.get("previoustrack")); + stopLast(); + assert.ok([...handlers.values()].every((handler) => handler === null)); +}); + test("media failure and revocation clear private metadata and remote controls", async (t) => { const { session, handlers, metadata } = browserSession(t); const media = new Media();