0

My React Native Track Player app implements its own playlist and I need a custom event to send "Next Event" and "Previous Event" to a component deeper in the component tree. In order to do so, I used (hacked) genre property of PlaybackMetadataReceived like so:

<IconButton
        icon="skip-next"
        onPress={() => {
          // TrackPlayer.skipToNext();
          (async () => {
            await TrackPlayer.updateMetadataForTrack(0, { genre: "next" });
            console.log(await TrackPlayer.getTrack(0)); // => genre is updated in the unique track of the queue
          })();
        }}
        size={iconSize}
      />

But the component that is supposed to receive this event never receives it :


useTrackPlayerEvents(
  [
    Event.PlaybackMetadataReceived,
    ...
  ],

  async (event) => { 
    try {
      switch (event.type) {
        case Event.PlaybackMetadataReceived:
          console.log(`E.PlaybackMetaReceived => e=${JSON.stringify(event, null, 10)}}`,);
          break;
             ....
      }
    } catch (e) {
      tr("Error useTrackPlayerEvents = " + e);
    }
  }
);

Do you see what I missed ? Thanks in advance

If I can't fix this issue, I was thinking of using a react native custom even library but I am not even sure it exists. If you know a good one that works like react native track player events, please let me know.

PS: I am testing my app on an Android expo dev client.

u2gilles
  • 6,888
  • 7
  • 51
  • 75

0 Answers0