簡體   English   中英

嘗試設置 react-native 調諧器時未處理的 promise 拒絕

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

我目前正在開發一個應用程序,它必須獲取有關當前音高的實時信息。 由於我已經使用相同的 function 建立了一個網站,因此我正在使用 react-native 和 expo。

對於音高檢測,我使用以下庫: https://github.com/qiuxiang/react-native-tuner ,它構建在https://www.npmjs.com/package/react-native-recording 之上

不幸的是,在調諧器 class 中調用 Recording.init() 后,我收到以下錯誤

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

此 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,
    });
...

調諧器 class 在這里初始化,所以我應該有權限在設備上提示后訪問麥克風:

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

    const tuner = new Tuner();
...

我不知道如何解決這個問題,因為這是我的第一個 react-native 應用程序。 很樂意為您提供任何幫助!

我認為 react-native 庫與 expo 不兼容。 將我的項目更改為 react-native 項目,它工作得很好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM