'Error thrown after ending the audio track / array of tracks in React Native Track Player

I'm using React Native Track Player in a React Native project and playing an array of music tracks. After ending the audio tracks, I'm getting the following error in the emulator: (This error is thrown not only when I send an array but also even after playing an individual music file)

Error:

Attempt to invoke virtual method 'double java.lang.Double.doubleValue()' on a null object reference.

enter image description here

As a solution what I tried to stop the player once the array of tracks is empty, but it is also.

useTrackPlayerEvents([Event.PlaybackQueueEnded], async event => {
  if (event.type === Event.PlaybackQueueEnded) {
    TrackPlayer.stop();
  }
});

Anybody who is familiar with react-native-track-player, can please help me to solve this issue?

Thank you.



Solution 1:[1]

The above code should be modified to check for undefined objects as follows (not null objects.)

useTrackPlayerEvents([Event.PlaybackQueueEnded], async event => {
  if (event.type === Event.PlaybackQueueEnded && event.nextTrack !== undefined) {
    TrackPlayer.stop();
  }
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pawara Siriwardhane