diff --git a/en/application-dev/reference/apis/js-apis-camera.md b/en/application-dev/reference/apis/js-apis-camera.md index cc34ebefa765c63b14d0bf65e1d8d26ebe64e4e1..baf10a887589617bee09f1a3220c70dd1b6d6cdb 100644 --- a/en/application-dev/reference/apis/js-apis-camera.md +++ b/en/application-dev/reference/apis/js-apis-camera.md @@ -84,7 +84,7 @@ Defines the camera profile. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Type | Read Only| Description | +| Name | Type | Mandatory| Description | | -------- | ----------------------------- |---- | ------------- | | format | [CameraFormat](#cameraformat) | Yes | Output format. | | size | [Size](#size) | Yes | Resolution. | @@ -95,7 +95,7 @@ Defines the frame rate range. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Type | Read Only| Description | +| Name | Type | Mandatory| Description | | -------- | ----------------------------- |---- | ------------- | | min | number | Yes | Minimum frame rate. | | max | number | Yes | Maximum frame rate. | @@ -106,7 +106,7 @@ Defines the video profile. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Type | Read Only| Description | +| Name | Type | Mandatory| Description | | ------------------------- | ----------------------------------------- | --- |----------- | | frameRateRange | [FrameRateRange](#frameraterange) | Yes | Frame rate range. | @@ -116,7 +116,7 @@ Defines the camera output capability. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Type | Read Only| Description | +| Name | Type | Mandatory| Description | | ----------------------------- | -------------------------------------------------- | --- |------------------- | | previewProfiles | Array<[Profile](#profile)\> | Yes | Supported preview profiles. | | photoProfiles | Array<[Profile](#profile)\> | Yes | Supported shooting profiles. | @@ -171,8 +171,8 @@ Obtains supported cameras. This API uses a promise to return the result. **Example** ```js -cameraManager.getSupportedCameras().then((cameraArray) => { - console.log(`Promise returned with an array of supported cameras: ${cameraArray.length}`); +cameraManager.getSupportedCameras().then((cameras) => { + console.log(`Promise returned with an array of supported cameras: ${cameras.length}`); }) ``` @@ -188,18 +188,21 @@ Obtains the output capability supported by a camera. This API uses an asynchrono | Name | Type | Mandatory| Description | | ------------ |--------------------------------------------------------------- | -- | -------------------------- | -| CameraDevice | [CameraDevice](#cameradevice) | Yes| Camera device. | +| cameraDevice | [CameraDevice](#cameradevice) | Yes| Target camera, which is obtained through **getSupportedCameras**. | | callback | AsyncCallback<[CameraOutputCapability](#cameraoutputcapability)\> | Yes| Callback used to return the output capability.| **Example** ```js -cameraManager.getSupportedOutputCapability(cameradevice, (err, cameras) => { - if (err) { - console.error(`Failed to get the cameras. ${err.message}`); - return; - } - console.log('Callback returned with an array of supported outputCapability'); +cameraManager.getSupportedCameras().then((cameras) => { + let cameraDevice = cameras[0]; + cameraManager.getSupportedOutputCapability(cameraDevice, (err, CameraOutputCapability) => { + if (err) { + console.error(`Failed to get the outputCapability. ${err.message}`); + return; + } + console.log('Callback returned with an array of supported outputCapability'); + }) }) ``` @@ -215,7 +218,7 @@ Obtains the output capability supported by a camera. This API uses a promise to | Name | Type | Mandatory | Description | | -------- | --------------------------------- | ---- | ---------- | -| camera | [CameraDevice](#cameradevice) | Yes | Camera device. | +| cameradevice | [CameraDevice](#cameradevice) | Yes | Target camera, which is obtained through **getSupportedCameras**. | **Return value** @@ -226,8 +229,11 @@ Obtains the output capability supported by a camera. This API uses a promise to **Example** ```js -cameraManager.getSupportedOutputCapability(cameradevice).then((cameraoutputcapability) => { - console.log('Promise returned with an array of supported outputCapability'); +cameraManager.getSupportedCameras().then((cameras) => { + let cameraDevice = cameras[0]; + cameraManager.getSupportedOutputCapability(cameraDevice).then((cameraoutputcapability) => { + console.log('Promise returned with an array of supported outputCapability'); + }) }) ``` @@ -250,7 +256,7 @@ Before calling the API, ensure that the camera can be muted. You can use [isCame **Example** ```js -let ismuted = await cameraManager.isCameraMuted(); +let ismuted = cameraManager.isCameraMuted(); ``` ### isCameraMuteSupported @@ -259,6 +265,8 @@ isCameraMuteSupported(): boolean Checks whether the camera can be muted. +This is a system API. + **System capability**: SystemCapability.Multimedia.Camera.Core **Return value** @@ -270,7 +278,7 @@ Checks whether the camera can be muted. **Example** ```js -let ismutesuppotred = await cameraManager.isCameraMuteSupported(); +let ismutesuppotred = cameraManager.isCameraMuteSupported(); ``` ### muteCamera @@ -279,6 +287,8 @@ muteCamera(mute: boolean): void Mutes or unmutes the camera. +This is a system API. + **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** @@ -290,6 +300,7 @@ Mutes or unmutes the camera. **Example** ```js +let mute = true; cameraManager.muteCamera(mute); ``` @@ -299,8 +310,6 @@ createCameraInput(camera: CameraDevice, callback: AsyncCallback): Creates a **CameraInput** instance with the specified **CameraDevice** object. 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 @@ -309,13 +318,14 @@ This is a system API. | Name | Type | Mandatory| Description | | -------- | ------------------------------------------- | ---- | --------------------------------- | -| camera | [CameraDevice](#cameradevice) | Yes | **CameraDevice** object. | +| cameraDevice | [CameraDevice](#cameradevice) | Yes | Target **CameraDevice** object, which is obtained through **getSupportedCameras**. | | callback | AsyncCallback<[CameraInput](#camerainput)\> | Yes | Callback used to return the **CameraInput** instance. | **Example** ```js -cameraManager.createCameraInput(camera, (err, cameraInput) => { +let cameraDevice = cameras[0]; +cameraManager.createCameraInput(cameraDevice, (err, cameraInput) => { if (err) { console.error(`Failed to create the CameraInput instance. ${err.message}`); return; @@ -326,12 +336,10 @@ cameraManager.createCameraInput(camera, (err, cameraInput) => { ### createCameraInput -createCameraInput(camera: CameraDevice): Promise +createCameraInput(cameraDevice: CameraDevice): Promise Creates a **CameraInput** instance with the specified **CameraDevice** object. 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 @@ -340,7 +348,7 @@ This is a system API. | Name | Type | Mandatory| Description | | -------- | ----------------------------- | ---- | ---------- | -| camera | [CameraDevice](#cameradevice) | Yes | **CameraDevice** object.| +| cameraDevice | [CameraDevice](#cameradevice) | Yes | Target **CameraDevice** object, which is obtained through **getSupportedCameras**.| **Return value** @@ -351,7 +359,8 @@ This is a system API. **Example** ```js -cameraManager.createCameraInput(camera).then((cameraInput) => { +let cameraDevice = cameras[0]; +cameraManager.createCameraInput(cameraDevice).then((cameraInput) => { console.log('Promise returned with the CameraInput instance'); }) ``` @@ -362,8 +371,6 @@ createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCal Creates a **CameraInput** instance with the specified camera position and type. 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 @@ -372,14 +379,17 @@ This is a system API. | Name | Type | Mandatory| Description | | -------- | ------------------------------------------- | ---- | --------------------------------- | -| position | [CameraPosition](#cameraposition) | Yes | Camera position. | -| type | [CameraType](#cameratype) | Yes | Camera type. | +| position | [CameraPosition](#cameraposition) | Yes | Camera position, which is obtained through **getSupportedCameras**. This API obtains a **CameraDevice** object, which contains the camera position information. | +| type | [CameraType](#cameratype) | Yes | Camera type, which is obtained through **getSupportedCameras**. This API obtains a **CameraDevice** object, which contains the camera type information. | | callback | AsyncCallback<[CameraInput](#camerainput)\> | Yes | Callback used to return the **CameraInput** instance. | **Example** ```js -cameraManager.createCameraInput(camera.CameraPosition.CAMERA_POSITION_BACK, camera.CameraType.CAMERA_TYPE_UNSPECIFIED, (err, cameraInput) => { +let cameraDevice = cameras[0]; +let position = cameraDevice.cameraPosition; +let type = cameraDevice.cameraType; +cameraManager.createCameraInput(position, type, (err, cameraInput) => { if (err) { console.error(`Failed to create the CameraInput instance. ${err.message}`); return; @@ -394,8 +404,6 @@ createCameraInput(position: CameraPosition, type:CameraType ): Promise { +let cameraDevice = cameras[0]; +let position = cameraDevice.cameraPosition; +let type = cameraDevice.cameraType; +cameraManager.createCameraInput(position, type).then((cameraInput) => { console.log('Promise returned with the CameraInput instance'); }) ``` @@ -433,14 +444,15 @@ Creates a **PreviewOutput** instance. This API uses an asynchronous callback to | Name | Type | Mandatory| Description | | -------- | ----------------------------------------------- | ---- | ------------------------------- | -| 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)**.| +| profile | [Profile](#profile) | Yes | Supported preview profiles, which are obtained through **getSupportedOutputCapability**.| +| surfaceId| string | Yes | Surface ID, which is obtained from [XComponent](../arkui-ts/ts-basic-components-xcomponent.md) or [ImageReceiver](js-apis-image.md#imagereceiver9).| | callback | AsyncCallback<[PreviewOutput](#previewoutput)\> | Yes | Callback used to return the **PreviewOutput** instance.| **Example** ```js -cameraManager.createPreviewOutput(profile, surfaceId, (err, previewoutput) => { +let profile = cameraoutputcapability.previewProfiles[0]; +cameraManager.createPreviewOutput(profile, surfaceId, (err, previewOutput) => { if (err) { console.error(`Failed to gcreate previewOutput. ${err.message}`); return; @@ -461,8 +473,8 @@ Creates a **PreviewOutput** instance. This API uses a promise to return the resu | Name | Type | Mandatory| Description | | -------- | ---------------------------------| ---- | ----------------- | -| 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)**.| +| profile | [Profile](#profile) | Yes | Supported preview profiles, which are obtained through **getSupportedOutputCapability**.| +| surfaceId| string | Yes | Surface ID, which is obtained from [XComponent](../arkui-ts/ts-basic-components-xcomponent.md) or [ImageReceiver](js-apis-image.md#imagereceiver9).| **Return value** @@ -473,7 +485,8 @@ Creates a **PreviewOutput** instance. This API uses a promise to return the resu **Example** ```js -cameraManager.createPreviewOutput(profile, surfaceId).then((previewoutput) => { +let profile = cameraoutputcapability.previewProfiles[0]; +cameraManager.createPreviewOutput(profile, surfaceId).then((previewOutput) => { console.log('Promise returned with previewOutput created.'); }) ``` @@ -490,14 +503,15 @@ Creates a **PhotoOutput** instance. This API uses an asynchronous callback to re | Name | Type | Mandatory| Description | | -------- | ------------------------------------------- | ---- | ----------------------------------- | -| profile | [Profile](#profile) | Yes | Supported shooting profile. | -| surfaceId| string | Yes | Surface ID, which is obtained from **[ImageReceiver](js-apis-image.md#imagereceiver9)**.| +| profile | [Profile](#profile) | Yes | Supported shooting profiles, which are obtained through **getSupportedOutputCapability**.| +| 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** ```js -cameraManager.createPhotoOutput(profile, surfaceId, (err, photooutput) => { +let profile = cameraoutputcapability.photoProfiles[0]; +cameraManager.createPhotoOutput(profile, surfaceId, (err, photoOutput) => { if (err) { console.error(`Failed to create photoOutput. ${err.message}`); return; @@ -518,8 +532,8 @@ Creates a **PhotoOutput** instance. This API uses a promise to return the result | Name | Type | Mandatory| Description | | -------- | ---------------------------------| ---- | ----------- | -| profile | [Profile](#profile) | Yes | Supported shooting profile. | -| surfaceId| string | Yes | Surface ID, which is obtained from **[ImageReceiver](js-apis-image.md#imagereceiver9)**.| +| profile | [Profile](#profile) | Yes | Supported shooting profiles, which are obtained through **getSupportedOutputCapability**.| +| surfaceId| string | Yes | Surface ID, which is obtained from [ImageReceiver](js-apis-image.md#imagereceiver9).| **Return value** @@ -530,7 +544,8 @@ Creates a **PhotoOutput** instance. This API uses a promise to return the result **Example** ```js -cameraManager.createPhotoOutput(profile, surfaceId).then((photooutput) => { +let profile = cameraoutputcapability.photoProfiles[0]; +cameraManager.createPhotoOutput(profile, surfaceId).then((photoOutput) => { console.log('Promise returned with photoOutput created.'); }) ``` @@ -547,14 +562,15 @@ Creates a **VideoOutput** instance. This API uses an asynchronous callback to re | 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)**.| +| profile | [VideoProfile](#videoprofile) | Yes | Supported video recording profiles, which are obtained through **getSupportedOutputCapability**.| +| 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** ```js -cameraManager.createVideoOutput(profile, surfaceId, (err, videooutput) => { +let profile = cameraoutputcapability.videoProfiles[0]; +cameraManager.createVideoOutput(profile, surfaceId, (err, videoOutput) => { if (err) { console.error(`Failed to create videoOutput. ${err.message}`); return; @@ -575,8 +591,8 @@ Creates a **VideoOutput** instance. This API uses a promise to return the result | 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)**.| +| profile | [VideoProfile](#videoprofile) | Yes | Supported video recording profiles, which are obtained through **getSupportedOutputCapability**.| +| surfaceId| string | Yes | Surface ID, which is obtained from [VideoRecorder](js-apis-media.md#videorecorder9).| **Return value** @@ -587,7 +603,8 @@ Creates a **VideoOutput** instance. This API uses a promise to return the result **Example** ```js -cameraManager.createVideoOutput(profile, surfaceId).then((videooutput) => { +let profile = cameraoutputcapability.videoProfiles[0]; +cameraManager.createVideoOutput(profile, surfaceId).then((videoOutput) => { console.log('Promise returned with videoOutput created.'); }) ``` @@ -604,13 +621,14 @@ Creates a **MetadataOutput** instance. This API uses an asynchronous callback to | Name | Type | Mandatory| Description | | -------------------- | -------------------------------------------------- | --- | ---------------------------- | -| metadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | Yes | Metadata object types. | +| metadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | Yes | Metadata object types, which are obtained through **getSupportedOutputCapability**.| | callback | AsyncCallback<[MetadataOutput](#metadataoutput)\> | Yes | Callback used to return the **MetadataOutput** instance. | **Example** ```js -cameraManager.createMetadataOutput(metadataObjectTypes, (err, metadataoutput) => { +let metadataObjectTypes = cameraoutputcapability.supportedMetadataObjectTypes; +cameraManager.createMetadataOutput(metadataObjectTypes, (err, metadataOutput) => { if (err) { console.error(`Failed to create metadataOutput. ${err.message}`); return; @@ -631,7 +649,7 @@ Creates a **MetadataOutput** instance. This API uses a promise to return the res | Name | Type | Mandatory| Description | | -------------------- | -------------------------------------------------- | --- | -------------------- | -| metadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | Yes | Metadata object types. | +| metadataObjectTypes | Array<[MetadataObjectType](#metadataobjecttype)\> | Yes | Metadata object types, which are obtained through **getSupportedOutputCapability**. | **Return value** @@ -642,7 +660,8 @@ Creates a **MetadataOutput** instance. This API uses a promise to return the res **Example** ```js -cameraManager.createMetadataOutput().then((metadataoutput) => { +let metadataObjectTypes = cameraoutputcapability.supportedMetadataObjectTypes; +cameraManager.createMetadataOutput(metadataObjectTypes).then((metadataOutput) => { console.log('Promise returned with metadataOutput created.'); }) ``` @@ -664,7 +683,7 @@ Creates a **CaptureSession** instance. This API uses an asynchronous callback to **Example** ```js -cameraManager.createCaptureSession((err, capturesession) => { +cameraManager.createCaptureSession((err, captureSession) => { if (err) { console.error(`Failed to create captureSession. ${err.message}`); return; @@ -690,7 +709,7 @@ Creates a **CaptureSession** instance. This API uses a promise to return the res **Example** ```js -cameraManager.createCaptureSession().then((capturesession) => { +cameraManager.createCaptureSession().then((captureSession) => { console.log('Promise returned with captureSession created.'); }) ``` @@ -729,6 +748,8 @@ on(type: 'cameraMute', callback: AsyncCallback): void Listens for camera mute status changes. This API uses an asynchronous callback to return the result. +This is a system API. + **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** @@ -736,12 +757,12 @@ Listens for camera mute status changes. This API uses an asynchronous callback t | Name | Type | Mandatory| Description | | -------- | --------------- | ---- | --------- | | 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. | +| callback | AsyncCallback | Yes | Callback used to return the camera mute status. | **Example** ```js -cameraManager.on('cameraMute', (err, cameraStatusInfo) => { +cameraManager.on('cameraMute', (err, curMuetd) => { if (err) { console.error(`Failed to get cameraMute callback. ${err.message}`); return; @@ -755,10 +776,10 @@ Describes the camera status information. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Type | Description | -| ------ | ----------------------------- | ---------- | -| camera | [CameraDevice](#cameradevice) | Camera object.| -| status | [CameraStatus](#camerastatus) | Camera status.| +| Name | Type | Mandatory | Description | +| ------ | ----------------------------- | -------------- | ---------- | +| camera | [CameraDevice](#cameradevice) | Yes | Camera object.| +| status | [CameraStatus](#camerastatus) | Yes | Camera status.| ## CameraPosition @@ -804,27 +825,13 @@ Defines the camera device information. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Type | Read Only| Description | +| Name | Type | Mandatory| 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** - -```js -async function getCameraInfo("cameraId") { - 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; -} -``` - ## Size Enumerates the camera output capability. @@ -853,7 +860,7 @@ Enumerates the camera output formats. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name | Default Value | Description | +| Name | Value | Description | | ----------------------- | --------- | ------------ | | CAMERA_FORMAT_RGBA_8888 | 3 | RGB image. | | CAMERA_FORMAT_YUV_420_SP| 1003 | YUV 420 SP image. | @@ -1009,7 +1016,7 @@ cameraInput.release().then(() => { ### on('error') -on(type: 'error', camera:CameraDevice, callback: ErrorCallback): void +on(type: 'error', cameraDevice:CameraDevice, callback: ErrorCallback): void Listens for **CameraInput** errors. This API uses a callback to return the result. @@ -1020,13 +1027,14 @@ Listens for **CameraInput** errors. This API uses a callback to return the resul | Name | Type | Mandatory| Description | | -------- | -------------------------------- | --- | ------------------------------------------- | | type | string | Yes | Event type. The value is fixed at **'error'**, indicating the camera input error event.| -| camera | [CameraDevice](#cameradevice) | Yes | **CameraDevice** object.| +| cameraDevice | [CameraDevice](#cameradevice) | Yes | **CameraDevice** object.| | callback | ErrorCallback<[CameraInputError](#camerainputerror)\> | Yes | Callback used to return the result. | **Example** ```js -cameraInput.on('error', camera, (cameraInputError) => { +let cameraDevice = cameras[0]; +cameraInput.on('error', cameraDevice, (cameraInputError) => { console.log(`Camera input error code: ${cameraInputError.code}`); }) ``` @@ -1052,9 +1060,9 @@ Defines an error object used for **[CameraInput](#camerainput)**. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name| Type | Description | -| ---- | --------------------------------------------- | --------------------- | -| code | [CameraInputErrorCode](#camerainputerrorcode) | **CameraInput** error code.| +| Name| Type | Mandatory | Description | +| ---- | --------------------------------------------- | ------------ |--------------------- | +| code | [CameraInputErrorCode](#camerainputerrorcode) | Yes |**CameraInput** error code.| ## FlashMode @@ -1334,9 +1342,9 @@ captureSession.removeInput(cameraInput).then(() => { ### addOutput -addOutput\(cameraOutput: CameraOutput, callback: AsyncCallback\): void +addOutput\(previewOutput: CameraOutput, callback: AsyncCallback\): void -Adds a **[CameraOutput](#cameraoutput)** instance to this **CaptureSession**. 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 @@ -1344,13 +1352,13 @@ Adds a **[CameraOutput](#cameraoutput)** instance to this **CaptureSession**. Th | Name | Type | Mandatory| Description | | ------------- | ------------------------------- | ---- | ------------------------ | -| cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to add.| +| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to add.| | callback | AsyncCallback | Yes | Callback used to return the result. | **Example** ```js -captureSession.addOutput(cameraOutput, (err) => { +captureSession.addOutput(previewOutput, (err) => { if (err) { console.error(`Failed to add output. ${err.message}`); return; @@ -1361,9 +1369,9 @@ captureSession.addOutput(cameraOutput, (err) => { ### addOutput -addOutput\(cameraOutput: CameraOutput\): Promise +addOutput\(previewOutput: CameraOutput\): Promise -Adds a **[CameraOutput](#cameraoutput)** instance to this **CaptureSession**. 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 @@ -1371,7 +1379,7 @@ Adds a **[CameraOutput](#cameraoutput)** instance to this **CaptureSession**. Th | Name | Type | Mandatory| Description | | ------------- | ------------------------------- | ---- | ------------------------- | -| cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to add.| +| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to add.| **Return value** @@ -1382,16 +1390,16 @@ Adds a **[CameraOutput](#cameraoutput)** instance to this **CaptureSession**. Th **Example** ```js -captureSession.addOutput(cameraOutput).then(() => { +captureSession.addOutput(previewOutput).then(() => { console.log('Promise returned with cameraOutput added.'); }) ``` ### removeOutput -removeOutput\(cameraOutput: CameraOutput, callback: AsyncCallback\): void +removeOutput\(previewOutput: CameraOutput, callback: AsyncCallback\): void -Removes a **[CameraOutput](#cameraoutput)** instance from this **CaptureSession**. 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 @@ -1399,13 +1407,13 @@ Removes a **[CameraOutput](#cameraoutput)** instance from this **CaptureSession* | Name | Type | Mandatory| Description | | ------------- | ------------------------------- | ---- | ------------------------ | -| cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to remove.| +| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to remove.| | callback | AsyncCallback | Yes | Callback used to return the result. | **Example** ```js -captureSession.removeOutput(cameraOutput, (err) => { +captureSession.removeOutput(previewOutput, (err) => { if (err) { console.error(`Failed to remove the CameraOutput instance. ${err.message}`); return; @@ -1416,9 +1424,9 @@ captureSession.removeOutput(cameraOutput, (err) => { ### removeOutput -removeOutput(cameraOutput: CameraOutput): Promise +removeOutput(previewOutput: CameraOutput): Promise -Removes a **[CameraOutput](#cameraoutput)** instance from this **CaptureSession**. 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 @@ -1426,7 +1434,7 @@ Removes a **[CameraOutput](#cameraoutput)** instance from this **CaptureSession* | Name | Type | Mandatory| Description | | ------------- | ------------------------------- | ---- | ------------------------- | -| cameraOutput | [CameraOutput](#cameraoutput) | Yes | **CameraOutput** instance to remove.| +| previewOutput | [PreviewOutput](#previewoutput) | Yes | **PreviewOutput** instance to remove.| **Return value** @@ -1439,7 +1447,7 @@ Removes a **[CameraOutput](#cameraoutput)** instance from this **CaptureSession* **Example** ```js -captureSession.removeOutput(cameraOutput).then(() => { +captureSession.removeOutput(previewOutput).then(() => { console.log('Promise returned to indicate that the CameraOutput instance is removed.'); }) ``` @@ -2106,8 +2114,8 @@ Obtains the exposure compensation values. This API uses a promise to return the **Example** ```js -captureSession.isExposureModeSupported(camera.ExposureMode.EXPOSURE_MODE_LOCKED).then((isSupported) => { - console.log(`Promise returned with exposure mode supported : ${isSupported}`); +captureSession.getExposureBiasRange().then((biasRangeArray) => { + console.log('Promise returned with the array of compenstation range: ' + JSON.stringify(biasRangeArray)); }) ``` @@ -2125,13 +2133,14 @@ Before the setting, you are advised to use **[getExposureBiasRange](#getexposure | Name | Type | Mandatory| Description | | -------- | -------------------------------| ---- | ------------------- | -| exposureBias | number | Yes | Compensation value. | +| exposureBias | number | Yes | Compensation value. You can use **getExposureBiasRange** to obtain the supported values.| | callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -captureSession.setExposureBias(-4,(err) => { +let exposureBias = biasRangeArray[0]; +captureSession.setExposureBias(exposureBias,(err) => { if (err) { console.log(`Failed to set the exposure bias ${err.message}`); return ; @@ -2154,7 +2163,7 @@ Before the setting, you are advised to use **[getExposureBiasRange](#getexposure | Name | Type | Mandatory| Description | | -------------- | --------- | ---- | --------- | -| exposureBias | number | Yes | Compensation value. | +| exposureBias | number | Yes | Compensation value. You can use **getExposureBiasRange** to obtain the supported values. | **Return value** @@ -2165,7 +2174,8 @@ Before the setting, you are advised to use **[getExposureBiasRange](#getexposure **Example** ```js -captureSession.setExposureBias(-4).then(() => { +let exposureBias = biasRangeArray[0]; +captureSession.setExposureBias(exposureBias).then(() => { console.log('Promise returned with the successful execution of setExposureBias.'); }) ``` @@ -2595,13 +2605,14 @@ Sets a zoom ratio. This API uses an asynchronous callback to return the result. | Name | Type | Mandatory| Description | | --------- | -------------------- | ---- | ------------------- | -| zoomRatio | number | Yes | Zoom ratio. | +| zoomRatio | number | Yes | Zoom ratio. You can use **getZoomRatioRange** to obtain the supported values.| | callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -captureSession.setZoomRatio(1, (err) => { +let zoomRatio = zoomRatioRange[0]; +captureSession.setZoomRatio(zoomRatio, (err) => { if (err) { console.error(`Failed to set the zoom ratio value ${err.message}`); return; @@ -2622,7 +2633,7 @@ Sets a zoom ratio. This API uses a promise to return the result. | Name | Type | Mandatory| Description | | --------- | ------ | ---- | --------- | -| zoomRatio | number | Yes | Zoom ratio.| +| zoomRatio | number | Yes | Zoom ratio. You can use **getZoomRatioRange** to obtain the supported values.| **Return value** @@ -2633,7 +2644,8 @@ Sets a zoom ratio. This API uses a promise to return the result. **Example** ```js -captureSession.setZoomRatio(1).then(() => { +let zoomRatio = zoomRatioRange[0]; +captureSession.setZoomRatio(zoomRatio).then(() => { console.log('Promise returned with the successful execution of setZoomRatio.'); }) ``` @@ -2902,45 +2914,49 @@ Defines a **CaptureSession** error. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name| Type | Description | -| ---- | ------------------------------------------- | -------------------------- | -| code | [CaptureSessionError](#capturesessionerror) | **CaptureSession** error code.| +| Name| Type | Mandatory | Description | +| ---- | ------------------------------------------- | -------------------------- |-------------------------- | +| code | [CaptureSessionError](#capturesessionerror) | Yes |**CaptureSession** error code.| ## CameraOutput Implements output information used in a **[CaptureSession](#capturesession)**. It is the base class of **output**. -### release +## PreviewOutput -release(callback: AsyncCallback): void +Implements preview output. It inherits **[CameraOutput](#cameraoutput)**. -Releases output resources. This API uses an asynchronous callback to return the result. +### start + +start(callback: AsyncCallback): 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 | Yes | Callback used to return the result.| **Example** ```js -cameraOutput.release((err) => { +previewOutput.start((err) => { if (err) { - console.error(`Failed to release the PreviewOutput instance ${err.message}`); + console.error(`Failed to start the previewOutput. ${err.message}`); return; } - console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.'); -}); + console.log('Callback returned with previewOutput started.'); +}) ``` -### release +### start -release(): Promise +start(): Promise -Releases output resources. This API uses a promise to return the result. +Starts to output preview streams. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core @@ -2953,20 +2969,16 @@ Releases output resources. This API uses a promise to return the result. **Example** ```js -cameraOutput.release().then(() => { - console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.'); +previewOutput.start().then(() => { + console.log('Promise returned with previewOutput started.'); }) ``` -## PreviewOutput - -Implements preview output. It inherits **[CameraOutput](#cameraoutput)**. - -### start +### stop -start(callback: AsyncCallback): void +stop(callback: AsyncCallback): void -Starts to output preview streams. This API uses an asynchronous callback to return the result. +Stops outputting preview streams. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core @@ -2979,82 +2991,82 @@ Starts to output preview streams. This API uses an asynchronous callback to retu **Example** ```js -previewOutput.start((err) => { +previewOutput.stop((err) => { if (err) { - console.error(`Failed to start the previewOutput. ${err.message}`); + console.error(`Failed to stop the previewOutput. ${err.message}`); return; } - console.log('Callback returned with previewOutput started.'); + console.log('Callback returned with previewOutput stopped.'); }) ``` -### start +### stop -start(): Promise +stop(): Promise -Starts to output preview streams. This API uses a promise to return the result. +Stops outputting preview streams. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Return value** | Type | Description | -| -------------- | ----------------------- | +| -------------- | ------------------------ | | Promise| Promise used to return the result.| **Example** ```js -previewOutput.start().then(() => { - console.log('Promise returned with previewOutput started.'); +previewOutput.stop().then(() => { + console.log('Callback returned with previewOutput stopped.'); }) ``` -### stop +### release -stop(callback: AsyncCallback): void +release(callback: AsyncCallback): void -Stops outputting preview streams. This API uses an asynchronous callback to return the result. +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 | Yes | Callback used to return the result.| **Example** ```js -previewOutput.stop((err) => { +previewOutput.release((err) => { if (err) { - console.error(`Failed to stop the previewOutput. ${err.message}`); + console.error(`Failed to release the PreviewOutput instance ${err.message}`); return; } - console.log('Callback returned with previewOutput stopped.'); -}) + console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.'); +}); ``` -### stop +### release -stop(): Promise +release(): Promise -Stops outputting preview streams. This API uses a promise to return the result. +Releases output resources. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Return value** | Type | Description | -| -------------- | ------------------------ | +| -------------- | ----------------------- | | Promise| Promise used to return the result.| **Example** ```js -previewOutput.stop().then(() => { - console.log('Callback returned with previewOutput stopped.'); +previewOutput.release().then(() => { + console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.'); }) ``` @@ -3143,9 +3155,9 @@ Defines the preview output error. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name| Type | Description | -| ---- | ------------------------------------------------- | ---------------------- | -| code | [PreviewOutputErrorCode](#previewoutputerrorcode) | **PreviewOutput** error code.| +| Name| Type | Mandatory | Description | +| ---- | ------------------------------------------------- | ---------------- |---------------------- | +| code | [PreviewOutputErrorCode](#previewoutputerrorcode) | Yes |**PreviewOutput** error code.| ## ImageRotation @@ -3191,16 +3203,16 @@ 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.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------------- | ---- | -----------------| +| quality | [QualityLevel](#qualitylevel) | No | Photo quality. | +| rotation | [ImageRotation](#imagerotation) | No | Rotation angle of the photo. | +| location | [Location](#location) | No | Geolocation information of the photo. | +| mirror | boolean | No |Whether mirroring is enabled. By default, mirroring is disabled.| ## PhotoOutput -Implements output information used in a **CaptureSession**. +Implements output information used in a shooting session. This class inherits from [CameraOutput](#cameraoutput). ### capture @@ -3246,9 +3258,16 @@ Captures a photo with the specified shooting parameters. This API uses an asynch **Example** ```js -let settings:PhotoCaptureSetting = { - quality = 1, - rotation = 0 +let captureLocation = { + latitude: 0, + longitude: 0, + altitude: 0, +} +let settings = { + quality: camera.QualityLevel.QUALITY_LEVEL_LOW, + rotation: camera.ImageRotation.ROTATION_0, + location: captureLocation, + mirror: false } photoOutput.capture(settings, (err) => { if (err) { @@ -3314,6 +3333,54 @@ photoOutput.isMirrorSupported((err, isSupported) => { }) ``` +### release + +release(callback: AsyncCallback): 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 | Yes | Callback used to return the result.| + +**Example** + +```js +photoOutput.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 + +Releases output resources. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.Camera.Core + +**Return value** + +| Type | Description | +| -------------- | ----------------------- | +| Promise| Promise used to return the result.| + +**Example** + +```js +photoOutput.release().then(() => { + console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.'); +}) +``` + ### isMirrorSupported isMirrorSupported(): Promise @@ -3471,13 +3538,13 @@ Defines a photo output error. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name| Type | Description | -| ---- | ------------------------------------- | ----------------------- | -| code | [PhotoOutputErrorCode](#photooutputerrorcode) | **PhotoOutput** error code.| +| Name| Type | Mandatory |Description | +| ---- | ------------------------------------- | --------- | ----------------------- | +| code | [PhotoOutputErrorCode](#photooutputerrorcode) | Yes | **PhotoOutput** error code.| ## VideoOutput -Implements output information used in a video recording session. +Implements output information used in a video recording session. This class inherits from [CameraOutput](#cameraoutput). ### start @@ -3576,6 +3643,54 @@ videoOutput.stop().then(() => { }) ``` +### release + +release(callback: AsyncCallback): 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 | Yes | Callback used to return the result.| + +**Example** + +```js +videoOutput.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 + +Releases output resources. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.Camera.Core + +**Return value** + +| Type | Description | +| -------------- | ----------------------- | +| Promise| Promise used to return the result.| + +**Example** + +```js +videoOutput.release().then(() => { + console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.'); +}) +``` + ### on('frameStart') on(type: 'frameStart', callback: AsyncCallback): void @@ -3662,348 +3777,354 @@ Defines a video output error. **System capability**: SystemCapability.Multimedia.Camera.Core -| Name| Type | Description | -| ---- | ------------------------------------- | ----------------------- | -| code | [PhotoOutputErrorCode](#photooutputerrorcode) | **VideoOutput** error code.| - -## MetadataObjectType - -Enumerates metadata streams. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name | Value | Description | -| ------------------------- | ---- | ----------------- | -| FACE_DETECTION | 0 | Metadata object type.| - -## Rect - -Defines a rectangle. +| Name| Type | Mandatory | Description | +| ---- | ------------------------------------- | ----------------- | ----------------------- | +| code | [PhotoOutputErrorCode](#photooutputerrorcode) | Yes | **VideoOutput** error code.| -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name | Type | Description | -| -------- | ------ | -------------------- | -| 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. | - -## MetadataObject +## MetadataOutput -Implements camera metadata, which is the data source of **[CameraInput](#camerainput)**. +Implements metadata streams. It inherits **[CameraOutput](#cameraoutput)**. -### getType +### start -getType(callback: AsyncCallback): void +start(callback: AsyncCallback): void -Obtains the metadata object type. This API uses an asynchronous callback to return the result. +Starts to output metadata. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | --------------------------------------------------------- | --- | -------------------- | -| callback | AsyncCallback<[MetadataObjectType](#metadataobjecttype)\> | Yes | Callback used to return the result.| +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------------------- | ---- | ------------------- | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -metadataObject.getType((err, metadataObjectType) => { +metadataOutput.start((err) => { if (err) { - console.error(`Failed to get type. ${err.message}`); + console.error(`Failed to start metadataOutput. ${err.message}`); return; } - console.log('Callback returned with an array of metadataObjectType.'); + console.log('Callback returned with metadataOutput started.'); }) ``` -### getType +### start -getType(): Promise +start(): Promise -Obtains the metadata object type. 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 **Return value** -| Type | Description | -| --------------------------------------------------- | --------------------------- | -| Promise<[MetadataObjectType](#metadataobjecttype)\> | Promise used to return the result.| +| Type | Description | +| ---------------------- | ------------------------ | +| Promise | Promise used to return the result.| **Example** ```js -metadataObject.getType().then((metadataObjectType) => { - console.log('Callback returned with an array of metadataObjectType.'); +metadataOutput.start().then(() => { + console.log('Callback returned with metadataOutput started.'); }) ``` -### getTimestamp +### stop -getTimestamp(callback: AsyncCallback): void +stop(callback: AsyncCallback): void -Obtains the metadata timestamp. 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 **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------------------- | ---- | ------------------------ | -| callback | AsyncCallback | Yes | Callback used to return the result.| +| Name | Type | Mandatory| Description | +| -------- | -------------------------- | ---- | ------------------- | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -metadataObject.getTimestamp((err,timestamp) => { +metadataOutput.stop((err) => { if (err) { - console.error(`Failed to get timestamp. ${err.message}`); + console.error(`Failed to stop the metadataOutput. ${err.message}`); return; } - console.log('Callback returned with timestamp getted timestamp : ${timestamp}'); + console.log('Callback returned with metadataOutput stopped.'); }) ``` -### getTimestamp +### stop -getTimestamp(): Promise +stop(): Promise -Obtains the metadata timestamp. This API uses a promise to return the result. +Stops outputting metadata. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Return value** -| Type | Description | -| ---------------- | --------------------------- | -| Promise | Promise used to return the result.| +| Type | Description | +| ---------------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** ```js -metadataObject.getTimestamp().then((timestamp) => { - console.log('Callback returned with timestamp getted timestamp : ${timestamp}'); +metadataOutput.stop().then(() => { + console.log('Callback returned with metadataOutput stopped.'); }) ``` -### getBoundingBox +### on('metadataObjectsAvailable') -getBoundingBox(callback: AsyncCallback): void +on(type: 'metadataObjectsAvailable', callback: AsyncCallback\>): void -Obtains the bounding box of metadata. This API uses an asynchronous callback to return the result. +Listens for metadata objects. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------------------- | ---- | ------------------------ | -| callback | AsyncCallback<[Rect](#rect)\> | Yes | Callback used to return the result.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------ | ---- | ------------------------------------ | +| type | string | Yes | Event type. The value is fixed at **'metadataObjectsAvailable'**, that is, the metadata object.| +| callback | Callback\> | Yes | Callback used to return the error information. | **Example** ```js -metadataObject.getBoundingBox((err, rect) => { - if (err) { - console.error(`Failed to get boundingBox. ${err.message}`); - return; - } - console.log('Callback returned with boundingBox getted.'); +metadataOutput.on('metadataObjectsAvailable', (metadataObjectArr) => { + console.log(`metadata output metadataObjectsAvailable`); }) ``` -### getBoundingBox +### on('error') -getBoundingBox(): Promise +on(type: 'error', callback: ErrorCallback): void -Obtains the bounding box of metadata. This API uses a promise to return the result. +Listens for metadata errors. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core -**Return value** +**Parameters** -| Type | Description | -| ---------------------- | --------------------------- | -| Promise<[Rect](#rect)\> | Promise used to return the result.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------ | ---- | --------------------------------------- | +| type | string | Yes | Event type. The value is fixed at **'error'**, that is, the metadata error.| +| callback | Callback<[MetadataOutputError](#metadataoutputerror)\> | Yes | Callback used to return the error information. | **Example** ```js -metadataObject.getBoundingBox().then((rect) => { - console.log('Callback returned with boundingBox getted.'); +metadataOutput.on('error', (metadataOutputError) => { + console.log(`Metadata output error code: ${metadataOutputError.code}`); }) ``` -## MetadataFaceObject +## MetadataOutputErrorCode -Implements the face object of metadata. It inherits [MetadataObject](#metadataobject). +Enumerates the codes used for metadata output errors. -## MetadataOutput +**System capability**: SystemCapability.Multimedia.Camera.Core -Implements metadata streams. It inherits **[CameraOutput](#cameraoutput)**. +| Name | Value | Description | +| ------------------------------- | ---- | -------- | +| ERROR_UNKNOWN | -1 | Unknown error.| +| ERROR_INSUFFICIENT_RESOURCES | 0 | Insufficient resources.| -### start +## MetadataOutputError -start(callback: AsyncCallback): void +Defines a metadata output error. -Starts to output metadata. This API uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Multimedia.Camera.Core + +| Name| Type | Mandatory | Description | +| ---- | ------------------------------------- | ----------------- | ----------------------- | +| code | [MetadataOutputErrorCode](#metadataoutputerrorcode) | Yes | **MetadataOutput** error code.| + +## MetadataObjectType + +Enumerates metadata streams. + +**System capability**: SystemCapability.Multimedia.Camera.Core + +| Name | Value | Description | +| ------------------------- | ---- | ----------------- | +| FACE_DETECTION | 0 | Metadata object type.| + +## Rect + +Defines a rectangle. + +**System capability**: SystemCapability.Multimedia.Camera.Core + +| Name | Type | Mandatory | Description | +| -------- | ------ | --------------- | -------------------- | +| topLeftX | number | Yes | X-axis coordinate of the upper left corner of the rectangle. | +| topLeftY | number | Yes | Y-axis coordinate of the upper left corner of the rectangle. | +| width | number | Yes | Width of the rectangle. | +| height | number | Yes |Height of the rectangle. | + +## MetadataObject + +Implements camera metadata, which is the data source of [CameraInput](#camerainput). The metadata is obtained through metadataOutput.on('metadataObjectsAvailable'). + +### getType + +getType(callback: AsyncCallback): void + +Obtains the metadata object type. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------------------- | ---- | ------------------- | -| callback | AsyncCallback | Yes | Callback used to return the result.| +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------------------------- | --- | -------------------- | +| callback | AsyncCallback<[MetadataObjectType](#metadataobjecttype)\> | Yes | Callback used to return the result.| **Example** ```js -metadataOutput.start((err) => { +let metadataObject = metadataObjectArr[0]; +metadataObject.getType((err, metadataObjectType) => { if (err) { - console.error(`Failed to start metadataOutput. ${err.message}`); + console.error(`Failed to get type. ${err.message}`); return; } - console.log('Callback returned with metadataOutput started.'); + console.log('Callback returned with an array of metadataObjectType.'); }) ``` -### start +### getType -start(): Promise +getType(): Promise -Starts to output metadata. 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 **Return value** -| Type | Description | -| ---------------------- | ------------------------ | -| Promise | Promise used to return the result.| +| Type | Description | +| --------------------------------------------------- | --------------------------- | +| Promise<[MetadataObjectType](#metadataobjecttype)\> | Promise used to return the result.| **Example** ```js -metadataOutput.start().then(() => { - console.log('Callback returned with metadataOutput started.'); +let metadataObject = metadataObjectArr[0]; +metadataObject.getType().then((metadataObjectType) => { + console.log('Callback returned with an array of metadataObjectType.'); }) ``` -### stop +### getTimestamp -stop(callback: AsyncCallback): void +getTimestamp(callback: AsyncCallback): void -Stops outputting metadata. 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 **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------------- | ---- | ------------------- | -| callback | AsyncCallback | Yes | Callback used to return the result.| +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------------------- | ---- | ------------------------ | +| callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -metadataOutput.stop((err) => { +let metadataObject = metadataObjectArr[0]; +metadataObject.getTimestamp((err,timestamp) => { if (err) { - console.error(`Failed to stop the metadataOutput. ${err.message}`); + console.error(`Failed to get timestamp. ${err.message}`); return; } - console.log('Callback returned with metadataOutput stopped.'); + console.log('Callback returned with timestamp getted timestamp : ${timestamp}'); }) ``` -### stop +### getTimestamp -stop(): Promise +getTimestamp(): Promise -Stops outputting metadata. 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 **Return value** -| Type | Description | -| ---------------------- | --------------------------- | -| Promise | Promise used to return the result.| +| Type | Description | +| ---------------- | --------------------------- | +| Promise | Promise used to return the result.| **Example** ```js -metadataOutput.stop().then(() => { - console.log('Callback returned with metadataOutput stopped.'); +let metadataObject = metadataObjectArr[0]; +metadataObject.getTimestamp().then((timestamp) => { + console.log('Callback returned with timestamp getted timestamp : ${timestamp}'); }) ``` -### on('metadataObjectsAvailable') +### getBoundingBox -on(type: 'metadataObjectsAvailable', callback: AsyncCallback\>): void +getBoundingBox(callback: AsyncCallback): void -Listens for metadata objects. 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 **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------ | ---- | ------------------------------------ | -| type | string | Yes | Event type. The value is fixed at **'metadataObjectsAvailable'**, that is, the metadata object.| -| callback | Callback\> | Yes | Callback used to return the error information. | +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------------------- | ---- | ------------------------ | +| callback | AsyncCallback<[Rect](#rect)\> | Yes | Callback used to return the result.| **Example** ```js -metadataOutput.on('metadataObjectsAvailable', (metadataObject) => { - console.log(`metadata output error code: ${metadataObject.code}`); +let metadataObject = metadataObjectArr[0]; +metadataObject.getBoundingBox((err, rect) => { + if (err) { + console.error(`Failed to get boundingBox. ${err.message}`); + return; + } + console.log('Callback returned with boundingBox getted.'); }) ``` -### on('error') +### getBoundingBox -on(type: 'error', callback: ErrorCallback): void +getBoundingBox(): Promise -Listens for metadata errors. This API uses an asynchronous callback 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 -**Parameters** +**Return value** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------ | ---- | --------------------------------------- | -| type | string | Yes | Event type. The value is fixed at **'error'**, that is, the metadata error.| -| callback | Callback<[MetadataOutputError](#metadataoutputerror)\> | Yes | Callback used to return the error information. | +| Type | Description | +| ---------------------- | --------------------------- | +| Promise<[Rect](#rect)\> | Promise used to return the result.| **Example** ```js -metadataOutput.on('error', (metadataOutputError) => { - console.log(`Metadata output error code: ${metadataOutputError.code}`); +let metadataObject = metadataObjectArr[0]; +metadataObject.getBoundingBox().then((rect) => { + console.log('Callback returned with boundingBox getted.'); }) ``` -## MetadataOutputErrorCode - -Enumerates the codes used for metadata output errors. - -**System capability**: SystemCapability.Multimedia.Camera.Core - -| Name | Value | Description | -| ------------------------------- | ---- | -------- | -| ERROR_UNKNOWN | -1 | Unknown error.| -| ERROR_INSUFFICIENT_RESOURCES | 0 | Insufficient resources.| - -## MetadataOutputError - -Defines a metadata output error. - -**System capability**: SystemCapability.Multimedia.Camera.Core +## MetadataFaceObject -| Name| Type | Description | -| ---- | ------------------------------------- | ----------------------- | -| code | [MetadataOutputErrorCode](#metadataoutputerrorcode) | **MetadataOutput** error code.| +Implements the face object of metadata. It inherits [MetadataObject](#metadataobject). diff --git a/en/application-dev/reference/apis/js-apis-vibrator.md b/en/application-dev/reference/apis/js-apis-vibrator.md index 95654a5829967c3e6f3be2be8c5daf3baf527386..cff7eed5a375d77355bf7f20d26b497bff57d7a9 100644 --- a/en/application-dev/reference/apis/js-apis-vibrator.md +++ b/en/application-dev/reference/apis/js-apis-vibrator.md @@ -1,6 +1,6 @@ # Vibrator -The **Vibrator** module provides APIs for triggering or stopping vibration. +The **vibrator** module provides APIs for starting or stopping vibration. > **NOTE** > @@ -17,7 +17,7 @@ import vibrator from '@ohos.vibrator'; startVibration(effect: VibrateEffect, attribute: VibrateAttribute, callback: AsyncCallback<void>): void -Triggers vibration with the specified effect and attribute. This API uses a promise to return the result. +Starts vibration with the specified effect and attribute. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.VIBRATE @@ -29,35 +29,35 @@ Triggers vibration with the specified effect and attribute. This API uses a prom | --------- | -------------------------------------- | ---- | :--------------------------------------------------------- | | effect | [VibrateEffect](#vibrateeffect9) | Yes | Vibration effect. | | attribute | [VibrateAttribute](#vibrateattribute9) | Yes | Vibration attribute. | -| callback | AsyncCallback<void> | Yes | Callback used to the result. If the vibration starts, **err** is **undefined**. Otherwise, **err** is an error object.| +| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the vibration starts, **err** is **undefined**; otherwise, **err** is an error object.| **Error codes** For details about the error codes, see [Vibrator Error Codes](../errorcodes/errorcode-vibrator.md). -| ID| Error Message | -| -------- | ------------------------- | -| 14600101 | Device operation failed.| +| ID| Error Message | +| -------- | ------------------------ | +| 14600101 | Device operation failed. | **Example** ```js try { vibrator.startVibration({ - type:'time', - duration:1000, - },{ - id:0, + type: 'time', + duration: 1000, + }, { + id: 0, usage: 'alarm' - }, (error)=>{ - if(error){ - console.log('vibrate fail, error.code: ' + error.code + 'error.message: ', + error.message); - }else{ - console.log('Callback returned to indicate a successful vibration.'); + }, (error) => { + if (error) { + console.error('vibrate fail, error.code: ' + error.code + 'error.message: ', + error.message); + return; } + console.log('Callback returned to indicate a successful vibration.'); }); -} catch(err) { - console.info('errCode: ' + err.code + ' ,msg: ' + err.message); +} catch (err) { + console.error('errCode: ' + err.code + ' ,msg: ' + err.message); } ``` @@ -65,7 +65,7 @@ try { startVibration(effect: VibrateEffect, attribute: VibrateAttribute): Promise<void> -Triggers vibration with the specified effect and attribute. This API uses a promise to return the result. +Starts vibration with the specified effect and attribute. This API uses a promise to return the result. **Required permissions**: ohos.permission.VIBRATE @@ -88,27 +88,27 @@ Triggers vibration with the specified effect and attribute. This API uses a prom For details about the error codes, see [Vibrator Error Codes](../errorcodes/errorcode-vibrator.md). -| ID| Error Message | -| -------- | ------------------------- | -| 14600101 | Device operation failed.| +| ID| Error Message | +| -------- | ------------------------ | +| 14600101 | Device operation failed. | **Example** ```js try { vibrator.startVibration({ - type: 'time', - duration: 1000 + type: 'time', + duration: 1000 }, { id: 0, usage: 'alarm' - }).then(()=>{ + }).then(() => { console.log('Promise returned to indicate a successful vibration'); - }).catch((error)=>{ - console.log('error.code' + error.code + 'error.message' + error.message); - }) -} catch(err) { - console.info('errCode: ' + err.code + ' ,msg: ' + err.message); + }, (error) => { + console.error('error.code' + error.code + 'error.message' + error.message); + }); +} catch (err) { + console.error('errCode: ' + err.code + ' ,msg: ' + err.message); } ``` @@ -116,7 +116,7 @@ try { stopVibration(stopMode: VibratorStopMode, callback: AsyncCallback<void>): void -Stops the vibration with the specified **stopMode**. This API uses a promise to return the result. If the specified **stopMode** is different from the mode used to trigger the vibration, this API fails to be called. +Stops vibration in the specified mode. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.VIBRATE @@ -127,21 +127,41 @@ Stops the vibration with the specified **stopMode**. This API uses a promise to | Name | Type | Mandatory| Description | | -------- | ------------------------------------- | ---- | ------------------------------------------------------------ | | stopMode | [VibratorStopMode](#vibratorstopmode) | Yes | Mode to stop the vibration. | -| callback | AsyncCallback<void> | Yes | Callback used to the result. If the vibration stops, **err** is **undefined**. Otherwise, **err** is an error object.| +| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the vibration stops, **err** is **undefined**; otherwise, **err** is an error object.| **Example** ```js try { - vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET, function(error){ - if(error){ + // Start vibration at a fixed duration. + vibrator.startVibration({ + type: 'time', + duration: 1000, + }, { + id: 0, + usage: 'alarm' + }, (error) => { + if (error) { + console.error('vibrate fail, error.code: ' + error.code + 'error.message: ', + error.message); + return; + } + console.log('Callback returned to indicate a successful vibration.'); + }); +} catch (err) { + console.error('errCode: ' + err.code + ' ,msg: ' + err.message); +} + +try { + // Stop vibration in VIBRATOR_STOP_MODE_TIME mode. + vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_TIME, function (error) { + if (error) { console.log('error.code' + error.code + 'error.message' + error.message); - }else{ - console.log('Callback returned to indicate successful.'); + return; } + console.log('Callback returned to indicate successful.'); }) -} catch(err) { - console.info('errCode: ' + err.code + ' ,msg: ' + err.message); +} catch (err) { + console.info('errCode: ' + err.code + ' ,msg: ' + err.message); } ``` @@ -149,7 +169,7 @@ try { stopVibration(stopMode: VibratorStopMode): Promise<void> -Stops the vibration with the specified **stopMode**. This API uses a promise to return the result. If the specified **stopMode** is different from the mode used to trigger the vibration, this API fails to be called. +Stops vibration in the specified mode. This API uses a promise to return the result. **Required permissions**: ohos.permission.VIBRATE @@ -171,25 +191,43 @@ Stops the vibration with the specified **stopMode**. This API uses a promise to ```js try { - vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then(()=>{ - console.log('Promise returned to indicate a successful vibration.'); - }, (error)=>{ + // Start vibration at a fixed duration. + vibrator.startVibration({ + type: 'time', + duration: 1000 + }, { + id: 0, + usage: 'alarm' + }).then(() => { + console.log('Promise returned to indicate a successful vibration'); + }, (error) => { + console.error('error.code' + error.code + 'error.message' + error.message); + }); +} catch (err) { + console.error('errCode: ' + err.code + ' ,msg: ' + err.message); +} + +try { + // Stop vibration in VIBRATOR_STOP_MODE_TIME mode. + vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then(() => { + console.log('Promise returned to indicate a successful vibration.'); + }, (error) => { console.log('error.code' + error.code + 'error.message' + error.message); }); -} catch(err) { - console.info('errCode: ' + err.code + ' ,msg: ' + err.message); +} catch (err) { + console.info('errCode: ' + err.code + ' ,msg: ' + err.message); } ``` ## EffectId -Describes the vibration effect ID. +Describes the preset vibration effect ID. **System capability**: SystemCapability.Sensors.MiscDevice -| Name | Default Value | Description | -| ------------------ | -------------------- | ------------------ | -| EFFECT_CLOCK_TIMER | "haptic.clock.timer" | Preset vibration effect ID.| +| Name | Value | Description | +| ------------------ | -------------------- | -------------------------------- | +| EFFECT_CLOCK_TIMER | "haptic.clock.timer" | Vibration effect of the vibrator when a user adjusts the timer.| ## VibratorStopMode @@ -198,10 +236,10 @@ Enumerates the modes available to stop the vibration. **System capability**: SystemCapability.Sensors.MiscDevice -| Name | Default Value | Description | -| ------------------------- | -------- | ------------------------------------------------------------ | -| VIBRATOR_STOP_MODE_TIME | "time" | The vibration to stop is in **duration** mode. This vibration is triggered with the parameter **duration** of the **number** type.| -| VIBRATOR_STOP_MODE_PRESET | "preset" | The vibration to stop is in **EffectId** mode. This vibration is triggered with the parameter **effectId** of the **EffectId** type.| +| Name | Value | Description | +| ------------------------- | -------- | ------------------------------ | +| VIBRATOR_STOP_MODE_TIME | "time" | The vibration to stop is in **duration** mode.| +| VIBRATOR_STOP_MODE_PRESET | "preset" | The vibration to stop is in **EffectId** mode.| ## VibrateEffect9+ @@ -220,7 +258,7 @@ Describes the vibration with the specified duration. **System capability**: SystemCapability.Sensors.MiscDevice -| Name | Default Value| Description | +| Name | Value| Description | | -------- | ------ | ------------------------------ | | type | "time" | Vibration with the specified duration.| | duration | - | Vibration duration, in ms. | @@ -231,7 +269,7 @@ Describes the vibration with a preset effect. **System capability**: SystemCapability.Sensors.MiscDevice -| Name | Default Value | Description | +| Name | Value | Description | | -------- | -------- | ------------------------------ | | type | "preset" | Vibration with the specified effect.| | effectId | - | Preset vibration effect ID. | @@ -243,7 +281,7 @@ Describes the vibration attribute. **System capability**: SystemCapability.Sensors.MiscDevice -| Name | Default Value| Description | +| Name | Value| Description | | ----- | ------ | -------------- | | id | 0 | Vibrator ID. | | usage | - | Vibration scenario.| @@ -293,9 +331,9 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sta **Example** ```js -vibrator.vibrate(1000).then(()=>{ +vibrator.vibrate(1000).then(() => { console.log('Promise returned to indicate a successful vibration.'); -}, (error)=>{ +}, (error) => { console.log('error.code' + error.code + 'error.message' + error.message); }); ``` @@ -317,15 +355,15 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sta | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------------------------------------------------------- | | duration | number | Yes | Vibration duration, in ms. | -| callback | AsyncCallback<void> | No | Callback used to the result. If the vibration starts, **err** is **undefined**. Otherwise, **err** is an error object.| +| callback | AsyncCallback<void> | No | Callback used to return the result. If the vibration starts, **err** is **undefined**; otherwise, **err** is an error object.| **Example** ```js -vibrator.vibrate(1000,function(error){ - if(error){ +vibrator.vibrate(1000, function (error) { + if (error) { console.log('error.code' + error.code + 'error.message' + error.message); - }else{ + } else { console.log('Callback returned to indicate a successful vibration.'); } }) @@ -359,9 +397,9 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sta **Example** ```js -vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER).then(()=>{ +vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER).then(() => { console.log('Promise returned to indicate a successful vibration.'); -}, (error)=>{ +}, (error) => { console.log('error.code' + error.code + 'error.message' + error.message); }); ``` @@ -384,15 +422,15 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sta | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------------------------------------------------------- | | effectId | [EffectId](#effectid) | Yes | Preset vibration effect ID. | -| callback | AsyncCallback<void> | No | Callback used to the result. If the vibration starts, **err** is **undefined**. Otherwise, **err** is an error object.| +| callback | AsyncCallback<void> | No | Callback used to return the result. If the vibration starts, **err** is **undefined**; otherwise, **err** is an error object.| **Example** ```js -vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER, function(error){ - if(error){ +vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER, function (error) { + if (error) { console.log('error.code' + error.code + 'error.message' + error.message); - }else{ + } else { console.log('Callback returned to indicate a successful vibration.'); } }) @@ -402,7 +440,7 @@ vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER, function(error){ stop(stopMode: VibratorStopMode): Promise<void> -Stops the vibration with the specified **stopMode**. This API uses a promise to return the result. If the specified **stopMode** is different from the mode used to trigger the vibration, this API fails to be called. +Stops vibration in the specified mode. This API uses a promise to return the result. This API is deprecated since API version 9. You are advised to use [vibrator.stopVibration](#vibratorstopvibration9-1) instead. @@ -425,9 +463,18 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sto **Example** ```js -vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then(()=>{ +// Start vibration based on the specified effect ID. +vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER, function (error) { + if (error) { + console.log('error.code' + error.code + 'error.message' + error.message); + } else { + console.log('Callback returned to indicate a successful vibration.'); + } +}) +// Stop vibration in VIBRATOR_STOP_MODE_PRESET mode. +vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then(() => { console.log('Promise returned to indicate a successful vibration.'); -}, (error)=>{ +}, (error) => { console.log('error.code' + error.code + 'error.message' + error.message); }); ``` @@ -437,7 +484,7 @@ vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then(()=>{ stop(stopMode: VibratorStopMode, callback?: AsyncCallback<void>): void -Stops the vibration with the specified **stopMode**. This API uses a promise to return the result. If the specified **stopMode** is different from the mode used to trigger the vibration, this API fails to be called. +Stops vibration in the specified mode. This API uses an asynchronous callback to return the result. This API is deprecated since API version 9. You are advised to use [vibrator.stopVibration](#vibratorstopvibration9) instead. @@ -450,15 +497,24 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sto | Name | Type | Mandatory| Description | | -------- | ------------------------------------- | ---- | ------------------------------------------------------------ | | stopMode | [VibratorStopMode](#vibratorstopmode) | Yes | Mode to stop the vibration. | -| callback | AsyncCallback<void> | No | Callback used to the result. If the vibration stops, **err** is **undefined**. Otherwise, **err** is an error object.| +| callback | AsyncCallback<void> | No | Callback used to return the result. If the vibration stops, **err** is **undefined**; otherwise, **err** is an error object.| **Example** ```js -vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET, function(error){ - if(error){ +// Start vibration based on the specified effect ID. +vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER, function (error) { + if (error) { + console.log('error.code' + error.code + 'error.message' + error.message); + } else { + console.log('Callback returned to indicate a successful vibration.'); + } +}) +// Stop vibration in VIBRATOR_STOP_MODE_PRESET mode. +vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET, function (error) { + if (error) { console.log('error.code' + error.code + 'error.message' + error.message); - }else{ + } else { console.log('Callback returned to indicate successful.'); } })