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
- Add a track to the queue
- Start playing the track
- 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
- More syntax updates and simplification — committed to doublesymmetry/SwiftAudioEx by dcvz 2 years ago
- fix(ios): fix an issue with `reset()` causing a crash on iOS due to out of range exception https://github.com/doublesymmetry/react-native-track-player/issues/1585 — committed to 5-stones/react-native-track-player by jspizziri 2 years ago
I’m resetting the playlist several times in the app; I thought I could do it. There is an example:
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!