react-native-audio-recorder-player icon indicating copy to clipboard operation
react-native-audio-recorder-player copied to clipboard

Recorder currentPosition is in milliseconds when seconds are expected from docs

Open gavrichards opened this issue 3 years ago • 6 comments

Version of react-native-audio-recorder-player

3.1.2

Version of React Native

0.64.2

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

iOS (not checked Android)

Expected behavior

When addRecordBackListener's callback is called, the currentPosition value steadily increases.

Actual behavior

Immediately after starting recording, currentPosition value is very high.

Steps to reproduce the behavior

const uri = await player.startRecorder();
player.addRecordBackListener((e) => {
  console.log({e});
});

An example of the console output is:

{"e": {"currentMetering": 0, "currentPosition": 575.8276643990929, "isRecording": true}}

This suggests 575 seconds have passed, when I would only expect no more than 1. I have seen other values above 600 too, it fluctuates.

gavrichards avatar Aug 24 '21 17:08 gavrichards

You need to use this if you want smaller or bigger steps (it defaults to 0.5 as you can see): https://github.com/hyochan/react-native-audio-recorder-player/blob/c5d3e66a3e9dffc833871fc0f16664ddd779bb08/Example/App.tsx#L137

truth is, it's not well documented on README

efstathiosntonas avatar Aug 25 '21 14:08 efstathiosntonas

@efstathiosntonas Thanks but I'm not sure I understand how that is related to it reporting a position of 572 seconds, less than a second into recording.

gavrichards avatar Aug 25 '21 16:08 gavrichards

This is a log of what I get from the addRecordBackListener event. It appears that currentPosition here represents milliseconds perhaps? But the README clearly suggests it is seconds.

 LOG  {"e": {"currentMetering": 0, "currentPosition": 519.2743764172335, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 1018.390022675737, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 1518.3219954648525, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 2018.6167800453516, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 2518.2312925170068, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 3019.2063492063494, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 3518.344671201814, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 4019.206349206349, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 4518.43537414966, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 5018.503401360544, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 5518.344671201814, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 6018.208616780045, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 6518.185941043084, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 7018.185941043084, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 7519.3877551020405, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 8018.820861678005, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 8518.934240362812, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 9018.934240362812, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 9518.412698412698, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 10018.208616780044, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 10519.047619047618, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 11018.321995464852, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 11518.458049886622, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 12019.20634920635, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 12518.412698412698, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 13018.458049886622, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 13518.412698412698, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 14018.321995464852, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 14518.27664399093, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 15019.22902494331, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 15518.185941043084, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 16018.548752834466, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 16519.0022675737, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 17018.18594104308, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 17518.639455782315, "isRecording": true}}
 LOG  {"e": {"currentMetering": 0, "currentPosition": 18018.707482993195, "isRecording": true}}

gavrichards avatar Sep 01 '21 09:09 gavrichards

This time a log from Android, similar result:

 LOG  {"e": {"currentPosition": 502}}
 LOG  {"e": {"currentPosition": 1003}}
 LOG  {"e": {"currentPosition": 1504}}
 LOG  {"e": {"currentPosition": 2004}}
 LOG  {"e": {"currentPosition": 2504}}
 LOG  {"e": {"currentPosition": 3005}}
 LOG  {"e": {"currentPosition": 3505}}
 LOG  {"e": {"currentPosition": 4006}}
 LOG  {"e": {"currentPosition": 4506}}
 LOG  {"e": {"currentPosition": 5007}}
 LOG  {"e": {"currentPosition": 5508}}
 LOG  {"e": {"currentPosition": 6008}}
 LOG  {"e": {"currentPosition": 6508}}
 LOG  {"e": {"currentPosition": 7009}}
 LOG  {"e": {"currentPosition": 7509}}
 LOG  {"e": {"currentPosition": 8010}}

gavrichards avatar Sep 01 '21 09:09 gavrichards

same issue

Wanderlust-sol avatar Nov 03 '21 02:11 Wanderlust-sol

@gavrichards @Wanderlust-sol

Had some things to do with the player and this is how i moved around it, this way it shows seconds

const uri = await player.startRecorder();
player.addRecordBackListener((e) => {
    console.log(player.mmssss(Math.floor(e.currentPosition)));
});

Notice the step between currentPosition update is half a second, in which case the solution from @efstathiosntonas comes in handy.

NK-Hertz avatar Jan 14 '22 11:01 NK-Hertz

This has been covered in the recent version. Try 3.5.1 and comeback.

hyochan avatar Oct 15 '22 12:10 hyochan