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-camera-events.md

82 lines
2.6 KiB

---
layout: page
title: "Camera Events"
subtitle: "Events and lifecycle"
description: "Events and lifecycle"
category: docs
date: 2018-12-20 20:02:08
order: 1
disqus: 1
---
The camera engine will notify anyone about camera events that took place, either on their own or
after developer action. To access these events, set up one or more `CameraListener` instances.
All actions taken on a `CameraView` instance are asynchronous, which means that the callback can be
executed at any time in the future. For convenience, all of them are executed on the UI thread.
```java
camera.addCameraListener(new CameraListener() {
public void onCameraOpened(CameraOptions options) {}
public void onCameraClosed() {}
public void onCameraError(CameraException error) {}
public void onPictureTaken(PictureResult result) {}
public void onVideoTaken(VideoResult result) {}
public void onOrientationChanged(int orientation) {}
public void onAutoFocusStart(PointF point) {}
public void onAutoFocusEnd(boolean successful, PointF point) {}
public void onZoomChanged(float newValue, float[] bounds, PointF[] fingers) {}
public void onExposureCorrectionChanged(float newValue, float[] bounds, PointF[] fingers) {}
public void onVideoRecordingStart() {}
});
```
### Lifecycle
CameraView has its own lifecycle, which is basically made of an open and a closed state.
You will listen to these events using `onCameraOpened` and `onCameraClosed` callbacks:
```java
camera.addCameraListener(new CameraListener() {
/**
* Notifies that the camera was opened.
* The options object collects all supported options by the current camera.
*/
@Override
public void onCameraOpened(CameraOptions options) {}
/**
* Notifies that the camera session was closed.
*/
@Override
public void onCameraClosed() {}
});
```
The open callback is especially important because the `CameraOptions` includes all the available
options of the current sensor. This can be used to adjust the UI, for example, show a flash icon
if flash is supported.
### Related APIs
|Method|Description|
|------|-----------|
|`open()`|Starts the engine. This will cause a future call to `onCameraOpened()` (or an error)|
|`close()`|Stops the engine. This will cause a future call to `onCameraClosed()`|
|`isOpened()`|Returns true if `open()` was called successfully. This does not mean that camera is showing preview already.|
|`getCameraOptions()`|If camera was opened, returns non-null object with information about what is supported.|
Take a look at public methods in `CameraOptions` to know more.