Hi all, I’m facing an issue which I need some help with. when testing my app via the expo go app, all works fine. but when I create an apk and test the app, it breaks.
on my component, when it is loads, I have a use Effect hook which starts a video recording using the expo-camera module.
This component is responsible for recording a video, saving it to file and then passing the file name and path to the onComplete function provided by the parent component
// Imports
import React, { useRef, useState, useEffect } from 'react';
import { Camera, CameraType, VideoCodec } from 'expo-camera';
export default function RecordAnswerView(props: any) {
const { question, onComplete, onRestart } = props;
const [isRecording, setIsRecording] = useState(false);
const [isCameraReady, setIsCameraReady] = useState<boolean>(false);
const cameraRef = useRef<any>(null);
const saveRecording = () => {
try {
if (isRecording) {
if (isCameraReady) {
cameraRef?.current?.stopRecording();
setIsRecording(false)
}
}
} catch (error) {
console.log(error)
}
};
const startRecording = () => {
setIsRecording(true);
cameraRef?.current?.recordAsync({
codec: VideoCodec.H264,
mute: false,
videoBitrate: 500*1000,
quality: '480p',
}).then((response: any) => {
if(!mustRestart){
onComplete(response?.uri);
}
}).catch((error: any) => {
console.log(error?.message)
})
};
const restartRecording = () => {
setMustRestart(true);
cameraRef?.current?.stopRecording();
onRestart();
};
useEffect(() => {
(async () => {
let camera = await Camera.getCameraPermissionsAsync();
let audio = await Camera.getMicrophonePermissionsAsync();
console.log(camera);
console.log(audio);
startRecording();
})();
}, []);
return (
<>
<View style={{ marginHorizontal: 12 }}>
<Text style={{ textAlign: 'center', fontSize: 22, marginVertical: 12 }}>Answer Recorder</Text>
<Camera
ratio={'4:3'}
ref={cameraRef}
type={CameraType.front}
onCameraReady={() => setIsCameraReady(true)}
style={{ width: windowWidth - 20, height: (windowWidth - 20) * 1.02 }}
useCamera2Api={true}
>
</Camera>
<PrimaryButton
onPress={saveRecording}
text={'Save'}
containerStyle={{ marginTop: 20, marginBottom: 8, width: windowWidth - 20 }}
fontSize={20}
/>
<PrimaryButton
onPress={restartRecording}
text={'Restart Recording'}
containerStyle={{ marginTop: 5, marginBottom: 10, width: windowWidth - 20 }}
fontSize={10}
height={32}
/>
</View>
</>
}