【问题标题】:Cant play music due to file path using react-native-track-player REACT-NATIVE由于使用 react-native-track-player REACT-NATIVE 的文件路径而无法播放音乐
【发布时间】:2020-11-11 17:07:30
【问题描述】:

我尝试使用调试模式在我的设备中播放音乐,但即使文件正确也无法播放,代码如下:

在componentDidMount中初始化播放器:

componentDidMount() {
    this.requestPermission();
    this.init_player();
}

init_player = async () => {
    await TrackPlayer.setupPlayer();
    await TrackPlayer.add({
        id: "1",
        url: "file:///storage/emulated/0/Download/Maluma-Hawai.mp3",
        title: "Dfdf",
        artist: "Dfdf",
    });
}

然后在按钮中调用方法:

TrackPlayer.play()

但它不起作用,尝试使用 file://+pathfile:///+path

我正在使用 android X

轨道播放器 gitbuh:music player

【问题讨论】:

  • 你有什么解决办法吗?

标签: javascript react-native android-studio


【解决方案1】:

这个对我有用: 我首先将曲目下载到 DocumentDirectoryPath。 然后我可以在网址中添加以下内容:

url: `file://${DocumentDirectoryPath}/GetLucky.m4a`

版本: "react-native-track-player": "^2.0.1",

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-18
    • 2022-11-10
    • 1970-01-01
    相关资源
    最近更新 更多