Fix issue where offline playback starts at the incorrect index (#355)

Fixes an issue where offline playback wouldn't start at the correct track and the player wouldn't reflect the currently playing track
This commit is contained in:
Violet Caulfield
2025-05-12 06:13:44 -05:00
committed by GitHub
parent b5ea805c32
commit 9f5b60f58e

View File

@@ -176,18 +176,28 @@ const QueueContextInitailizer = () => {
setSkipping(true)
// Get the item at the start index
const startingTrack = audioItems[startIndex]
const availableAudioItems = filterTracksOnNetworkStatus(
networkStatus as networkStatusTypes,
audioItems,
downloadedTracks ?? [],
)
// The start index may have changed due to the filtered out items
const filteredStartIndex = availableAudioItems.findIndex(
(item) => item.Id === startingTrack.Id,
)
console.debug(
`Filtered out ${
audioItems.length - availableAudioItems.length
} due to network status being ${networkStatus}`,
)
console.debug(`Filtered start index is ${filteredStartIndex}`)
const queue = availableAudioItems.map((item) =>
mapDtoToTrack(api!, sessionId, item, downloadedTracks ?? [], QueuingType.FromSelection),
)
@@ -196,11 +206,11 @@ const QueueContextInitailizer = () => {
await TrackPlayer.setQueue(queue)
setPlayQueue(queue)
await TrackPlayer.skip(startIndex)
await TrackPlayer.skip(filteredStartIndex)
setSkipping(false)
console.debug(`Queued ${queue.length} tracks, starting at ${startIndex}`)
console.debug(`Queued ${queue.length} tracks, starting at ${filteredStartIndex}`)
await play()
}