如何解决该错误>>警告可能未处理的承诺拒绝ID:0:

问题描述

我正在尝试制作一个应用程序来记录和播放所记录的内容,但我出现了这个错误

错误类型错误:_this2.onStartPlay 不是函数。 (在 '_this2.onStartPlay()' 中,'_this2.onStartPlay' 未定义) 错误参考错误:找不到变量:onPausePlay

LOG audioSet {"AVEncoderAudioQualityKeyIOS": 96,"AVFormatIDKeyIOS": "aac","AVNumberOfChannelsKeyIOS": 2,"AudioEncoderAndroid": 3,"AudioSourceAndroid": 1} LOG audioSet {"AVEncoderAudioQualityKeyIOS": 96,"AudioSourceAndroid": 1} LOG uri: 已经记录 警告可能未处理的承诺拒绝 (id: 0):

这是我的代码

import React,{Component} from 'react';

import AudioRecorderPlayer,{
  AVEncoderAudioQualityIOSType,AVEncodingOption,AudioEncoderAndroidType,AudioSet,AudioSourceAndroidType,} from 'react-native-audio-recorder-player';

import {View,Button,Text} from 'react-native';

export default class App extends Component {
  onStartRecord = async () => {
    const path = 'hello.m4a';
    const audioSet = {
      AudioEncoderAndroid: AudioEncoderAndroidType.AAC,AudioSourceAndroid: AudioSourceAndroidType.MIC,AVEncoderAudioQualityKeyIOS: AVEncoderAudioQualityIOSType.high,AVNumberOfChannelsKeyIOS: 2,AVFormatIDKeyIOS: AVEncodingOption.aac,};
    console.log('audioSet',audioSet);
    const uri = await this.audioRecorderPlayer.startRecorder(path,audioSet);
    this.audioRecorderPlayer.addRecordBackListener(e => {
      this.setState({
        recordSecs: e.current_position,recordTime: this.audioRecorderPlayer.mmssss(
          Math.floor(e.current_position),),});
    });
    console.log(`uri: ${uri}`);
  };

  onStopRecord = async () => {
    const result = await this.audioRecorderPlayer.stopRecorder();
    this.audioRecorderPlayer.removeRecordBackListener();
    this.setState({
      recordSecs: 0,});
    console.log(result);
  };

  constructor(props) {
    super(props);

    this.state = {
      isLoggingIn: false,recordSecs: 0,recordTime: '00:00:00',currentPositionSec: 0,currentDurationSec: 0,playTime: '00:00:00',duration: '00:00:00',};

    this.audioRecorderPlayer = new AudioRecorderPlayer();
    this.audioRecorderPlayer.setSubscriptionDuration(0.09); // optional. Default is 0.1
    // onPausePlay = async e => {
    //   await this.audioRecorderPlayer.pausePlayer();
    // };

    // onStopPlay = async e => {
    //   console.log('onStopPlay');

    //   this.audioRecorderPlayer.stopPlayer();

    //   this.audioRecorderPlayer.removePlayBackListener();
    // };
  }
  render() {
    return (
      <View
        style={{
          flex: 1,flexDirection: 'row',alignItems: 'center',alignContent: 'center',alignSelf: 'center',}}>
        <View>
          <Text>InstaPlayer</Text>
          <Text>{this.state.recordTime}</Text>
          <Button
            title="Record"
            mode="contained"
            onPress={() => this.onStartRecord()}
            // onPress={onStartRecord}
          />
          <Button title="stop" onPress={() => this.onStopRecord()} />

          <Text>
            {this.state.playTime} / {this.state.duration}
          </Text>

          <Button title="play" onPress={() => this.onStartPlay()} />
          {/* <Button title="pause" onPress={() => this.onPausePlay()} /> */}
          {/* <Button title="stop" onPress={() => this.onStopPlay()} /> */}
        </View>
      </View>
    );
  }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)