harisu
harisu

Reputation: 1416

React native track player fails to add songs to playlist

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.

Upvotes: 1

Views: 1642

Answers (1)

Tavin
Tavin

Reputation: 86

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

Upvotes: 1

Related Questions