cordova-plugin-camera-preview
cordova-plugin-camera-preview copied to clipboard
startCamera() callback - camera not available on Android
The camera is not available when using a plugin method related to camera parameters.
Here is my code:
constructor(public navCtrl: NavController, private cameraPreview: CameraPreview, private platform: Platform) {
this.platform.ready().then(() => {
let options = {
x: 0,
y: 20,
width: window.screen.width,
height: window.screen.height-40,
camera: this.cameraPreview.CAMERA_DIRECTION.BACK,
toBack: true,
tapPhoto: false,
previewDrag: false
};
this.cameraPreview.startCamera(options).then((value) => {
console.log("startCamera: " + value);
this.cameraPreview.getMaxZoom().then((value) => {
console.log("Max Zoom:" + value);
}, (error) => {
console.log("Error getting zoom: " + error);
});
I got the following message in the log:
startCamera: Camera started
Error getting zoom: No Camera
Taking a look to the plugin code, it seems the mCamera value in the CameraActivity.java is not initialized at the time the success callback of startCamera() is called. I tried to find a way having the mCamera initialized or placing the callback when the mCamera is initialized, but did not succeed. I found this issue testing on both Galaxy S8+ and Galaxy SIV
Do anybody know how to fix it ?
Thanks !
PR #260 probably introduced this bug. See that commit and it will help you find your solution. We may have to undo some of those changes.
I've recently come across this issue while trying to set the zoom level after starting the camera. Is it something that can be fixed in the plugin?
We've been using a delayed set of the zoom as a workaround, but it's not ideal.
Here's how I ended up working around the issue https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview/issues/433#issuecomment-370605876. As stated not ideal but even the setTimeout proved problematic depending on the device being used.