Audio Recorder is crashing whenever any third party application is using mike in React Native

Viewed 157

I have created an Audio recording component with react native audio recorder player, which is working perfectly fine until any third party application like Google meet is using mike. To handle that exception I have wrapped the onstartRecord() inside try catch and I want to reset the data to empty there on. I have tried as follows:

const onStartRecord = async (isFromRecordButton) => {
    console.log(1)
    try
    {
      console.log(2)
      if (isFromRecordButton)
      {
        console.log(3)
      } else
      {
        console.log(4)
        setrecordingfile(false);
      }
      let iswritestoragegranted = await writetoexternalstorage();
      console.log(5)
      let isrecordgranted = await recordaudiopermission();
      console.log(6)
        if (iswritestoragegranted && isrecordgranted)
        {
          console.log(7)
          try
          {
            setrecording(true);
            isRecordFileExists = true;
            // const path = Platform.select({
            //   ios: "hello.m4a",
            //   android: "sdcard/hello.mp4",
            // });
            console.log(100)
            const result = await audioRecorderPlayer.startRecorder(mRecordTrack);
            console.log(99)
            audioRecorderPlayer.addRecordBackListener((e) => {
              setRecordTime(
                audioRecorderPlayer.mmss(Math.floor(e.current_position / 1000))
              );
              console.log("Recording . . . ", e.current_position);
              console.log("file...", e);
              // setrecording(true);
              return;
            });
            console.log(result);
            console.log(8)
          } catch (e)
          {
            console.log('after 7 err',e)
          }
        }
    }catch(e){
      console.log('audio recorder', e)
      console.log(9)
      props.refRBSheet.current.close();
      console.log(10)
      audioRecorderPlayer._isRecording = false
      console.log(11)
      const audio = await audioRecorderPlayer.stopRecorder();
      console.log(12)
      audioRecorderPlayer.removeRecordBackListener();
      console.log(13)
      // await audioRecorderPlayer.stopPlayer();
     // await audioRecorderPlayer.removePlayBackListener();
      setrecordingfile(false);
    }
    
  };

on using consoles and try catch I got to know that it is breaking on the following line,

const result = await audioRecorderPlayer.startRecorder(mRecordTrack);

the second time, even though I have mentioned the stopRecorder(), removeRecordBackListener() but it is not clearing at all, instead when I stop using meet and click on record button again, it shows Already Recording! and crashes.

0 Answers
Related