android 错误:使用Expo和expo-av时缺少音频录制权限

o2gm4chl  于 2023-06-27  发布在  Android
关注(0)|答案(1)|浏览(133)

我正在使用Expo开发一个应用程序,遇到了音频录制权限问题。当我尝试通过单击应用程序中的按钮开始录制时,我在控制台中收到以下错误消息:

LOG  Requesting permissions..
LOG  Starting recording..
ERROR  Failed to start recording [Error: Missing audio recording permissions.]

没有对话框显示请求麦克风权限,我还修改了startRecording函数行中请求权限的地方,我添加了. then和. catch,但它直接转到catch语句,这意味着权限被自动拒绝
我尝试了以下步骤来解决此问题:
通过在"microphonePermission"配置中包含expo-av插件,在我的app.json文件中添加了必要的麦克风权限。
已验证是否在app.json文件中设置了麦克风权限消息"Allow Anonimia to access your microphone."。
更新了app.json中的plugins部分,以删除expo-image-picker插件配置中值为false的microphonePermission键。
重新构建了开发客户端,并确保我使用的是最新版本的expo-cli和expo sdk。
尽管进行了这些尝试,但错误仍然存在,我无法在应用程序中开始录制音频。我将非常感谢任何关于如何解决这个问题的见解或指导。提前感谢您的帮助。
下面是startRecording函数:

async function startRecording() {
        try {
            console.log("Requesting permissions..");
            await Audio.requestPermissionsAsync();
            await Audio.setAudioModeAsync({
                allowsRecordingIOS: true,
                playsInSilentModeIOS: true,
            });
            console.log("Starting recording..");
            const { recording } = await Audio.Recording.createAsync(
                Audio.RecordingOptionsPresets.HIGH_QUALITY
            );
            setRecording(recording);
            setIsRecording(true);
            console.log("Recording started");
        } catch (err) {
            console.error("Failed to start recording", err);
        }
    }

这是我的app.json

{
  "expo": {
    "userInterfaceStyle": "automatic",
    "name": "Anonimia",
    "slug": "anonymous-chat",
    "description": "Anonymous chat app",
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "userInterfaceStyle": "light",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "assetBundlePatterns": ["**/*"],
    "ios": {
      "supportsTablet": true,
      "bundleIdentifier": "app.anonimia.messenger"
    },
    "plugins": [
      "@react-native-firebase/app",
      [
        "expo-image-picker",
        {
          "photosPermission": "Allow Anonimia to open photos",
          "cameraPermission": "Allow Anonimia to open the camera",
        }
      ],
      [
        "expo-av",
        {
          "microphonePermission": "Allow Anonimia to access your microphone."
        }
      ]
    ],
    "android": {
      "backgroundColor": "#222831",
      "package": "app.anonimia.messenger",
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#ffffff"
      },
      "googleServicesFile": "./google-services.json"
    },
    "web": {
      "favicon": "./assets/favicon.png"
    },
    "extra": {
      "eas": {
        "projectId": "682e0444-81fd-45b2-8bec-aecdd8b4e48d"
      }
    }
  }
}
vngu2lb8

vngu2lb81#

你解决了吗你介意告诉我哪里出了问题吗?

相关问题