react-native-track-player: v2.2.0-rc4 introduces fatal crash on iOS when calling TrackPlayer.reset()

Describe the Bug Calling TrackPlayer.reset() while playing a track on iOS causes a fatal crash in v2.2.0-rc4. Crash was not present on v2.2.0-rc3 or below.

Steps To Reproduce

  1. Add a track to the queue
  2. Start playing the track
  3. Call TrackPlayer.reset()

Code To Reproduce

await TrackPlayer.add(listOfTracks);
await TrackPlayer.play();
await TrackPlayer.reset();

Environment Info: Tested on iOS simulator with RNTP version v2.2.0-rc4 and RN version v0.68.2

How I can Help Dug into this with the old and new version. The crash happens on https://github.com/doublesymmetry/react-native-track-player/blob/main/ios/RNTrackPlayer/RNTrackPlayer.swift#L825.

With both rc3 and rc4, when calling TrackPlayer.reset(), I see onCurrentIndexChanged of QueuedAudioPlayer in SwiftAudioEx get executed twice, from which handleAudioPlayerQueueIndexChange gets called. In rc3, the nextIndex param has a value of nil both times, but in rc4, the second time it has a value of 0 which triggers a crash because player.items is empty. This value of 0 traces back to the newIndex param of onCurrentIndexChanged and is clearly the bug, but is not the root cause, which I have not had a chance to dig deeper into yet. I’m hoping one of the maintainers can save some time with an understanding of what changed recently that broke this.

In the meantime, v2.2.0-rc4 is not usable on iOS unfortunately.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 20 (1 by maintainers)

Commits related to this issue

Most upvoted comments

First I don’t think you should be calling reset twice. Second, I’ll need a link to a fork with a repro in the example if you want me to look into it

I’m resetting the playlist several times in the app; I thought I could do it. There is an example:

  ......
  await TrackPlayer.reset(); // no crash
  await TrackPlayer.add(track);
  .....
  await TrackPlayer.reset(); // the crash happens

Btw: I found that I could also reset the playlist using TrackPlayer.remove(tracksInTheState), so there is no need to look at this issue if reset() should only be called once; thx!