React-native-track-player: Error: Track is missing a required key

Created on 18 Dec 2017  路  8Comments  路  Source: react-native-kit/react-native-track-player

Hi there - Running into an issue loading up an array of tracks into the player. Here's some information.

Checking the docs it looks like I have all of the required keys for the track object structure.
I am mapping an array of data I have into the format the player wants like so

const mapTracksForPlayer = (show) => {
  return show.tracks.map(track => ({
    id: track.id,
    url: track.mp3,
    title: track.title,
    artist: 'Phish',
    album: show.date,
    genre: 'Phish',
    artwork: 'https://s3.amazonaws.com/hose/images/' + show.date + '.jpg'
  }));
}

I am then passing the returned array of data into the trackplayer methods like so

    TrackPlayer.setupPlayer().then(() => {
      TrackPlayer.add(tracksForPlayer).then(() => {
        // TrackPlayer.skip(track.id);
        TrackPlayer.play();
      });
    })

Wondering if i'm going crazy and misspelled something but cannot seem to find any small issues like that in my code. Some screenshots for what one of the objects in the array looks like, as well as the error message from the console.

screen shot 2017-12-18 at 11 35 08 am
screen shot 2017-12-18 at 11 35 17 am

Most helpful comment

On the iOS, the artist key is required.

All 8 comments

Found the problem - Closing this issue as I followed the example in the readme (using await and async). This should be added to the docs if add is an asynchronous call.

@chrisbendel I'm encountering the same issue.Can you please share the fix you did to solve this error.Also this only persists in iOS.Android works well

@chrisbendel Can you please post the solution here? @viveksri96 Have you fixed this issue?

For me, my track id was NOT a string... once I changed it to a string this error went away

On the iOS, the artist key is required.

Digging code; id, title, artist, url required.
```
init?(dictionary: [String: Any]) {
guard let id = dictionary["id"] as? String,
let title = dictionary["title"] as? String,
let artist = dictionary["artist"] as? String,
let url = MediaURL(object: dictionary["url"])
else { return nil }

```

You don't need to dig code, it's right in the Track Object documentation.

Only the id, url, title and artist properties are required for basic playback

Digging code; id, title, artist, url required.

 init?(dictionary: [String: Any]) {
       guard let id = dictionary["id"] as? String,
           let title = dictionary["title"] as? String,
           let artist = dictionary["artist"] as? String,
           let url = MediaURL(object: dictionary["url"])
           else { return nil }

this helped me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EhteshamAnwar picture EhteshamAnwar  路  3Comments

mnlbox picture mnlbox  路  4Comments

tarahiw picture tarahiw  路  3Comments

moduval picture moduval  路  4Comments

amed picture amed  路  4Comments