React Native Audio Recorder Player库中的onStopRecord函数问题

8nuwlpux  于 2023-11-21  发布在  React
关注(0)|答案(1)|浏览(131)
// 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);
  }
}, []);

字符串
我在使用React Native Audio Recorder Player库时遇到了'onStopRecord'函数的问题。具体来说,我无法正确停止录制,我正在寻求解决此问题的指导。

xzv2uavs

xzv2uavs1#

我从这条线上得到了问题:

const audioRecorderPlayer = new AudioRecorderPlayer();

字符串
我在我的类中声明了它,但它应该在类外声明,这解决了我的onstoprecord和onstopplay不工作的问题。

相关问题