With the APIs provided by the **Camera** module, you can access and operate camera devices and develop new functions. Common operations include preview, photographing, and video recording. You can also implement flash control, exposure time control, focus mode control, zooming control, and many others.
With the APIs provided by the **Camera** module, you can access and operate camera devices and develop new functions. Common operations include preview, photographing, and video recording. You can also implement flash control, exposure time control, focus mode control, zoom control, and much more.
Before calling camera APIs, be familiar with the following concepts:
Before calling camera APIs, be familiar with the following concepts:
-**Static camera capabilities**: A series of parameters used to describe inherent capabilities of a camera, such as orientation and supported resolution.
-**Static camera capabilities**: A series of parameters used to describe inherent capabilities of a camera, such as orientation and supported resolution.
-**Physical camera**: An independent camera device. The physical camera ID is a string that uniquely identifies a physical camera.
-**Physical camera**: An independent camera device. The physical camera ID is a string that uniquely identifies a physical camera.
-**Asynchronous operation**: To prevent the UI thread from being blocked, most **Camera** calls are asynchronous. Each API provides the callback and promise functions.
-**Asynchronous operation**: A non-blocking operation that allows other operations to execute before it completes. To prevent the UI thread from being blocked, some **Camera** calls are asynchronous. Each asynchronous API provides the callback and promise functions.
## How to Develop
## How to Develop
...
@@ -22,7 +22,7 @@ The full process includes applying for permissions, creating an instance, settin
...
@@ -22,7 +22,7 @@ The full process includes applying for permissions, creating an instance, settin
#### Applying for Permissions
#### Applying for Permissions
You must apply for the permission for your application to access the camera device and other functions. The following table lists camera-related permissions.
You must apply for the permissions for your application to access the camera device and other functions. The following table lists camera-related permissions.
| Permission| Attribute Value |
| Permission| Attribute Value |
| -------- | ------------------------------ |
| -------- | ------------------------------ |
...
@@ -51,82 +51,108 @@ function applyPermission() {
...
@@ -51,82 +51,108 @@ function applyPermission() {
#### Creating an Instance
#### Creating an Instance
You must create an independent **CameraManager** instance before performing camera operations. If this operation fails, the camera may be occupied or unusable. If the camera is occupied, wait until it is released. You can call **getSupportedCameras()** to obtain the list of cameras supported by the current device. The list stores all camera IDs of the current device. If the list is not empty, each ID in the list can be used to create an independent camera instance. If the list is empty, no camera is available for the current device and subsequent operations cannot be performed. The camera has preview, shooting, video recording, and metadata streams. You can use **getSupportedOutputCapability()** to obtain the output stream capabilities of the camera and configure them in the **profile** field in **CameraOutputCapability**. The procedure for creating a **CameraManager** instance is as follows:
You must create an independent **CameraManager** instance before performing camera operations. If this operation fails, the camera may be occupied or unusable. If the camera is occupied, wait until it is released. You can call **getSupportedCameras()** to obtain the list of cameras supported by the current device. The list stores all camera IDs of the current device. Each of these IDs can be used to create an independent **CameraManager** instance. If the list is empty, no camera is available for the current device and subsequent operations cannot be performed. The camera has preview, shooting, video recording, and metadata output streams. You can use **getSupportedOutputCapability()** to obtain the output stream capabilities of the camera and configure them in the **profile** field in **CameraOutputCapability**. The procedure for creating a **CameraManager** instance is as follows:
// Create a preview stream. For details about the surfaceId parameter, see the XComponent section. The preview stream is the surface provided by the XComponent.
// Create a preview stream. For details about the surfaceId parameter, see the XComponent section. The preview stream is the surface provided by the XComponent.
console.error("Failed to create the PreviewOutput instance.")
console.error("Failed to create the PreviewOutput instance.")
}
}
// Create an ImageReceiver object and set photo parameters. The resolution is set based on the photographing resolutions supported by the current device, which are obtained by photoProfilesArray.
// Create an ImageReceiver instance and set photo parameters. Wherein, the resolution must be one of the photographing resolutions supported by the current device, which are obtained by photoProfilesArray.
Surfaces must be created in advance for the preview, shooting, and video recording stream. The preview stream is the surface provided by the **XComponent**, the shooting stream is the surface provided by **ImageReceiver**, and the video recording stream is the surface provided by **VideoRecorder**.
Surfaces must be created in advance for the preview, shooting, and video recording stream. The preview stream is the surface provided by the **XComponent**, the shooting stream is the surface provided by **ImageReceiver**, and the video recording stream is the surface provided by **VideoRecorder**.
...
@@ -247,24 +279,45 @@ function getVideoRecorderSurface() {
...
@@ -247,24 +279,45 @@ function getVideoRecorderSurface() {
| Promise<[CameraInput](#camerainput)\> | Promise used to return the **CameraInput** instance.|
| [CameraInput](#camerainput) | **CameraInput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
| position | [CameraPosition](#cameraposition) | Yes | Camera position, which is obtained through **getSupportedCameras**. This API obtains a **CameraDevice** object, which contains the camera position information. |
| position | [CameraPosition](#cameraposition) | Yes | Camera position, which is obtained through **getSupportedCameras**. This API obtains a **CameraDevice** object, which contains the camera position information. |
| type | [CameraType](#cameratype) | Yes | Camera type, which is obtained through **getSupportedCameras**. This API obtains a **CameraDevice** object, which contains the camera type information. |
| type | [CameraType](#cameratype) | Yes | Camera type, which is obtained through **getSupportedCameras**. This API obtains a **CameraDevice** object, which contains the camera type information. |
| callback | AsyncCallback<[CameraInput](#camerainput)\> | Yes | Callback used to return the **CameraInput** instance. |
| position | [CameraPosition](#cameraposition) | Yes | Camera position, which is obtained through **getSupportedCameras**. This API obtains a **CameraDevice** object, which contains the camera position information. |
| type | [CameraType](#cameratype) | Yes | Camera type, which is obtained through **getSupportedCameras**. This API obtains a **CameraDevice** object, which contains the camera type information. |
| Promise<[CameraInput](#camerainput)\> | Promise used to return the **CameraInput** instance.|
| [CameraInput](#camerainput) | **CameraInput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
...
@@ -427,16 +296,20 @@ Creates a **CameraInput** instance with the specified camera position and type.
...
@@ -427,16 +296,20 @@ Creates a **CameraInput** instance with the specified camera position and type.
| profile | [Profile](#profile) | Yes | Supported preview profiles, which are obtained through **getSupportedOutputCapability**.|
| profile | [Profile](#profile) | Yes | Supported preview profiles, which are obtained through **getSupportedOutputCapability**.|
| surfaceId| string | Yes | Surface ID, which is obtained from [XComponent](../arkui-ts/ts-basic-components-xcomponent.md) or [ImageReceiver](js-apis-image.md#imagereceiver9).|
| surfaceId| string | Yes | Surface ID, which is obtained from [XComponent](../arkui-ts/ts-basic-components-xcomponent.md) or [ImageReceiver](js-apis-image.md#imagereceiver9).|
| callback | AsyncCallback<[PreviewOutput](#previewoutput)\> | Yes | Callback used to return the **PreviewOutput** instance.|
| profile | [Profile](#profile) | Yes | Supported preview profiles, which are obtained through **getSupportedOutputCapability**.|
| surfaceId| string | Yes | Surface ID, which is obtained from [XComponent](../arkui-ts/ts-basic-components-xcomponent.md) or [ImageReceiver](js-apis-image.md#imagereceiver9).|
| Promise<[PreviewOutput](#previewoutput)\> | Promise used to return the **PreviewOutput** instance. |
| [PreviewOutput](#previewoutput) | **PreviewOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
| Promise<[PhotoOutput](#photooutput)\> | Promise used to return the **PhotoOutput** instance. |
| [PhotoOutput](#photooutput) | **PhotoOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
| Promise<[VideoOutput](#videooutput)\> | Promise used to return the **VideoOutput** instance. |
| [VideoOutput](#videooutput) | **VideoOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
| metadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | Yes | Metadata object types, which are obtained through **getSupportedOutputCapability**.|
| metadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | Yes | Metadata object types, which are obtained through **getSupportedOutputCapability**.|
| callback | AsyncCallback<[MetadataOutput](#metadataoutput)\> | Yes | Callback used to return the **MetadataOutput** instance. |
| Promise<[MetadataOutput](#metadataoutput)\> | Promise used to return the **MetadataOutput** instance.|
| [MetadataOutput](#metadataoutput) | **MetadataOutput** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
| Promise<[CaptureSession](#capturesession)\> | Promise used to return the **CaptureSession** instance.|
| [CaptureSession](#capturesession) | **CaptureSession** instance created. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
| type | string | Yes | Event type. The value is fixed at **'cameraStatus'**, indicating the camera status change event.|
| type | string | Yes | Event type. The value is fixed at **'cameraStatus'**. The callback function returns the camera information, including the device and device status (available or unavailable). The event can be listened for only when a **CameraManager** instance is obtained.|
| callback | AsyncCallback<[CameraStatusInfo](#camerastatusinfo)\> | Yes | Callback used to return the camera status change. |
| callback | AsyncCallback<[CameraStatusInfo](#camerastatusinfo)\> | Yes | Callback used to return the camera status change. |
| type | string | Yes | Event type. The value is fixed at **'cameraMute'**, indicating the camera mute status change event.|
| type | string | Yes | Event type. The value is fixed at **'cameraMute'**. The callback function returns the mute status changes. The event can be listened for only when a **CameraManager** instance is obtained.|
| callback | AsyncCallback\<boolean> | Yes | Callback used to return the camera mute status. |
| callback | AsyncCallback\<boolean> | Yes | Callback used to return the camera mute status. |
**Example**
**Example**
```js
```js
cameraManager.on('cameraMute',(err,curMuetd)=>{
cameraManager.on('cameraMute',(curMuetd)=>{
if(err){
letisMuted=curMuetd;
console.error(`Failed to get cameraMute callback. ${err.message}`);
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
cameraInput.open((err)=>{
cameraInput.open((err)=>{
if(err){
if(err){
console.error(`Failed to open the camera. ${err.message}`);
console.error(`Failed to open the camera. ${err.code}`);
return;
return;
}
}
console.log('Callback returned with camera opened.');
console.log('Callback returned with camera opened.');
...
@@ -908,14 +653,16 @@ Opens this camera. This API uses a promise to return the result.
...
@@ -908,14 +653,16 @@ Opens this camera. This API uses a promise to return the result.
| Type | Description |
| Type | Description |
| -------------- | ----------------------- |
| -------------- | ----------------------- |
| Promise<void\>| Promise used to return the result.|
| Promise<void\>| Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
cameraInput.open().then(()=>{
cameraInput.open().then(()=>{
console.log('Promise returned with camera opened.');
console.log('Promise returned with camera opened.');
})
}).catch((err)=>{
console.error(`Failed to open the camera. ${err.code}`);
});
```
```
### close
### close
...
@@ -930,14 +677,14 @@ Closes this camera. This API uses an asynchronous callback to return the result.
...
@@ -930,14 +677,14 @@ Closes this camera. This API uses an asynchronous callback to return the result.
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
cameraInput.close((err)=>{
cameraInput.close((err)=>{
if(err){
if(err){
console.error(`Failed to close the cameras. ${err.message}`);
console.error(`Failed to close the cameras. ${err.code}`);
return;
return;
}
}
console.log('Callback returned with camera closed.');
console.log('Callback returned with camera closed.');
...
@@ -963,111 +710,39 @@ Closes this camera. This API uses a promise to return the result.
...
@@ -963,111 +710,39 @@ Closes this camera. This API uses a promise to return the result.
```js
```js
cameraInput.close().then(()=>{
cameraInput.close().then(()=>{
console.log('Promise returned with camera closed.');
console.log('Promise returned with camera closed.');
})
}).catch((err)=>{
console.error(`Failed to close the cameras. ${err.code}`);
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
| type | string | Yes | Event type. The value is fixed at **'error'**. The callback function returns an error code, for example, an error code indicating that the device is unavailable or a conflict occurs. The event can be listened for only when a **CameraInput** instance is obtained.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
captureSession.commitConfig((err)=>{
captureSession.commitConfig((err)=>{
if(err){
if(err){
console.error(`Failed to commit the configuration. ${err.message}`);
console.log('Failed to commitConfig '+err.code);
return;
return;
}
}
console.log('Callback invoked to indicate the commit config success.');
console.log('Callback invoked to indicate the commit config success.');
Commits the configuration for this **CaptureSession** instance. This API uses a promise to return the result.
Commits the configuration for this **CaptureSession** instance. This API uses a promise to return the result.
...
@@ -1220,48 +871,24 @@ Commits the configuration for this **CaptureSession** instance. This API uses a
...
@@ -1220,48 +871,24 @@ Commits the configuration for this **CaptureSession** instance. This API uses a
| Type | Description |
| Type | Description |
| -------------- | ------------------------ |
| -------------- | ------------------------ |
| Promise<void\>| Promise used to return the result.|
| Promise<void\>| Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
captureSession.commitConfig().then(()=>{
captureSession.commitConfig().then(()=>{
console.log('Promise returned to indicate the commit config success.');
console.log('Promise returned to indicate the commit config success.');
})
}).catch((err)=>{
```
// If the operation fails, error.code is returned and processed.
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
captureSession.start((err)=>{
captureSession.start((err)=>{
if(err){
if(err){
console.error(`Failed to start the session ${err.message}`);
console.error(`Failed to start the session ${err.code}`);
return;
return;
}
}
console.log('Callback invoked to indicate the session start success.');
console.log('Callback invoked to indicate the session start success.');
...
@@ -1497,7 +1053,9 @@ Starts this **CaptureSession**. This API uses a promise to return the result.
...
@@ -1497,7 +1053,9 @@ Starts this **CaptureSession**. This API uses a promise to return the result.
```js
```js
captureSession.start().then(()=>{
captureSession.start().then(()=>{
console.log('Promise returned to indicate the session start success.');
console.log('Promise returned to indicate the session start success.');
})
}).catch((err)=>{
console.error(`Failed to start the session ${err.code}`);
});
```
```
### stop
### stop
...
@@ -1512,14 +1070,14 @@ Stops this **CaptureSession**. This API uses an asynchronous callback to return
...
@@ -1512,14 +1070,14 @@ Stops this **CaptureSession**. This API uses an asynchronous callback to return
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
captureSession.stop((err)=>{
captureSession.stop((err)=>{
if(err){
if(err){
console.error(`Failed to stop the session ${err.message}`);
console.error(`Failed to stop the session ${err.code}`);
return;
return;
}
}
console.log('Callback invoked to indicate the session stop success.');
console.log('Callback invoked to indicate the session stop success.');
...
@@ -1538,14 +1096,16 @@ Stops this **CaptureSession**. This API uses a promise to return the result.
...
@@ -1538,14 +1096,16 @@ Stops this **CaptureSession**. This API uses a promise to return the result.
| Type | Description |
| Type | Description |
| -------------- | ----------------------- |
| -------------- | ----------------------- |
| Promise<void\>| Promise used to return the result.|
| Promise<void\>| Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
captureSession.stop().then(()=>{
captureSession.stop().then(()=>{
console.log('Promise returned to indicate the session stop success.');
console.log('Promise returned to indicate the session stop success.');
})
}).catch((err)=>{
console.error(`Failed to stop the session ${err.code}`);
});
```
```
### release
### release
...
@@ -1560,14 +1120,14 @@ Releases this **CaptureSession**. This API uses an asynchronous callback to retu
...
@@ -1560,14 +1120,14 @@ Releases this **CaptureSession**. This API uses an asynchronous callback to retu
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
captureSession.release((err)=>{
captureSession.release((err)=>{
if(err){
if(err){
console.error(`Failed to release the CaptureSession instance ${err.message}`);
console.error(`Failed to release the CaptureSession instance ${err.code}`);
return;
return;
}
}
console.log('Callback invoked to indicate that the CaptureSession instance is released successfully.');
console.log('Callback invoked to indicate that the CaptureSession instance is released successfully.');
...
@@ -1586,69 +1146,48 @@ Releases this **CaptureSession**. This API uses a promise to return the result.
...
@@ -1586,69 +1146,48 @@ Releases this **CaptureSession**. This API uses a promise to return the result.
| Type | Description |
| Type | Description |
| -------------- | ------------------------ |
| -------------- | ------------------------ |
| Promise<void\>| Promise used to return the result.|
| Promise<void\>| Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
captureSession.release().then(()=>{
captureSession.release().then(()=>{
console.log('Promise returned to indicate that the CaptureSession instance is released successfully.');
console.log('Promise returned to indicate that the CaptureSession instance is released successfully.');
})
}).catch((err)=>{
console.error(`Failed to release the CaptureSession instance ${err.code}`);
});
```
```
### hasFlash
### hasFlash
hasFlash(callback: AsyncCallback<boolean\>): void
hasFlash(): boolean
Checks whether the device has flash. This API uses an asynchronous callback to return the result.
Checks whether the device has flash. This API uses an asynchronous callback to return the result.
| Promise<boolean\> | Promise used to return the flash support status. The value **true** means that the device has flash.|
| boolean | Returns **true** if the device has flash; returns **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
captureSession.hasFlash().then((status)=>{
try{
console.log(`Promise returned with the flash light support status: ${status}`);
letstatus=captureSession.hasFlash();
})
}catch(error){
// If the operation fails, error.code is returned and processed.
| callback | AsyncCallback<boolean\> | Yes | Callback used to return the flash mode support status. The value **true** means that the flash mode is supported, and **false** means the opposite.|
| Promise<boolean\> | Promise used to return the flash mode support status. The value **true** means that the flash mode is supported, and **false** means the opposite.|
| boolean | Returns **true** if the flash mode is supported; returns **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
| callback | AsyncCallback<boolean\> | Yes | Callback used to return the exposure mode support status. The value **true** means that the exposure mode is supported, and **false** means the opposite.|
| Promise<boolean\> | Promise used to return the exposure mode support status. The value **true** means that the exposure mode is supported, and **false** means the opposite.|
| boolean | Returns **true** if the exposure mode is supported; returns **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
| Promise<[ExposureMode](#exposuremode)\> | Promise used to return the exposure mode.|
| [ExposureMode](#exposuremode) | Exposure mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
| exposureBias | number | Yes | Compensation value. You can use **getExposureBiasRange** to obtain the supported values.|
| exposureBias | number | Yes | Exposure bias to set, which must be within the range obtained by running **getExposureBiasRange** interface. If the API call fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
| callback | AsyncCallback<boolean\> | Yes | Callback used to return the focus mode support status. The value **true** means that the focus mode is supported, and **false** means the opposite.|
| Promise<boolean\> | Promise used to return the focus mode support status. The value **true** means that the focus mode is supported, and **false** means the opposite.|
| boolean | Returns **true** if the focus mode is supported; returns **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
| Promise<Array<number\>\> | Promise used to return an array containing the minimum and maximum zoom ratios.|
| Array<number\> | Callback used to return an array containing the minimum and maximum zoom ratios. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
| callback | AsyncCallback<boolean\> | Yes | Callback used to return whether the video stabilization mode is supported. The value **true** means that the video stabilization mode is supported, and **false** means the opposite. |
| Promise<boolean\> | Promise used to return whether the video stabilization mode is supported. The value **true** means that the video stabilization mode is supported, and **false** means the opposite.|
| Promise<VideoStabilizationMode\> | Promise used to return the video stabilization mode. |
| boolean | Returns **true** if the video stabilization mode is supported; returns **false** otherwise. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
| VideoStabilizationMode | Video stabilization mode obtained. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**, indicating the focus state change event.|
| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The callback function returns the focus state change. The event can be listened for only when the session is created.|
| callback | AsyncCallback<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. |
| callback | AsyncCallback<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. |
| type | string | Yes | Event type. The value is fixed at **'error'**, indicating the capture session error event.|
| type | string | Yes | Event type. The value is fixed at **'error'**. The callback function returns the error code corresponding to an error that occurs during the call of a **CaptureSession** API, for example, **beginConfig()**, **commitConfig()**, or **addInput()**.|
| callback | ErrorCallback<[CaptureSessionError](#capturesessionerror)\> | Yes | Callback used to return the error information. |
| callback | ErrorCallback<BusinessError\> | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
previewOutput.start((err)=>{
previewOutput.start((err)=>{
if(err){
if(err){
console.error(`Failed to start the previewOutput. ${err.message}`);
console.error(`Failed to start the previewOutput. ${err.code}`);
return;
return;
}
}
console.log('Callback returned with previewOutput started.');
console.log('Callback returned with previewOutput started.');
...
@@ -2964,14 +1929,16 @@ Starts to output preview streams. This API uses a promise to return the result.
...
@@ -2964,14 +1929,16 @@ Starts to output preview streams. This API uses a promise to return the result.
| Type | Description |
| Type | Description |
| -------------- | ----------------------- |
| -------------- | ----------------------- |
| Promise<void\>| Promise used to return the result.|
| Promise<void\>| Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
previewOutput.start().then(()=>{
previewOutput.start().then(()=>{
console.log('Promise returned with previewOutput started.');
console.log('Promise returned with previewOutput started.');
})
}).catch((err)=>{
console.log('Failed to previewOutput start '+err.code);
});
```
```
### stop
### stop
...
@@ -2993,7 +1960,7 @@ Stops outputting preview streams. This API uses an asynchronous callback to retu
...
@@ -2993,7 +1960,7 @@ Stops outputting preview streams. This API uses an asynchronous callback to retu
```js
```js
previewOutput.stop((err)=>{
previewOutput.stop((err)=>{
if(err){
if(err){
console.error(`Failed to stop the previewOutput. ${err.message}`);
console.error(`Failed to stop the previewOutput. ${err.code}`);
return;
return;
}
}
console.log('Callback returned with previewOutput stopped.');
console.log('Callback returned with previewOutput stopped.');
...
@@ -3019,7 +1986,9 @@ Stops outputting preview streams. This API uses a promise to return the result.
...
@@ -3019,7 +1986,9 @@ Stops outputting preview streams. This API uses a promise to return the result.
```js
```js
previewOutput.stop().then(()=>{
previewOutput.stop().then(()=>{
console.log('Callback returned with previewOutput stopped.');
console.log('Callback returned with previewOutput stopped.');
})
}).catch((err)=>{
console.log('Failed to previewOutput stop '+err.code);
});
```
```
### release
### release
...
@@ -3034,14 +2003,14 @@ Releases output resources. This API uses an asynchronous callback to return the
...
@@ -3034,14 +2003,14 @@ Releases output resources. This API uses an asynchronous callback to return the
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
previewOutput.release((err)=>{
previewOutput.release((err)=>{
if(err){
if(err){
console.error(`Failed to release the PreviewOutput instance ${err.message}`);
console.error(`Failed to release the PreviewOutput instance ${err.code}`);
return;
return;
}
}
console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
...
@@ -3060,14 +2029,16 @@ Releases output resources. This API uses a promise to return the result.
...
@@ -3060,14 +2029,16 @@ Releases output resources. This API uses a promise to return the result.
| Type | Description |
| Type | Description |
| -------------- | ----------------------- |
| -------------- | ----------------------- |
| Promise<void\>| Promise used to return the result.|
| Promise<void\>| Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
previewOutput.release().then(()=>{
previewOutput.release().then(()=>{
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
})
}).catch((err)=>{
console.log('Failed to previewOutput release '+err.code);
});
```
```
### on('frameStart')
### on('frameStart')
...
@@ -3082,7 +2053,7 @@ Listens for preview frame start events. This API uses an asynchronous callback t
...
@@ -3082,7 +2053,7 @@ Listens for preview frame start events. This API uses an asynchronous callback t
| type | string | Yes | Event type. The value is fixed at **'frameStart'**, indicating the preview frame start event.|
| type | string | Yes | Event type. The value is fixed at **'frameStart'**. The callback is invoked when the preview on the first frame starts. This event can be listened for only when a **previewOutput** instance is created.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example**
**Example**
...
@@ -3105,7 +2076,7 @@ Listens for preview frame end events. This API uses an asynchronous callback to
...
@@ -3105,7 +2076,7 @@ Listens for preview frame end events. This API uses an asynchronous callback to
| type | string | Yes | Event type. The value is fixed at **'frameEnd'**, indicating the preview frame end event.|
| type | string | Yes | Event type. The value is fixed at **'frameEnd'**. The callback is invoked when the preview on the last frame ends. This event can be listened for only when a **previewOutput** instance is created.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
| type | string | Yes | Event type. The value is fixed at **'error'**, indicating the preview output error event.|
| type | string | Yes | Event type. The value is fixed at **'error'**. The callback function returns the error code corresponding to an error that occurs during the call of a **PreviewOutput** API, for example, **start()** or **release()**.|
| callback | ErrorCallback<[PreviewOutputErrorCode](#previewoutputerrorcode)\> | Yes | Callback used to return the error information. |
| callback | ErrorCallback<BusinessError\> | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
photoOutput.capture((err)=>{
photoOutput.capture((err)=>{
if(err){
if(err){
console.error(`Failed to capture the photo ${err.message}`);
console.error(`Failed to capture the photo ${err.code}`);
return;
return;
}
}
console.log('Callback invoked to indicate the photo capture request success.');
console.log('Callback invoked to indicate the photo capture request success.');
| Promise<void\>| Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
```js
photoOutput.capture().then(()=>{
console.log('Promise returned to indicate that photo capture request success.');
}).catch((err)=>{
console.log('Failed to photoOutput capture '+err.code);
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned. |
**Example**
**Example**
...
@@ -3271,7 +2246,7 @@ let settings = {
...
@@ -3271,7 +2246,7 @@ let settings = {
}
}
photoOutput.capture(settings,(err)=>{
photoOutput.capture(settings,(err)=>{
if(err){
if(err){
console.error(`Failed to capture the photo ${err.message}`);
console.error(`Failed to capture the photo ${err.code}`);
return;
return;
}
}
console.log('Callback invoked to indicate the photo capture request success.');
console.log('Callback invoked to indicate the photo capture request success.');
...
@@ -3296,41 +2271,37 @@ Captures a photo with the specified shooting parameters. This API uses a promise
...
@@ -3296,41 +2271,37 @@ Captures a photo with the specified shooting parameters. This API uses a promise
| Type | Description |
| Type | Description |
| -------------- | ------------------------ |
| -------------- | ------------------------ |
| Promise<void\>| Promise used to return the result.|
| Promise<void\>| Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
photoOutput.capture().then(()=>{
photoOutput.capture(settings).then(()=>{
console.log('Promise returned to indicate that photo capture request success.');
console.log('Promise returned to indicate that photo capture request success.');
})
}).catch((err)=>{
console.log('Failed to photoOutput capture '+err.code);
| callback | AsyncCallback<boolean\> | Yes | Callback used to return the mirroring support status. The value **true** means that mirroring is supported, and **false** means the opposite. |
| boolean | Returns **true** if mirroring is supported; returns **false** otherwise.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
photoOutput.release((err)=>{
photoOutput.release((err)=>{
if(err){
if(err){
console.error(`Failed to release the PreviewOutput instance ${err.message}`);
console.error(`Failed to release the PreviewOutput instance ${err.code}`);
return;
return;
}
}
console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
...
@@ -3371,36 +2342,16 @@ Releases output resources. This API uses a promise to return the result.
...
@@ -3371,36 +2342,16 @@ Releases output resources. This API uses a promise to return the result.
| Type | Description |
| Type | Description |
| -------------- | ----------------------- |
| -------------- | ----------------------- |
| Promise<void\>| Promise used to return the result.|
| Promise<void\>| Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
photoOutput.release().then(()=>{
photoOutput.release().then(()=>{
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
})
}).catch((err)=>{
```
console.log('Failed to photoOutput release '+err.code);
});
### isMirrorSupported
isMirrorSupported(): Promise<boolean\>
Checks whether mirroring is supported. This API uses a promise to return the result.
| Promise<boolean\> | Promise used to return the mirroring support status. The value **true** means that mirroring is supported, and **false** means the opposite. |
| type | string | Yes | Event type. The value is fixed at **'frameShutter'**, indicating the frame shutter event.|
| type | string | Yes | Event type. The value is fixed at **'frameShutter'**. The callback function returns the captured frame information (captureId and time).|
| callback | AsyncCallback<[FrameShutterInfo](#frameshutterinfo)\> | Yes | Callback used to return the result. |
| callback | AsyncCallback<[FrameShutterInfo](#frameshutterinfo)\> | Yes | Callback used to return the result. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
videoOutput.start((err)=>{
videoOutput.start((err)=>{
if(err){
if(err){
console.error(`Failed to start the video output ${err.message}`);
console.error(`Failed to start the video output ${err.code}`);
return;
return;
}
}
console.log('Callback invoked to indicate the video output start success.');
console.log('Callback invoked to indicate the video output start success.');
...
@@ -3584,7 +2512,7 @@ Starts video recording. This API uses a promise to return the result.
...
@@ -3584,7 +2512,7 @@ Starts video recording. This API uses a promise to return the result.
| Type | Description |
| Type | Description |
| -------------- | ----------------------- |
| -------------- | ----------------------- |
| Promise<void\>| Promise used to return the result.|
| Promise<void\>| Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
...
@@ -3592,7 +2520,9 @@ Starts video recording. This API uses a promise to return the result.
...
@@ -3592,7 +2520,9 @@ Starts video recording. This API uses a promise to return the result.
```js
```js
videoOutput.start().then(()=>{
videoOutput.start().then(()=>{
console.log('Promise returned to indicate that start method execution success.');
console.log('Promise returned to indicate that start method execution success.');
})
}).catch((err)=>{
console.log('Failed to videoOutput start '+err.code);
});
```
```
### stop
### stop
...
@@ -3614,7 +2544,7 @@ Stops video recording. This API uses an asynchronous callback to return the resu
...
@@ -3614,7 +2544,7 @@ Stops video recording. This API uses an asynchronous callback to return the resu
```js
```js
videoOutput.stop((err)=>{
videoOutput.stop((err)=>{
if(err){
if(err){
console.error(`Failed to stop the video output ${err.message}`);
console.error(`Failed to stop the video output ${err.code}`);
return;
return;
}
}
console.log('Callback invoked to indicate the video output stop success.');
console.log('Callback invoked to indicate the video output stop success.');
...
@@ -3640,8 +2570,10 @@ Stops video recording. This API uses a promise to return the result.
...
@@ -3640,8 +2570,10 @@ Stops video recording. This API uses a promise to return the result.
```js
```js
videoOutput.stop().then(()=>{
videoOutput.stop().then(()=>{
console.log('Promise returned to indicate that stop method execution success.');
console.log('Promise returned to indicate that stop method execution success.');
})
}).catch((err)=>{
```
console.log('Failed to videoOutput stop '+err.code);
});
```
### release
### release
...
@@ -3655,14 +2587,14 @@ Releases output resources. This API uses an asynchronous callback to return the
...
@@ -3655,14 +2587,14 @@ Releases output resources. This API uses an asynchronous callback to return the
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
videoOutput.release((err)=>{
videoOutput.release((err)=>{
if(err){
if(err){
console.error(`Failed to release the PreviewOutput instance ${err.message}`);
console.error(`Failed to release the PreviewOutput instance ${err.code}`);
return;
return;
}
}
console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
...
@@ -3681,14 +2613,16 @@ Releases output resources. This API uses a promise to return the result.
...
@@ -3681,14 +2613,16 @@ Releases output resources. This API uses a promise to return the result.
| Type | Description |
| Type | Description |
| -------------- | ----------------------- |
| -------------- | ----------------------- |
| Promise<void\>| Promise used to return the result.|
| Promise<void\>| Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
videoOutput.release().then(()=>{
videoOutput.release().then(()=>{
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
})
}).catch((err)=>{
console.log('Failed to videoOutput release '+err.code);
});
```
```
### on('frameStart')
### on('frameStart')
...
@@ -3703,7 +2637,7 @@ Listens for video recording start events. This API uses an asynchronous callback
...
@@ -3703,7 +2637,7 @@ Listens for video recording start events. This API uses an asynchronous callback
| type | string | Yes | Event type. The value is fixed at **`frameStart`**, indicating the video recording start event.|
| type | string | Yes | Event type. The value is fixed at **'frameStart'**. The callback is invoked when the recording on the first frame of an image starts.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example**
**Example**
...
@@ -3726,7 +2660,7 @@ Listens for video recording stop events. This API uses an asynchronous callback
...
@@ -3726,7 +2660,7 @@ Listens for video recording stop events. This API uses an asynchronous callback
| type | string | Yes | Event type. The value is fixed at **'frameEnd'**, indicating the video recording stop event.|
| type | string | Yes | Event type. The value is fixed at **'frameEnd'**. The callback is invoked when the recording on the last frame of an image stops.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
| type | string | Yes | Event type. The value is fixed at **'error'**, indicating the video output error event.|
| type | string | Yes | Event type. The value is fixed at **'error'**. The callback function returns the error code corresponding to an error that occurs during the call of a **VideoOutput** API, for example, **start()** or **release()**.|
| callback | Callback<[VideoOutputError](#videooutputerror)\> | Yes | Callback used to return the error information. |
| callback | Callback<BusinessError\> | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void\>| Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
metadataOutput.start((err)=>{
metadataOutput.start((err)=>{
if(err){
if(err){
console.error(`Failed to start metadataOutput. ${err.message}`);
console.error(`Failed to start metadataOutput. ${err.code}`);
return;
return;
}
}
console.log('Callback returned with metadataOutput started.');
console.log('Callback returned with metadataOutput started.');
...
@@ -3823,14 +2736,16 @@ Starts to output metadata. This API uses a promise to return the result.
...
@@ -3823,14 +2736,16 @@ Starts to output metadata. This API uses a promise to return the result.
| Promise<void\> | Promise used to return the result.|
| Promise<void\> | Promise used to return the result. If the operation fails, an error code defined in [CameraErrorCode](#cameraerrorcode) is returned.|
**Example**
**Example**
```js
```js
metadataOutput.start().then(()=>{
metadataOutput.start().then(()=>{
console.log('Callback returned with metadataOutput started.');
console.log('Callback returned with metadataOutput started.');
})
}).catch((err)=>{
console.log('Failed to metadataOutput start '+err.code);
});
```
```
### stop
### stop
...
@@ -3852,7 +2767,7 @@ Stops outputting metadata. This API uses an asynchronous callback to return the
...
@@ -3852,7 +2767,7 @@ Stops outputting metadata. This API uses an asynchronous callback to return the
```js
```js
metadataOutput.stop((err)=>{
metadataOutput.stop((err)=>{
if(err){
if(err){
console.error(`Failed to stop the metadataOutput. ${err.message}`);
console.error(`Failed to stop the metadataOutput. ${err.code}`);
return;
return;
}
}
console.log('Callback returned with metadataOutput stopped.');
console.log('Callback returned with metadataOutput stopped.');
...
@@ -3878,7 +2793,9 @@ Stops outputting metadata. This API uses a promise to return the result.
...
@@ -3878,7 +2793,9 @@ Stops outputting metadata. This API uses a promise to return the result.
```js
```js
metadataOutput.stop().then(()=>{
metadataOutput.stop().then(()=>{
console.log('Callback returned with metadataOutput stopped.');
console.log('Callback returned with metadataOutput stopped.');
})
}).catch((err)=>{
console.log('Failed to metadataOutput stop '+err.code);
});
```
```
### on('metadataObjectsAvailable')
### on('metadataObjectsAvailable')
...
@@ -3893,8 +2810,8 @@ Listens for metadata objects. This API uses an asynchronous callback to return t
...
@@ -3893,8 +2810,8 @@ Listens for metadata objects. This API uses an asynchronous callback to return t
| type | string | Yes | Event type. The value is fixed at **'metadataObjectsAvailable'**, that is, the metadata object.|
| type | string | Yes | Event type. The value is fixed at **'metadataObjectsAvailable'**. The callback function returns the valid metadata. This event can be listened for only when a **MetadataOutput** instance is created.|
| callback | Callback<Array<[MetadataObject](#metadataobject)\>\> | Yes | Callback used to return the error information. |
| callback | Callback<Array<[MetadataObject](#metadataobject)\>\> | Yes | Callback used to return the metadata.|
| type | string | Yes | Event type. The value is fixed at **'error'**, that is, the metadata error.|
| type | string | Yes | Event type. The value is fixed at **'error'**. The callback function returns the error code corresponding to an error that occurs during the call of a **MetadataOutput** instance API, for example, **start()** or **release()**.|
| callback | Callback<[MetadataOutputError](#metadataoutputerror)\> | Yes | Callback used to return the error information. |
| callback | Callback<BusinessError\> | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). |
Implements camera metadata, which is the data source of [CameraInput](#camerainput). The metadata is obtained through metadataOutput.on('metadataObjectsAvailable').
Implements camera metadata, which is the data source of [CameraInput](#camerainput). The metadata is obtained through metadataOutput.on('metadataObjectsAvailable').