You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CameraView/docs/_posts/2018-12-20-error-handling.md

51 lines
1.8 KiB

---
layout: page
title: "Error Handling"
category: docs
Feature/overlays (#502) * Overlays (#421) * get overlay working * fix overlay drawing * allow disabling overlay in pictures or videos * Fix picture snapshot colors when there is an overlay * Bug fixes * Update example with watermark * Fix bug * Fix overlay orientation in pictures * Fix overlay orientation in videos * Fix overlay when changing preview size * Fix bug * Experiment * Refactor EglViewport * Refactor SnapshotPictureRecorder * Use single EglViewport * Refactor SnapshotVideoRecorder * Bug fix * fix some of the requested changes * clean adding View to OverlayLayout * Specify where to draw the overlay * Refactor * Remove unnecessary variable from CameraPreview * Use mWithOverlay in SnapshotVideoRecorder * Use multiple OverlayLayout * Add explanation for OverlayLayoutManager * override removeView * Remove DisableOverlayFor * Reorder to overlay package * Address issues * Draw selectively on preview, picture or video * Use single Overlay with three targets * Fix picture snapshots * Add demo app control * Fix video snapshot rotation for Camera2 * Fix video snapshot overlay rotation for Camera2 only * Fix tests, improve performance * Add animating watermark * Add tests in CameraViewTest * Add integration tests * Fix race condition * Improve README * Remove isOverlay * Remove isOverlay from docs * Add documentation empty page * Add documentation links * Add real documentation * Remove isOverlay from attrs * Add doc links to main README * Fix tests and logs * Small changes in AudioMediaEncoder * Add changelog line
5 years ago
order: 12
date: 2018-12-20 20:02:31
6 years ago
disqus: 1
---
Errors are posted to the registered `CameraListener`s callback:
```java
@Override
public void onCameraError(CameraException error) {
// Got error!
};
```
You are supposed to inspect the `CameraException` object as it contains useful information about
what happened and what should be done, if anything. All things that fail can end up throwing this
exception, which includes temporary actions like taking a picture, or functional actions like
starting the camera preview.
### Unrecoverable errors
You can exclude unrecoverable errors using `CameraException.isUnrecoverable()`.
If this function returns true, at this point the camera has been released and it is likely showing
a black preview. The operation can't go on.
You can try to call `camera.start()` again, but that's not guaranteed to work. For example, the
camera sensor might be in use by another application, so there's nothing we could do.
### Other errors
For more fine grained control over what happened, inspect the reason using `CameraException.getReason()`.
This will return one of the `CameraException.REASON_` constants:
|Constant|Description|Unrecoverable|
|--------|-----------|-------------|
|`REASON_UNKNOWN`|Unknown error. No other info available.|No|
|`REASON_FAILED_TO_CONNECT`|Failed to connect to the camera service.|Yes|
|`REASON_FAILED_TO_START_PREVIEW`|Failed to start the camera preview.|Yes|
|`REASON_DISCONNECTED`|Camera was forced to disconnect by the system.|Yes|
|`REASON_PICTURE_FAILED`|Could not take a picture or picture snapshot.|No|
|`REASON_VIDEO_FAILED`|Could not take a video or video snapshot.|No|
|`REASON_NO_CAMERA`|Could not find a camera for this `Facing` value. You can try another.|No|