0
  useEffect(() => {
    try {
      const voiceover = parseOrGet(item.scenes[selectedIndex].voiceover);
      voiceover["title"]="test"
      voiceover["artist"]="test"
      voiceover["id"]="2"
      voiceover["artwork"]="https://url_to_artwork.jpg"
      delete voiceover.metadata
      delete voiceover.name
      delete voiceover.type
      console.log(voiceover)
      if (voiceover) {
        TrackPlayer.add(voiceover);
        TrackPlayer.play();
        setSelectedTrack(voiceover);
      }else{
        TrackPlayer.destroy();
      }
    } catch (error) {
      console.log('my initial error', error);
    }
  }, [selectedIndex]);

在这里,我正在添加 trackplayer 配音,但我无法收听配音音乐,它无法正常工作

这是我的配音对象

{"artist": "test", "artwork": "https://url_to_artwork.jpg", "id": 1, "title": "test", "url": "https://d3bm2z03a5d1kp.cloudfront.net/hindi-narration/1.mp3"}

让 mw 知道我在哪里做错了

4

1 回答 1

1

尝试从

if (voiceover) {
  TrackPlayer.add(voiceover);
  TrackPlayer.play();
  setSelectedTrack(voiceover);
} else {
  TrackPlayer.destroy();
}

if (voiceover) {
  await TrackPlayer.add(voiceover);
  await TrackPlayer.play();
  setSelectedTrack(voiceover);
} else {
  await TrackPlayer.destroy();
}

并将您的功能定义为useEffect(async () => ....)

于 2022-01-20T14:55:54.167 回答