README
react-native-android-audiorecorder
Getting started
$ npm install react-native-android-audiorecorder --save
Mostly automatic installation
$ react-native link react-native-android-audiorecorder
Manual installation
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.reactlibrary.RNAndroidAudiorecorderPackage;
to the imports at the top of the file - Add
new RNAndroidAudiorecorderPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-android-audiorecorder' project(':react-native-android-audiorecorder').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-audiorecorder/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-android-audiorecorder')
Usage
import {AudioRecorder, AudioUtils} from 'react-native-android-audiorecorder';
class example extends Component {
...
state = {
currentTime: 0.0,
recording: false,
stoppedRecording: false,
finished: false
};
prepareRecordingPath(audioPath){
AudioRecorder.prepareRecordingAtPath(audioPath, {
SampleRate: 22050,
Channels: 1,
AudioQuality: "Low",
AudioEncoding: "aac",
AudioEncodingBitRate: 32000
});
}
componentDidMount() {
let audioPath = AudioUtils.MusicDirectoryPath + '/test.aac';
this.prepareRecordingPath(audioPath);
}
...
_stop() {
if (this.state.recording) {
AudioRecorder.stopRecording();
this.setState({stoppedRecording: true, recording: false});
}
}
_record() {
if(this.state.stoppedRecording){
let audioPath = AudioUtils.DocumentDirectoryPath + '/test.aac';
this.prepareRecordingPath(audioPath);
}
AudioRecorder.startRecording();
this.setState({recording: true, playing: false});
}
based on project react-native-audio from jsierles