Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Super Contributor
Posts: 306
Registered: ‎08-10-2010
My Device: Not Specified

Camera not invoke on App start

[ Edited ]

Hi,

I want to invoke camera as my app start. I add the following code in my constructor but then also it not open camera as app start.

if (mViewfinderWindow) {
if (createViewfinder(CAMERA_UNIT_REAR,
mViewfinderWindow->windowGroup().toStdString().c_str(),
mViewfinderWindow->windowId().toStdString().c_str()) == EOK) {
qDebug() << "MViewFinderWindow";
}
}

 

When i put the same code on button click or image tap event it works and camera is invoke. I put one image and on tap of image viewfinder is invoke and it works fine.

 

Byfinding the root cause i come to know that flow is stop at particular if condition which i bold out in below code.

 

int App::createViewfinder(camera_unit_t cameraUnit, const QString &group,
const QString &id) {

qDebug() << "createViewfinder App Start";
if (mCameraHandle != CAMERA_HANDLE_INVALID) {
qDebug() << "camera already running";
return EBUSY;
}
mCameraUnit = cameraUnit;
if (camera_open(mCameraUnit, CAMERA_MODE_RW | CAMERA_MODE_ROLL,
&mCameraHandle) != CAMERA_EOK) {
qDebug() << "could not open camera";
return EIO;
}
qDebug() << "camera opened";
if (camera_set_photovf_property(mCameraHandle,
CAMERA_IMGPROP_WIN_GROUPID, group.toStdString().c_str(),
CAMERA_IMGPROP_WIN_ID, id.toStdString().c_str()) == CAMERA_EOK) {
qDebug() << "viewfinder configured";

if(camera_can_feature(mCameraHandle,CAMERA_FEATURE_PHOTO)){
qDebug() << "Can Feature";
}
qDebug() << mCameraHandle;

// Below if condition is not become true and view finder is not started.
if (camera_start_photo_viewfinder(mCameraHandle, NULL, NULL, NULL)
== CAMERA_EOK) {
qDebug() << "viewfinder started";
return EOK;
}

qDebug() << "couldn't start viewfinder";
camera_close(mCameraHandle);
mCameraHandle = CAMERA_HANDLE_INVALID;
return EIO;
}

 

This code is HelloCamera code from github.  I get following error when i debug my code,

camera_start_photo_viewfinder() CAMERA_EINVAL: 22
Start_photo_viewfinder() CAMERA_EINVAL. 

When i click on button at that time this error is not come and viewfinder is start.

 

 

 

 

 


BlackBerry Development Advisor
Posts: 683
Registered: ‎11-29-2011
My Device: PRIV
My Carrier: Rogers

Re: Camera not invoke on App start

There used to be a Cascades bug and I am not sure if it is fixed int the NDK version you are using.  ForeignWindow wouldn't know the correct groupid yet so when you try to start the viewfinder it will fail trying to join the specified window group.

You should dump the windowId and windowGroup before you call createViewfinder.

 

Also, it's possible that some bindings aren't valid yet in the constructor because you haven't set the initial scene yet.  Not sure on that.. you'd have to debug.

 

Cheers,

Sean