[DEPRECATED]: I have to update the ObjC and Java code. And update RN version.
- Install the module
npm i --save react-native-record-sound
- In
android/settings.gradle
...
include ':react-native-record-sound', ':app'
project(':react-native-record-sound').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-record-sound/android')
- In
android/app/build.gradle
...
dependencies {
...
compile project(':react-native-record-sound')
}
- Register module (in MainActivity.java)
import com.reactnativerecordsound.ReactNativeRecordSoundPackager; // <--- import
public class MainActivity extends ReactActivity {
......
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new ReactNativeRecordSoundPackager() // <------ add here
);
}
......
}
import Record from 'react-native-record-sound';
let isRecording = false;
...
recordSound() {
if (isRecording === false)
Record.startRecord(path + 'sound.mp4', (err) => {console.log(err)});
else
Record.stopRecord();
isRecording = !isRecording;
}