Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Adding tracks before index in queue #81

Merged
merged 1 commit into from
Apr 11, 2024

Conversation

shantanu-daisy
Copy link
Contributor

Our team was using the react-native-track-player and found that when trying to add tracks before an index, the queue would fail. This was particularly true when just adding one single track. Through that, we diagnosed the problem in the single comparison that we noted.

React-Native Function to replicate problem:

async function playTrackandQueuePlaylist(track, playlist) {
      await TrackPlayer.add(track);
      await TrackPlayer.play();
      if (playlist){
             let currentTrackIndex = playlist.findIndex((track) => track.track_id === currentTrack?.track_id);
             const beforeTracks = aiTracks.slice(0, currentTrackIndex);
             const afterTracks = aiTracks.slice(currentTrackIndex + 1);
             TrackPlayer.add(beforeTracks, 0);
             TrackPlayer.add(afterTracks);
      }
}

Running this code and tracing through the swift code would show you that the items are not being added when beforeTracks has a size of one. It would work fine when handling more than 2 tracks, but failed in this edge case. We solved it with full functionality when made the comparison to 0 instead of 1.

Seems super silly to PR this, but this one bug had me stuck trying to get our queue manager working for 4 hours, and is the biggest pain in the butt.

fix queue manager to handle adding only one item before the current item
@shantanu-daisy shantanu-daisy changed the title fix queue manager Fix Adding tracks before index in queue Apr 3, 2024
@dcvz
Copy link
Collaborator

dcvz commented Apr 11, 2024

Great job catching this @shantanu-daisy! Will wait for tests to pass and merge this in

@dcvz dcvz merged commit a574f94 into doublesymmetry:main Apr 11, 2024
1 check failed
@dcvz dcvz mentioned this pull request Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants