Add identifiers for multiple tracks

This commit is contained in:
Lei Nelissen
2020-07-10 15:47:03 +02:00
parent 46ee047c3c
commit d27a0d3691
3 changed files with 16 additions and 10 deletions

View File

@@ -23,14 +23,17 @@ export default function usePlayTrack() {
}
// GUARD: Check if the track is already in the queue
if (!queue?.some((t) => t.id === trackId)) {
// If it is not, we must then generate it, and add it to the queue
const newTrack = generateTrack(track, credentials);
await TrackPlayer.add([ newTrack ]);
}
const trackInstances = queue.filter((t) => t.id.startsWith(trackId));
// Generate the new track for the queue
const newTrack = {
...(trackInstances.length ? trackInstances[0] : generateTrack(track, credentials)),
id: `${trackId}_${trackInstances.length}`
};
await TrackPlayer.add([ newTrack ]);
// Then we'll skip to it and play it
await TrackPlayer.skip(trackId);
await TrackPlayer.skip(newTrack.id);
TrackPlayer.play();
}, [credentials, tracks, queue]);
}