# Interface (MetadataOutput) > **NOTE** > > The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. MetadataOutput implements metadata streams. It inherits from [CameraOutput](arkts-apis-camera-CameraOutput.md). ## Modules to Import ```ts import { camera } from '@kit.CameraKit'; ``` ## start start(callback: AsyncCallback\): void Starts to output metadata. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 19. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------- | ---- | ------------------- | | callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation fails, an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode) is returned.| **Error codes** For details about the error codes, see [Camera Error Codes](errorcode-camera.md). | ID | Error Message | | --------------- | --------------- | | 7400103 | Session not config. | | 7400201 | Camera service fatal error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; function startMetadataOutput(metadataOutput: camera.MetadataOutput): void { metadataOutput.start((err: BusinessError) => { if (err) { console.error(`Failed to start metadata output, error code: ${err.code}.`); return; } console.info('Callback returned with metadata output started.'); }); } ``` ## start start(): Promise\ Starts to output metadata. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 19. **System capability**: SystemCapability.Multimedia.Camera.Core **Return value** | Type | Description | | ---------------------- | ------------------------ | | Promise\ | Promise that returns no value.| **Error codes** For details about the error codes, see [Camera Error Codes](errorcode-camera.md). | ID | Error Message | | --------------- | --------------- | | 7400103 | Session not config. | | 7400201 | Camera service fatal error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; function startMetadataOutput(metadataOutput: camera.MetadataOutput): void { metadataOutput.start().then(() => { console.info('Callback returned with metadata output started.'); }).catch((error: BusinessError) => { console.error(`Failed to metadata output stop, error code: ${error.code}`); }); } ``` ## stop stop(callback: AsyncCallback\): void Stops outputting metadata. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 19. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------- | ---- | ------------------- | | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void { metadataOutput.stop((err: BusinessError) => { if (err) { console.error(`Failed to stop the metadata output, error code: ${err.code}.`); return; } console.info('Callback returned with metadata output stopped.'); }) } ``` ## stop stop(): Promise\ Stops outputting metadata. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 19. **System capability**: SystemCapability.Multimedia.Camera.Core **Return value** | Type | Description | | ---------------------- | --------------------------- | | Promise\ | Promise that returns no value.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void { metadataOutput.stop().then(() => { console.info('Callback returned with metadata output stopped.'); }).catch((error: BusinessError) => { console.error(`Failed to metadata output stop, error code: ${error.code}`); }); } ``` ## on('metadataObjectsAvailable') on(type: 'metadataObjectsAvailable', callback: AsyncCallback\\>): void Subscribes to events indicating available metadata objects. This API uses an asynchronous callback to return the result. > **NOTE** > > Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. **Atomic service API**: This API can be used in atomic services since API version 19. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------- | ---- | ------------------------------------ | | type | string | Yes | Event type. The value is fixed at **'metadataObjectsAvailable'**. The event can be listened for when a metadataOutput instance is created. This event is triggered and the corresponding metadata is returned when valid metadata is detected.| | callback | AsyncCallback\\> | Yes | Callback used to return the metadata.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; function callback(err: BusinessError, metadataObjectArr: Array): void { if (err !== undefined && err.code !== 0) { console.error(`Callback Error, errorCode: ${err.code}`); return; } console.info('metadata output metadataObjectsAvailable'); } function registerMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void { metadataOutput.on('metadataObjectsAvailable', callback); } ``` ## off('metadataObjectsAvailable') off(type: 'metadataObjectsAvailable', callback?: AsyncCallback\\>): void Unsubscribes from events indicating available metadata objects. **Atomic service API**: This API can be used in atomic services since API version 19. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------- | ---- | ------------------------------------ | | type | string | Yes | Event type. The value is fixed at **'metadataObjectsAvailable'**. The event can be listened for when a metadataOutput instance is created.| | callback | AsyncCallback\\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| **Example** ```ts function unregisterMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void { metadataOutput.off('metadataObjectsAvailable'); } ``` ## on('error') on(type: 'error', callback: ErrorCallback): void Subscribes to metadata error events. This API uses an asynchronous callback to return the result. > **NOTE** > > Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. **Atomic service API**: This API can be used in atomic services since API version 19. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------- | ---- | --------------------------------------- | | type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a metadataOutput instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the use of a metadata-related API such as [start](#start-1) or [CameraOutput.release](arkts-apis-camera-CameraOutput.md#release-1).| | callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode). | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; function callback(metadataOutputError: BusinessError): void { console.error(`Metadata output error code: ${metadataOutputError.code}`); } function registerMetadataOutputError(metadataOutput: camera.MetadataOutput): void { metadataOutput.on('error', callback); } ``` ## off('error') off(type: 'error', callback?: ErrorCallback): void Unsubscribes from metadata error events. **Atomic service API**: This API can be used in atomic services since API version 19. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------- | ---- | --------------------------------------- | | type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a metadataOutput instance is created.| | callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| **Example** ```ts function unregisterMetadataOutputError(metadataOutput: camera.MetadataOutput): void { metadataOutput.off('error'); } ```