feat(web): add enqueueTrack, enqueueTracks, playRadio to player store
enqueueTrack/enqueueTracks append to the queue without disturbing playback state (no auto-play on append, no state mutation when queue was non-empty). playRadio fetches /api/radio?seed_track=<id> and feeds the response into playQueue. Empty response leaves queue alone.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { TrackRef } from '$lib/api/types';
|
||||
import type { TrackRef, RadioResponse } from '$lib/api/types';
|
||||
import { api } from '$lib/api/client';
|
||||
|
||||
export type PlayerState = 'idle' | 'loading' | 'playing' | 'paused' | 'error';
|
||||
export type RepeatMode = 'off' | 'all' | 'one';
|
||||
@@ -196,3 +197,21 @@ export function reportStateFromAudio(
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
export function enqueueTrack(t: TrackRef): void {
|
||||
_queue = [..._queue, t];
|
||||
if (_state === 'idle') _index = 0;
|
||||
}
|
||||
|
||||
export function enqueueTracks(ts: TrackRef[]): void {
|
||||
if (ts.length === 0) return;
|
||||
_queue = [..._queue, ...ts];
|
||||
if (_state === 'idle') _index = 0;
|
||||
}
|
||||
|
||||
export async function playRadio(seedTrackId: string): Promise<void> {
|
||||
const resp = await api.get<RadioResponse>(
|
||||
`/api/radio?seed_track=${encodeURIComponent(seedTrackId)}`
|
||||
);
|
||||
if (resp.tracks.length > 0) playQueue(resp.tracks, 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user