Skip to content

Instantly share code, notes, and snippets.

@ajsmth
Created July 16, 2021 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajsmth/2323d2654dacc32f5262714845566afb to your computer and use it in GitHub Desktop.
Save ajsmth/2323d2654dacc32f5262714845566afb to your computer and use it in GitHub Desktop.
Video Quality Bug
import * as React from 'react';
import { Camera } from 'expo-camera';
import { View, Button, Text, useWindowDimensions, LogBox, Alert } from 'react-native';
LogBox.ignoreLogs(['-[EXCamera']);
export default function App() {
const { width, height } = useWindowDimensions();
const cameraRef = React.useRef(null);
React.useEffect(() => {
Camera.requestCameraPermissionsAsync();
Camera.requestMicrophonePermissionsAsync();
}, []);
const [isRecording, setIsRecording] = React.useState(false);
function toggleRecording() {
isRecording ? stopRecording() : startRecording();
}
async function startRecording() {
const videoOptions = {
muted: true,
quality: Camera.Constants.VideoQuality['720p'],
};
setIsRecording(true);
const data = await cameraRef.current?.recordAsync(videoOptions);
console.log({ data });
Alert.alert(JSON.stringify(data, null, '\t'));
}
function stopRecording() {
cameraRef.current?.stopRecording();
setIsRecording(false);
}
const buttonLabel = isRecording ? 'Stop Recording' : 'Start Recording';
return (
<View style={{ flex: 1, paddingTop: 40, paddingBottom: 40, alignItems: 'center' }}>
<Button title={buttonLabel} onPress={toggleRecording} />
<Camera
style={{ flex: 1, width: width - 40 }}
type={Camera.Constants.Type.front}
ref={cameraRef}
/>
</View>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment