hyochan / react-native-audio-recorder-player

react-native native module for audio recorder and player.
MIT License
716 stars 213 forks source link

audioRecorderPlayer.mmssss(Math.floor(e.current_position)) showing aN:aN #370

Closed trinaChaudhuri closed 3 years ago

trinaChaudhuri commented 3 years ago

Please fill the template to help you out. Also, please try the Example project compare before submiting the issue when you have certain issue with your project setup.

Version of react-native-audio-recorder-player

"react-native-audio-recorder-player": "^3.1.1"

Version of React Native

"react-native": "0.64.2",

Platforms you faced the error (IOS or Android or both?)

Both-IOS and Android

Expected behavior

The method should be giving the current time in mm:ss format

Actual behavior

The method is giving aN:aN

Steps to reproduce the behabior

create a react native project install react-native-audio-player create a button for start record create a state : const [recordTime, setRecordTime] = useState("00:00");

onstartRecord for the button method is as follows:

const onStartRecord = async (isFromRecordButton) => { console.log('ggg') try { if (isFromRecordButton) { } else { setrecordingfile(false); } console.log('hh') let iswritestoragegranted = await writetoexternalstorage(); let isrecordgranted = await recordaudiopermission(); if(Platform.OS=="android"){ if (iswritestoragegranted && isrecordgranted) { setrecording(true); isRecordFileExists = true; // const path = Platform.select({ // ios: "hello.m4a", // android: "sdcard/hello.mp4", // }); const result = await audioRecorderPlayer.startRecorder(mRecordTrack); audioRecorderPlayer.addRecordBackListener((e) => { console.log('EEEE',audioRecorderPlayer.mmss(e.current_position)); setRecordTime( audioRecorderPlayer.mmss(Math.floor(e.current_position)) ); // console.log("Recording . . . ", e.current_position); // console.log("file...", e); return; }); console.log(result); } }else{ console.log('jjjj') setrecording(true); isRecordFileExists = true; // const path = Platform.select({ // ios: "hello.m4a", // android: "sdcard/hello.mp4", // }); const result = await audioRecorderPlayer.startRecorder(mRecordTrack);

      audioRecorderPlayer.addRecordBackListener((e) => {

        console.log('e',audioRecorderPlayer.mmssss(Math.floor(e.current_position)));
        setRecordTime(
          audioRecorderPlayer.mmss(Math.floor(e.current_position / 1000))
        );
        // console.log("Recording . . . ", e.current_position);

        return;
      });
      console.log(result);
  }

} catch (e) {
  console.log("audio recorder", e);
}

};

fellipe-ribeiro commented 3 years ago

Try this: audioRecorderPlayer.mmssss(e.currentPosition);

hyochan commented 3 years ago

Yes please refer to the example code

Yandamuri commented 1 month ago

To be precise, use currentPosition instead of current_position