Reactjs 让expo camera ref开始在功能组件中录制视频
我正在试着让世博会摄像机录制视频。但是,我得到一个错误:Reactjs 让expo camera ref开始在功能组件中录制视频,reactjs,react-native,camera,expo,ref,Reactjs,React Native,Camera,Expo,Ref,我正在试着让世博会摄像机录制视频。但是,我得到一个错误: [TypeError: camera.recordAsync is not a function. (In ‘camera.recordAsync()’, ‘camera.recordAsync’ is undefined)] 这是执行: <Camera style={{ flex: 1 }} type={type} ref={ca
[TypeError: camera.recordAsync is not a function. (In ‘camera.recordAsync()’, ‘camera.recordAsync’ is undefined)]
这是执行:
<Camera
style={{ flex: 1 }}
type={type}
ref={camera}
>
<View
style={{
flex: 1,
backgroundColor: 'transparent',
flexDirection: 'row',
}}>
<View style={{ alignSelf: 'flex-end', alignItems: 'center', padding: 20, flexDirection: 'row', justifyContent: 'space-between', width: '100%'}}>
<MaterialIcons name="video-library" onPress={pickVideo} color={"#eee"} size={45}/>
<RecordingIcon />
<Ionicons name="ios-reverse-camera" onPress={setCameraType} color={"#eee"} size={45}/>
</View>
</View>
</Camera>
但是,由于顶部的错误,这两种方法都不起作用:
async function record(){
console.log("record", camera);
if(camera){
let recording = await camera.recordAsync();
}
}
async function stopRecording(){
console.log("stop recording", camera);
if(camera){
let stopRecording = await camera.stopRecording();
}
}
这就是我初始化相机参考的方式
let camera = useRef(null);
非常感谢任何人帮助解决此错误。我也尝试过使用camera.current.recordAsync()和camera.current.stopRecording(),但得到了相同的错误。使用camera.current
async function record(){
console.log("record", camera);
if(camera){
let recording = await camera.current.recordAsync();
}
}
async function stopRecording(){
console.log("stop recording", camera);
if(camera){
let stopRecording = await camera.current.stopRecording();
}
}
不确定是否已解决此问题,但您是否考虑过针对ref的摄影机组件执行类似{setCamera(ref);}}>
let camera = useRef(null);
async function record(){
console.log("record", camera);
if(camera){
let recording = await camera.current.recordAsync();
}
}
async function stopRecording(){
console.log("stop recording", camera);
if(camera){
let stopRecording = await camera.current.stopRecording();
}
}