我正在尝试使用 expo go 51 录制视频,在将相机 API 更新为相机视图后,我收到了本问题标题中提到的错误。
问题是代码在 50 中可以工作,但在 51 中不起作用,这有点奇怪。
这是我的代码:
async function takeVideo() {
// request permission to record audio
const { status } = await Camera.requestMicrophonePermissionsAsync();
if (cameraRef.current) {
if (isRecording) {
console.log('Stopped recording isRecording:', isRecording);
cameraRef.current.stopRecording();
setIsRecording(false);
} else {
setIsRecording(true);
console.log('Start recording');
const video = cameraRef.current.recordAsync();
video.then((video) => {
console.log('Video saved:', video?.uri);
const asset = MediaLibrary.createAssetAsync(video?.uri as string);
});
// console.log('Video saved:', video?.uri);
// const asset = await MediaLibrary.createAssetAsync(video?.uri as string);
console.log('Stopped recording');
}
}
}
相机组件:
<CameraView ref={cameraRef} style={styles.camera} facing={type as CameraType}>
<View style={styles.buttonContainer}>
<TouchableOpacity style={styles.button} onPress={toggleCameraType}>
<Text style={styles.text}>Flip Camera {selectedRatio}</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={takeVideo}>
<Text style={styles.text}>{ isRecording? "Stop" : "Take" } Video</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={takePicture}>
<Text style={styles.text}>Take Picture</Text>
</TouchableOpacity>
{image && <Image source={{ uri: image }} style={{
flex: 1, width: 100, height: 100, alignSelf: 'flex-end',
alignItems: 'center', justifyContent: 'center', resizeMode: 'contain'
}} />}
</View>
</CameraView>
问题是我的cameraView组件中没有模式,将模式设置为视频解决了它。
<CameraView mode="video" ref={cameraRef} style={styles.camera} facing={type as CameraType}>