expo-av nude错误:缺少录音权限

时间:2019-05-16 16:07:57

标签: react-native react-native-android expo

希望在react-native中将最新可用的expo软件包用于已分离或“裸”的应用。

遇到以下错误:

错误:缺少录音权限。

但是我已经调用了expo-permissions库来确保获得RecordAudio权限。

有关完整的示例项目,请参见https://github.com/Glorifundel/bareaudio

App.js

import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View, Button } from 'react-native';
import * as Permissions from 'expo-permissions';
import { Audio } from 'expo-av';

export default class App extends Component {
  render() {
    return (
      <View style={{ flex: 1 }}>
        <Text style={styles.welcome}>Welcome to React Native!</Text>
        <Button title="Get Permission" onPress={this.onPressPermission} />
        <Button title="Record" onPress={this.onPressRecord} />
      </View>
    );
  }
  onPressPermission = async () => {
    const { status, expires, permissions } = await Permissions.askAsync(
      Permissions.CAMERA_ROLL,
      Permissions.AUDIO_RECORDING
    );
    alert(`permission: ${status}`);
  };
  onPressRecord = async () => {
    const recording = new Audio.Recording();
    try {
      await recording.prepareToRecordAsync(
        Audio.RECORDING_OPTIONS_PRESET_LOW_QUALITY
      );
      await recording.startAsync();
      alert(`onPressRecord recording!`);
    } catch (error) {
      alert(`onPressRecord error: ${error}`);
    }
  };
}

按下“获取权限”按钮将报告警报“权限:已授予”,然后再按下“记录”按钮将产生警报“ onPressRecord错误:错误:缺少录音权限”。

感谢任何见识,

环境详细信息:我正在Windows 10上,运行android API 27(8.1 Oreo)的android模拟器上运行。是否进行了新的Node v10.15.3安装以及最新的react-native-cli expo-cli安装,并使用expo init --template最小模板生成了项目。接下来是纱线添加expo-av和纱线添加expo-permissions,并遵循两个软件包自述文件中的说明。

0 个答案:

没有答案