Bug with getURI in Expo.Recording for Android

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?

Just a lucky guess: %40 and %2F look like URL encoded special chars @ and forward slash. Try to decode them before uploading.

Thanks, I tried that.

Looks like the path with swapping out %40 and %2F doesn’t work either. I have trouble locating where the recording actually lives.

file:///data/user/0/host.exp.exponent/cache/ExperienceData/@hongyuchen/speechling/Audio/recording-9c744555-84c9-4d14-90b0-c434a79b462f.3gp

(used a different one)

@nikki do you know about this?

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.

Finally figured it out :slight_smile:

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://

Lots of guess & check >.>

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.

Sorry all, this will be fixed in the new release which should come out today! :slightly_smiling_face:

2 Likes

have u got solution for this problem