Expo Audio record/play settings

#1

I’ve downloaded and run the code from the recording app example (http://expo.io/@community/record, https://github.com/expo/audio-recording-example).

It’s up and running on an emulator and working fine. I have a requirement for a project to use .amr files.

When I change the config to use .amr encoding, on clicking play in the app I receive error:

[Unhandled Promise rejection: Error: java.lang.IllegalStateException: mSimpleExoPlayer is null!]
- node_modules\react-native\Libraries\BatchedBridge\NativeModules.js:117:42 in createErrorFromErrorData
- node_modules\react-native\Libraries\BatchedBridge\NativeModules.js:80:57 in <unknown>

The only code i have changed is this line:

this.recordingSettings = JSON.parse(JSON.stringify(Audio.RECORDING_OPTIONS_PRESET_HIGH_QUALITY));

To use the following options:

const rs = {
      android: {
          extension: '.amr',
          outputFormat: Audio.RECORDING_OPTION_ANDROID_OUTPUT_FORMAT_AMR_NB,
          audioEncoder: Audio.RECORDING_OPTION_ANDROID_AUDIO_ENCODER_AMR_NB,
          sampleRate: 8000,
          numberOfChannels: 1,
          bitRate: 128000,
      },
      ios: {
          extension: '.amr',
          outputFormat: Audio.RECORDING_OPTION_IOS_OUTPUT_FORMAT_AMR,
          audioQuality: Audio.RECORDING_OPTION_IOS_AUDIO_QUALITY_HIGH,
          sampleRate: 8000,
          numberOfChannels: 1,
          bitRate: 128000,
          linearPCMBitDepth: 16,
          linearPCMIsBigEndian: false,
          linearPCMIsFloat: false,
      }
  };
    this.recordingSettings = JSON.parse(JSON.stringify(rs));

What am I doing wrong? Are the options wrong for recording, so the player won’t initialise correctly when trying to play the file?

#2

Thanks for letting us know. Looks like this might be a bug on our end. I’ll forward this to the person working on Audio issues.

#3

Hi there, the options for the recording are ok, the .amr file is probably being saved correctly (I haven’t played it, but there are no errors).

The problem you’ve run into is caused by a nasty bug in Expo’s SimpleExoPlayerData.java, which calls loadSuccess prematurely (thus using up the Promise callbacks) so when the loading errored, the player wouldn’t be able to notify JS of the problem. Therefore the Sound JS object would think everything went ok, and just when it wanted to play it, would get an error that the underlying native player hasn’t been initialised.

I submitted a PR fixing this behavior.

#4

Hi @sjchmiela

Thanks for this. Makes sense.

Any ETA on the PR? And will it just be a case of updating expo in my project?

#5

@jamadanman we’ll release the fix with our next SDK version, which will come out in about a week and a half. Once that’s out you’ll have to update to the new SDK version to get the fix.

1 Like