提交 2dec5290 编写于 作者: G Gloria

Update docs against 10621+10647+10764+10939+11043+11123+11147

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 d6eada90
...@@ -21,8 +21,8 @@ Obtains a **CameraManager** instance. This API uses an asynchronous callback to ...@@ -21,8 +21,8 @@ Obtains a **CameraManager** instance. This API uses an asynchronous callback to
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------- | ---- | ---------------------------------- | | -------- | ----------------------------------------------- | ---- | ---------------------------- |
| context | Context | Yes | Application context. | | context | [Context](../../ability/context-userguide.md) | Yes | Application context. |
| callback | AsyncCallback<[CameraManager](#cameramanager)\> | Yes | Callback used to return the **CameraManager** instance.| | callback | AsyncCallback<[CameraManager](#cameramanager)\> | Yes | Callback used to return the **CameraManager** instance.|
**Example** **Example**
...@@ -30,7 +30,7 @@ Obtains a **CameraManager** instance. This API uses an asynchronous callback to ...@@ -30,7 +30,7 @@ Obtains a **CameraManager** instance. This API uses an asynchronous callback to
```js ```js
camera.getCameraManager(context, (err, cameraManager) => { camera.getCameraManager(context, (err, cameraManager) => {
if (err) { if (err) {
console.error('Failed to get the CameraManager instance ${err.message}'); console.error(`Failed to get the CameraManager instance ${err.message}`);
return; return;
} }
console.log('Callback returned with the CameraManager instance'); console.log('Callback returned with the CameraManager instance');
...@@ -49,12 +49,12 @@ Obtains a **CameraManager** instance. This API uses a promise to return the resu ...@@ -49,12 +49,12 @@ Obtains a **CameraManager** instance. This API uses a promise to return the resu
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------- | ---- | ------------ | | ------- | ------- | ---- | ------------ |
| context | Context | Yes | Application context.| | context | [Context](../../ability/context-userguide.md) | Yes | Application context.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------- | ----------------------------------------- | | ----------------------------------------- | ----------------------------------- |
| Promise<[CameraManager](#cameramanager)\> | Promise used to return the **CameraManager** instance.| | Promise<[CameraManager](#cameramanager)\> | Promise used to return the **CameraManager** instance.|
**Example** **Example**
...@@ -78,876 +78,884 @@ Enumerates the camera statuses. ...@@ -78,876 +78,884 @@ Enumerates the camera statuses.
| CAMERA_STATUS_AVAILABLE | 2 | The camera is available. | | CAMERA_STATUS_AVAILABLE | 2 | The camera is available. |
| CAMERA_STATUS_UNAVAILABLE | 3 | The camera is unavailable.| | CAMERA_STATUS_UNAVAILABLE | 3 | The camera is unavailable.|
## Profile
## CameraPosition Defines the camera profile.
Enumerates the camera positions.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description | | Name | Type | Read Only| Description |
| --------------------------- | ---- | ---------------- | | -------- | ----------------------------- |---- | ------------- |
| CAMERA_POSITION_UNSPECIFIED | 0 | Unspecified position.| | format | [CameraFormat](#cameraformat) | Yes | Output format. |
| CAMERA_POSITION_BACK | 1 | Rear camera. | | size | [Size](#size) | Yes | Resolution. |
| CAMERA_POSITION_FRONT | 2 | Front camera. |
## CameraType ## FrameRateRange
Enumerates the camera types. Defines the frame rate range.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description | | Name | Type | Read Only| Description |
| ----------------------- | ---- | ---------------- | | -------- | ----------------------------- |---- | ------------- |
| CAMERA_TYPE_UNSPECIFIED | 0 | Unspecified camera type.| | min | number | Yes | Minimum frame rate. |
| CAMERA_TYPE_WIDE_ANGLE | 1 | Wide camera. | | max | number | Yes | Maximum frame rate. |
| CAMERA_TYPE_ULTRA_WIDE | 2 | Ultra wide camera. |
| CAMERA_TYPE_TELEPHOTO | 3 | Telephoto camera. |
| CAMERA_TYPE_TRUE_DEPTH | 4 | Camera with depth of field information. |
## VideoProfile
## ConnectionType Defines the video profile.
Enumerates the camera connection types.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description | | Name | Type | Read Only| Description |
| ---------------------------- | ---- | ------------- | | ------------------------- | ----------------------------------------- | --- |----------- |
| CAMERA_CONNECTION_BUILT_IN | 0 | Built-in camera. | | frameRateRange | [FrameRateRange](#frameraterange) | Yes | Frame rate range. |
| CAMERA_CONNECTION_USB_PLUGIN | 1 | Camera connected using USB.|
| CAMERA_CONNECTION_REMOTE | 2 | Remote camera. |
## Size ## CameraOutputCapability
Defines the image size that can be used in previewing, photographing, and video recording. Defines the camera output capability.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Readable| Writable| Description | | Name | Type | Read Only| Description |
| ------ | ------ | ---- | ---- | ------------ | | ----------------------------- | -------------------------------------------------- | --- |------------------- |
| height | string | Yes | Yes | Image height.| | previewProfiles | Array<[Profile](#profile)\> | Yes | Supported preview profiles. |
| width | number | Yes | Yes | Image width.| | photoProfiles | Array<[Profile](#profile)\> | Yes | Supported shooting profiles. |
| videoProfiles | Array<[VideoProfile](#videoprofile)\> | Yes | Supported video recording profiles. |
| supportedMetadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | Yes | Supported metadata object types.|
## CameraManager ## CameraManager
Implements camera management. Before calling any API in **CameraManager**, you must use **getCameraManager** to obtain a **CameraManager** instance. Implements camera management. Before calling any API in **CameraManager**, you must use **getCameraManager** to obtain a **CameraManager** instance.
### getCameras ### getSupportedCameras
getCameras(callback: AsyncCallback<Array<Camera\>\>): void getSupportedCameras(callback: AsyncCallback<Array<CameraDevice\>\>): void
Obtains all cameras supported by the device. This API uses an asynchronous callback to return the array of supported cameras. Obtains supported cameras. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------------------ | | -------- | ----------------------------------------------------- | ---- | ------------------------------- |
| callback | AsyncCallback<Array<[Camera](#camera)\>\> | Yes | Callback used to return the array of supported cameras.| | callback | AsyncCallback<Array<[CameraDevice](#cameradevice)\>\> | Yes | Callback used to return the array of supported cameras.|
**Example** **Example**
```js ```js
cameraManager.getCameras((err, cameras) => { cameraManager.getSupportedCameras((err, cameras) => {
if (err) { if (err) {
console.error('Failed to get the cameras. ${err.message}'); console.error(`Failed to get the cameras. ${err.message}`);
return; return;
} }
console.log('Callback returned with an array of supported cameras: ' + cameras.length); console.log(`Callback returned with an array of supported cameras: ${cameras.length}`);
}) })
``` ```
### getCameras ### getSupportedCameras
getCameras(): Promise<Array<Camera\>\> getSupportedCameras(): Promise<Array<CameraDevice\>\>
Obtains all cameras supported by the device. This API uses a promise to return the array of supported cameras. Obtains supported cameras. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------- | ----------------------------- | | ----------------------------------------------- | ------------------------- |
| Promise<Array<[Camera](#camera)\>\> | Promise used to return the array of supported cameras.| | Promise<Array<[CameraDevice](#cameradevice)\>\> | Promise used to return the array of supported cameras.|
**Example** **Example**
```js ```js
cameraManager.getCameras().then((cameraArray) => { cameraManager.getSupportedCameras().then((cameraArray) => {
console.log('Promise returned with an array of supported cameras: ' + cameraArray.length); console.log(`Promise returned with an array of supported cameras: ${cameraArray.length}`);
}) })
``` ```
### createCameraInput ### getSupportedOutputCapability
createCameraInput(cameraId: string, callback: AsyncCallback<CameraInput\>): void
Creates a **CameraInput** instance with the specified camera ID. This API uses an asynchronous callback to return the result. getSupportedOutputCapability(camera:CameraDevice, callback: AsyncCallback<CameraOutputCapability\>): void
**Required permissions**: ohos.permission.CAMERA Obtains the output capability supported by a camera. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------- | ---- | ----------------------------------- | | ------------ |--------------------------------------------------------------- | -- | -------------------------- |
| cameraId | string | Yes | ID of the target camera. | | CameraDevice | [CameraDevice](#cameradevice) | Yes| Camera device. |
| callback | AsyncCallback<[CameraInput](#camerainput)\> | Yes | Callback used to return the **CameraInput** instance.| | callback | AsyncCallback<[CameraOutputCapability](#cameraoutputcapability)\> | Yes| Callback used to return the output capability.|
**Example** **Example**
```js ```js
cameraManager.createCameraInput(cameraId, (err, cameraInput) => { cameraManager.getSupportedOutputCapability(cameradevice, (err, cameras) => {
if (err) { if (err) {
console.error('Failed to create the CameraInput instance. ${err.message}'); console.error(`Failed to get the cameras. ${err.message}`);
return; return;
} }
console.log('Callback returned with the CameraInput instance.'); console.log('Callback returned with an array of supported outputCapability');
}) })
``` ```
### createCameraInput ### getSupportedOutputCapability
createCameraInput(cameraId: string): Promise<CameraInput\>
Creates a **CameraInput** instance with the specified camera ID. This API uses a promise to return the result. getSupportedOutputCapability(camera:CameraDevice): Promise<CameraOutputCapability\>
**Required permissions**: ohos.permission.CAMERA Obtains the output capability supported by a camera. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ------------ | | -------- | --------------------------------- | ---- | ---------- |
| cameraId | string | Yes | ID of the target camera.| | camera | [CameraDevice](#cameradevice) | Yes | Camera device. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------------- | ---------------------------------------- | | -------------------------------------------------------------- | ----------------------------- |
| Promise<[CameraInput](#camerainput)\> | Promise used to return the **CameraInput** instance.| | Promise<[CameraOutputCapability](#cameraoutputcapability)\> | Promise used to return the output capability.|
**Example** **Example**
```js ```js
cameraManager.createCameraInput(cameraId).then((cameraInput) => { cameraManager.getSupportedOutputCapability(cameradevice).then((cameraoutputcapability) => {
console.log('Promise returned with the CameraInput instance'); console.log('Promise returned with an array of supported outputCapability');
}) })
``` ```
### createCameraInput ### isCameraMuted
createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback<CameraInput\>): void isCameraMuted(): boolean
Creates a **CameraInput** instance with the specified camera position and type. This API uses an asynchronous callback to return the result. Checks whether the camera is muted.
**Required permissions**: ohos.permission.CAMERA Before calling the API, ensure that the camera can be muted. You can use [isCameraMuteSupported](#iscameramutesupported) to check whether the camera can be muted.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Return value**
| Name | Type | Mandatory| Description | | Type | Description |
| -------- | ------------------------------------------- | ---- | ----------------------------------- | | ---------- | -------------------------------------------- |
| position | [CameraPosition](#cameraposition) | Yes | Camera position. | | boolean | Returns **true** if the camera is muted; returns **false** otherwise.|
| type | [CameraType](#cameratype) | Yes | Camera type. |
| callback | AsyncCallback<[CameraInput](#camerainput)\> | Yes | Callback used to return the **CameraInput** instance.|
**Example** **Example**
```js ```js
cameraManager.createCameraInput(camera.CameraPosition.CAMERA_POSITION_BACK, camera.CameraType.CAMERA_TYPE_UNSPECIFIED, (err, cameraInput) => { let ismuted = await cameraManager.isCameraMuted();
if (err) {
console.error('Failed to create the CameraInput instance. ${err.message}');
return;
}
console.log('Callback returned with the CameraInput instance');
})
``` ```
### createCameraInput ### isCameraMuteSupported
createCameraInput(position: CameraPosition, type: CameraType): Promise<CameraInput\>
Creates a **CameraInput** instance with the specified camera position and type. This API uses a promise to return the result. isCameraMuteSupported(): boolean
**Required permissions**: ohos.permission.CAMERA Checks whether the camera can be muted.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------- | ---- | ---------- |
| position | [CameraPosition](#cameraposition) | Yes | Camera position.|
| type | [CameraType](#cameratype) | Yes | Camera type.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------------- | ---------------------------------------- | | ---------- | ----------------------------- |
| Promise<[CameraInput](#camerainput)\> | Promise used to return the **CameraInput** instance.| | boolean | Returns **true** if the camera can be muted; returns **false** otherwise.|
**Example** **Example**
```js ```js
cameraManager.createCameraInput(camera.CameraPosition.CAMERA_POSITION_BACK, camera.CameraType.CAMERA_TYPE_UNSPECIFIED).then((cameraInput) => { let ismutesuppotred = await cameraManager.isCameraMuteSupported();
console.log('Promise returned with the CameraInput instance.');
})
``` ```
### on('cameraStatus') ### muteCamera
on(type: 'cameraStatus', callback: AsyncCallback<CameraStatusInfo\>): void muteCamera(mute: boolean): void
Listens for camera status changes. This API uses an asynchronous callback to return the result. Mutes or unmutes the camera.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :------- | :---------------------------------------------------- | :--- | :--------------------------------------------------- | | -------- | --------------------------------- | ---- | ---------- |
| type | string | Yes | Event type. The value is fixed at **`cameraStatus`**, indicating the camera status change event.| | mute | boolean | Yes | Whether to mute the camera. The value **true** means to mute the camera, and **false** means the opposite. |
| callback | AsyncCallback<[CameraStatusInfo](#camerastatusinfo)\> | Yes | Callback used to return the camera status change. |
**Example**
```js
cameraManager.on('cameraStatus', (err, cameraStatusInfo) => {
if (err) {
console.error('Failed to get cameraStatus callback. ${err.message}');
return;
}
console.log('camera : ' + cameraStatusInfo.camera.cameraId);
console.log('status: ' + cameraStatusInfo.status);
})
```
## Camera
After **[camera.getCameraManager](#cameragetcameramanager)** is called, a camera instance is returned, with camera-related metadata such as **cameraId**, **cameraPosition**, **cameraType**, and **connectionType**.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read only| Description |
| -------------- | --------------------------------- | ---- | -------------- |
| cameraId | string | Yes | Camera ID. |
| cameraPosition | [CameraPosition](#cameraposition) | Yes | Camera position. |
| cameraType | [CameraType](#cameratype) | Yes | Camera type. |
| connectionType | [ConnectionType](#connectiontype) | Yes | Camera connection type.|
**Example** **Example**
```js ```js
async function getCameraInfo("cameraId") { cameraManager.muteCamera(mute);
var cameraManager = await camera.getCameraManager(context);
var cameras = await cameraManager.getCameras();
var cameraObj = cameras[0];
var cameraId = cameraObj.cameraId;
var cameraPosition = cameraObj.cameraPosition;
var cameraType = cameraObj.cameraType;
var connectionType = cameraObj.connectionType;
}
``` ```
## CameraStatusInfo ### createCameraInput
Describes the camera status information.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Description |
| ------ | ----------------------------- | ---------- |
| camera | [Camera](#camera) | Camera object.|
| status | [CameraStatus](#camerastatus) | Camera status.|
## CameraInput
Implements a **CameraInput** instance. Before calling any API in **CameraInput**, you must create a **CameraInput** instance. createCameraInput(camera: CameraDevice, callback: AsyncCallback<CameraInput\>): void
### getCameraId Creates a **CameraInput** instance with the specified **CameraDevice** object. This API uses an asynchronous callback to return the result.
getCameraId(callback: AsyncCallback<string\>\): void This is a system API.
Obtains the camera ID based on which this **CameraInput** instance is created. This API uses an asynchronous callback to return the camera ID. **Required permissions**: ohos.permission.CAMERA
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | -------------------------- | | -------- | ------------------------------------------- | ---- | --------------------------------- |
| callback | AsyncCallback<string\> | Yes | Callback used to return the camera ID.| | camera | [CameraDevice](#cameradevice) | Yes | **CameraDevice** object. |
| callback | AsyncCallback<[CameraInput](#camerainput)\> | Yes | Callback used to return the **CameraInput** instance. |
**Example** **Example**
```js ```js
cameraInput.getCameraId((err, cameraId) => { cameraManager.createCameraInput(camera, (err, cameraInput) => {
if (err) { if (err) {
console.error('Failed to get the camera ID. ${err.message}'); console.error(`Failed to create the CameraInput instance. ${err.message}`);
return; return;
} }
console.log('Callback returned with the camera ID: ' + cameraId); console.log('Callback returned with the CameraInput instance.');
}) })
``` ```
### getCameraId ### createCameraInput
createCameraInput(camera: CameraDevice): Promise<CameraInput\>
getCameraId(): Promise<string\> Creates a **CameraInput** instance with the specified **CameraDevice** object. This API uses a promise to return the result.
Obtains the camera ID based on which this **CameraInput** instance is created. This API uses a promise to return the camera ID. This is a system API.
**Required permissions**: ohos.permission.CAMERA
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------- | ---- | ---------- |
| camera | [CameraDevice](#cameradevice) | Yes | **CameraDevice** object.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------- | ----------------------------- | | ------------------------------------- | ------------------------------------ |
| Promise<string\> | Promise used to return the camera ID.| | Promise<[CameraInput](#camerainput)\> | Promise used to return the **CameraInput** instance.|
**Example** **Example**
```js ```js
cameraInput.getCameraId().then((cameraId) => { cameraManager.createCameraInput(camera).then((cameraInput) => {
console.log('Promise returned with the camera ID:' + cameraId); console.log('Promise returned with the CameraInput instance');
}) })
``` ```
### createCameraInput
### hasFlash createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback<CameraInput\>): void
hasFlash(callback: AsyncCallback<boolean\>): void Creates a **CameraInput** instance with the specified camera position and type. 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. This is a system API.
**Required permissions**: ohos.permission.CAMERA
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ------------------------------------------- | ---- | --------------------------------- |
| callback | AsyncCallback<boolean\> | Yes | Callback used to return the flash support status. The value **true** means that the device has flash.| | position | [CameraPosition](#cameraposition) | Yes | Camera position. |
| type | [CameraType](#cameratype) | Yes | Camera type. |
| callback | AsyncCallback<[CameraInput](#camerainput)\> | Yes | Callback used to return the **CameraInput** instance. |
**Example** **Example**
```js ```js
cameraInput.hasFlash((err, status) => { cameraManager.createCameraInput(camera.CameraPosition.CAMERA_POSITION_BACK, camera.CameraType.CAMERA_TYPE_UNSPECIFIED, (err, cameraInput) => {
if (err) { if (err) {
console.error('Failed to check whether the device has flash light. ${err.message}'); console.error(`Failed to create the CameraInput instance. ${err.message}`);
return; return;
} }
console.log('Callback returned with flash light support status: ' + status); console.log('Callback returned with the CameraInput instance');
}) })
``` ```
### hasFlash ### createCameraInput
hasFlash(): Promise<boolean\> createCameraInput(position: CameraPosition, type:CameraType ): Promise<CameraInput\>
Checks whether the device has flash. This API uses a promise to return the result. Creates a **CameraInput** instance with the specified camera position and type. This API uses a promise to return the result.
This is a system API.
**Required permissions**: ohos.permission.CAMERA
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------- | ---- | ------------ |
| position | [CameraPosition](#cameraposition) | Yes | Camera position. |
| type | [CameraType](#cameratype) | Yes | Camera type. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------- | ------------------------------------------------------- | | ------------------------------------- | ------------------------------------ |
| Promise<boolean\> | Promise used to return the flash support status. The value **true** means that the device has flash.| | Promise<[CameraInput](#camerainput)\> | Promise used to return the **CameraInput** instance.|
**Example** **Example**
```js ```js
cameraInput.hasFlash().then((status) => { cameraManager.createCameraInput(camera.CameraPosition.CAMERA_POSITION_BACK, camera.CameraType.CAMERA_TYPE_UNSPECIFIED).then((cameraInput) => {
console.log('Promise returned with the flash light support status:' + status); console.log('Promise returned with the CameraInput instance');
}) })
``` ```
### isFlashModeSupported ### createPreviewOutput
isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback<boolean\>): void createPreviewOutput(profile: Profile, surfaceId: string, callback: AsyncCallback<PreviewOutput\>): void
Checks whether a specified flash mode is supported. This API uses an asynchronous callback to return the result. Creates a **PreviewOutput** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ----------------------- | ---- | ---------------------------------------- | | -------- | ----------------------------------------------- | ---- | ------------------------------- |
| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. | | profile | [Profile](#profile) | Yes | Supported preview profile. |
| 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.| | 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.|
**Example** **Example**
```js ```js
cameraInput.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO, (err, status) => { cameraManager.createPreviewOutput(profile, surfaceId, (err, previewoutput) => {
if (err) { if (err) {
console.error('Failed to check whether the flash mode is supported. ${err.message}'); console.error(`Failed to gcreate previewOutput. ${err.message}`);
return; return;
} }
console.log('Callback returned with the flash mode support status: ' + status); console.log('Callback returned with previewOutput created.');
}) })
``` ```
### isFlashModeSupported ### createPreviewOutput
isFlashModeSupported(flashMode: FlashMode): Promise<boolean\> createPreviewOutput(profile: Profile, surfaceId: string): Promise<PreviewOutput\>
Checks whether a specified flash mode is supported. This API uses a promise to return the result. Creates a **PreviewOutput** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ----------------------- | ---- | ---------------- | | -------- | ---------------------------------| ---- | ----------------- |
| flashMode | [FlashMode](#flashmode) | Yes | Flash mode.| | profile | [Profile](#profile) | Yes | Supported preview profile. |
| surfaceId| string | Yes | Surface ID, which is obtained from **[XComponent](../arkui-ts/ts-basic-components-xcomponent.md)** or **[ImageReceiver](js-apis-image.md#imagereceiver9)**.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------- | ------------------------------------------------------------ | | ---------------------------------------- | ---------------------------------------- |
| 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.| | Promise<[PreviewOutput](#previewoutput)\> | Promise used to return the **PreviewOutput** instance. |
**Example** **Example**
```js ```js
cameraInput.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO).then((status) => { cameraManager.createPreviewOutput(profile, surfaceId).then((previewoutput) => {
console.log('Promise returned with flash mode support status.' + status); console.log('Promise returned with previewOutput created.');
}) })
``` ```
### setFlashMode ### createPhotoOutput
setFlashMode(flashMode: FlashMode, callback: AsyncCallback<void\>): void
Sets the flash mode. This API uses an asynchronous callback to return the result.
Before the setting, do the following checks: createPhotoOutput(profile: Profile, surfaceId: string, callback: AsyncCallback<PhotoOutput\>): void
1. Use **[hasFlash](#hasflash)** to check whether the device has flash. Creates a **PhotoOutput** instance. This API uses an asynchronous callback to return the result.
2. Use **[isFlashModeSupported](#isflashmodesupported)** to check whether the device supports the flash mode.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ----------------------- | ---- | ------------------------ | | -------- | ------------------------------------------- | ---- | ----------------------------------- |
| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. | | profile | [Profile](#profile) | Yes | Supported shooting profile. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.| | surfaceId| string | Yes | Surface ID, which is obtained from **[ImageReceiver](js-apis-image.md#imagereceiver9)**.|
| callback | AsyncCallback<[PhotoOutput](#photooutput)\> | Yes | Callback used to return the **PhotoOutput** instance. |
**Example** **Example**
```js ```js
cameraInput.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO, (err) => { cameraManager.createPhotoOutput(profile, surfaceId, (err, photooutput) => {
if (err) { if (err) {
console.error('Failed to set the flash mode ${err.message}'); console.error(`Failed to create photoOutput. ${err.message}`);
return; return;
} }
console.log('Callback returned with the successful execution of setFlashMode.'); console.log('Callback returned with photoOutput created.');
}) })
``` ```
### setFlashMode ### createPhotoOutput
setFlashMode(flashMode: FlashMode): Promise<void\>
Sets a flash mode. This API uses a promise to return the result.
Before the setting, do the following checks: createPhotoOutput(profile: Profile, surfaceId: string): Promise<PhotoOutput\>
1. Use **[hasFlash](#hasflash)** to check whether the device has flash. Creates a **PhotoOutput** instance. This API uses a promise to return the result.
2. Use **[isFlashModeSupported](#isflashmodesupported)** to check whether the device supports the flash mode.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ----------------------- | ---- | ---------------- | | -------- | ---------------------------------| ---- | ----------- |
| flashMode | [FlashMode](#flashmode) | Yes | Flash mode.| | profile | [Profile](#profile) | Yes | Supported shooting profile. |
| surfaceId| string | Yes | Surface ID, which is obtained from **[ImageReceiver](js-apis-image.md#imagereceiver9)**.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | ------------------------------------- | -------------------------------------- |
| Promise<void\>| Promise used to return the result.| | Promise<[PhotoOutput](#photooutput)\> | Promise used to return the **PhotoOutput** instance. |
**Example** **Example**
```js ```js
cameraInput.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO).then(() => { cameraManager.createPhotoOutput(profile, surfaceId).then((photooutput) => {
console.log('Promise returned with the successful execution of setFlashMode.'); console.log('Promise returned with photoOutput created.');
}) })
``` ```
### getFlashMode ### createVideoOutput
getFlashMode(callback: AsyncCallback<FlashMode\>): void createVideoOutput(profile: VideoProfile, surfaceId: string, callback: AsyncCallback<VideoOutput\>): void
Obtains the flash mode in use. This API uses an asynchronous callback to return the result. Creates a **VideoOutput** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------------------------- | ---- | ------------------------------ |
| callback | AsyncCallback<[FlashMode](#flashmode)\> | Yes | Callback used to return the flash mode.| | profile | [VideoProfile](#videoprofile) | Yes | Supported video recording profile. |
| surfaceId| string | Yes | Surface ID, which is obtained from **[VideoRecorder](js-apis-media.md#videorecorder9)**.|
| callback | AsyncCallback<[VideoOutput](#videooutput)\> | Yes | Callback used to return the **VideoOutput** instance.|
**Example** **Example**
```js ```js
cameraInput.getFlashMode((err, flashMode) => { cameraManager.createVideoOutput(profile, surfaceId, (err, videooutput) => {
if (err) { if (err) {
console.error('Failed to get the flash mode ${err.message}'); console.error(`Failed to create videoOutput. ${err.message}`);
return; return;
} }
console.log('Callback returned with current flash mode: ' + flashMode); console.log('Callback returned with an array of supported outputCapability' );
}) })
``` ```
### getFlashMode ### createVideoOutput
getFlashMode(): Promise<FlashMode\> createVideoOutput(profile: VideoProfile, surfaceId: string): Promise<VideoOutput\>
Obtains the flash mode in use. This API uses a promise to return the result. Creates a **VideoOutput** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------| ---- | ---------- |
| profile | [VideoProfile](#videoprofile) | Yes | Supported video recording profile. |
| surfaceId| string | Yes | Surface ID, which is obtained from **[VideoRecorder](js-apis-media.md#videorecorder9)**.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------------------- | --------------------------------------- | | ------------------------------------- | -------------------------------------- |
| Promise<[FlashMode](#flashmode)\> | Promise used to return the flash mode.| | Promise<[VideoOutput](#videooutput)\> | Promise used to return the **VideoOutput** instance. |
**Example** **Example**
```js ```js
cameraInput.getFlashMode().then((flashMode) => { cameraManager.createVideoOutput(profile, surfaceId).then((videooutput) => {
console.log('Promise returned with current flash mode : ' + flashMode); console.log('Promise returned with videoOutput created.');
}) })
``` ```
### isFocusModeSupported ### createMetadataOutput
isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback<boolean\>): void createMetadataOutput(metadataObjectTypes:Array<MetadataObjectType\>, callback: AsyncCallback<MetadataOutput\>): void
Checks whether a specified focus mode is supported. This API uses an asynchronous callback to return the result. Creates a **MetadataOutput** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------------------- | -------------------------------------------------- | --- | ---------------------------- |
| afMode | [FocusMode](#focusmode) | Yes | Focus mode. | | metadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | Yes | Metadata object types. |
| 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.| | callback | AsyncCallback<[MetadataOutput](#metadataoutput)\> | Yes | Callback used to return the **MetadataOutput** instance. |
**Example** **Example**
```js ```js
cameraInput.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO, (err, status) => { cameraManager.createMetadataOutput(metadataObjectTypes, (err, metadataoutput) => {
if (err) { if (err) {
console.error('Failed to check whether the focus mode is supported. ${err.message}'); console.error(`Failed to create metadataOutput. ${err.message}`);
return; return;
} }
console.log('Callback returned with the focus mode support status: ' + status); console.log('Callback returned with metadataOutput created.');
}) })
``` ```
### isFocusModeSupported ### createMetadataOutput
isFocusModeSupported(afMode: FocusMode): Promise<boolean\> createMetadataOutput(metadataObjectTypes:Array<MetadataObjectType\>): Promise<MetadataOutput\>
Checks whether a specified focus mode is supported. This API uses a promise to return the result. Creates a **MetadataOutput** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------ | ----------------------- | ---- | ---------------- | | -------------------- | -------------------------------------------------- | --- | -------------------- |
| afMode | [FocusMode](#focusmode) | Yes | Focus mode.| | metadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | Yes | Metadata object types. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------- | ----------------------------------------------------------- | | ------------------------------------------ | ----------------------------------------- |
| 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.| | Promise<[MetadataOutput](#metadataoutput)\> | Promise used to return the **MetadataOutput** instance.|
**Example** **Example**
```js ```js
cameraInput.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO).then((status) => { cameraManager.createMetadataOutput().then((metadataoutput) => {
console.log('Promise returned with focus mode support status.' + status); console.log('Promise returned with metadataOutput created.');
}) })
``` ```
### setFocusMode ### createCaptureSession
setFocusMode(afMode: FocusMode, callback: AsyncCallback<void\>): void
Sets a focus mode. This API uses an asynchronous callback to return the result. createCaptureSession(callback: AsyncCallback<CaptureSession\>): void
Before the setting, use **[isFocusModeSupported](#isfocusmodesupported)** to check whether the focus mode is supported. Creates a **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| -------- | ----------------------- | ---- | ------------------------ | | -------------------- | ----------------------------------------- | ----------- | ---------------------------- |
| afMode | [FocusMode](#focusmode) | Yes | Focus mode. | | callback | AsyncCallback<[CaptureSession](#capturesession)\> | Yes | Callback used to return the **CaptureSession** instance.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
cameraInput.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO, (err) => { cameraManager.createCaptureSession((err, capturesession) => {
if (err) { if (err) {
console.error('Failed to set the focus mode ${err.message}'); console.error(`Failed to create captureSession. ${err.message}`);
return; return;
} }
console.log('Callback returned with the successful execution of setFocusMode.'); console.log('Callback returned with captureSession created.');
}) })
``` ```
### setFocusMode ### createCaptureSession
setFocusMode(afMode: FocusMode): Promise<void\>
Sets a focus mode. This API uses a promise to return the result. createCaptureSession(): Promise<CaptureSession\>
Before the setting, use **[isFocusModeSupported](#isfocusmodesupported)** to check whether the focus mode is supported. Creates a **CaptureSession** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------ | ----------------------- | ---- | ---------------- |
| afMode | [FocusMode](#focusmode) | Yes | Focus mode.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | ------------------------------------------- | ---------------------------------------- |
| Promise<void\>| Promise used to return the result.| | Promise<[CaptureSession](#capturesession)\> | Promise used to return the **CaptureSession** instance.|
**Example** **Example**
```js ```js
cameraInput.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO).then(() => { cameraManager.createCaptureSession().then((capturesession) => {
console.log('Promise returned with the successful execution of setFocusMode.'); console.log('Promise returned with captureSession created.');
}) })
``` ```
### getFocusMode ### on('cameraStatus')
getFocusMode(callback: AsyncCallback<FocusMode\>): void on(type: 'cameraStatus', callback: AsyncCallback<CameraStatusInfo\>): void
Obtains the focus mode in use. This API uses an asynchronous callback to return the result. Listens for camera status changes. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | -------------------------------------- | | -------- | ----------------------------------------------------- | ---- | --------- |
| callback | AsyncCallback<[FocusMode](#focusmode)\> | Yes | Callback used to return the focus mode.| | type | string | Yes | Event type. The value is fixed at **'cameraStatus'**, indicating the camera status change event.|
| callback | AsyncCallback<[CameraStatusInfo](#camerastatusinfo)\> | Yes | Callback used to return the camera status change. |
**Example** **Example**
```js ```js
cameraInput.getFocusMode((err, afMode) => { cameraManager.on('cameraStatus', (err, cameraStatusInfo) => {
if (err) { if (err) {
console.error('Failed to get the focus mode ${err.message}'); console.error(`Failed to get cameraStatus callback. ${err.message}`);
return; return;
} }
console.log('Callback returned with current focus mode: ' + afMode); console.log(`camera : ${cameraStatusInfo.camera.cameraId}`);
console.log(`status: ${cameraStatusInfo.status}`);
}) })
``` ```
### getFocusMode ### on('cameraMute')
getFocusMode(): Promise<FocusMode\> on(type: 'cameraMute', callback: AsyncCallback<boolean\>): void
Obtains the focus mode in use. This API uses a promise to return the result. Listens for camera mute status changes. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Return value** **Parameters**
| Type | Description | | Name | Type | Mandatory| Description |
| ------------------- | ------------------------------------- | | -------- | --------------- | ---- | --------- |
| Promise<FocusMode\> | Promise used to return the focus mode.| | type | string | Yes | Event type. The value is fixed at **'cameraMute'**, indicating the camera mute status change event.|
| callback | boolean | Yes | Callback used to return the camera mute status. |
**Example** **Example**
```js ```js
cameraInput.getFocusMode().then((afMode) => { cameraManager.on('cameraMute', (err, cameraStatusInfo) => {
console.log('Promise returned with current focus mode : ' + afMode); if (err) {
console.error(`Failed to get cameraMute callback. ${err.message}`);
return;
}
}) })
``` ```
### getZoomRatioRange ## CameraStatusInfo
getZoomRatioRange\(callback: AsyncCallback<Array<number\>\>\): void Describes the camera status information.
Obtains the zoom ratio range. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Description |
| ------ | ----------------------------- | ---------- |
| camera | [CameraDevice](#cameradevice) | Camera object.|
| status | [CameraStatus](#camerastatus) | Camera status.|
## CameraPosition
Enumerates the camera positions.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** | Name | Value | Description |
| --------------------------- | ---- | -------------- |
| CAMERA_POSITION_UNSPECIFIED | 0 | Unspecified position. |
| CAMERA_POSITION_BACK | 1 | Rear camera. |
| CAMERA_POSITION_FRONT | 2 | Front camera. |
| Name | Type | Mandatory| Description | ## CameraType
| -------- | ------------------------------ | ---- | ------------------------ |
| callback | AsyncCallback<Array<number\>\> | Yes | Callback used to return an array containing the minimum and maximum zoom ratios.|
**Example** Enumerates the camera types.
```js **System capability**: SystemCapability.Multimedia.Camera.Core
cameraInput.getZoomRatioRange((err, zoomRatioRange) => {
if (err) {
console.error('Failed to get the zoom ratio range. ${err.message}');
return;
}
console.log('Callback returned with zoom ratio range: ' + zoomRatioRange.length);
})
```
### getZoomRatioRange | Name | Value | Description |
| ----------------------- | ---- | -------------- |
| CAMERA_TYPE_UNSPECIFIED | 0 | Unspecified camera type. |
| CAMERA_TYPE_WIDE_ANGLE | 1 | Wide camera. |
| CAMERA_TYPE_ULTRA_WIDE | 2 | Ultra wide camera. |
| CAMERA_TYPE_TELEPHOTO | 3 | Telephoto camera. |
| CAMERA_TYPE_TRUE_DEPTH | 4 | Camera with depth of field information.|
getZoomRatioRange\(\): Promise<Array<number\>\> ## ConnectionType
Obtains the zoom ratio range. This API uses a promise to return the result. Enumerates the camera connection types.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Return value** | Name | Value | Description |
| ---------------------------- | ---- | ------------- |
| CAMERA_CONNECTION_BUILT_IN | 0 | Built-in camera. |
| CAMERA_CONNECTION_USB_PLUGIN | 1 | Camera connected using USB.|
| CAMERA_CONNECTION_REMOTE | 2 | Remote camera.|
| Type | Description | ## CameraDevice
| ------------------------ | ------------------------------------------- |
| Promise<Array<number\>\> | Promise used to return an array containing the minimum and maximum zoom ratios.| Defines the camera device information.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Read Only| Description |
| -------------- | --------------------------------- | ---- | ---------- |
| cameraId | string | Yes | **CameraDevice** object.|
| cameraPosition | [CameraPosition](#cameraposition) | Yes | Camera position. |
| cameraType | [CameraType](#cameratype) | Yes | Camera type. |
| connectionType | [ConnectionType](#connectiontype) | Yes | Camera connection type.|
**Example** **Example**
```js ```js
cameraInput.getZoomRatioRange().then((zoomRatioRange) => { async function getCameraInfo("cameraId") {
console.log('Promise returned with zoom ratio range: ' + zoomRatioRange.length); let cameraManager = await camera.getCameraManager(context);
}) let cameras = await cameraManager.getSupportedCameras();
let cameraObj = cameras[0];
let cameraId = cameraObj.cameraId;
let cameraPosition = cameraObj.cameraPosition;
let cameraType = cameraObj.cameraType;
let connectionType = cameraObj.connectionType;
}
``` ```
### setZoomRatio ## Size
setZoomRatio(zoomRatio: number, callback: AsyncCallback<void\>): void Enumerates the camera output capability.
Sets a zoom ratio. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Readable| Writable| Description |
| ------ | ------ | ---- | ---- | ------------ |
| height | number | Yes | Yes | Image height, in pixels.|
| width | number | Yes | Yes | Image width, in pixels.|
## Point
Enumerates the point coordinates, which are used for focus and exposure configuration.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------------ |
| x | number | Yes | X coordinate of a point. |
| y | number | Yes | Y coordinate of a point. |
## CameraFormat
Enumerates the camera output formats.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Default Value | Description |
| ----------------------- | --------- | ------------ |
| CAMERA_FORMAT_RGBA_8888 | 3 | RGB image. |
| CAMERA_FORMAT_YUV_420_SP| 1003 | YUV 420 SP image. |
| CAMERA_FORMAT_JPEG | 2000 | JPEG image. |
## CameraInput
Provides camera information used in **[CaptureSession](#capturesession)**.
### open
open\(callback: AsyncCallback<void\>\): void
Opens this camera. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | -------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | ------------------- |
| zoomRatio | number | Yes | Zoom ratio. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
cameraInput.setZoomRatio(1, (err) => { cameraInput.open((err) => {
if (err) { if (err) {
console.error('Failed to set the zoom ratio value ${err.message}'); console.error(`Failed to open the camera. ${err.message}`);
return; return;
} }
console.log('Callback returned with the successful execution of setZoomRatio.'); console.log('Callback returned with camera opened.');
}) })
``` ```
### setZoomRatio ### open
setZoomRatio(zoomRatio: number): Promise<void\> open(): Promise<void\>
Sets a zoom ratio. This API uses a promise to return the result. Opens this camera. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | ------------ |
| zoomRatio | number | Yes | Zoom ratio.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | -------------- | ----------------------- |
| Promise<void\>| Promise used to return the result.| | Promise<void\>| Promise used to return the result.|
**Example** **Example**
```js ```js
cameraInput.setZoomRatio(1).then(() => { cameraInput.open().then(() => {
console.log('Promise returned with the successful execution of setZoomRatio.'); console.log('Promise returned with camera opened.');
}) })
``` ```
### getZoomRatio ### close
getZoomRatio(callback: AsyncCallback<number\>): void close\(callback: AsyncCallback<void\>\): void
Obtains the zoom ratio in use. This API uses an asynchronous callback to return the result. Closes this camera. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback<number\> | Yes | Callback used to return the result.| | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
cameraInput.getZoomRatio((err, zoomRatio) => { cameraInput.close((err) => {
if (err) { if (err) {
console.error('Failed to get the zoom ratio ${err.message}'); console.error(`Failed to close the cameras. ${err.message}`);
return; return;
} }
console.log('Callback returned with current zoom ratio: ' + zoomRatio); console.log('Callback returned with camera closed.');
}) })
``` ```
### getZoomRatio ### close
getZoomRatio(): Promise<number\> close(): Promise<void\>
Obtains the zoom ratio in use. This API uses a promise to return the result. Closes this camera. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------- | --------------------------- | | -------------- | ----------------------- |
| Promise<number\> | Promise used to return the zoom ratio.| | Promise<void\>| Promise used to return the result.|
**Example** **Example**
```js ```js
cameraInput.getZoomRatio().then((zoomRatio) => { cameraInput.close().then(() => {
console.log('Promise returned with current zoom ratio : ' + zoomRatio); console.log('Promise returned with camera closed.');
}) })
``` ```
...@@ -955,14 +963,14 @@ cameraInput.getZoomRatio().then((zoomRatio) => { ...@@ -955,14 +963,14 @@ cameraInput.getZoomRatio().then((zoomRatio) => {
release\(callback: AsyncCallback<void\>\): void release\(callback: AsyncCallback<void\>\): void
Releases this **CameraInput** instance. This API uses an asynchronous callback to return the result. Releases this camera. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -970,7 +978,7 @@ Releases this **CameraInput** instance. This API uses an asynchronous callback t ...@@ -970,7 +978,7 @@ Releases this **CameraInput** instance. This API uses an asynchronous callback t
```js ```js
cameraInput.release((err) => { cameraInput.release((err) => {
if (err) { if (err) {
console.error('Failed to release the CameraInput instance ${err.message}'); console.error(`Failed to release the CameraInput instance ${err.message}`);
return; return;
} }
console.log('Callback invoked to indicate that the CameraInput instance is released successfully.'); console.log('Callback invoked to indicate that the CameraInput instance is released successfully.');
...@@ -981,14 +989,14 @@ cameraInput.release((err) => { ...@@ -981,14 +989,14 @@ cameraInput.release((err) => {
release(): Promise<void\> release(): Promise<void\>
Releases this **CameraInput** instance. This API uses a promise to return the result. Releases this camera. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | -------------- | ----------------------- |
| Promise<void\>| Promise used to return the result.| | Promise<void\>| Promise used to return the result.|
**Example** **Example**
...@@ -999,32 +1007,9 @@ cameraInput.release().then(() => { ...@@ -999,32 +1007,9 @@ cameraInput.release().then(() => {
}) })
``` ```
### on('focusStateChange')
on(type: 'focusStateChange', callback: AsyncCallback<FocusState\>): void
Listens for focus state changes. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| :------- | :---------------------------------------- | :--- | :------------------------------------------------------- |
| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**, indicating the focus state change event.|
| callback | AsyncCallback<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. |
**Example**
```js
cameraInput.on('focusStateChange', (focusState) => {
console.log('Focus state : ' + focusState);
})
```
### on('error') ### on('error')
on(type: 'error', callback: ErrorCallback<CameraInputError\>): void on(type: 'error', camera:CameraDevice, callback: ErrorCallback<CameraInputError\>): void
Listens for **CameraInput** errors. This API uses a callback to return the result. Listens for **CameraInput** errors. This API uses a callback to return the result.
...@@ -1033,36 +1018,42 @@ Listens for **CameraInput** errors. This API uses a callback to return the resul ...@@ -1033,36 +1018,42 @@ Listens for **CameraInput** errors. This API uses a callback to return the resul
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------- | :--- | :----------------------------------------------- | | -------- | -------------------------------- | --- | ------------------------------------------- |
| type | string | Yes | Event type. The value is fixed at **'error'**, indicating the camera input error event.| | type | string | Yes | Event type. The value is fixed at **'error'**, indicating the camera input error event.|
| camera | [CameraDevice](#cameradevice) | Yes | **CameraDevice** object.|
| callback | ErrorCallback<[CameraInputError](#camerainputerror)\> | Yes | Callback used to return the result. | | callback | ErrorCallback<[CameraInputError](#camerainputerror)\> | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
cameraInput.on('error', (cameraInputError) => { cameraInput.on('error', camera, (cameraInputError) => {
console.log('Camera input error code: ' + cameraInputError.code); console.log(`Camera input error code: ${cameraInputError.code}`);
}) })
``` ```
## CameraInputErrorCode ## CameraInputErrorCode
Enumerates the error codes used in a **CameraInput** instance. Enumerates the error codes used for camera input.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description | | Name | Value | Description |
| ------------- | ---- | ---------- | | ------------------------- | ---- | ---------- |
| ERROR_UNKNOWN | -1 | Unknown error.| | ERROR_UNKNOWN | -1 | Unknown error.|
| ERROR_NO_PERMISSION | 0 | You do not have the required permission.|
| ERROR_DEVICE_PREEMPTED | 1 | The camera is preempted.|
| ERROR_DEVICE_DISCONNECTED | 2 | The camera is disconnected.|
| ERROR_DEVICE_IN_USE | 3 | The camera is in use.|
| ERROR_DRIVER_ERROR | 4 | Driver error. |
## CameraInputError ## CameraInputError
Defines a **CameraInput** error. Defines an error object used for **[CameraInput](#camerainput)**.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name| Type | Description | | Name| Type | Description |
| ---- | ------------------------------------------- | -------------------------- | | ---- | --------------------------------------------- | --------------------- |
| code | [CameraInputErrorCode](#camerainputerrorcode) | **CameraInput** error code.| | code | [CameraInputErrorCode](#camerainputerrorcode) | **CameraInput** error code.|
...@@ -1073,20 +1064,32 @@ Enumerates the flash modes. ...@@ -1073,20 +1064,32 @@ Enumerates the flash modes.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description | | Name | Value | Description |
| ---------------------- | ---- | ------------ | | ---------------------- | ---- | ---------- |
| FLASH_MODE_CLOSE | 0 | The flash is off.| | FLASH_MODE_CLOSE | 0 | The flash is off.|
| FLASH_MODE_OPEN | 1 | The flash is on.| | FLASH_MODE_OPEN | 1 | The flash is on.|
| FLASH_MODE_AUTO | 2 | The flash mode is auto, indicating that the flash fires automatically depending on the shooting conditions.| | FLASH_MODE_AUTO | 2 | The flash mode is auto, indicating that the flash fires automatically depending on the shooting conditions.|
| FLASH_MODE_ALWAYS_OPEN | 3 | The flash is steady on.| | FLASH_MODE_ALWAYS_OPEN | 3 | The flash is steady on.|
## FocusMode ## ExposureMode
Enumerates the exposure modes.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| ----------------------------- | ---- | ----------- |
| EXPOSURE_MODE_LOCKED | 0 | Exposure locked.|
| EXPOSURE_MODE_AUTO | 1 | Auto exposure.|
| EXPOSURE_MODE_CONTINUOUS_AUTO | 2 | Continuous auto exposure.|
## FocusMode
Enumerates the focus modes. Enumerates the focus modes.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description | | Name | Value | Description |
| -------------------------- | ---- | ------------------ | | -------------------------- | ---- | ------------ |
| FOCUS_MODE_MANUAL | 0 | Manual focus. | | FOCUS_MODE_MANUAL | 0 | Manual focus. |
| FOCUS_MODE_CONTINUOUS_AUTO | 1 | Continuous auto focus.| | FOCUS_MODE_CONTINUOUS_AUTO | 1 | Continuous auto focus.|
| FOCUS_MODE_AUTO | 2 | Auto focus. | | FOCUS_MODE_AUTO | 2 | Auto focus. |
...@@ -1099,69 +1102,28 @@ Enumerates the focus states. ...@@ -1099,69 +1102,28 @@ Enumerates the focus states.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description | | Name | Value | Description |
| --------------------- | ---- | ------------ | | --------------------- | ---- | --------- |
| FOCUS_STATE_SCAN | 0 | Focusing. | | FOCUS_STATE_SCAN | 0 | Focusing. |
| FOCUS_STATE_FOCUSED | 1 | Focused.| | FOCUS_STATE_FOCUSED | 1 | Focused. |
| FOCUS_STATE_UNFOCUSED | 2 | Unfocused.| | FOCUS_STATE_UNFOCUSED | 2 | Unfocused.|
## camera.createCaptureSession ## VideoStabilizationMode
createCaptureSession\(context: Context, callback: AsyncCallback<CaptureSession\>\): void
Creates a **CaptureSession** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | -------------------------------------- |
| context | Context | Yes | Application context. |
| callback | AsyncCallback<[CaptureSession](#capturesession)\> | Yes | Callback used to return the **CaptureSession** instance.|
**Example**
```js
camera.createCaptureSession((context), (err, captureSession) => {
if (err) {
console.error('Failed to create the CaptureSession instance. ${err.message}');
return;
}
console.log('Callback returned with the CaptureSession instance.' + captureSession);
});
```
## camera.createCaptureSession
createCaptureSession(context: Context\): Promise<CaptureSession\>; Enumerates the video stabilization modes.
Creates a **CaptureSession** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** | Name | Value | Description |
| --------- | ---- | ------------ |
| Name | Type | Mandatory| Description | | OFF | 0 | Video stabilization is disabled. |
| ------- | ------- | ---- | ------------ | | LOW | 1 | The basic video stabilization algorithm is used. |
| context | Context | Yes | Application context.| | MIDDLE | 2 | A video stabilization algorithm with a stabilization effect better than that of the **LOW** type is used. |
| HIGH | 3 | A video stabilization algorithm with a stabilization effect better than that of the **MIDDLE** type is used. |
**Return value** | AUTO | 4 | Automatic video stabilization is used. |
| Type | Description |
| ------------------------------------------- | ----------------------------------------- |
| Promise<[CaptureSession](#capturesession)\> | Promise used to return the **CaptureSession** instance.|
**Example**
```js
camera.createCaptureSession(context).then((captureSession) => {
console.log('Promise returned with the CaptureSession instance');
})
```
## CaptureSession ## CaptureSession
Implements a shooting session. Implements a shooting session, which saves all **[CameraInput](#camerainput)** and **[CameraOutput](#cameraoutput)** instances required to run the camera and requests the camera to complete shooting or video recording.
### beginConfig ### beginConfig
...@@ -1174,7 +1136,7 @@ Starts configuration for this **CaptureSession** instance. This API uses an asyn ...@@ -1174,7 +1136,7 @@ Starts configuration for this **CaptureSession** instance. This API uses an asyn
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -1182,7 +1144,7 @@ Starts configuration for this **CaptureSession** instance. This API uses an asyn ...@@ -1182,7 +1144,7 @@ Starts configuration for this **CaptureSession** instance. This API uses an asyn
```js ```js
captureSession.beginConfig((err) => { captureSession.beginConfig((err) => {
if (err) { if (err) {
console.error('Failed to start the configuration. ${err.message}'); console.error(`Failed to start the configuration. ${err.message}`);
return; return;
} }
console.log('Callback invoked to indicate the begin config success.'); console.log('Callback invoked to indicate the begin config success.');
...@@ -1200,7 +1162,7 @@ Starts configuration for this **CaptureSession** instance. This API uses a promi ...@@ -1200,7 +1162,7 @@ Starts configuration for this **CaptureSession** instance. This API uses a promi
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | -------------- | ------------------------ |
| Promise<void\>| Promise used to return the result.| | Promise<void\>| Promise used to return the result.|
...@@ -1223,7 +1185,7 @@ Commits the configuration for this **CaptureSession** instance. This API uses an ...@@ -1223,7 +1185,7 @@ Commits the configuration for this **CaptureSession** instance. This API uses an
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -1231,7 +1193,7 @@ Commits the configuration for this **CaptureSession** instance. This API uses an ...@@ -1231,7 +1193,7 @@ Commits the configuration for this **CaptureSession** instance. This API uses an
```js ```js
captureSession.commitConfig((err) => { captureSession.commitConfig((err) => {
if (err) { if (err) {
console.error('Failed to commit the configuration. ${err.message}'); console.error(`Failed to commit the configuration. ${err.message}`);
return; return;
} }
console.log('Callback invoked to indicate the commit config success.'); console.log('Callback invoked to indicate the commit config success.');
...@@ -1249,7 +1211,7 @@ Commits the configuration for this **CaptureSession** instance. This API uses a ...@@ -1249,7 +1211,7 @@ Commits the configuration for this **CaptureSession** instance. This API uses a
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | -------------- | ------------------------ |
| Promise<void\>| Promise used to return the result.| | Promise<void\>| Promise used to return the result.|
**Example** **Example**
...@@ -1264,14 +1226,14 @@ captureSession.commitConfig().then(() => { ...@@ -1264,14 +1226,14 @@ captureSession.commitConfig().then(() => {
addInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void addInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void
Adds a **CameraInput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result. Adds a **[CameraInput](#camerainput)** instance to this **CaptureSession**. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- | | ----------- | --------------------------- | ---- | ------------------------ |
| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to add.| | cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to add.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
...@@ -1280,7 +1242,7 @@ Adds a **CameraInput** instance to this **CaptureSession** instance. This API us ...@@ -1280,7 +1242,7 @@ Adds a **CameraInput** instance to this **CaptureSession** instance. This API us
```js ```js
captureSession.addInput(cameraInput, (err) => { captureSession.addInput(cameraInput, (err) => {
if (err) { if (err) {
console.error('Failed to add the CameraInput instance. ${err.message}'); console.error(`Failed to add the CameraInput instance. ${err.message}`);
return; return;
} }
console.log('Callback invoked to indicate that the CameraInput instance is added.'); console.log('Callback invoked to indicate that the CameraInput instance is added.');
...@@ -1291,20 +1253,20 @@ captureSession.addInput(cameraInput, (err) => { ...@@ -1291,20 +1253,20 @@ captureSession.addInput(cameraInput, (err) => {
addInput\(cameraInput: CameraInput\): Promise<void\> addInput\(cameraInput: CameraInput\): Promise<void\>
Adds a **CameraInput** instance to this **CaptureSession** instance. This API uses a promise to return the result. Adds a **[CameraInput](#camerainput)** instance to this **CaptureSession**. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- | | ----------- | --------------------------- | ---- | ------------------------ |
| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to add.| | cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to add.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | -------------- | ------------------------ |
| Promise<void\>| Promise used to return the result.| | Promise<void\>| Promise used to return the result.|
**Example** **Example**
...@@ -1315,969 +1277,2262 @@ captureSession.addInput(cameraInput).then(() => { ...@@ -1315,969 +1277,2262 @@ captureSession.addInput(cameraInput).then(() => {
}) })
``` ```
### addOutput ### removeInput
addOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): void removeInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void
Adds a **PreviewOutput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result. Removes a **[CameraInput](#camerainput)** instance from this **CaptureSession**. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------------- | ------------------------------- | ---- | ----------------------------- | | ----------- | --------------------------- | ---- | ------------------------ |
| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to add.| | cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to remove.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
captureSession.addOutput(previewOutput, (err) => { captureSession.removeInput(cameraInput, (err) => {
if (err) { if (err) {
console.error('Failed to add the PreviewOutput instance ${err.message}'); console.error(`Failed to remove the CameraInput instance. ${err.message}`);
return; return;
} }
console.log('Callback invoked to indicate that the PreviewOutput instance is added.'); console.log('Callback invoked to indicate that the cameraInput instance is removed.');
}); });
``` ```
### addOutput ### removeInput
addOutput\(previewOutput: PreviewOutput\): Promise<void\> removeInput\(cameraInput: CameraInput\): Promise<void\>
Adds a **PreviewOutput** instance to this **CaptureSession** instance. This API uses a promise to return the result. Removes a **[CameraInput](#camerainput)** instance from this **CaptureSession**. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------------- | ------------------------------- | ---- | ----------------------------- | | ----------- | --------------------------- | ---- | ------------------------ |
| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to add.| | cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to remove.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | -------------- | ------------------------- |
| Promise<void\>| Promise used to return the result.| | Promise\<void\> | Promise used to return the result.|
**Example** **Example**
```js ```js
captureSession.addOutput(previewOutput).then(() => { captureSession.removeInput(cameraInput).then(() => {
console.log('Promise used to indicate that the PreviewOutput instance is added.'); console.log('Promise returned to indicate that the cameraInput instance is removed.');
}) })
``` ```
### addOutput ### addOutput
addOutput\(photoOutput: PhotoOutput, callback: AsyncCallback<void\>\): void addOutput\(cameraOutput: CameraOutput, callback: AsyncCallback<void\>\): void
Adds a **PhotoOutput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result. Adds a **[CameraOutput](#cameraoutput)** instance to this **CaptureSession**. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- | | ------------- | ------------------------------- | ---- | ------------------------ |
| photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to add.| | cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to add.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
captureSession.addOutput(photoOutput, (err) => { captureSession.addOutput(cameraOutput, (err) => {
if (err) { if (err) {
console.error('Failed to add the PhotoOutput instance ${err.message}'); console.error(`Failed to add output. ${err.message}`);
return; return;
} }
console.log('Callback invoked to indicate that the PhotoOutput instance is added.'); console.log('Callback returned with output added.');
}); })
``` ```
### addOutput ### addOutput
addOutput\(photoOutput: PhotoOutput\): Promise<void\> addOutput\(cameraOutput: CameraOutput\): Promise<void\>
Adds a **PhotoOutput** instance to this **CaptureSession** instance. This API uses a promise to return the result. Adds a **[CameraOutput](#cameraoutput)** instance to this **CaptureSession**. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- | | ------------- | ------------------------------- | ---- | ------------------------- |
| photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to add.| | cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to add.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | -------------- | ----------------------- |
| Promise\<void> | Promise used to return the result.| | Promise<void\>| Promise used to return the result.|
**Example** **Example**
```js ```js
captureSession.addOutput(photoOutput).then(() => { captureSession.addOutput(cameraOutput).then(() => {
console.log('Promise used to indicate that the PhotoOutput instance is added.'); console.log('Promise returned with cameraOutput added.');
}) })
``` ```
### addOutput ### removeOutput
addOutput\(videoOutput: VideoOutput, callback: AsyncCallback<void\>\): void removeOutput\(cameraOutput: CameraOutput, callback: AsyncCallback<void\>\): void
Adds a **VideoOutput** instance to this **CaptureSession** instance. This API uses an asynchronous callback to return the result. Removes a **[CameraOutput](#cameraoutput)** instance from this **CaptureSession**. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- | | ------------- | ------------------------------- | ---- | ------------------------ |
| videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to add.| | cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to remove.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
captureSession.addOutput(videoOutput, (err) => { captureSession.removeOutput(cameraOutput, (err) => {
if (err) { if (err) {
console.error('Failed to add the VideoOutput instance ${err.message}'); console.error(`Failed to remove the CameraOutput instance. ${err.message}`);
return; return;
} }
console.log('Callback invoked to indicate that the VideoOutput instance is added.'); console.log('Callback invoked to indicate that the CameraOutput instance is removed.');
}); });
``` ```
### addOutput ### removeOutput
addOutput\(videoOutput: VideoOutput\): Promise<void\> removeOutput(cameraOutput: CameraOutput): Promise<void\>
Adds a **VideoOutput** instance to this **CaptureSession** instance. This API uses a promise to return the result. Removes a **[CameraOutput](#cameraoutput)** instance from this **CaptureSession**. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- | | ------------- | ------------------------------- | ---- | ------------------------- |
| videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to add.| | cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to remove.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | -------------- | ------------------------ |
| Promise\<void> | Promise used to return the result.| | Promise<void\>| Promise used to return the result.|
**Example** **Example**
```js ```js
captureSession.addOutput(videoOutput).then(() => { captureSession.removeOutput(cameraOutput).then(() => {
console.log('Promise used to indicate that the VideoOutput instance is added.'); console.log('Promise returned to indicate that the CameraOutput instance is removed.');
}) })
``` ```
### removeInput ### start
removeInput\(cameraInput: CameraInput, callback: AsyncCallback<void\>\): void start\(callback: AsyncCallback<void\>\): void
Removes a **CameraInput** instance from this **CaptureSession** instance. This API uses an asynchronous callback to return the result. Starts this **CaptureSession**. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- | | -------- | -------------------- | ---- | -------------------- |
| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to remove.| | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
captureSession.removeInput(cameraInput, (err) => { captureSession.start((err) => {
if (err) { if (err) {
console.error('Failed to remove the CameraInput instance. ${err.message}'); console.error(`Failed to start the session ${err.message}`);
return; return;
} }
console.log('Callback invoked to indicate that the cameraInput instance is removed.'); console.log('Callback invoked to indicate the session start success.');
}); });
``` ```
### removeInput ### start
removeInput\(cameraInput: CameraInput\): Promise<void\> start\(\): Promise<void\>
Removes a **CameraInput** instance from this **CaptureSession** instance. This API uses a promise to return the result. Starts this **CaptureSession**. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput | [CameraInput](#camerainput) | Yes | **CameraInput** instance to remove.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | -------------- | ------------------------ |
| Promise\<void> | Promise used to return the result.| | Promise<void\>| Promise used to return the result.|
**Example** **Example**
```js ```js
captureSession.removeInput(cameraInput).then(() => { captureSession.start().then(() => {
console.log('Promise returned to indicate that the cameraInput instance is removed.'); console.log('Promise returned to indicate the session start success.');
}) })
``` ```
### removeOutput ### stop
removeOutput\(previewOutput: PreviewOutput, callback: AsyncCallback<void\>\): void stop\(callback: AsyncCallback<void\>\): void
Removes a **PreviewOutput** instance from this **CaptureSession** instance. This API uses an asynchronous callback to return the result. Stops this **CaptureSession**. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------------- | ------------------------------- | ---- | ----------------------------- | | -------- | -------------------- | ---- | ------------------- |
| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to remove.| | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
captureSession.removeOutput(previewOutput, (err) => { captureSession.stop((err) => {
if (err) { if (err) {
console.error('Failed to remove the PreviewOutput instance. ${err.message}'); console.error(`Failed to stop the session ${err.message}`);
return; return;
} }
console.log('Callback invoked to indicate that the PreviewOutput instance is removed.'); console.log('Callback invoked to indicate the session stop success.');
}); });
``` ```
### removeOutput ### stop
removeOutput(previewOutput: PreviewOutput): Promise<void\> stop(): Promise<void\>
Removes a **PreviewOutput** instance from this **CaptureSession** instance. This API uses a promise to return the result. Stops this **CaptureSession**. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to remove.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | -------------- | ----------------------- |
| Promise<void\>| Promise used to return the result.| | Promise<void\>| Promise used to return the result.|
**Example** **Example**
```js ```js
captureSession.removeOutput(previewOutput).then(() => { captureSession.stop().then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is removed.'); console.log('Promise returned to indicate the session stop success.');
}) })
``` ```
### removeOutput ### release
removeOutput(photoOutput: PhotoOutput, callback: AsyncCallback<void\>): void release\(callback: AsyncCallback<void\>\): void
Removes a **PhotoOutput** instance from this **CaptureSession** instance. This API uses an asynchronous callback to return the result. Releases this **CaptureSession**. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- | | -------- | -------------------- | ---- | -------------------- |
| photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to remove.| | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
captureSession.removeOutput(photoOutput, (err) => { captureSession.release((err) => {
if (err) { if (err) {
console.error('Failed to remove the PhotoOutput instance. ${err.message}'); console.error(`Failed to release the CaptureSession instance ${err.message}`);
return; return;
} }
console.log('Callback invoked to indicate that the PhotoOutput instance is removed.'); console.log('Callback invoked to indicate that the CaptureSession instance is released successfully.');
}); });
``` ```
### removeOutput ### release
removeOutput(photoOutput: PhotoOutput): Promise<void\> release(): Promise<void\>
Removes a **PhotoOutput** instance from this **CaptureSession** instance. This API uses a promise to return the result. Releases this **CaptureSession**. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput | [PhotoOutput](#photooutput) | Yes | **PhotoOutput** instance to remove.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | -------------- | ------------------------ |
| Promise<void\>| Promise used to return the result.| | Promise<void\>| Promise used to return the result.|
**Example** **Example**
```js ```js
captureSession.removeOutput(photoOutput).then(() => { captureSession.release().then(() => {
console.log('Promise returned to indicate that the PhotoOutput instance is removed.'); console.log('Promise returned to indicate that the CaptureSession instance is released successfully.');
}) })
``` ```
### removeOutput ### hasFlash
removeOutput(videoOutput: VideoOutput, callback: AsyncCallback<void\>): void hasFlash(callback: AsyncCallback<boolean\>): void
Removes a **VideoOutput** instance from this **CaptureSession** instance. 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.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- | | -------- | ----------------------- | ---- | -------------------------------- |
| videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to remove.| | callback | AsyncCallback<boolean\> | Yes | Callback used to return the flash support status. The value **true** means that the device has flash.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
captureSession.removeOutput(videoOutput, (err) => { captureSession.hasFlash((err, status) => {
if (err) { if (err) {
console.error('Failed to remove the VideoOutput instance. ${err.message}'); console.error(`Failed to check whether the device has flash light. ${err.message}`);
return; return;
} }
console.log('Callback invoked to indicate that the VideoOutput instance is removed.'); console.log(`Callback returned with flash light support status: ${status}`);
}); })
``` ```
### removeOutput ### hasFlash
removeOutput(videoOutput: VideoOutput): Promise<void\> hasFlash(): Promise<boolean\>
Removes a **VideoOutput** instance from this **CaptureSession** instance. This API uses a promise to return the result. Checks whether the device has flash. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput | [VideoOutput](#videooutput) | Yes | **VideoOutput** instance to remove.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | ----------------- | ----------------------------------------------- |
| Promise<void\>| Promise used to return the result.| | Promise<boolean\> | Promise used to return the flash support status. The value **true** means that the device has flash.|
**Example** **Example**
```js ```js
captureSession.removeOutput(videoOutput).then(() => { captureSession.hasFlash().then((status) => {
console.log('Promise returned to indicate that the VideoOutput instance is removed.'); console.log(`Promise returned with the flash light support status: ${status}`);
}) })
``` ```
### start ### isFlashModeSupported
start\(callback: AsyncCallback<void\>\): void isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback<boolean\>): void
Starts this **CaptureSession** instance. This API uses an asynchronous callback to return the result. Checks whether a specified flash mode is supported. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ | | --------- | ----------------------- | ---- | --------------------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.| | flashMode | [FlashMode](#flashmode) | Yes | Flash mode. |
| 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.|
**Example** **Example**
```js ```js
captureSession.start((err) => { captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO, (err, status) => {
if (err) { if (err) {
console.error('Failed to start the session ${err.message}'); console.error(`Failed to check whether the flash mode is supported. ${err.message}`);
return; return;
} }
console.log('Callback invoked to indicate the session start success.'); console.log(`Callback returned with the flash mode support status: ${status}`);
}); })
``` ```
### start ### isFlashModeSupported
start\(\): Promise<void\> isFlashModeSupported(flashMode: FlashMode): Promise<boolean\>
Starts this **CaptureSession** instance. This API uses a promise to return the result. Checks whether a specified flash mode is supported. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ----------------------- | ---- | ------------- |
| flashMode | [FlashMode](#flashmode) | Yes | Flash mode.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | ----------------- | ---------------------------------------------------- |
| Promise<void\>| Promise used to return the result.| | 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.|
**Example** **Example**
```js ```js
captureSession.start().then(() => { captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO).then((status) => {
console.log('Promise returned to indicate the session start success.'); console.log(`Promise returned with flash mode support status.${status}`);
}) })
``` ```
### stop ### setFlashMode
stop\(callback: AsyncCallback<void\>\): void setFlashMode(flashMode: FlashMode, callback: AsyncCallback<void\>): void
Sets the flash mode. This API uses an asynchronous callback to return the result.
Before the setting, do the following checks:
Stops this **CaptureSession** instance. This API uses an asynchronous callback to return the result. 1. Use **[hasFlash](#hasflash)** to check whether the device has flash.
2. Use **[isFlashModeSupported](#isflashmodesupported)** to check whether the device supports the flash mode.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ | | --------- | ----------------------- | ---- | --------------------- |
| flashMode | [FlashMode](#flashmode) | Yes | Flash mode. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
captureSession.stop((err) => { captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO, (err) => {
if (err) { if (err) {
console.error('Failed to stop the session ${err.message}'); console.error(`Failed to set the flash mode ${err.message}`);
return; return;
} }
console.log('Callback invoked to indicate the session stop success.'); console.log('Callback returned with the successful execution of setFlashMode.');
}); })
``` ```
### stop ### setFlashMode
stop(): Promise<void\> setFlashMode(flashMode: FlashMode): Promise<void\>
Sets a flash mode. This API uses a promise to return the result.
Before the setting, do the following checks:
Stops this **CaptureSession** instance. This API uses a promise to return the result. 1. Use **[hasFlash](#hasflash)** to check whether the device has flash.
2. Use **[isFlashModeSupported](#isflashmodesupported)** to check whether the device supports the flash mode.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ----------------------- | ---- | ------------- |
| flashMode | [FlashMode](#flashmode) | Yes | Flash mode.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | -------------- | ------------------------ |
| Promise<void\>| Promise used to return the result.| | Promise<void\>| Promise used to return the result.|
**Example** **Example**
```js ```js
captureSession.stop().then(() => { captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO).then(() => {
console.log('Promise returned to indicate the session stop success.'); console.log('Promise returned with the successful execution of setFlashMode.');
}) })
``` ```
### release ### getFlashMode
release\(callback: AsyncCallback<void\>\): void getFlashMode(callback: AsyncCallback<FlashMode\>): void
Releases this **CaptureSession** instance. This API uses an asynchronous callback to return the result. Obtains the flash mode in use. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ | | -------- | --------------------------------------- | ---- | --------------------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback<[FlashMode](#flashmode)\> | Yes | Callback used to return the flash mode.|
**Example** **Example**
```js ```js
captureSession.release((err) => { captureSession.getFlashMode((err, flashMode) => {
if (err) { if (err) {
console.error('Failed to release the CaptureSession instance ${err.message}'); console.error(`Failed to get the flash mode ${err.message}`);
return; return;
} }
console.log('Callback invoked to indicate that the CaptureSession instance is released successfully.'); console.log(`Callback returned with current flash mode: ${flashMode}`);
}); })
``` ```
### release ### getFlashMode
release(): Promise<void\> getFlashMode(): Promise<FlashMode\>
Releases this **CaptureSession** instance. This API uses a promise to return the result. Obtains the flash mode in use. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | --------------------------------- | --------------------------------- |
| Promise<void\>| Promise used to return the result.| | Promise<[FlashMode](#flashmode)\> | Promise used to return the flash mode.|
**Example** **Example**
```js ```js
captureSession.release().then(() => { captureSession.getFlashMode().then((flashMode) => {
console.log('Promise returned to indicate that the CaptureSession instance is released successfully.'); console.log(`Promise returned with current flash mode : ${flashMode}`);
}) })
``` ```
### on('error') ### isExposureModeSupported
on(type: 'error', callback: ErrorCallback<CaptureSessionError\>): void isExposureModeSupported(aeMode: ExposureMode, callback: AsyncCallback<boolean\>): void;
Listens for **CaptureSession** errors. This API uses a callback to return the errors. Checks whether a specified exposure mode is supported. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :------- | :---------------------------------------------------------- | :--- | :-------------------------------------------- | | -------- | -------------------------------| ---- | ----------------------------- |
| type | string | Yes | Event type. The value is fixed at **'error'**, indicating the capture session error event.| | aeMode | [ExposureMode](#exposuremode) | Yes | Exposure mode. |
| callback | ErrorCallback<[CaptureSessionError](#capturesessionerror)\> | Yes | Callback used to return the error information. | | 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.|
**Example** **Example**
```js ```js
captureSession.on('error', (captureSessionError) => { captureSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED,(err) => {
console.log('Capture session error code: ' + captureSessionError.code); if (err) {
console.log(`Failed to check exposure mode supported ${err.message}`);
return ;
}
console.log('Callback returned with the successful execution of isExposureModeSupported');
}) })
``` ```
## CaptureSessionErrorCode ### isExposureModeSupported
Enumerates the error codes used in a **CaptureSession** instance. isExposureModeSupported(aeMode: ExposureMode): Promise<boolean\>
Checks whether a specified exposure mode is supported. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description | **Parameters**
| ------------- | ---- | ---------- |
| ERROR_UNKNOWN | -1 | Unknown error.|
## CaptureSessionError | Name | Type | Mandatory | Description |
| -------- | -------------------------------| ---- | ----------------------------- |
| aeMode | [ExposureMode](#exposuremode) | Yes | Exposure mode. |
Defines a **CaptureSession** error. **Return value**
**System capability**: SystemCapability.Multimedia.Camera.Core | Name | Description |
| ----------------- |--------------------------------- |
| 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.|
| Name| Type | Description | **Example**
| ---- | ------------------------------------------- | -------------------------- |
| code | [CaptureSessionError](#capturesessionerror) | **CaptureSession** error code.|
## camera.createPreviewOutput ```js
captureSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED).then((isSupported) => {
console.log(`Promise returned with exposure mode supported : ${isSupported}`);
})
```
createPreviewOutput(surfaceId: string, callback: AsyncCallback<PreviewOutput\>): void ### getExposureMode
Creates a **PreviewOutput** instance. This API uses an asynchronous callback to return the result. getExposureMode(callback: AsyncCallback<ExposureMode\>): void
Obtains the exposure mode in use. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ----------------------------------------------- | ---- | ------------------------------------- | | -------- | -------------------------------| ---- | ---------------------------------------- |
| surfaceId | string | Yes | Surface ID, which is obtained from **XComponent**. | | callback | AsyncCallback<[ExposureMode](#exposuremode)\> | Yes | Callback used to return the exposure mode.|
| callback | AsyncCallback<[PreviewOutput](#previewoutput)\> | Yes | Callback used to return the **PreviewOutput** instance.|
**Example** **Example**
```js ```js
camera.createPreviewOutput(("surfaceId"), (err, previewOutput) => { captureSession.getExposureMode((err, exposureMode) => {
if (err) { if (err) {
console.error('Failed to create the PreviewOutput instance. ${err.message}'); console.log(`Failed to get the exposure mode ${err.message}`);
return; return ;
} }
console.log('Callback returned with previewOutput instance'); console.log(`Callback returned with current exposure mode: ${exposureMode}`);
}); })
``` ```
## camera.createPreviewOutput ### getExposureMode
createPreviewOutput(surfaceId: string): Promise\<PreviewOutput> getExposureMode(): Promise<ExposureMode\>
Creates a **PreviewOutput** instance. This API uses a promise to return the result. Obtains the exposure mode in use. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Name | Description |
| --------------------------------------- |------------------------------- |
| Promise<[ExposureMode](#exposuremode)\> | Promise used to return the exposure mode.|
**Example**
```js
captureSession.getExposureMode().then((exposureMode) => {
console.log(`Promise returned with current exposure mode : ${exposureMode}`);
})
```
### setExposureMode
setExposureMode(aeMode: ExposureMode, callback: AsyncCallback<void\>): void
Sets an exposure mode. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ------ | ---- | ---------------------------------- | | -------- | -------------------------------| ---- | ----------------------- |
| surfaceId | string | Yes | Surface ID, which is obtained from **XComponent**.| | aeMode | [ExposureMode](#exposuremode) | Yes | Exposure mode. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```js
captureSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED,(err) => {
if (err) {
console.log(`Failed to set the exposure mode ${err.message}`);
return ;
}
console.log('Callback returned with the successful execution of setExposureMode');
})
```
### setExposureMode
setExposureMode(aeMode: ExposureMode): Promise<void\>
Sets an exposure mode. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value** **Return value**
| Type | Description | | Name | Description |
| ----------------------------------------- | --------------------------- | | ----------------- |---------------------------- |
| Promise<[PreviewOutput](#previewoutput)\> | Promise used to return the result.| | Promise<void\> | Promise used to return the result.|
**Example** **Example**
```js ```js
camera.createPreviewOutput("surfaceId").then((previewOutput) => { captureSession.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_LOCKED).then(() => {
console.log('Promise returned with the PreviewOutput instance'); console.log('Promise returned with the successful execution of setExposureMode.');
}) })
``` ```
## PreviewOutput ### getMeteringPoint
Implements preview output.
### release
release(callback: AsyncCallback<void\>): void getMeteringPoint(callback: AsyncCallback<Point\>): void
Releases this **PreviewOutput** instance. This API uses an asynchronous callback to return the result. Obtains the center of the metering area. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ | | -------- | -------------------------------| ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback<[Point](#point)\>| Yes | Callback used to return the center of the metering area.|
**Example** **Example**
```js ```js
previewOutput.release((err) => { captureSession.getMeteringPoint((err, exposurePoint) => {
if (err) { if (err) {
console.error('Failed to release the PreviewOutput instance ${err.message}'); console.log(`Failed to get the current exposure point ${err.message}`);
return; return ;
} }
console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.'); console.log(`Callback returned with current exposure point: ${exposurePoint}`);
}); })
``` ```
### release ### getMeteringPoint
release(): Promise<void\> getMeteringPoint(): Promise<Point\>
Releases this **PreviewOutput** instance. This API uses a promise to return the result. Obtains the center of the metering area. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Return value** **Return value**
| Type | Description | | Name | Description |
| -------------- | --------------------------- | | ------------------------- |----------------------------- |
| Promise<void\>| Promise used to return the result.| | Promise<[Point](#point)\> | Promise used to return the center of the metering area.|
**Example** **Example**
```js ```js
previewOutput.release().then(() => { captureSession.getMeteringPoint().then((exposurePoint) => {
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.'); console.log(`Promise returned with current exposure point : ${exposurePoint}`);
}) })
``` ```
### on('frameStart') ### setMeteringPoint
on(type: 'frameStart', callback: AsyncCallback<void\>): void setMeteringPoint(point: Point, callback: AsyncCallback<void\>): void
Listens for preview frame start events. This API uses an asynchronous callback to return the result. Sets the center of the metering area. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| :------- | :------------------- | :--- | :------------------------------------------- | | ------------- | -------------------------------| ---- | ------------------- |
| type | string | Yes | Event type. The value is fixed at **'frameStart'**, indicating the preview frame start event.| | exposurePoint | [Point](#point) | Yes | Exposure point. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
previewOutput.on('frameStart', () => { const Point1 = {x: 1, y: 1};
console.log('Preview frame started');
captureSession.setMeteringPoint(Point1,(err) => {
if (err) {
console.log(`Failed to set the exposure point ${err.message}`);
return ;
}
console.log('Callback returned with the successful execution of setMeteringPoint');
}) })
``` ```
### on('frameEnd') ### setMeteringPoint
on(type: 'frameEnd', callback: AsyncCallback<void\>): void setMeteringPoint(point: Point): Promise<void\>
Listens for preview frame end events. This API uses an asynchronous callback to return the result. Sets the center of the metering area. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| :------- | :------------------- | :--- | :----------------------------------------- | | ------------- | -------------------------------| ---- | ------------------- |
| type | string | Yes | Event type. The value is fixed at **'frameEnd'**, indicating the preview frame end event.| | exposurePoint | [Point](#point) | Yes | Exposure point. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Return value**
| Name | Description |
| ----------------- |------------------------ |
| Promise<void\> | Promise used to return the center of the metering area.|
**Example** **Example**
```js ```js
previewOutput.on('frameEnd', () => { const Point2 = {x: 2, y: 2};
console.log('Preview frame ended');
captureSession.setMeteringPoint(Point2).then(() => {
console.log('Promise returned with the successful execution of setMeteringPoint');
}) })
``` ```
### on('error') ### getExposureBiasRange
on(type: 'error', callback: ErrorCallback<PreviewOutputError\>): void getExposureBiasRange(callback: AsyncCallback<Array<number\>\>): void
Listens for **PreviewOutput** errors. This API uses a callback to return the errors. Obtains the exposure compensation values. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| :------- | :----------------------------------------------------------- | :--- | :-------------------------------------------- | | -------- | -------------------------------| ---- | ----------------------------- |
| type | string | Yes | Event type. The value is fixed at **'error'**, indicating the preview output error event.| | callback | AsyncCallback<Array<number\>\> | Yes | Callback used to return the array of compensation values.|
| callback | ErrorCallback<[PreviewOutputErrorCode](#previewoutputerrorcode)\> | Yes | Callback used to return the error information. |
**Example** **Example**
```js ```js
previewOutput.on('error', (previewOutputError) => { captureSession.getExposureBiasRange((err, biasRangeArray) => {
console.log('Preview output error code: ' + previewOutputError.code); if (err) {
console.log(`Failed to get the array of compenstation range ${err.message}`);
return ;
}
console.log('Callback returned with the array of compenstation range: ' + JSON.stringify(biasRangeArray));
}) })
``` ```
## PreviewOutputErrorCode ### getExposureBiasRange
getExposureBiasRange(): Promise<Array<number\>\>
Enumerates the error codes used in a **PreviewOutput** instance. Obtains the exposure compensation values. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description | **Return value**
| ------------- | ---- | ---------- |
| ERROR_UNKNOWN | -1 | Unknown error.|
## PreviewOutputError | Name | Description |
| ----------------- |-------------------------------------- |
| Promise<Array<number\>\> | Promise used to return the array of compensation values.|
Defines a **PreviewOutput** error. **Example**
**System capability**: SystemCapability.Multimedia.Camera.Core ```js
captureSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED).then((isSupported) => {
console.log(`Promise returned with exposure mode supported : ${isSupported}`);
})
```
| Name| Type | Description | ### setExposureBias
| ---- | ------------------------------------------------- | ---------------------- |
| code | [PreviewOutputErrorCode](#previewoutputerrorcode) | **PreviewOutput** error code.|
## camera.createPhotoOutput setExposureBias(exposureBias: number, callback: AsyncCallback<void\>): void
createPhotoOutput(surfaceId: string, callback: AsyncCallback<PhotoOutput\>): void Sets an exposure compensation value. This API uses an asynchronous callback to return the result.
Creates a **PhotoOutput** instance. This API uses an asynchronous callback to return the result. Before the setting, you are advised to use **[getExposureBiasRange](#getexposurebiasrange)** to obtain the supported values.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ------------------------------------------- | ---- | ----------------------------------- | | -------- | -------------------------------| ---- | ------------------- |
| surfaceId | string | Yes | Surface ID, which is obtained from **[ImageReceiver](js-apis-image.md#imagereceiver9)**. | | exposureBias | number | Yes | Compensation value. |
| callback | AsyncCallback<[PhotoOutput](#photooutput)\> | Yes | Callback used to return the **PhotoOutput** instance.| | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
camera.createPhotoOutput(("surfaceId"), (err, photoOutput) => { captureSession.setExposureBias(-4,(err) => {
if (err) { if (err) {
console.error('Failed to create the PhotoOutput instance. ${err.message}'); console.log(`Failed to set the exposure bias ${err.message}`);
return; return ;
} }
console.log('Callback returned with the PhotoOutput instance.'); console.log('Callback returned with the successful execution of setExposureBias');
}); })
``` ```
## camera.createPhotoOutput ### setExposureBias
createPhotoOutput(surfaceId: string): Promise<PhotoOutput\> setExposureBias(exposureBias: number): Promise<void\>
Creates a **PhotoOutput** instance. This API uses a promise to return the result. Sets an exposure compensation value. This API uses a promise to return the result.
Before the setting, you are advised to use **[getExposureBiasRange](#getexposurebiasrange)** to obtain the supported values.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ------ | ---- | --------------------------------- | | -------------- | --------- | ---- | --------- |
| surfaceId | string | Yes | Surface ID, which is obtained from **[ImageReceiver](js-apis-image.md#imagereceiver9)**.| | exposureBias | number | Yes | Compensation value. |
**Return value** **Return value**
| Type | Description | | Name | Description |
| ------------------------------------- | -------------------------------------- | | ----------------- |------------------------- |
| Promise<[PhotoOutput](#photooutput)\> | Promise used to return the **PhotoOutput** instance.| | Promise<void\> | Promise used to return the result.|
**Example** **Example**
```js ```js
camera.createPhotoOutput("surfaceId").then((photoOutput) => { captureSession.setExposureBias(-4).then(() => {
console.log('Promise returned with PhotoOutput instance'); console.log('Promise returned with the successful execution of setExposureBias.');
}) })
``` ```
## ImageRotation
Enumerates the image rotation angles. ### getExposureValue
getExposureValue(callback: AsyncCallback<number\>): void
Obtains the exposure value in use. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description | **Parameters**
| ------------ | ---- | --------------- |
| ROTATION_0 | 0 | The image rotates 0 degrees. |
| ROTATION_90 | 90 | The image rotates 90 degrees. |
| ROTATION_180 | 180 | The image rotates 180 degrees.|
| ROTATION_270 | 270 | The image rotates 270 degrees.|
## QualityLevel | Name | Type | Mandatory| Description |
| -------- | ------------------------| ---- | --------------------- |
| callback | AsyncCallback<number\> | Yes | Callback used to the exposure value.|
Enumerates the image quality levels. **Example**
```js
captureSession.getExposureValue((err, exposureValue) => {
if (err) {
console.log(`Failed to get the exposure value ${err.message}`);
return ;
}
console.log(`Callback returned with the exposure value: ${exposureValue}`);
})
```
### getExposureValue
getExposureValue(): Promise<number\>
Obtains the exposure value in use. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Name | Description |
| ----------------- |-------------------------- |
| Promise<number\> | Promise used to the exposure value.|
**Example**
```js
captureSession.getExposureValue().then((exposureValue) => {
console.log(`Promise returned with exposure value: ${exposureValude}`);
})
```
### isFocusModeSupported
isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback<boolean\>): void
Checks whether a specified focus mode is supported. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------- |
| afMode | [FocusMode](#focusmode) | Yes | Focus mode. |
| 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.|
**Example**
```js
captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO, (err, status) => {
if (err) {
console.error(`Failed to check whether the focus mode is supported. ${err.message}`);
return;
}
console.log(`Callback returned with the focus mode support status: ${status}`);
})
```
### isFocusModeSupported
isFocusModeSupported(afMode: FocusMode): Promise<boolean\>
Checks whether a specified focus mode is supported. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------ | ----------------------- | ---- | ------------- |
| afMode | [FocusMode](#focusmode) | Yes | Focus mode.|
**Return value**
| Type | Description |
| ----------------- | --------------------------------------------------- |
| 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.|
**Example**
```js
captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_AUTO).then((status) => {
console.log(`Promise returned with focus mode support status ${status}.`);
})
```
### setFocusMode
setFocusMode(afMode: FocusMode, callback: AsyncCallback<void\>): void
Sets a focus mode. This API uses an asynchronous callback to return the result.
Before the setting, use **[isFocusModeSupported](#isfocusmodesupported)** to check whether the focus mode is supported.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ------------------- |
| afMode | [FocusMode](#focusmode) | Yes | Focus mode. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```js
captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO, (err) => {
if (err) {
console.error(`Failed to set the focus mode ${err.message}`);
return;
}
console.log('Callback returned with the successful execution of setFocusMode.');
})
```
### setFocusMode
setFocusMode(afMode: FocusMode): Promise<void\>
Sets a focus mode. This API uses a promise to return the result.
Before the setting, use **[isFocusModeSupported](#isfocusmodesupported)** to check whether the focus mode is supported.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------ | ----------------------- | ---- | ------------- |
| afMode | [FocusMode](#focusmode) | Yes | Focus mode.|
**Return value**
| Type | Description |
| -------------- | ------------------------ |
| Promise<void\>| Promise used to return the result.|
**Example**
```js
captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO).then(() => {
console.log('Promise returned with the successful execution of setFocusMode.');
})
```
### getFocusMode
getFocusMode(callback: AsyncCallback<FocusMode\>): void
Obtains the focus mode in use. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ------------------------------- |
| callback | AsyncCallback<[FocusMode](#focusmode)\> | Yes | Callback used to return the focus mode.|
**Example**
```js
captureSession.getFocusMode((err, afMode) => {
if (err) {
console.error(`Failed to get the focus mode ${err.message}`);
return;
}
console.log(`Callback returned with current focus mode: ${afMode}`);
})
```
### getFocusMode
getFocusMode(): Promise<FocusMode\>
Obtains the focus mode in use. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ------------------- | -------------------------------- |
| Promise<FocusMode\> | Promise used to return the focus mode.|
**Example**
```js
captureSession.getFocusMode().then((afMode) => {
console.log(`Promise returned with current focus mode : ${afMode}`);
})
```
### setFocusPoint
setFocusPoint(point: Point, callback: AsyncCallback<void\>): void
Sets a focus point. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ------------------- |
| point | [Point](#point) | Yes | Focal point. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```js
const Point1 = {x: 1, y: 1};
captureSession.setFocusPoint(Point1, (err) => {
if (err) {
console.error(`Failed to set the focus point ${err.message}`);
return;
}
console.log('Callback returned with the successful execution of setFocusPoint.');
})
```
### setFocusPoint
setFocusPoint(point: Point): Promise<void\>
Sets a focal point. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ------------------- |
| point | [Point](#point) | Yes | Focal point. |
**Return value**
| Type | Description |
| -------------- | ----------------------- |
| Promise<void\>| Promise used to return the result.|
**Example**
```js
const Point2 = {x: 2, y: 2};
captureSession.setFocusPoint(Point2).then(() => {
console.log('Promise returned with the successful execution of setFocusPoint.');
})
```
### getFocusPoint
getFocusPoint(callback: AsyncCallback<Point\>): void
Obtains the focal point. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | ----------------------- |
| callback | AsyncCallback<[Point](#point)\> | Yes | Callback used to return the focal point.|
**Example**
```js
captureSession.getFocusPoint((err, point) => {
if (err) {
console.error(`Failed to get the current focus point ${err.message}`);
return;
}
console.log('Callback returned with the current focus point: ' + JSON.stringify(point));
})
```
### getFocusPoint
getFocusPoint(): Promise<Point\>
Obtains the focal point. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| --------------- | --------------------------- |
| Promise<Point\> | Promise used to return the focal point.|
**Example**
```js
captureSession.getFocusPoint().then((point) => {
console.log('Promise returned with the current focus point: ' + JSON.stringify(point));
})
```
### getFocalLength
getFocalLength(callback: AsyncCallback<number\>): void
Obtains the focal length. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ----------------------- |
| callback | AsyncCallback<number\> | Yes | Callback used to return the focal length.|
**Example**
```js
captureSession.getFocalLength((err, focalLength) => {
if (err) {
console.error(`Failed to get the current focal length ${err.message}`);
return;
}
console.log(`Callback returned with the current focal length: ${focalLength}`);
})
```
### getFocalLength
getFocalLength(): Promise<number\>
Obtains the focal length. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------------- | ----------------------- |
| Promise<number\> | Promise used to return the focal length.|
**Example**
```js
captureSession.getFocalLength().then((focalLength) => {
console.log(`Promise returned with the current focal length: ${focalLength}`);
})
```
### getZoomRatioRange
getZoomRatioRange\(callback: AsyncCallback<Array<number\>\>\): void
Obtains the zoom ratio range. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------ | ---- | ------------------- |
| callback | AsyncCallback<Array<number\>\> | Yes | Callback used to return an array containing the minimum and maximum zoom ratios.|
**Example**
```js
captureSession.getZoomRatioRange((err, zoomRatioRange) => {
if (err) {
console.error(`Failed to get the zoom ratio range. ${err.message}`);
return;
}
console.log(`Callback returned with zoom ratio range: ${zoomRatioRange.length}`);
})
```
### getZoomRatioRange
getZoomRatioRange\(\): Promise<Array<number\>\>
Obtains the zoom ratio range. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ------------------------ | --------------------------- |
| Promise<Array<number\>\> | Promise used to return an array containing the minimum and maximum zoom ratios.|
**Example**
```js
captureSession.getZoomRatioRange().then((zoomRatioRange) => {
console.log(`Promise returned with zoom ratio range: ${zoomRatioRange.length}`);
})
```
### setZoomRatio
setZoomRatio(zoomRatio: number, callback: AsyncCallback<void\>): void
Sets a zoom ratio. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | -------------------- | ---- | ------------------- |
| zoomRatio | number | Yes | Zoom ratio. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```js
captureSession.setZoomRatio(1, (err) => {
if (err) {
console.error(`Failed to set the zoom ratio value ${err.message}`);
return;
}
console.log('Callback returned with the successful execution of setZoomRatio.');
})
```
### setZoomRatio
setZoomRatio(zoomRatio: number): Promise<void\>
Sets a zoom ratio. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | --------- |
| zoomRatio | number | Yes | Zoom ratio.|
**Return value**
| Type | Description |
| -------------- | ----------------------- |
| Promise<void\>| Promise used to return the result.|
**Example**
```js
captureSession.setZoomRatio(1).then(() => {
console.log('Promise returned with the successful execution of setZoomRatio.');
})
```
### getZoomRatio
getZoomRatio(callback: AsyncCallback<number\>): void
Obtains the zoom ratio in use. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------- |
| callback | AsyncCallback<number\> | Yes | Callback used to return the result.|
**Example**
```js
captureSession.getZoomRatio((err, zoomRatio) => {
if (err) {
console.error(`Failed to get the zoom ratio ${err.message}`);
return;
}
console.log(`Callback returned with current zoom ratio: ${zoomRatio}`);
})
```
### getZoomRatio
getZoomRatio(): Promise<number\>
Obtains the zoom ratio in use. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------------- | ----------------------- |
| Promise<number\> | Promise used to return the zoom ratio.|
**Example**
```js
captureSession.getZoomRatio().then((zoomRatio) => {
console.log(`Promise returned with current zoom ratio : ${zoomRatio}`);
})
```
### isVideoStabilizationModeSupported
isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode, callback: AsyncCallback<boolean\>): void
Checks whether the specified video stabilization mode is supported. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | ------------------------------ |
| vsMode | [VideoStabilizationMode](#videostabilizationmode) | Yes | Video stabilization mode. |
| 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. |
**Example**
```js
captureSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF, (err, isSupported) => {
if (err) {
console.error(`Failed to check whether video stabilization mode supported. ${err.message}`);
return;
}
console.log(`Callback returned with the successful execution of isVideoStabilizationModeSupported`);
})
```
### isVideoStabilizationModeSupported
isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): Promise<boolean\>
Checks whether the specified video stabilization mode is supported. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ----------------- | --------------------------------------------- |
| 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.|
**Example**
```js
captureSession.isVideoStabilizationModeSupported(camera.VideoStabilizationMode.OFF).then((isSupported) => {
console.log(`Promise returned with video stabilization mode supported: ${isSupported}`);
})
```
### getActiveVideoStabilizationMode
getActiveVideoStabilizationMode(callback: AsyncCallback<VideoStabilizationMode\>): void
Obtains the video stabilization mode in use. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------------ |
| callback | AsyncCallback<VideoStabilizationMode\> | Yes | Callback used to return the video stabilization mode. |
**Example**
```js
captureSession.getActiveVideoStabilizationMode((err, vsMode) => {
if (err) {
console.error(`Failed to get active video stabilization mode ${err.message}`);
return;
}
console.log('Callback returned with the successful execution of getActiveVideoStabilizationMode.');
})
```
### getActiveVideoStabilizationMode
getActiveVideoStabilizationMode(): Promise<VideoStabilizationMode\>
Obtains the video stabilization mode in use. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------------------------- | ------------------------------------------------- |
| Promise<VideoStabilizationMode\> | Promise used to return the video stabilization mode. |
**Example**
```js
captureSession.getActiveVideoStabilizationMode().then((vsMode) => {
console.log(`Promise returned with the current video stabilization mode: ${vsMode}`);
})
```
### setVideoStabilizationMode
setVideoStabilizationMode(mode: VideoStabilizationMode, callback: AsyncCallback<void\>): void
Sets a video stabilization mode. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | --------------------- |
| mode | [VideoStabilizationMode](#videostabilizationmode) | Yes | Video stabilization mode. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example**
```js
captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF, (err) => {
if (err) {
console.error(`Failed to set the video stabilization mode ${err.message}`);
return;
}
console.log('Callback returned with the successful execution of setVideoStabilizationMode.');
})
```
### setVideoStabilizationMode
setVideoStabilizationMode(mode: VideoStabilizationMode): Promise<void\>
Sets a video stabilization mode. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | --------------------- |
| mode | [VideoStabilizationMode](#videostabilizationmode) | Yes | Video stabilization mode. |
**Return value**
| Type | Description |
| -------------- | ------------------------------------------------- |
| Promise<void\>| Promise used to return the result. |
**Example**
```js
captureSession.setVideoStabilizationMode(camera.VideoStabilizationMode.OFF).then(() => {
console.log('Promise returned with the successful execution of setVideoStabilizationMode.');
})
```
### on('focusStateChange')
on(type: 'focusStateChange', callback: AsyncCallback<FocusState\>): void
Listens for focus state changes. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------ |
| type | string | Yes | Event type. The value is fixed at **'focusStateChange'**, indicating the focus state change event.|
| callback | AsyncCallback<[FocusState](#focusstate)\> | Yes | Callback used to return the focus state change. |
**Example**
```js
captureSession.on('focusStateChange', (focusState) => {
console.log(`Focus state : ${focusState}`);
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<CaptureSessionError\>): void
Listens for **CaptureSession** errors. This API uses a callback to return the errors.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'error'**, indicating the capture session error event.|
| callback | ErrorCallback<[CaptureSessionError](#capturesessionerror)\> | Yes | Callback used to return the error information. |
**Example**
```js
captureSession.on('error', (captureSessionError) => {
console.log(`Capture session error code: ${captureSessionError.code}`);
})
```
## CaptureSessionErrorCode
Enumerates the error codes used in a **CaptureSession**.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| ----------------------------- | ---- | -------- |
| ERROR_UNKNOWN | -1 | Unknown error.|
| ERROR_INSUFFICIENT_RESOURCES | 0 | Insufficient resources.|
| ERROR_TIMEOUT | 1 | Timeout.|
## CaptureSessionError
Defines a **CaptureSession** error.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name| Type | Description |
| ---- | ------------------------------------------- | -------------------------- |
| code | [CaptureSessionError](#capturesessionerror) | **CaptureSession** error code.|
## CameraOutput
Implements output information used in a **[CaptureSession](#capturesession)**. It is the base class of **output**.
### release
release(callback: AsyncCallback<void\>): void
Releases output resources. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```js
cameraOutput.release((err) => {
if (err) {
console.error(`Failed to release the PreviewOutput instance ${err.message}`);
return;
}
console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
});
```
### release
release(): Promise<void\>
Releases output resources. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | ----------------------- |
| Promise<void\>| Promise used to return the result.|
**Example**
```js
cameraOutput.release().then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
})
```
## PreviewOutput
Implements preview output. It inherits **[CameraOutput](#cameraoutput)**.
### start
start(callback: AsyncCallback<void\>): void
Starts to output preview streams. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```js
previewOutput.start((err) => {
if (err) {
console.error(`Failed to start the previewOutput. ${err.message}`);
return;
}
console.log('Callback returned with previewOutput started.');
})
```
### start
start(): Promise<void\>
Starts to output preview streams. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | ----------------------- |
| Promise<void\>| Promise used to return the result.|
**Example**
```js
previewOutput.start().then(() => {
console.log('Promise returned with previewOutput started.');
})
```
### stop
stop(callback: AsyncCallback<void\>): void
Stops outputting preview streams. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```js
previewOutput.stop((err) => {
if (err) {
console.error(`Failed to stop the previewOutput. ${err.message}`);
return;
}
console.log('Callback returned with previewOutput stopped.');
})
```
### stop
stop(): Promise<void\>
Stops outputting preview streams. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| -------------- | ------------------------ |
| Promise<void\>| Promise used to return the result.|
**Example**
```js
previewOutput.stop().then(() => {
console.log('Callback returned with previewOutput stopped.');
})
```
### on('frameStart')
on(type: 'frameStart', callback: AsyncCallback<void\>): void
Listens for preview frame start events. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | --------------------------------------- |
| type | string | Yes | Event type. The value is fixed at **'frameStart'**, indicating the preview frame start event.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example**
```js
previewOutput.on('frameStart', () => {
console.log('Preview frame started');
})
```
### on('frameEnd')
on(type: 'frameEnd', callback: AsyncCallback<void\>): void
Listens for preview frame end events. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------------------- |
| type | string | Yes | Event type. The value is fixed at **'frameEnd'**, indicating the preview frame end event.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example**
```js
previewOutput.on('frameEnd', () => {
console.log('Preview frame ended');
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<PreviewOutputError\>): void
Listens for **PreviewOutput** errors. This API uses a callback to return the errors.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------------------------- | ---- | ------------------------ |
| type | string | Yes | Event type. The value is fixed at **'error'**, indicating the preview output error event.|
| callback | ErrorCallback<[PreviewOutputErrorCode](#previewoutputerrorcode)\> | Yes | Callback used to return the error information. |
**Example**
```js
previewOutput.on('error', (previewOutputError) => {
console.log(`Preview output error code: ${previewOutputError.code}`);
})
```
## PreviewOutputErrorCode
Enumerates the error codes used for preview output.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| ------------- | ---- | -------- |
| ERROR_UNKNOWN | -1 | Unknown error.|
## PreviewOutputError
Defines the preview output error.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name| Type | Description |
| ---- | ------------------------------------------------- | ---------------------- |
| code | [PreviewOutputErrorCode](#previewoutputerrorcode) | **PreviewOutput** error code.|
## ImageRotation
Enumerates the image rotation angles.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description |
| ------------ | ---- | ------------- |
| ROTATION_0 | 0 | The image rotates 0 degrees. |
| ROTATION_90 | 90 | The image rotates 90 degrees. |
| ROTATION_180 | 180 | The image rotates 180 degrees.|
| ROTATION_270 | 270 | The image rotates 270 degrees.|
## Location
Defines geolocation information.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Mandatory|Description |
| ------------ | ------ | --- |------------ |
| latitude | number | Yes |Latitude, in degrees. |
| longitude | number | Yes |Longitude, in degrees. |
| altitude | number | Yes |Altitude, in meters. |
## QualityLevel
Enumerates the image quality levels.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description | | Name | Value | Description |
| -------------------- | ---- | -------------- | | -------------------- | ---- | ------------ |
| QUALITY_LEVEL_HIGH | 0 | High image quality. | | QUALITY_LEVEL_HIGH | 0 | High image quality. |
| QUALITY_LEVEL_MEDIUM | 1 | Medium image quality.| | QUALITY_LEVEL_MEDIUM | 1 | Medium image quality.|
| QUALITY_LEVEL_LOW | 2 | Low image quality. | | QUALITY_LEVEL_LOW | 2 | Low image quality. |
## PhotoCaptureSetting ## PhotoCaptureSetting
Defines the settings for photo capture.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Mandatory | Default Value | Description |
| -------- | ------------------------------- | ---- | ----------------- | -----------------|
| quality | [QualityLevel](#qualitylevel) | No | QUALITY_LEVEL_HIGH| Photo quality. |
| rotation | [ImageRotation](#imagerotation) | No | ROTATION_0 | Rotation angle of the photo. |
| location | [Location](#location) | No | (0,0,0) | Geolocation information of the photo. |
| mirror | boolean | No | false |Whether mirroring is enabled. By default, mirroring is disabled.|
## PhotoOutput
Implements output information used in a **CaptureSession**.
### capture
capture(callback: AsyncCallback<void\>): void
Captures a photo with the default shooting parameters. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example**
```js
photoOutput.capture((err) => {
if (err) {
console.error(`Failed to capture the photo ${err.message}`);
return;
}
console.log('Callback invoked to indicate the photo capture request success.');
});
```
### capture
capture(setting: PhotoCaptureSetting, callback: AsyncCallback<void\>): void
Captures a photo with the specified shooting parameters. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------- | ---- | -------------------- |
| setting | [PhotoCaptureSetting](#photocapturesetting) | Yes | Shooting settings. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example**
```js
let settings:PhotoCaptureSetting = {
quality = 1,
rotation = 0
}
photoOutput.capture(settings, (err) => {
if (err) {
console.error(`Failed to capture the photo ${err.message}`);
return;
}
console.log('Callback invoked to indicate the photo capture request success.');
});
```
### capture
capture(setting?: PhotoCaptureSetting): Promise<void\>
Captures a photo with the specified shooting parameters. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------------------------------------------- | ---- | -------- |
| setting | [PhotoCaptureSetting](#photocapturesetting) | No | Shooting settings.|
**Return value**
| Type | Description |
| -------------- | ------------------------ |
| Promise<void\>| Promise used to return the result.|
**Example**
```js
photoOutput.capture().then(() => {
console.log('Promise returned to indicate that photo capture request success.');
})
```
### isMirrorSupported
isMirrorSupported(callback: AsyncCallback<boolean\>): void
Checks whether mirroring is supported. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | -------------------------- |
| 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. |
**Example**
```js
photoOutput.isMirrorSupported((err, isSupported) => {
if (err) {
console.error(`Failed to check mirror is supported ${err.message}`);
return;
}
console.log('Callback returned with the successful execution of isMirrorSupported.');
})
```
### isMirrorSupported
isMirrorSupported(): Promise<boolean\>
Checks whether mirroring is supported. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ----------------- | ------------------------------------------- |
| Promise<boolean\> | Promise used to return the mirroring support status. The value **true** means that mirroring is supported, and **false** means the opposite. |
**Example**
```js
photoOutput.isMirrorSupported().then((isSupported) => {
console.log(`Promise returned with mirror supported: ${isSupported}`);
})
```
### on('captureStart')
on(type: 'captureStart', callback: AsyncCallback<number\>): void
Listens for shooting start events. This API uses an asynchronous callback to return the capture ID.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'captureStart'**, indicating the shooting start event.|
| callback | AsyncCallback<number\> | Yes | Callback used to return the capture ID. |
**Example**
```js
photoOutput.on('captureStart', (err, captureId) => {
console.log(`photo capture stated, captureId : ${captureId}`);
})
```
### on('frameShutter')
on(type: 'frameShutter', callback: AsyncCallback<FrameShutterInfo\>): void
Listens for frame shutter events. This API uses an asynchronous callback to return the event information.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------------- | --- | ------------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'frameShutter'**, indicating the frame shutter event.|
| callback | AsyncCallback<[FrameShutterInfo](#frameshutterinfo)\> | Yes | Callback used to return the result. |
**Example**
```js
photoOutput.on('frameShutter', (err, frameShutterInfo) => {
console.log(`photo capture end, captureId : ${frameShutterInfo.captureId}`);
console.log(`Timestamp for frame : ${frameShutterInfo.timestamp}`);
})
```
### on('captureEnd')
on(type: 'captureEnd', callback: AsyncCallback<CaptureEndInfo\>): void
Listens for shooting end events. This API uses an asynchronous callback to return the event information.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is fixed at **'captureEnd'**, indicating the shooting end event.|
| callback | AsyncCallback<[CaptureEndInfo](#captureendinfo)\> | Yes | Callback used to return the result. |
**Example**
```js
photoOutput.on('captureEnd', (err, captureEndInfo) => {
console.log(`photo capture end, captureId : ${captureEndInfo.captureId}`);
console.log(`frameCount : ${captureEndInfo.frameCount}`);
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<PhotoOutputError\>): void
Listens for **PhotoOutput** errors. This API uses a callback to return the errors.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------------- | ---- | ----------------------------------- |
| type | string | Yes | Event type. The value is fixed at **'error'**, indicating the photo output error event.|
| callback | ErrorCallback<[PhotoOutputError](#photooutputerror)\> | Yes | Callback used to return the error information. |
**Example**
```js
photoOutput.on('error', (err, photoOutputError) => {
console.log(`Photo output error code: ${photoOutputError.code}`);
})
```
## FrameShutterInfo
Defines the frame shutter information.
**System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | ---------- |
| captureId | number | Yes | ID of this capture action. |
| timestamp | number | Yes | Timestamp when the frame shutter event is triggered.|
## CaptureEndInfo
Defines the settings for photo capture. Defines the capture end information.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | -------------- | | ---------- | ------ | ---- | ---------|
| quality | [QualityLevel](#qualitylevel) | No | Photo quality. | | captureId | number | Yes | ID of this capture action.|
| rotation | [ImageRotation](#imagerotation) | No | Rotation angle of the photo.| | frameCount | number | Yes | Number of frames captured. |
## PhotoOutputErrorCode
## PhotoOutput Enumerates the error codes used for photo output.
Implements photo output. **System capability**: SystemCapability.Multimedia.Camera.Core
### capture | Name | Value | Description |
| ----------------------------- | ---- | --------------- |
| ERROR_UNKNOWN | -1 | Unknown error. |
| ERROR_DRIVER_ERROR | 0 | The driver or hardware is faulty.|
| ERROR_INSUFFICIENT_RESOURCES | 1 | Insufficient resources. |
| ERROR_TIMEOUT | 2 | Timeout. |
capture(callback: AsyncCallback<void\>): void ## PhotoOutputError
Captures a photo with the default shooting settings. This API uses an asynchronous callback to return the result. Defines a photo output error.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** | Name| Type | Description |
| ---- | ------------------------------------- | ----------------------- |
| Name | Type | Mandatory| Description | | code | [PhotoOutputErrorCode](#photooutputerrorcode) | **PhotoOutput** error code.|
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** ## VideoOutput
```js Implements output information used in a video recording session.
photoOutput.capture((err) => {
if (err) {
console.error('Failed to capture the photo ${err.message}');
return;
}
console.log('Callback invoked to indicate the photo capture request success.');
});
```
### capture ### start
capture(setting: PhotoCaptureSetting, callback: AsyncCallback<void\>): void start(callback: AsyncCallback<void\>): void
Captures a photo with the specified shooting settings. This API uses an asynchronous callback to return the result. Starts video recording. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | -------------------- |
| setting | [PhotoCaptureSetting](#photocapturesetting) | Yes | Shooting settings. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
let settings:PhotoCaptureSetting = { videoOutput.start((err) => {
quality = 1,
rotation = 0
}
photoOutput.capture(settings, (err) => {
if (err) { if (err) {
console.error('Failed to capture the photo ${err.message}'); console.error(`Failed to start the video output ${err.message}`);
return; return;
} }
console.log('Callback invoked to indicate the photo capture request success.'); console.log('Callback invoked to indicate the video output start success.');
}); });
``` ```
### capture ### start
capture(setting?: PhotoCaptureSetting): Promise<void\> start(): Promise<void\>
Captures a photo with the specified shooting settings. This API uses a promise to return the result. Starts video recording. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------------------------------------------- | ---- | ---------- |
| setting | [PhotoCaptureSetting](#photocapturesetting) | No | Shooting settings.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | -------------- | ----------------------- |
| Promise<void\>| Promise used to return the result.| | Promise<void\>| Promise used to return the result.|
**Example** **Example**
```js ```js
photoOutput.capture().then(() => { videoOutput.start().then(() => {
console.log('Promise returned to indicate that photo capture request success.'); console.log('Promise returned to indicate that start method execution success.');
}) })
``` ```
### release ### stop
release(callback: AsyncCallback<void\>): void stop(callback: AsyncCallback<void\>): void
Releases this **PhotoOutput** instance. This API uses an asynchronous callback to return the result. Stops video recording. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
...@@ -2290,465 +3545,465 @@ Releases this **PhotoOutput** instance. This API uses an asynchronous callback t ...@@ -2290,465 +3545,465 @@ Releases this **PhotoOutput** instance. This API uses an asynchronous callback t
**Example** **Example**
```js ```js
photoOutput.release((err) => { videoOutput.stop((err) => {
if (err) { if (err) {
console.error('Failed to release the PhotoOutput instance ${err.message}'); console.error(`Failed to stop the video output ${err.message}`);
return; return;
} }
console.log('Callback invoked to indicate that the PhotoOutput instance is released successfully.'); console.log('Callback invoked to indicate the video output stop success.');
}); });
``` ```
### release ### stop
release(): Promise<void\> stop(): Promise<void\>
Releases this **PhotoOutput** instance. This API uses a promise to return the result. Stops video recording. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | -------------- | ----------------------- |
| Promise<void\>| Promise used to return the result.| | Promise<void\>| Promise used to return the result.|
**Example**
```js
photoOutput.release().then(() => {
console.log('Promise returned to indicate that the PhotoOutput instance is released successfully.');
})
```
### on('captureStart')
on(type: 'captureStart', callback: AsyncCallback<number\>): void
Listens for shooting start events. This API uses an asynchronous callback to return the capture ID.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| :------- | :--------------------- | :--- | :----------------------------------------------- |
| type | string | Yes | Event type. The value is fixed at **'captureStart'**, indicating the shooting start event.|
| callback | AsyncCallback<number\> | Yes | Callback used to return the capture ID. |
**Example** **Example**
```js ```js
photoOutput.on('captureStart', (err, captureId) => { videoOutput.stop().then(() => {
console.log('photo capture stated, captureId : ' + captureId); console.log('Promise returned to indicate that stop method execution success.');
}) })
``` ```
### on('frameShutter') ### on('frameStart')
on(type: 'frameShutter', callback: AsyncCallback<FrameShutterInfo\>): void on(type: 'frameStart', callback: AsyncCallback<void\>): void
Listens for frame shutter events. This API uses an asynchronous callback to return the event information. Listens for video recording start events. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------------------------------------- | :--- | :--------------------------------------------- | | -------- | -------------------- | ---- | ----------------------------------------- |
| 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 **`frameStart`**, indicating the video recording start event.|
| callback | AsyncCallback<[FrameShutterInfo](#frameshutterinfo)\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
photoOutput.on('frameShutter', (err, frameShutterInfo) => { videoOutput.on('frameStart', () => {
console.log('photo capture end, captureId : ' + frameShutterInfo.captureId); console.log('Video frame started');
console.log('Timestamp for frame : ' + frameShutterInfo.timestamp);
}) })
``` ```
### on('captureEnd') ### on('frameEnd')
on(type: 'captureEnd', callback: AsyncCallback<CaptureEndInfo\>): void on(type: 'frameEnd', callback: AsyncCallback<void\>): void
Listens for shooting end events. This API uses an asynchronous callback to return the event information. Listens for video recording stop events. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------------------------ | :--- | :--------------------------------------------- | | -------- | -------------------- | ---- | ------------------------------------------ |
| type | string | Yes | Event type. The value is fixed at **'captureEnd'**, indicating the shooting end event.| | type | string | Yes | Event type. The value is fixed at **'frameEnd'**, indicating the video recording stop event.|
| callback | AsyncCallback<[CaptureEndInfo](#captureendinfo)\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
photoOutput.on('captureEnd', (err, captureEndInfo) => { videoOutput.on('frameEnd', () => {
console.log('photo capture end, captureId : ' + captureEndInfo.captureId); console.log('Video frame ended');
console.log('frameCount : ' + captureEndInfo.frameCount);
}) })
``` ```
### on('error') ### on('error')
on(type: 'error', callback: ErrorCallback<PhotoOutputError\>): void on(type: 'error', callback: ErrorCallback<VideoOutputError\>): void
Listens for **PhotoOutput** errors. This API uses a callback to return the errors. Listens for errors that occur during video recording. This API uses a callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------------------------------------- | :--- | :---------------------------------------- | | -------- | ------------------------------------------------ | ---- | -------------------------------------- |
| type | string | Yes | Event type. The value is fixed at **'error'**, indicating the photo output error event.| | type | string | Yes | Event type. The value is fixed at **'error'**, indicating the video output error event.|
| callback | ErrorCallback<[PhotoOutputError](#photooutputerror)\> | Yes | Callback used to return the error information. | | callback | Callback<[VideoOutputError](#videooutputerror)\> | Yes | Callback used to return the error information. |
**Example** **Example**
```js ```js
photoOutput.on('error', (err, photoOutputError) => { videoOutput.on('error', (VideoOutputError) => {
console.log('Photo output error code: ' + photoOutputError.code); console.log(`Video output error code: ${VideoOutputError.code}`);
}) })
``` ```
## FrameShutterInfo ## VideoOutputErrorCode
Defines the frame shutter information. Enumerates the error codes used for video recording.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Mandatory| Description | | Name | Value | Description |
| --------- | ------ | ---- | ----------------------------- | | --------------------- | ---- | ------------ |
| captureId | number | Yes | ID of this capture action.| | ERROR_UNKNOWN | -1 | Unknown error. |
| timestamp | number | Yes | Timestamp when the frame shutter event is triggered. | | ERROR_DRIVER_ERROR | 0 | The driver or hardware is faulty.|
## CaptureEndInfo ## VideoOutputError
Defines the capture end information. Defines a video output error.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Type | Mandatory| Description | | Name| Type | Description |
| ---------- | ------ | ---- | ----------------------------- | | ---- | ------------------------------------- | ----------------------- |
| captureId | number | Yes | ID of this capture action.| | code | [PhotoOutputErrorCode](#photooutputerrorcode) | **VideoOutput** error code.|
| frameCount | number | Yes | Number of frames captured. |
## PhotoOutputErrorCode ## MetadataObjectType
Enumerates the error codes used in a **PhotoOutput** instance. Enumerates metadata streams.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description | | Name | Value | Description |
| ------------- | ---- | ---------- | | ------------------------- | ---- | ----------------- |
| ERROR_UNKNOWN | -1 | Unknown error.| | FACE_DETECTION | 0 | Metadata object type.|
## PhotoOutputError ## Rect
Defines a **PhotoOutput** error. Defines a rectangle.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name| Type | Description | | Name | Type | Description |
| ---- | ------------------------------------- | ----------------------- | | -------- | ------ | -------------------- |
| code | [PhotoOutputError](#photooutputerror) | **PhotoOutput** error code.| | topLeftX | number | X-axis coordinate of the upper left corner of the rectangle. |
| topLeftY | number | Y-axis coordinate of the upper left corner of the rectangle. |
| width | number | Width of the rectangle. |
| height | number | Height of the rectangle. |
## camera.createVideoOutput ## MetadataObject
createVideoOutput(surfaceId: string, callback: AsyncCallback<VideoOutput\>): void Implements camera metadata, which is the data source of **[CameraInput](#camerainput)**.
Creates a **VideoOutput** instance. This API uses an asynchronous callback to return the result. ### getType
getType(callback: AsyncCallback<MetadataObjectType\>): void
Obtains the metadata object type. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ------------------------------------------- | ---- | ----------------------------------- | | -------- | --------------------------------------------------------- | --- | -------------------- |
| surfaceId | string | Yes | Surface ID, which is obtained from **VideoRecorder**. | | callback | AsyncCallback<[MetadataObjectType](#metadataobjecttype)\> | Yes | Callback used to return the result.|
| callback | AsyncCallback<[VideoOutput](#videooutput)\> | Yes | Callback used to return the **VideoOutput** instance.|
**Example** **Example**
```js ```js
camera.createVideoOutput(("surfaceId"), (err, videoOutput) => { metadataObject.getType((err, metadataObjectType) => {
if (err) { if (err) {
console.error('Failed to create the VideoOutput instance. ${err.message}'); console.error(`Failed to get type. ${err.message}`);
return; return;
} }
console.log('Callback returned with the VideoOutput instance'); console.log('Callback returned with an array of metadataObjectType.');
}); })
``` ```
## camera.createVideoOutput ### getType
createVideoOutput(surfaceId: string): Promise<VideoOutput\> getType(): Promise<MetadataObjectType\>
Creates a **VideoOutput** instance. This API uses a promise to return the result. Obtains the metadata object type. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | --------------------------------- |
| surfaceId | string | Yes | Surface ID, which is obtained from **VideoRecorder**.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------------- | -------------------------------------- | | --------------------------------------------------- | --------------------------- |
| Promise<[VideoOutput](#videooutput)\> | Promise used to return the **VideoOutput** instance.| | Promise<[MetadataObjectType](#metadataobjecttype)\> | Promise used to return the result.|
**Example** **Example**
```js ```js
camera.createVideoOutput("surfaceId" metadataObject.getType().then((metadataObjectType) => {
).then((videoOutput) => { console.log('Callback returned with an array of metadataObjectType.');
console.log('Promise returned with the VideoOutput instance');
}) })
``` ```
## VideoOutput ### getTimestamp
Implements output information used in a video recording session.
### start
start(callback: AsyncCallback<void\>): void getTimestamp(callback: AsyncCallback<number\>): void
Starts video recording. This API uses an asynchronous callback to return the result. Obtains the metadata timestamp. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ | | -------- | ----------------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback<number\> | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
videoOutput.start((err) => { metadataObject.getTimestamp((err,timestamp) => {
if (err) { if (err) {
console.error('Failed to start the video output ${err.message}'); console.error(`Failed to get timestamp. ${err.message}`);
return; return;
} }
console.log('Callback invoked to indicate the video output start success.'); console.log('Callback returned with timestamp getted timestamp : ${timestamp}');
}); })
``` ```
### start ### getTimestamp
start(): Promise<void\> getTimestamp(): Promise<number\>
Starts video recording. This API uses a promise to return the result. Obtains the metadata timestamp. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | ---------------- | --------------------------- |
| Promise<void\>| Promise used to return the result.| | Promise<number)\> | Promise used to return the result.|
**Example** **Example**
```js ```js
videoOutput.start().then(() => { metadataObject.getTimestamp().then((timestamp) => {
console.log('Promise returned to indicate that start method execution success.'); console.log('Callback returned with timestamp getted timestamp : ${timestamp}');
}) })
``` ```
### stop ### getBoundingBox
stop(callback: AsyncCallback<void\>): void getBoundingBox(callback: AsyncCallback<Rect\>): void
Stops video recording. This API uses an asynchronous callback to return the result. Obtains the bounding box of metadata. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ | | -------- | ----------------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback<[Rect](#rect)\> | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
videoOutput.stop((err) => { metadataObject.getBoundingBox((err, rect) => {
if (err) { if (err) {
console.error('Failed to stop the video output ${err.message}'); console.error(`Failed to get boundingBox. ${err.message}`);
return; return;
} }
console.log('Callback invoked to indicate the video output stop success.'); console.log('Callback returned with boundingBox getted.');
}); })
``` ```
### stop ### getBoundingBox
stop(): Promise<void\> getBoundingBox(): Promise<Rect\>
Stops video recording. This API uses a promise to return the result. Obtains the bounding box of metadata. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | ---------------------- | --------------------------- |
| Promise<void\>| Promise used to return the result.| | Promise<[Rect](#rect)\> | Promise used to return the result.|
**Example** **Example**
```js ```js
videoOutput.start().then(() => { metadataObject.getBoundingBox().then((rect) => {
console.log('Promise returned to indicate that stop method execution success.'); console.log('Callback returned with boundingBox getted.');
}) })
``` ```
### release ## MetadataFaceObject
release(callback: AsyncCallback<void\>): void Implements the face object of metadata. It inherits [MetadataObject](#metadataobject).
Releases this **VideoOutput** instance. This API uses an asynchronous callback to return the result. ## MetadataOutput
Implements metadata streams. It inherits **[CameraOutput](#cameraoutput)**.
### start
start(callback: AsyncCallback<void\>): void
Starts to output metadata. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ | | -------- | ----------------------------------------------------------- | ---- | ------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
videoOutput.release((err) => { metadataOutput.start((err) => {
if (err) { if (err) {
console.error('Failed to release the VideoOutput instance ${err.message}'); console.error(`Failed to start metadataOutput. ${err.message}`);
return; return;
} }
console.log('Callback invoked to indicate that the VideoOutput instance is released successfully.'); console.log('Callback returned with metadataOutput started.');
}); })
``` ```
### release ### start
release(): Promise<void\> start(): Promise<void\>
Releases this **VideoOutput** instance. This API uses a promise to return the result. Starts to output metadata. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | --------------------------- | | ---------------------- | ------------------------ |
| Promise<void\>| Promise used to return the result.| | Promise<void\> | Promise used to return the result.|
**Example** **Example**
```js ```js
videoOutput.release().then(() => { metadataOutput.start().then(() => {
console.log('Promise returned to indicate that the VideoOutput instance is released successfully.'); console.log('Callback returned with metadataOutput started.');
}) })
``` ```
### on('frameStart') ### stop
on(type: 'frameStart', callback: AsyncCallback<void\>): void stop(callback: AsyncCallback<void\>): void
Listens for video recording start events. This API uses an asynchronous callback to return the result. Stops outputting metadata. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| :------- | :------------------- | :--- | :----------------------------------------------- | | -------- | -------------------------- | ---- | ------------------- |
| type | string | Yes | Event type. The value is fixed at **`frameStart`**, indicating the video recording start event.| | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
videoOutput.on('frameStart', () => { metadataOutput.stop((err) => {
console.log('Video frame started'); if (err) {
console.error(`Failed to stop the metadataOutput. ${err.message}`);
return;
}
console.log('Callback returned with metadataOutput stopped.');
}) })
``` ```
### on('frameEnd') ### stop
on(type: 'frameEnd', callback: AsyncCallback<void\>): void stop(): Promise<void\>
Stops outputting metadata. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core
**Return value**
| Type | Description |
| ---------------------- | --------------------------- |
| Promise<void\> | Promise used to return the result.|
**Example**
```js
metadataOutput.stop().then(() => {
console.log('Callback returned with metadataOutput stopped.');
})
```
### on('metadataObjectsAvailable')
Listens for video recording end events. This API uses an asynchronous callback to return the result. on(type: 'metadataObjectsAvailable', callback: AsyncCallback<Array<MetadataObject\>\>): void
Listens for metadata objects. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| :------- | :------------------- | :--- | :--------------------------------------------- | | -------- | ------------------------------------------------ | ---- | ------------------------------------ |
| type | string | Yes | Event type. The value is fixed at **`frameEnd`**, indicating the video frame end event.| | type | string | Yes | Event type. The value is fixed at **'metadataObjectsAvailable'**, that is, the metadata object.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | Callback<Array<[MetadataObject](#metadataobject)\>\> | Yes | Callback used to return the error information. |
**Example** **Example**
```js ```js
videoOutput.on('frameEnd', () => { metadataOutput.on('metadataObjectsAvailable', (metadataObject) => {
console.log('Video frame ended'); console.log(`metadata output error code: ${metadataObject.code}`);
}) })
``` ```
### on('error') ### on('error')
on(type: 'error', callback: ErrorCallback<VideoOutputError\>): void on(type: 'error', callback: ErrorCallback<MetadataOutputError\>): void
Listens for **VideoOutput** errors. This API uses a callback to return the result. Listens for metadata errors. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| :------- | :----------------------------------------------- | :--- | :-------------------------------------------- | | -------- | ------------------------------------------------ | ---- | --------------------------------------- |
| 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'**, that is, the metadata error.|
| callback | Callback<[VideoOutputError](#videooutputerror)\> | Yes | Callback used to return the error information. | | callback | Callback<[MetadataOutputError](#metadataoutputerror)\> | Yes | Callback used to return the error information. |
**Example** **Example**
```js ```js
videoOutput.on('error', (VideoOutputError) => { metadataOutput.on('error', (metadataOutputError) => {
console.log('Video output error code: ' + VideoOutputError.code); console.log(`Metadata output error code: ${metadataOutputError.code}`);
}) })
``` ```
## VideoOutputErrorCode ## MetadataOutputErrorCode
Enumerates the error codes used in a **VideoOutput** instance. Enumerates the codes used for metadata output errors.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name | Value | Description | | Name | Value | Description |
| ------------- | ---- | ---------- | | ------------------------------- | ---- | -------- |
| ERROR_UNKNOWN | -1 | Unknown error.| | ERROR_UNKNOWN | -1 | Unknown error.|
| ERROR_INSUFFICIENT_RESOURCES | 0 | Insufficient resources.|
## VideoOutputError ## MetadataOutputError
Defines a **VideoOutput** error. Defines a metadata output error.
**System capability**: SystemCapability.Multimedia.Camera.Core **System capability**: SystemCapability.Multimedia.Camera.Core
| Name| Type | Description | | Name| Type | Description |
| ---- | ------------------------------------- | ----------------------- | | ---- | ------------------------------------- | ----------------------- |
| code | [PhotoOutputError](#photooutputerror) | **VideoOutput** error code.| | code | [MetadataOutputErrorCode](#metadataoutputerrorcode) | **MetadataOutput** error code.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册