首页 > 解决方案 > React Native:下载后无法找到音频文件

问题描述

我正在使用 react-native-simple-download-manager 将音频文件下载到应用程序的下载文件夹中:

headers = {
              Authorization: "Téléchargement"
            };

            config = {
              downloadTitle: `${audio.Title}`,
              downloadDescription: "Téléchargement",
              saveAsName: audio.Title +'.mp3',
              allowedInRoaming: true,
              allowedInMetered: true,
              showInDownloads: true,
              external: false, //when false basically means use the default Download path (version ^1.3)
            };
            downloadManager
              .download((url = audio.FileUrl), (headers = headers), (config = config))
              .then(response => {
                saveData(audio);
              })
              .catch(err => {
                           if(index > -1) {
                  global.downloadingSongId.splice(index,1);
                }
              });

我可以在手机上找到下载的音频文件,但是播放器无法读取以下路径给出的音频:dirs.DocumentDir + '/Download/' + audio.Title + '.mp3'

当我使用 RNFetchBlob 检查路径是否存在时,它总是返回 false :

let path = dirs.DocumentDir + '/' + audio.Title + '.mp3';
RNFetchBlob.fs.exists(path);

如果有人能提供帮助,我真的很感激!

标签: react-nativeaudio

解决方案


推荐阅读