简体   繁体   English

尝试设置 react-native 调谐器时未处理的 promise 拒绝

[英]Unhandled promise rejection while trying to set up a react-native tuner

I'm currently developing an app which has to get real-time information about the current pitch.我目前正在开发一个应用程序,它必须获取有关当前音高的实时信息。 Since I already build a website with the same function, I'm am using react-native with expo.由于我已经使用相同的 function 建立了一个网站,因此我正在使用 react-native 和 expo。

For pitch detection I use the following libary: https://github.com/qiuxiang/react-native-tuner which is build ontop of https://www.npmjs.com/package/react-native-recording .对于音高检测,我使用以下库: https://github.com/qiuxiang/react-native-tuner ,它构建在https://www.npmjs.com/package/react-native-recording 之上

Unfortunatly after calling Recording.init() inside the tuner class I get following error不幸的是,在调谐器 class 中调用 Recording.init() 后,我收到以下错误

[Unhandled promise rejection: TypeError: Cannot read property 'init' of undefined]

The code in this class looks like this:此 class 中的代码如下所示:

import Recording from "react-native-recording";
import PitchFinder from "pitchfinder";

export default class Tuner {
 ...

  constructor(sampleRate = 22050, bufferSize = 2048) {
    this.sampleRate = sampleRate;
    this.bufferSize = bufferSize;
    this.pitchFinder = new PitchFinder.YIN({ sampleRate: this.sampleRate });
  }

  start() {
    Recording.init({
      sampleRate: this.sampleRate,
      bufferSize: this.bufferSize,
    });
...

The tuner class is initialized here, so I should have permission to access the microphone after the prompt on the device:调谐器 class 在这里初始化,所以我应该有权限在设备上提示后访问麦克风:

...
async componentDidMount() {
    if (Platform.OS === "android") {
      await PermissionsAndroid.requestMultiple([
        PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
      ]);
    }

    const tuner = new Tuner();
...

I have no idea on how to fix that since this is my first react-native app.我不知道如何解决这个问题,因为这是我的第一个 react-native 应用程序。 Would gladly appreciate any help!很乐意为您提供任何帮助!

I figured that react-native libarys are not compatible with expo.我认为 react-native 库与 expo 不兼容。 Changed my project to a react-native one and it worked just fine.将我的项目更改为 react-native 项目,它工作得很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 反应本地可能未处理的诺言拒绝 - Possible unhandled promise rejection in react-native React Native Unhandled promise 拒绝 | React-Native, 异步, - React Native Unhandled promise rejection | React-Native, Async, (本机)可能未处理的承诺拒绝FBSDK - (React-Native) Possible Unhandled Promise Rejection FBSDK 可能未处理的 Promise 拒绝 - React-Native with Firebase - Possible Unhandled Promise Rejection - React-Native with Firebase React Native中未处理的承诺拒绝 - Unhandled promise rejection in react native react-native 错误:[未处理的 promise 拒绝:错误:获取 Expo 令牌时遇到错误:TypeError:网络请求失败。] - react-native error:[Unhandled promise rejection: Error: Error encountered while fetching Expo token: TypeError: Network request failed.] Axios 承诺处理 - 在 react-native 中获取“可能未处理的承诺拒绝 - 类型错误:网络请求失败” - Axios Promise Handling - Getting “Possible Unhandled Promise Rejection - TypeError: Network request failed” in react-native React Native Axios 未处理的承诺拒绝 - React Native Axios unhandled promise rejection React-Native:未处理的 promise 拒绝:错误:对象作为 React 子对象无效 - React-Native: Unhandled promise rejection: Error: Objects are not valid as a React child 反应原生的未处理承诺拒绝错误? - Unhandled promise rejection error in react native?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM