goodatlas / react-native-audio-record

Audio record buffers for React Native (iOS and Android)
MIT License
176 stars 101 forks source link

null is not an object (evaluating 'RNAudioRecord.init') #81

Closed tGrothmannFluffy closed 1 year ago

tGrothmannFluffy commented 1 year ago

Hi there,

I am getting this error:

[Unhandled promise rejection: TypeError: null is not an object (evaluating 'RNAudioRecord.init')]
at node_modules/react-native-audio-record/index.js:7:43 in AudioRecord.init
at components/AudioTest.tsx:38:20 in recordSound

In AudioTest.tsx I just have a button that calls the following method (basically copied from the README):

import AudioRecord from "react-native-audio-record";

...

async function recordSound() {
  await PermissionsAndroid.requestMultiple([
    PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
  ]);

  const options = {
    sampleRate: 16000,  // default 44100
    channels: 1,        // 1 or 2, default 1
    bitsPerSample: 16,  // 8 or 16, default 16
    audioSource: 6,     // android only (see below)
    wavFile: 'test.wav' // default 'audio.wav'
  };

  AudioRecord.init(options); // <--- error happens here

  AudioRecord.start();

  AudioRecord.stop();
  // or to get the wav file path
  let audioFile = await AudioRecord.stop();

  AudioRecord.on('data', data => {
    console.log('data');
    // base64-encoded audio data chunks
  }); 
}

Can you tell me what I am doing wrong?


I am using expo on Android versions "react-native-audio-record": "^0.2.2"

tGrothmannFluffy commented 1 year ago

Turns out it was expo. I ejected to use react-native-cli and it works.