1

在我的应用程序中,我使用 Expo-AV 来录制在 Android 上运行良好但在 iPhone 上运行良好的音频。尝试记录时出现此错误: Prepare 遇到错误: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);
  }
}

}

当我触摸按钮开始录制时,会调用此函数。尝试更改 setAudioModeAsync 和 prepareToRecordAsync for iOS 中的编解码器配置,尝试 m4a、caaf、wav、ac3 格式

编解码器配置中是否有任何更改?请建议。

4

0 回答 0