我正试图在我的React中实现react-native-vision-camera,它在iOS上运行得非常完美,但在Android上却拒绝正常工作。在Android上,我会遇到以下错误.
[session/camera-not-ready] The Camera is not ready yet! Wait for the onInitialized() callback!
据我所见,在验证权限之前调用is时会发生此错误,而在我的应用程序中并非如此。考虑以下几点..。
// Camera Permission State
const [cameraPerm, setCameraPerm] = useState(false)
// Checks Mic and Video Permissions as soon as page loads
useEffect(() => {
checkPermissions();
}, []);
// Called in a useEffect to gain permissions
const checkPermissions = async () => {
// Request Permissions on component load
await Camera.requestCameraPermission();
await Camera.requestMicrophonePermission();
await requestPermission()
const cameraPermission = await Camera.getCameraPermissionStatus();
setCameraPerm(cameraPermission)
const microphonePermission = await Camera.getMicrophonePermissionStatus();
};
// Renders The Camera, if permissed and not done recording
function renderCameraScreen(){
// No permissions
if (device == null) return <View style={{backgroundColor: 'black'}}/>;
// Video Recorded
if (recorded){
return(
<View>
<Text style={{...FONTS.Title, textAlign: 'center', marginTop: 100}}>
Video Recorded
</Text>
</View>
)
}
if (!cameraPerm){
return(
<View>
<Text style={{...FONTS.Title, textAlign: 'center', marginTop: 100}}>
Please enable video permissions from your settings to access the camera
</Text>
</View>
)
}
return (
<View style={{backgroundColor: 'black', height: maxHeight * 0.70,}}>
<Camera
style={StyleSheet.absoluteFill}
device={device}
isActive={true}
video={true}
audio={true}
ref={camera}
/>
<View style={{alignSelf: 'center', marginTop: maxHeight * 0.65}}>
{renderRecordButton()}
</View>
</View>
);
};考虑到这一点,我不知道为什么会有这个错误。老实说,我在任何文档中都没有提到onInitialized(),所以我不确定如何使用该函数,以及在哪里使用该函数。
发布于 2022-11-15 16:56:16
据https://github.com/mrousavy/react-native-vision-camera/issues/789说,也许你需要隐藏相机,直到你的应用程序被授权使用相机。
https://stackoverflow.com/questions/74449379
复制相似问题