微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在Redmi / Mi Android设备中使用录音或音频播放时,React本机Android应用程序崩溃

如何解决在Redmi / Mi Android设备中使用录音或音频播放时,React本机Android应用程序崩溃

我正在尝试为我的应用程序实现音频录制和音频播放。对于三星设备,语音录制和播放音频工作正常,唯一的问题是redmi / mi android设备。

我的功能是我需要录制语音播放音频

我正在使用以下程序包来进行语音记录和播放音频

react-native-voice-recorder

这是我的录音功能

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

    this.props.setLoader(true);

    try {
      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);
          this.setState({ recordFilePath:  imguri})
          recordingPath = imguri;
          Alert.alert(
            'Do you want to save this voice deflation?','',[
              {text: 'Cancel',onPress: () => {
                this.props.setLoader(false);},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");
        }
      })
    } catch (e) {
      console.log("Error",e);
    }
  }

这是我的播放音频功能

_onPlay = async (idx,file,fileValidate) => {
    console.log("idx: "+idx);
    console.log("file: "+file);
    console.log("fileValidate: "+fileValidate);
    console.log("recordingPath: "+recordingPath);


    let playPath = (file && file != '') ? file : recordingPath;
    if(playPath && playPath != ''){

      console.log("this.state.recordFilePath",this.state.recordFilePath);
      let path = this.state.recordFilePath;
      try {
        RNVoiceRecorder.Play({
          path: path,onDone: (path) => {
            console.log("After Play Ka PATH ====>>>>>>>",path);
          },onCancel: () => {
            this.props.setLoader(false);
            console.log("Vishwas hai bhai ko");
          }
        })
      }catch (e) {
        console.log("Error",e.message);
      }
    }else{
      this.handler('error',"Please complete the recording first.");
    }
  }

请让我知道是否有人可以解决上述问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。