// Import the required library
import AudioRecorderPlayer from "react-native-audio-recorder-player";
// Function to stop recording (issue here)
const onStopRecord = React.useCallback(async () => {
try {
// Issue occurs within this function
const result = await audioRecorderPlayer.stopRecorder();
audioRecorderPlayer.removeRecordBackListener();
setRecordSecs(0);
console.log(result);
console.log(result, "Recorder result");
} catch (error) {
console.error("Error stopping recorder:", error);
}
}, []);
I am encountering a problem with the `onStopRecord` function when using the React Native Audio Recorder Player library. Specifically, I am unable to stop the recording properly, and I’m seeking guidance on resolving this issue.
2
Answers
I was getting issue from this line:- const audioRecorderPlayer = new AudioRecorderPlayer();
I declared it inside of my class, but it should be declare in outside of class, This solved my issue of onstoprecord and onstopplay not working.
You have used
useCallback
hook for the function .. Have you tried usingonStopRecord
function without this hook ?I guess the
onStopRecord
doesn’t have the updated value ofaudioRecorderPlayer
thats why its not working as expected.try this :