prscX / react-native-voice-recorder

React Native: Native Audio Recorder View
Apache License 2.0
93 stars 14 forks source link

Android app crashed on simulator #24

Open rahulmishra1991 opened 4 years ago

rahulmishra1991 commented 4 years ago

When i am clicking on my onrecord function app is crashing on my simulator. It's working on my testing device but not working on the some other devices.

_onRecord = async (idx, relation) => { const token = await AsyncStorage.getItem('access_token');

this.props.setLoader(true);

RNVoiceRecorder.Record({
  onDone: (path) => {
    console.log("PATH",path);

    const imgUri = Platform.OS === 'android' ? 'file://' + path : path;
    const templateId = this.props.navigation.getParam('templateId', 0);
    const documentId = this.props.navigation.getParam('documentId', 0);
    recordingPath = imgUri;
    Alert.alert(
      'Are you sure you want to use this declaration?',
      '',
      [
        {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
        {
          text: 'OK', onPress: () => {
            console.log("templateId >> "+templateId);
            console.log("relation >> "+relation);
            RNFetchBlob.fetch('POST', API_PATHS.AUDIO_RECORDING, {
              Authorization : "Bearer "+token,
              'Content-Type' : 'multipart/form-data',
            }, [

              { name : 'file_input', filename : 'dotcom_recorded_audio.wav', type:'audio/wav', data: RNFetchBlob.wrap(imgUri)},
              {name: 'documentId', data: documentId.toString()},
              {name: 'relation', data: relation}
            ]).then((resp) => {
              let response = resp.json();
              console.log("response.data => ",response.status);
              if (response.success) {
                recordingPath = '';
                this.state.audioRecordings[idx].file = response.data;
                this.state.audioRecordings[idx].fileValidate = true;
                this.handler('success','Success',response.message);

                this.props.setLoader(false);
                console.log("this.state.audioRecordings",this.state.audioRecordings);
              }else{
                this.props.setLoader(false);
              }
            }).catch((err) => {
              console.log("ERROR",err);
              this.handler('error','Error',err.message);
              this.props.setLoader(false);
            })

          }
        },
      ],
      { cancelable: false }
    )
  },
  onCancel: () => {
    this.props.setLoader(false);
    console.log("Mood sahi nhi hai");
  }
})

}