mirror of
https://github.com/Jellify-Music/App.git
synced 2026-04-24 11:59:02 -05:00
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:
@@ -176,18 +176,28 @@ const QueueContextInitailizer = () => {
|
|||||||
|
|
||||||
setSkipping(true)
|
setSkipping(true)
|
||||||
|
|
||||||
|
// Get the item at the start index
|
||||||
|
const startingTrack = audioItems[startIndex]
|
||||||
|
|
||||||
const availableAudioItems = filterTracksOnNetworkStatus(
|
const availableAudioItems = filterTracksOnNetworkStatus(
|
||||||
networkStatus as networkStatusTypes,
|
networkStatus as networkStatusTypes,
|
||||||
audioItems,
|
audioItems,
|
||||||
downloadedTracks ?? [],
|
downloadedTracks ?? [],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// The start index may have changed due to the filtered out items
|
||||||
|
const filteredStartIndex = availableAudioItems.findIndex(
|
||||||
|
(item) => item.Id === startingTrack.Id,
|
||||||
|
)
|
||||||
|
|
||||||
console.debug(
|
console.debug(
|
||||||
`Filtered out ${
|
`Filtered out ${
|
||||||
audioItems.length - availableAudioItems.length
|
audioItems.length - availableAudioItems.length
|
||||||
} due to network status being ${networkStatus}`,
|
} due to network status being ${networkStatus}`,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
console.debug(`Filtered start index is ${filteredStartIndex}`)
|
||||||
|
|
||||||
const queue = availableAudioItems.map((item) =>
|
const queue = availableAudioItems.map((item) =>
|
||||||
mapDtoToTrack(api!, sessionId, item, downloadedTracks ?? [], QueuingType.FromSelection),
|
mapDtoToTrack(api!, sessionId, item, downloadedTracks ?? [], QueuingType.FromSelection),
|
||||||
)
|
)
|
||||||
@@ -196,11 +206,11 @@ const QueueContextInitailizer = () => {
|
|||||||
|
|
||||||
await TrackPlayer.setQueue(queue)
|
await TrackPlayer.setQueue(queue)
|
||||||
setPlayQueue(queue)
|
setPlayQueue(queue)
|
||||||
await TrackPlayer.skip(startIndex)
|
await TrackPlayer.skip(filteredStartIndex)
|
||||||
|
|
||||||
setSkipping(false)
|
setSkipping(false)
|
||||||
|
|
||||||
console.debug(`Queued ${queue.length} tracks, starting at ${startIndex}`)
|
console.debug(`Queued ${queue.length} tracks, starting at ${filteredStartIndex}`)
|
||||||
|
|
||||||
await play()
|
await play()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user