Высушите функцию takeVideo:
Код: Выделить всё
const takeVideo = async () =>{
setButtonVisible(false); // Oculta o botão imediatamente ao clicar
const cameraInstance = cameraRef.current;
if (cameraInstance) {
try {
console.log('Trying to record video...');
const video = await cameraInstance.recordAsync({
maxDuration: 5
});
console.log(video);
if (video?.uri) {
const videoUri = video.uri;
setCapturedVideo(videoUri);
setMessage('Image captured successfully!');
setIsError(false);
} else {
setMessage('Error capturing image!');
setIsError(true);
console.log('Failed to record video.');
}
} catch (error) {
console.log('Failed to record video:', error);
setMessage(''Error capturing image!');
setIsError(true);
} finally {
cameraInstance.stopRecording();
setCameraVisible(false);
}
} else {
setMessage('Error when trying to open the camera');
setIsError(true);
console.error('Camera reference not found.');
}
}
Код: Выделить всё
{buttonVisible && ( // Só exibe o botão se 'buttonVisible' for true
Iniciar
)}
Подробнее здесь: https://stackoverflow.com/questions/790 ... or-android
Мобильная версия