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

How can i get the audio file size in iOS

Open arundev-kv opened this issue 2 years ago • 1 comments

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

3.1.1

Version of React Native

61.5

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

IOS

Expected behavior

Should get the file information using RNFetchBlob.stat(pathToFile). I'm getting the file path only. And I use RNFetchBlob.stat to access the file details.

Actual behavior

I'm getting the error failed to stat path because it does not exist or it is not a folder

Steps to reproduce the behabior

My code.

conststopRecord = useCallback(async () => {​​​​​​​​

constresult = awaitaudioRecorderPlayer.stopRecorder();

audioRecorderPlayer.removeRecordBackListener();

const {​​​​​​​​ stat }​​​​​​​​ = RNFetchBlob.fs; const {​​​​​​​​ size }​​​​​​​​ = awaitstat(pathFunction());

setFilePath(result);

setFileSize(bytesToSize(size));

setShowStop(false);

setShowPlay(true);

}​​​​​​​​, [audioRecorderPlayer, pathFunction]);

pathFunction

const pathFunction = useCallback(() => {
const { dirs } = RNFetchBlob.fs;
const path = Platform.select({
ios: `${fileName}`,
android: `${dirs.CacheDir}/${fileName}`,
 });
return path;
 }, [fileName])
;

Note:

Its working file in Android, but getting error in iOS

arundev-kv avatar Aug 06 '21 08:08 arundev-kv

@arundev-kv im using react-native-fs which I think has a similar api and have managed to get it working doing this

const uri = `${RNFS.CachesDirectoryPath}/sound.${Platform.OS === 'ios' ? 'm4a' : 'mp4'}`;
const result = await RNFS.stat(uri);
const size = result.size; // size is in bytes;

moulie415 avatar Jan 10 '22 14:01 moulie415