我正在试着让世博会的摄像机来录制视频。但是,我得到了一个错误:
[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>重要的一行是RecordingIcon。
function RecordingIcon (){
if(recording){
stopRecording()
return (
<MaterialIcons name="fiber-manual-record" onPress={() => setRecording(false)} color={"#FF0000"} size={60}/>
)
} else {
record()
return (
<MaterialIcons name="fiber-manual-record" onPress={() => setRecording(true)} color={"#eee"} size={60}/>
)
}
}每次我点击录制图标时,就会调用这两个函数中的一个。
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();
}
}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);发布于 2021-05-17 18:39:30
使用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();
}
}https://stackoverflow.com/questions/61628442
复制相似问题