[英]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.