1

我正在开发一个反应原生的音乐播放器,并且一直在使用包 react-native-track-player。到目前为止,我对 android 中的包没有任何问题。但是当我尝试在 ios 上运行它时出现错误 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.

产生错误的代码是

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())
    }
  }

我正在使用这个版本的包"react-native-track-player": "^2.0.0-rc13", 我不知道是否有我遗漏的东西。我将感谢您在解决此问题方面的帮助。

4

1 回答 1

1

将您的曲目更改为:

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

网址应该是 astring或 aResource Object

于 2020-08-31T20:07:02.260 回答