react-native-audio-recorder-player
react-native-audio-recorder-player copied to clipboard
How to configure this library in ios RN-Cli
I have added the already permissions.
And i am try to setup the IOS manually than show this error in Xcode #import "React/RCTBridgeModule.h" this file not found show error .
And Adding the following under "Build Settings" -> "Header Search Paths". $(SRCROOT)/../node_modules/react-native/React
But this error not solve..
And this code working in android but i am trying to record in iOS i am facing this error very time this--
- ERROR Error in micHandler: [Error: Error occurred during recording]
- ERROR Error in micHandler: [Error: Failed to stop recorder. It is already nil.]
- ERROR Error uploading audio: [TypeError: Network request failed]
---------------------------------- This code is android perfectly working but IOS not working --------------------------------
const micHandler = async () => {
const baseDir = ${RNFS.DocumentDirectoryPath}/cinch-all-audio
;
try {
if (!isRecording) {
await RNFS.mkdir(baseDir, {NSURLIsExcludedFromBackupKey: true});
const fileName = `${Date.now()}.mp3`;
const audioPath = `${baseDir}/${fileName}`;
const audioSet = {
AudioEncoderAndroid: AudioEncoderAndroidType.AAC,
AudioSourceAndroid: 6,
};
// Start recording
const result = await audioRecorderPlayer.startRecorder(
audioPath,
audioSet,
);
setIsRecording(true);
} else {
const result = await audioRecorderPlayer.stopRecorder();
setIsRecording(false);
const parts = result.split('/');
const fileName = parts[parts.length - 1];
const reference = ref(storage, `/${'recordedAudio'}/${fileName}`);
const pathToFile = result;
try {
const fileData = await fetch(pathToFile).then(response =>
response.blob(),
);
const uploadAudioFile = await uploadBytes(reference, fileData);
if (uploadAudioFile) {
const audioURL = await getDownloadURL(reference);
console.log(audioURL);
} else {
console.error('File upload failed');
}
} catch (error) {
console.error('Error uploading audio:', error);
}
}
} catch (error) {
console.error('Error in micHandler:', error);
alert(error);
}
};
i faced some issue, fixed by changing extension from .mp3 -> .m4a. I dont know why but on ios mp3 doesnt work. On android it also NO issues with m4a.
Also make sure to grant permissions to write document directory on ios.