ios - react native 录音机播放器 : Cannot read property 'startRecorder' of undefined

标签 ios react-native audio

我的代码在 android 平台上运行完美,但在 ios 中我得到:unhandled Promise Rejection: Cannot read property 'startRecorder' of undefined 错误

我一直在寻找一个用于 react-native 的录音机包,这个包似乎是最好的解决方案,但它在 ios 平台上不起作用

  const audioRecorderPlayer = new AudioRecorderPlayer();
  class QuestionSection extends Component {
    async onRecordPressed() {
      if (await this.requestPermissions()) {
        console.warn('start');
        await audioRecorderPlayer.startRecorder();
    }
  }

最佳答案

在构造函数中添加这些行并享受

 this.audioRecorderPlayer = new AudioRecorderPlayer();
this.audioRecorderPlayer.setSubscriptionDuration(0.09);

在钩子(Hook)中使用在 UseEffect 中添加这些行

audioRecorderPlayer = new AudioRecorderPlayer();
audioRecorderPlayer.setSubscriptionDuration(0.09);

关于ios - react native 录音机播放器 : Cannot read property 'startRecorder' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57634239/

相关文章:

audio - 从传输流中提取音频并保留长度

objective-c - iOS 上的自定义 EQ AudioUnit

Iphone Http请求响应使用json

ios - Objective-C KVC 改变属性的类型

javascript - Prop 类型失败 : Invalid prop 'value' of type 'object' supplied to 'TextInput' React Native

javascript - CodePush react-native ios 失败

ios - 同时播放和录制音频

iphone - 创建协议(protocol)后访问 UIPageViewController 的委托(delegate)方法

ios - 纵向

react-native-push-notification - 本地通知不适用于 Android