I’ve been stuck on something for days and it’s really been bugging me.
After recording something on Android with Expo.Record, I call getURI and it returns /data/user/0/host.exp.exponent/cache/ExperienceData/%40hongyuchen%2Fspeechling/Audio/recording-64ae745c-7381-4c88-8963-8ca79c6604e4.3gp.
I’m trying to upload this file to my server, but I can’t because file:///data/user/0/host.exp.exponent/cache/ExperienceData/%40hongyuchen%2Fspeechling/Audio/recording-64ae745c-7381-4c88-8963-8ca79c6604e4.3gp doesn’t exist.
I can however pass the /data… path to Expo.Audio and play the sound out, and it works just fine. This only fails on Android and not iOS. Any clue what’s going on here and what I can do?
I hear this is getting fixed in a minor release, but what’s a workaround I can do in the mean time?
Still stuck on this. I’m really just happy with finding the location of the directory where the recordings are stored on Android. I hear from @greg that the bug’s in code review. Any clue when it would get resolved in a minor release, or what a workaround would look like?
I’ve even tried looking at ImagePicker to find what a valid path looks like.
Turns out the valid file format is swapping out the %40 and %2F, not for @ and forward slash, but rather for %2540 and %252F, as well as prepending file://
Wow. I was about at wits end until I opened this topic on a whim. For me, this is not only a problem in recordingInstance.getURI(), but I couldn’t load nor play a sound on Android until I found your solution @hongyuchen.
soundInstance.loadAsync() threw an E_AUDIO_PLAYERNOTFOUND error on Android when everything worked properly on iOS. I guess it makes sense that it can’t load from a file path that points to nowhere.
A simple workaround function I created for SDK v 16.0.0:
if(Platform.OS === 'android'){
sound = adjustURIForAndroid(sound);
}
...
const adjustURIForAndroid = sound => {
let uri = sound._uri;
if (uri.includes('%40')){
uri = uri.replace('%40', '%2540');
}
if (uri.includes('%2F')){
uri = uri.replace('%2F', '%252F');
}
uri = 'file://' + uri;
sound._uri = uri;
return sound;
}
Hopefully this might save someone time and frustration.