Created
July 16, 2021 17:41
-
-
Save ajsmth/2323d2654dacc32f5262714845566afb to your computer and use it in GitHub Desktop.
Video Quality Bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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