I spent 2 days to find out the solution and now I’m here. Like the title of this topic, I have downloaded mp3 audio files using FileSystem.downloadAsync function. I stored the download files in FileSystem.documentDirectory and everything worked fine. But I got an issue when I played my audio files from FileSystem.documentDirectory.
This is my code:
async _onPressPlaySound(soundUri) {
//sound uri: https://mytestAPI.com/audio/32313123/l_gbspeaking.mp3
var arr = soundUri.toString().split("/"); console.log(`uri for sound: ${soundUri}`); var filename= arr[arr.length-1];
FileSystem.downloadAsync(soundUri, FileSystem.documentDirectory+ filename)
.then(({uri})=>{
console.log("finished downloading to", uri)
})
.catch(error=>{
console.error(error);
});
const sound = new Audio.Sound();
try {
await sound.loadAsync(require(FileSystem.documentDirectory+filename));
await sound.playAsync();
// Your sound is playing!
} catch (error) {
// An error occurred!
}
}