Andrew Kim
Andrew Kim

Reputation: 1

Error: Video recording failed: Recording was stopped before any data could be produced

I've been getting an unhandled error when trying to record a video using react native. I am currently using npm version 10.8.2 and expo-camera version 15.0.16.

The current behaviour that I am experiencing is the code runs recordasync and then doesn't actually run the code after that. And then after stoprecording is pressed, the error message that nothing has been running comes out. I've tried the debugging and I am positive that there is something wrong with recordasync.

Or if there is a version of expo-camera that 100% works with the npm version 10.8.2 please let me know and I will give that a try too. Last time I tried forcing expo-camera module into my project it crashed my entire work.

    /* Function to start video recording */
    let startRecording = async () => {
        console.log("***");
        console.log("***");
        console.log('called start record');
        console.log('useRef ', recording.current);
        console.log('useState ', isRecording);
        
        if (!cameraRef.current || isRecordingRef.current) {
            console.error("Camera ref is not set.");
            return;
        }

        isRecordingRef.current = true;

        if (!hasCameraPermission || !hasMicrophonePermission) {
            console.error("Permissions not granted for camera or microphone.");
            return;
        }

        setIsRecording(true);
        recording.current = true;
        setCameraReady(false);
        
        try {
            const recordedVideo = await cameraRef.current.recordAsync({maxDuration: 5});
            console.log('done');
            setVideo(recordedVideo);
        } catch (error) {
            console.error("Error while recording: ", error);
            console.log("Full error object: ", error);
        } finally {
            isRecordingRef.current = false;
            // setIsRecording(true);
            recording.current = false;
        }
        
        console.log('***');
        console.log('finished start record');
        console.log('useRef ', recording.current);
        console.log('useState ', isRecording);
    };

    /* Function to stop video recording */
    let stopRecording = () => {
        console.log('***');
        console.log('called stop record');
        console.log('useRef ', recording.current);
        console.log('useState ', isRecording);
        if (cameraRef.current && isRecording) {
        // if (cameraRef.current && !recording.current) {
            try {
                setIsRecording(false);
                cameraRef.current.stopRecording();
                recording.current = false;
                isRecordingRef.current = false;
            } catch (error) {
                console.error("Error stopping recording: ", error);
            }
        }

        console.log("***");
        console.log('finished stop record');
        console.log('useRef ', recording.current);
        console.log('useState ', isRecording);
    };

Note: Please ignore all of the console.log and the useState and useRef duplicates I am still debugging.

Upvotes: 0

Views: 86

Answers (0)

Related Questions