fix(web): show a restored queue on the lock screen
A queue that came back after a reload was set before the player started to follow the state, so the lock screen never heard about its song: no title and no controls until the song changed, and a press of play told it nothing. The lock screen is now told about the restored song, paused, where it was.
This commit is contained in:
parent
23845391d4
commit
a2d6d2a925
2 changed files with 27 additions and 0 deletions
|
|
@ -151,6 +151,25 @@ test('a queue saved by an earlier page comes back paused, on the same song and a
|
||||||
expect(audio.currentTime).toBe(61)
|
expect(audio.currentTime).toBe(61)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('a queue that comes back is on the lock screen at once, paused, where it was', async () => {
|
||||||
|
const native = { update: vi.fn(), stop: vi.fn() }
|
||||||
|
window.SondaNative = native
|
||||||
|
try {
|
||||||
|
usePlayer.getState().playTracks([track, { ...track, id: 2, title: 'Paranoid Android' }], 1)
|
||||||
|
usePlayer.setState({ positionMs: 61_000 })
|
||||||
|
saveQueue(1, usePlayer.getState())
|
||||||
|
usePlayer.getState().playTracks([])
|
||||||
|
native.update.mockClear()
|
||||||
|
native.stop.mockClear()
|
||||||
|
renderHook(() => usePlayerEngine())
|
||||||
|
await waitFor(() => expect(native.update).toHaveBeenCalled())
|
||||||
|
expect(JSON.parse(native.update.mock.calls.at(-1)![0])).toMatchObject({ title: 'Paranoid Android', playing: false, positionMs: 61_000, durationMs: 284_000 })
|
||||||
|
} finally {
|
||||||
|
delete window.SondaNative
|
||||||
|
delete window.sondaNativeAction
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
test('the queue of another person is not restored', () => {
|
test('the queue of another person is not restored', () => {
|
||||||
usePlayer.getState().playTracks([track])
|
usePlayer.getState().playTracks([track])
|
||||||
saveQueue(2, usePlayer.getState())
|
saveQueue(2, usePlayer.getState())
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,14 @@ export function usePlayerEngine(): void {
|
||||||
prev: () => usePlayer.getState().prev(),
|
prev: () => usePlayer.getState().prev(),
|
||||||
seekTo: (ms: number) => usePlayer.getState().seek(ms),
|
seekTo: (ms: number) => usePlayer.getState().seek(ms),
|
||||||
}
|
}
|
||||||
|
// A queue that came back above was there before this started listening: tell the lock screen about it now.
|
||||||
|
const current = usePlayer.getState()
|
||||||
|
const restored = currentTrack(current)
|
||||||
|
if (restored) {
|
||||||
|
setMediaSession(restored, keys)
|
||||||
|
setPlaybackState(current.playing)
|
||||||
|
setPosition(current.positionMs, restored.duration_ms)
|
||||||
|
}
|
||||||
const stopMediaSession = usePlayer.subscribe((state, previous) => {
|
const stopMediaSession = usePlayer.subscribe((state, previous) => {
|
||||||
const track = currentTrack(state)
|
const track = currentTrack(state)
|
||||||
const before = currentTrack(previous)
|
const before = currentTrack(previous)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue