React-native-track-player: iOS: operations do not guarantee order of execution in async JS functions

Created on 12 Feb 2021  路  2Comments  路  Source: react-native-kit/react-native-track-player

I've noticed that some sequence of calls will not work.

await TrackPlayer.reset();
await TrackPlayer.add(track);

The code above will sometimes clear the added track. The reset happens after the track is added to the queue.

Also if I track the player position:

await TrackPlayer.getPosition();
await TrackPlayer.getCurrentTrack();
await TrackPlayer.getDuration();

I'll sometimes get the state that current track switched to the next one but the position and the duration are from the previous track.

From looking at the code it looks like reject resolve functions in the RN bridge are instantly resolved in some cases. Swift does not seem to use them when async code is run.
Android on the other hand wraps the promise into runnable and I guess resolves it correctly.

Also, if some of these state values will update inbetween await calls maybe a unified call for the whole player state is a better interface.

Bug Needs Confirmation

Most helpful comment

Sounds like my case as well

All 2 comments

Sounds like my case as well

To clarify,

await TrackPlayer.reset();
await TrackPlayer.add(track);

If player is playing and reset is called on track end, then if another track is added the position and duration lags and the player (on native side) thinks that it's the new track that is also ending, so it clears it too.

It looks like there's a lot of issues with internal state.

Was this page helpful?
0 / 5 - 0 ratings