skip to Main Content
// 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


  1. Chosen as BEST ANSWER

    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.


  2. You have used useCallback hook for the function .. Have you tried using onStopRecord function without this hook ?
    I guess the onStopRecord doesn’t have the updated value of audioRecorderPlayer thats why its not working as expected.
    try this :

    const onStopRecord=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);
      }
    }
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search