Getting expo-camera ref to start working to record videos

Hi everyone! I am trying to get expo-camera to record videos. However, I am getting an error:

[TypeError: camera.recordAsync is not a function. (In ‘camera.recordAsync()’, ‘camera.recordAsync’ is undefined)]

This is implementation:

<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>

The important row is . This represents the icon that can be pressed to record and stop recording.


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}/>  
            )
        }
    }

Every time I tap the recording icon, one of these two functions gets called.

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(); 
        }
    }

However, both of these don’t work because of the error at the top:

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(); 
        }
    }

This is how I initialized my camera reference.

let camera = useRef(null);

Really appreciate anyone’s help to figure out to resolve this error. I tried doing camera.current.recordAsync() and camera.current.stopRecording() too, but I got the same error.

use this.camera instead of camera

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.