react-native-audio-recorder-player
react-native-audio-recorder-player copied to clipboard
Can't start recording audio due to unhandled promise rejection Id = 0
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. I
m 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.
I've just tried myself with m1 mackbook air
. I could not reproduce this.
Help you tried the Example
project in the repo?
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`,
});
Still happening. Any update?
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 any update on how it got resolved?
Still this error, any updates?
Hello, any update on this one? I also have same problem
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
In my case it was related to the number of channels. Now it works with AVNumberOfChannelsKeyIOS = 2.
Error: Error occured during recording Any One Pls Give Solution for above error i am facing only IOS Platform
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