12-07-2012 11:01 PM
Hi,
I have an app that utilizes the camera in QML. It works fine, but if the screen dims while my app is open the camera no longer works till I restart the app.
Here is the entire camera qml page :
import bb.cascades 1.0 import bb.cascades.multimedia 1.0 /** * Most of this code was copied from: * https://developer.blackberry.com/cascades/documentation/design/camera/taking_a_photo_with_the_front_ ... */ Page { property string pictureLocation: "" function closeCamera() { createReportNavigationPane.cameraClosed(pictureLoc ation) pictureLocation = ""; saveID.enabled = false; sheetCamera.close(); } titleBar: TitleBar { acceptAction: ActionItem { title: qsTr("Save") id: saveID enabled: false //title: "Save" onTriggered: { closeCamera(); } } // The 'Cancel' action dismissAction: ActionItem { title: "Cancel" onTriggered: { pictureLocation = ""; closeCamera(); } } } onCreationCompleted: { // Check to see if any cameras are currently accessible. if (camera.allCamerasAccessible) { // Open the rear camera. camera.open(CameraUnit.Rear); camera.isOpen = true } } Container { layout: DockLayout { } // The Camera object. Camera { id: camera preferredWidth: 768 preferredHeight: 1280 objectName: "camera" property bool photoBeingTaken property bool isOpen: false onTouch: { if (event.isDown()) { if (photoBeingTaken == false) { // Take a photo, and automatically // save it to the file system. camera.capturePhoto(); } } } // The following are examples of slots that can // be used with the Camera object to handle // the various signals that are emitted. onCameraOpened: { // Once the camera is open, start the viewfinder. camera.startViewfinder(); } onCameraOpenFailed: { console.debug("Camera cannot open"); } onViewfinderStarted: { console.debug("Viewfinder has been started"); photoBeingTaken = false; } onViewfinderStartFailed: { console.debug("Viewfinder could not be started"); } onPhotoCaptureFailed: { console.debug("Photo could not be taken"); photoBeingTaken = false; } onPhotoSaveFailed: { console.debug("Photo could not be saved"); photoBeingTaken = false; } onPhotoSaved: { saveID.enabled = true; photoBeingTaken = true; console.debug("Photo has been successfully saved"); photoBeingTaken = false; console.log(fileName); pictureLocation = fileName; var imageName = pictureLocation.substring(pictureLocation.lastInde xOf("/") + 1); var imagePath = "/accounts/1000/shared/camera/" + imageName; cameraPreview.imageSource = app.getCameraPreview(imageName, imagePath); } } Container { layout: StackLayout { } leftPadding: 10.0 topPadding: 10.0 Container { preferredHeight: 200 preferredWidth: 200 horizontalAlignment: HorizontalAlignment.Left Container { verticalAlignment: VerticalAlignment.Center ImageView { id: cameraPreview verticalAlignment: VerticalAlignment.Fill horizontalAlignment: HorizontalAlignment.Fill scalingMethod: ScalingMethod.Fill } } } } } }
Thanks,
Gerry
Solved! Go to Solution.
12-08-2012 11:01 PM
The camera hardware gets powered off when the screen is powered off.
I will ask the Cascades Camera API folks what they recommend doing.. I believe you would just need to restart the viewfinder. It may not auto-restart for you.
12-10-2012 11:10 AM
it definately does not auto start
... I've encountered this issue as well
12-10-2012 12:01 PM
so, there is a cameraResourceReleased signal which you can listen for which will tell you that the camera has been stopped.
After this happens, you can restart the viewfinder after your app returns to the foreground.
We have a corner case that we're still working on which centers around the case where the screen starts to shut-down (causing the camera to stop), but the user wakes it up before navigator tells your app to background. In this case, you may not receive a foreground event. You can probably work around that case by starting a timer and checking after a second or so whether the app was removed from the foreground or not.. if it is still in the foreground, then you could try restarting the viewfinder
Cheers,
Sean