1

I am working on a music player in react native and have been using the package react-native-track-player. I have so far not had a problem with the package in android. but when I try to run it on ios I get the error You attempted to set the key0with the value

{"id":"0",
 "url":{"uri":"https://urltosong.mp3"},
 "artwork":"https://url_to_artwork.jpg",
 "artist":"author",
 "title":"song titile"
} 

on an object that is meant to be immutable and has been frozen.

The code that generate the error is

async function togglePlayback() {
    const currentTrack = await TrackPlayer.getCurrentTrack();
    if (currentTrack == null) {
      await TrackPlayer.reset();
      await TrackPlayer.add(playlist); //this was never adding and die silently
      await TrackPlayer.play();
    } else {
            await TrackPlayer.add(playlist); //adding this line the error above appeared
            await TrackPlayer.play();
            //console.warn(TrackPlayer.getCurrentTrack())
    }
  }

I am using this version of the package "react-native-track-player": "^2.0.0-rc13", I don't know if there is something I am missing. I will appreciate your help in fixing this.

AmerllicA
  • 29,059
  • 15
  • 130
  • 154
harisu
  • 1,376
  • 8
  • 17

1 Answers1

1

Change your track to this:

{"id":"0",
 "url":"https://urltosong.mp3",
 "artwork":"https://url_to_artwork.jpg",
 "artist":"author",
 "title":"song titile"
} 

Urls should be either a string or a Resource Object

Tavin
  • 76
  • 9