Expo AV audio recorder failing to record on iOS / iPhone

In my app, I’m using Expo-AV to record audio which works fine on Android, but not on iPhone. I get this error when I try to record: Prepare encountered an error: Error Domain=NSOSStatusErrorDomain Code=561145203 “(null)”

async startRecordingAudio() {
if (!this.state.isRecording) {
  const recording = new Audio.Recording();
  this.setState({
    timerDisplay: "01:30",
    timerCnt: 90,
  });
  try {
    await Audio.setAudioModeAsync({
      playsInSilentModeIOS: true,
      allowsRecordingIOS: true,
      staysActiveInBackground: false,
      interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
      shouldDuckAndroid: true,
      interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
      playThroughEarpieceAndroid: false,
    });
    await recording.prepareToRecordAsync({
      android: {
        extension: ".mp3",
        outputFormat: RECORDING_OPTION_ANDROID_OUTPUT_FORMAT_MPEG_4,
        audioEncoder: RECORDING_OPTION_ANDROID_AUDIO_ENCODER_AAC,
        sampleRate: 44100,
        numberOfChannels: 2,
        bitRate: 128000,
      },
      ios: {
        extension: ".m4a",
        outputFormat:
          Audio.RECORDING_OPTION_IOS_OUTPUT_FORMAT_APPLELOSSLESS,
        audioQuality: Audio.RECORDING_OPTION_IOS_AUDIO_QUALITY_MIN,
        sampleRate: 44100,
        numberOfChannels: 2,
        bitRate: 128000,
        linearPCMBitDepth: 16,
        linearPCMIsBigEndian: false,
        linearPCMIsFloat: false,
        allowsRecordingIOS: true,
      },
    });
    console.log("prepare record");
    let x = await recording.startAsync();
    this.setState({
      refreshDisabled: true,
      recordDisabled: false,
      playDisabled: true,
    });
    let recInt = setInterval(() => {
      let counter = this.state.timerCnt - 1;
      let mins = parseInt(counter / 60, 10);
      let secs = parseInt(counter % 60, 10);

      mins = mins < 10 ? "0" + mins : mins;
      secs = secs < 10 ? "0" + secs : secs;
      Helpers.printLog(current_page_name, 2, mins + ":" + secs);
      this.setState({ timerDisplay: mins + ":" + secs, timerCnt: counter });

      if (counter <= 0) {
        clearInterval(this.state.intTimer);
        this.setState({
          isRecording: false,
          timerDisplay: "01:30",
          timerCnt: 90,
          refreshDisabled: false,
          recordDisabled: false,
          playDisabled: false,
        });
      }
    }, 1000);

    this.setState({
      recording: recording,
      isRecording: true,
      intTimer: recInt,
    });

    // Helpers.printLog(current_page_name, "3" + " recording status - ", x);
  } catch (error) {
    console.log(error);
    // Helpers.printLog(
    //   current_page_name,
    //   4,
    //   "Audio recording error - ",
    //   error
    // );
    console.log(error);
  }
} else {
  try {
    await Audio.setAudioModeAsync({
      allowsRecordingIOS: true,
      interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
      playsInSilentModeIOS: true,
      playsInSilentLockedModeIOS: true,
      shouldDuckAndroid: true,
      interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
    });
    let rec = this.state.recording;
    let y = await rec.stopAndUnloadAsync();
    this.setState({
      refreshDisabled: false,
      recordDisabled: false,
      playDisabled: false,
      recordingURI: rec.getURI(),
    });
    // Helpers.printLog(current_page_name, "5 record stopped object- ", y);
    console.log("5 record stopped object- " + y);

    clearInterval(this.state.intTimer);
    this.setState({
      isRecording: false,
      timerCnt: 90,
      recordingDuration: y.durationMillis,
      filePath: rec.getURI(),
    });
  } catch (error) {
    // Helpers.printLog(
    //   current_page_name,
    //   "6 Audio recording stopped error - ",
    //   error
    // );
    console.log(error);
  }
}
}

This function gets called when I touch the button to start recording. Tried changing the codec config in setAudioModeAsync and prepareToRecordAsync for iOS, tried m4a, caaf, wav, ac3 formats

Is there any change to do in the codec config? Please suggest.

Expo CLI 3.28.2 environment info:
System:
OS: Windows 10 10.0.17763
Binaries:
Node: 12.13.0 - C:\Users\DELL\AppData\Roaming\npm\node.CMD
Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.14.7 - C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: Version 4.0.0.0 AI-193.6911.18.40.6626763
npmPackages:
expo: ~40.0.0 => 40.0.0
react: 16.13.1 => 16.13.1
react-dom: 16.13.1 => 16.13.1
react-native: https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz => 0.63.2
react-native-web: ~0.13.12 => 0.13.18
Expo Workflow: managed

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.