fix long queue issues

This commit is contained in:
Boof2015
2026-07-01 18:33:22 -04:00
parent 7f00e87823
commit 06c822f513
7 changed files with 370 additions and 63 deletions
+9 -1
View File
@@ -1,5 +1,6 @@
import { create } from 'zustand';
import TrackPlayer, { type Track as RntpTrack } from 'react-native-track-player';
import { nativeIndexToAbsolute, queueLoadSettled } from '@/audio/queueLoader';
/**
* Live mirror of RNTP's native queue for the queue tray. Playback actions keep
@@ -35,6 +36,8 @@ export const useQueueStore = create<QueueStore>((set) => ({
activeIndex: -1,
hasSnapshot: false,
refreshFromNative: async () => {
// Mid chunked-load the native queue is partial and index-shifted — wait it out.
await queueLoadSettled();
const [tracks, activeIndex] = await Promise.all([
TrackPlayer.getQueue(),
TrackPlayer.getActiveTrackIndex(),
@@ -47,7 +50,12 @@ export const useQueueStore = create<QueueStore>((set) => ({
},
refreshActiveIndex: async () => {
const activeIndex = await TrackPlayer.getActiveTrackIndex();
set((s) => ({ activeIndex: normalizeActiveIndex(activeIndex, s.tracks.length) }));
set((s) => ({
activeIndex: normalizeActiveIndex(
activeIndex == null ? activeIndex : nativeIndexToAbsolute(activeIndex),
s.tracks.length,
),
}));
},
setSnapshot: (tracks, activeIndex = 0) =>
set({