I am using react-native-image-crop-picker in my react-native application and recording video from the camera in Android It is returning [Error: User cancelled image selection]
react-native-image-crop-picker
Versions used
react-native-image-crop-picker v^0.40.2
react-native v0.72.0
react v18.2.0
Android v13
Platform – Android
Expected behaviour
When we record video using ImagePicker.openCamera recorder video path must be returned as it returns when the image is captured.
Actual behaviour
After the video is recorded and we click ok it gives [Error: User cancelled image selection]
Steps to reproduce
- Open Camera.
- Record the Video and click OK.
- Then we must get the recorded video path but it returns an error [Error: User cancelled image selection].
Sample code
recordVideo = async() => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.CAMERA,
{
title: "App Camera Permission",
message:"App needs access to your camera ",
buttonNeutral: "Ask Me Later",
buttonNegative: "Cancel",
buttonPositive: "OK"
}
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
ImagePicker.openCamera({
mediaType:'video'
})
.then((image) => {
console.log(" Image ", image)
})
.catch((error) => {
if (error && error.code === 'E_PICKER_CANCELLED') {
return false;
}
})
} else {
console.log("Camera permission denied");
}
} catch (err) {
console.warn(err);
}
}
2
Answers
Uninstall using npm uninstall react-native-image-crop-picker and again install using npm i react-native-image-crop-picker and don’t forget to add to android/app/src/main/AndroidManifest.xml.
Please follow the final step of installation instructions for Android:
If you use SDK version >= 33, add following to app/src/main/AndroidManifest.xml
[Optional] If you want to use camera picker in your project, add following to app/src/main/AndroidManifest.xml
[Optional] If you want to use front camera, also add following to app/src/main/ AndroidManifest.xml