jsierles / react-native-audio

Audio recorder library for React Native
MIT License
1.16k stars 539 forks source link

Unable to store audio in MainBundlePath #320

Open shubhanus opened 5 years ago

shubhanus commented 5 years ago

Version

react-native-audio : 4.3.0 react-native :0.58.4 react : 16.6.3 using react-native-sound ? Yes

Expected behaviour :

Trying to store recording in main bundle path it should store

Actual behaviour

Possible Unhandled Promise Rejection (id: 0): Error: /medias/1552823365335.aac: open failed: ENOENT (No such file or directory) Error: /medias/1552823365335.aac: open failed: ENOENT (No such file or directory) at createErrorFromErrorData (blob:file:///e39c3725-7e2b-4d30-a1fa-a63f4b9e1b88:2014:17) at blob:file:///e39c3725-7e2b-4d30-a1fa-a63f4b9e1b88:1966:27 at MessageQueue.invokeCallback (blob:file:///e39c3725-7e2b-4d30-a1fa-a63f4b9e1b88:2533:18) at blob:file:///e39c3725-7e2b-4d30-a1fa-a63f4b9e1b88:2264:18 at MessageQueue.guard (blob:file:///e39c3725-7e2b-4d30-a1fa-a63f4b9e1b88:2437:13) at MessageQueue.invokeCallbackAndReturnFlushedQueue (blob:file:///e39c3725-7e2b-4d30-a1fa-a63f4b9e1b88:2263:14) at e (file:///Applications/React%20Native%20Debugger.app/Contents/Resources/app.asar/js/RNDebuggerWorker.js:1:94022)

Steps to reproduce

export const MEDIA_DIR = `${AudioUtils.MainBundlePath}/medias`;
export const AUDIO_BASE_CONFIG = {
  SampleRate: 22050,
  Channels: 1,
  AudioQuality: 'Medium',
  AudioEncoding: 'aac',
  AudioEncodingBitRate: 12800,
};

await AudioRecorder.prepareRecordingAtPath(
      `${MEDIA_DIR}/${audioSubPath}.aac`,
      AUDIO_BASE_CONFIG,
    );

try {
      AudioRecorder.startRecording();
 } catch (error) {
   console.error(error);
}
aJIEw commented 5 years ago

MainBundlePath only works on iOS, you can check the android source code here, and it's usually used to access files embedded in iOS app only.