react-native-audio-recorder-player icon indicating copy to clipboard operation
react-native-audio-recorder-player copied to clipboard

Can't start recording audio due to unhandled promise rejection Id = 0

Open vitorrafaelm opened this issue 1 year ago • 11 comments

I have a project and when I ran this project I cant record any audio, It works fine on android emulator, but on IOS simulator It just not works at all. Im running this project on a Mac M1.

There is the code that I used to start recording audio on Android emulator and it works well.

`const path = Platform.select({
    ios: `file://${user.uid}.m4a`,
    android: `${dirs.CacheDir}/${user.uid}.mp3`,
  });
const onStartRecord = async () => {
    try {
      if (Platform.OS === 'android') {
        try {
          const grants = await PermissionsAndroid.requestMultiple([
            PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
            PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
            PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
          ]);
          if (
            grants['android.permission.WRITE_EXTERNAL_STORAGE'] ===
              PermissionsAndroid.RESULTS.GRANTED &&
            grants['android.permission.READ_EXTERNAL_STORAGE'] ===
              PermissionsAndroid.RESULTS.GRANTED &&
            grants['android.permission.RECORD_AUDIO'] ===
              PermissionsAndroid.RESULTS.GRANTED
          ) {
            // console.log('permissions granted');
          } else {
            // console.log('All required permissions not granted');
            return;
          }
        } catch (err) {
          console.warn(err);
          return;
        }
      }
  
      const audioSet: AudioSet = {
        AudioEncoderAndroid: AudioEncoderAndroidType.AAC,
        AudioSourceAndroid: AudioSourceAndroidType.MIC,
        AVEncoderAudioQualityKeyIOS: AVEncoderAudioQualityIOSType.high,
        AVNumberOfChannelsKeyIOS: 2,
        AVFormatIDKeyIOS: AVEncodingOption.aac,
        OutputFormatAndroid: OutputFormatAndroidType.AAC_ADTS,
      };
  
      await audioRecorderPlayer.startRecorder(path, audioSet);
  
      audioRecorderPlayer.addRecordBackListener((e: RecordBackType) => {
        setRecorderState({
          ...recorderState,
          recordSecs: e.currentPosition,
          recordTime: audioRecorderPlayer.mmssss(Math.floor(e.currentPosition)),
        });
      });
    } catch (error) {
      console.log(error);
    }`

When I try this on IOS simulator I got this error: Possible Unhandled Promise Rejection (id: 0): Error: Error occured during initiating recorder Error: Error occured during initiating recorder at Object.promiseMethodWrapper [as startRecorder

I do not know why it happens, I already execute the following commands as a attempt to make it work

  • arch -x86_64 pod deintegrate
  • arch -x86_64 pod install
  • arch -x86_64 yarn run ios

Debugging this on chrome developer tools I found the error is in the current line of code: return _context.abrupt("return", RNAudioRecorderPlayer.startRecorder(uri != null ? uri : 'DEFAULT', audioSets, meteringEnabled != null ? meteringEnabled : false));

Version of react-native-audio-recorder-player: 3.5.1

Version of React Native: "react-native": "0.67",

Platforms you faced the error (IOS or Android or both?) : just IOS

Expected behavior: initiate the audio record

Actual behavior: It just give me the error: Possible Unhandled Promise Rejection (id: 0): and when I click on the button to stop recording I have another error: LogBox.js:173 Sending rn-recordback with no listeners registered.

vitorrafaelm avatar Aug 20 '22 23:08 vitorrafaelm

DT7LB68ju4

I've just tried myself with m1 mackbook air. I could not reproduce this. Help you tried the Example project in the repo?

hyochan avatar Oct 15 '22 12:10 hyochan

I got the same error on IOS. Solved it by appending file:// to IOS path.

const path = Platform.select({
    ios: `file://${user.uid}.m4a`, 
    android: `${dirs.CacheDir}/${user.uid}.mp3`,
  });

nipunravisara avatar Dec 16 '22 05:12 nipunravisara

Still happening. Any update?

a-vikor avatar Jan 17 '23 11:01 a-vikor

Still happening. Any update?

Same here on Simulator and Real device. I just get

WARN Possible Unhandled Promise Rejection (id: 0): Error: Error occured during initiating recorder

Tucker2015 avatar Feb 04 '23 14:02 Tucker2015

@Tucker2015 any update on how it got resolved?

Lordhacker756 avatar Apr 29 '23 14:04 Lordhacker756

Still this error, any updates?

yaonimingsanqian avatar May 23 '23 14:05 yaonimingsanqian

Hello, any update on this one? I also have same problem

AlkanV avatar Jul 10 '23 16:07 AlkanV

it's still happening now.

for some first tries, it works, but then suddenly it says Error occured during initiating recorder without any reason, even deleting app and rerun is not working

maitrungduc1410 avatar Aug 07 '23 04:08 maitrungduc1410

In my case it was related to the number of channels. Now it works with AVNumberOfChannelsKeyIOS = 2.

claudiozam avatar Sep 13 '23 20:09 claudiozam

Error: Error occured during recording Any One Pls Give Solution for above error i am facing only IOS Platform

Vneerajbadode avatar Dec 12 '23 13:12 Vneerajbadode

Same issue for me guys. In the swift file RNAudioRecorderPlayer: 293 if !isRecordStarted { reject("RNAudioPlayerRecorder", "Error occured during initiating recorder", nil) return }

The debugger shows isRecordStarted as false

NektariosPapergo avatar Apr 11 '24 20:04 NektariosPapergo