当我使用expo audio录制音频时,总是出现错误:无法开始录制,TypeError:undefined不是评估'_ExponentAV.default.requestPermissionsAsync'的对象,位于node_modules\expo\build\environment\react-native-logs.fx.js:27:23,在启动记录中的src\components\Chat\ChatForm.tsx:189:19发生错误
import React, { useState } from "react";
import { Audio } from "expo-av";
type ChatFormProps = {
onSend: () => void;
};
const ChatForm: React.FC<ChatFormProps> = ({ onSend }) => {
const [isRecording, setIsRecording] = useState(false);
const [recordTime, setRecordTime] = useState<string>("00:00");
const recording = new Audio.Recording();
const startRecording = async () => {
try {
console.log("Requesting permissions..");
// console.log(Audio);
await Audio.requestPermissionsAsync();
await Audio.setAudioModeAsync({
allowsRecordingIOS: true,
playsInSilentModeIOS: true,
});
console.log("Starting recording..");
await recording.prepareToRecordAsync(
Audio.RECORDING_OPTIONS_PRESET_HIGH_QUALITY
);
await recording.startAsync();
setIsRecording(!isRecording);
console.log("Recording started");
} catch (err) {
console.error("Failed to start recording", err);
}
};
const stopRecording = async () => {
try {
console.log("Stopping recording..");
setIsRecording(!isRecording);
await recording.stopAndUnloadAsync();
const uri = recording.getURI();
console.log("Recording stopped and stored at", uri);
} catch (err) {
console.error("Failed to stop recording", err);
}
};
}
1条答案
按热度按时间tvmytwxo1#
尝试初始化try块内的记录