audio player respects group context
This commit is contained in:
@@ -60,6 +60,12 @@ type AudioPlayerState = {
|
||||
type AudioPlayerActions = {
|
||||
play: (track: AudioTrack) => void;
|
||||
playPlaylist: (tracks: AudioTrack[], startIndex?: number) => void;
|
||||
/**
|
||||
* Gives the track that's already playing a queue to sit in, without
|
||||
* restarting it — for a queue that arrives after playback began. Ignored
|
||||
* if the current track isn't in it (the user moved on meanwhile).
|
||||
*/
|
||||
attachQueue: (tracks: AudioTrack[]) => void;
|
||||
pause: () => void;
|
||||
resume: () => void;
|
||||
togglePlayPause: () => void;
|
||||
@@ -469,6 +475,14 @@ export function AudioPlayerProvider({ children }: { children: ReactNode }) {
|
||||
[saveCurrent],
|
||||
);
|
||||
|
||||
const attachQueue = useCallback((tracks: AudioTrack[]) => {
|
||||
const current = currentTrackRef.current;
|
||||
const idx = current ? tracks.findIndex((t) => t.url === current.url) : -1;
|
||||
if (idx < 0) return;
|
||||
setPlaylist(tracks);
|
||||
setCurrentIndex(idx);
|
||||
}, []);
|
||||
|
||||
const pause = useCallback(() => {
|
||||
audioRef.current?.pause();
|
||||
saveCurrent();
|
||||
@@ -630,6 +644,7 @@ export function AudioPlayerProvider({ children }: { children: ReactNode }) {
|
||||
currentIndex,
|
||||
play,
|
||||
playPlaylist,
|
||||
attachQueue,
|
||||
pause,
|
||||
resume,
|
||||
togglePlayPause,
|
||||
|
||||
Reference in New Issue
Block a user