1e41f4b71Sopenharmony_ci# @ohos.multimedia.media (Media) (System API) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe multimedia subsystem provides a set of simple and easy-to-use APIs for you to access the system and use media resources. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci> - This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.multimedia.media (Media)](js-apis-media.md). 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## Modules to Import 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci```ts 13e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit'; 14e41f4b71Sopenharmony_ci``` 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci## media.createVideoRecorder<sup>9+</sup> 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_cicreateVideoRecorder(callback: AsyncCallback\<VideoRecorder>): void 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ciCreates a **VideoRecorder** instance. This API uses an asynchronous callback to return the result. 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ciOnly one **VideoRecorder** instance can be created per device. 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci**System API**: This is a system API. 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci**Parameters** 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 31e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 32e41f4b71Sopenharmony_ci| callback | AsyncCallback<[VideoRecorder](#videorecorder9)> | Yes | Callback used to return the result. If the operation is successful, a **VideoRecorder** instance is returned; otherwise, **null** is returned. The instance can be used to record video.| 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci**Error codes** 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci| ID| Error Message | 39e41f4b71Sopenharmony_ci| -------- | ------------------------------ | 40e41f4b71Sopenharmony_ci| 5400101 | No memory. Return by callback. | 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci**Example** 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci```ts 45e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_cilet videoRecorder: media.VideoRecorder; 48e41f4b71Sopenharmony_cimedia.createVideoRecorder((error: BusinessError, video: media.VideoRecorder) => { 49e41f4b71Sopenharmony_ci if (video != null) { 50e41f4b71Sopenharmony_ci videoRecorder = video; 51e41f4b71Sopenharmony_ci console.info('video createVideoRecorder success'); 52e41f4b71Sopenharmony_ci } else { 53e41f4b71Sopenharmony_ci console.error(`video createVideoRecorder fail, error message:${error.message}`); 54e41f4b71Sopenharmony_ci } 55e41f4b71Sopenharmony_ci}); 56e41f4b71Sopenharmony_ci``` 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci## media.createVideoRecorder<sup>9+</sup> 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_cicreateVideoRecorder(): Promise\<VideoRecorder> 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ciCreates a **VideoRecorder** instance. This API uses a promise to return the result. 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ciOnly one **VideoRecorder** instance can be created per device. 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci**System API**: This is a system API. 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci**Return value** 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci| Type | Description | 73e41f4b71Sopenharmony_ci| ----------------------------------------- | ------------------------------------------------------------ | 74e41f4b71Sopenharmony_ci| Promise<[VideoRecorder](#videorecorder9)> | Promise used to return the result. If the operation is successful, a **VideoRecorder** instance is returned; otherwise, **null** is returned. The instance can be used to record video.| 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci**Error codes** 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci| ID| Error Message | 81e41f4b71Sopenharmony_ci| -------- | ----------------------------- | 82e41f4b71Sopenharmony_ci| 5400101 | No memory. Return by promise. | 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci**Example** 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci```ts 87e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_cilet videoRecorder: media.VideoRecorder; 90e41f4b71Sopenharmony_cimedia.createVideoRecorder().then((video: media.VideoRecorder) => { 91e41f4b71Sopenharmony_ci if (video != null) { 92e41f4b71Sopenharmony_ci videoRecorder = video; 93e41f4b71Sopenharmony_ci console.info('video createVideoRecorder success'); 94e41f4b71Sopenharmony_ci } else { 95e41f4b71Sopenharmony_ci console.error('video createVideoRecorder fail'); 96e41f4b71Sopenharmony_ci } 97e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 98e41f4b71Sopenharmony_ci console.error(`video catchCallback, error message:${error.message}`); 99e41f4b71Sopenharmony_ci}); 100e41f4b71Sopenharmony_ci``` 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci## media.reportAVScreenCaptureUserChoice<sup>12+</sup> 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_cireportAVScreenCaptureUserChoice(sessionId: number, choice: string): Promise\<void> 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ciReports the user selection result in the screen capture privacy dialog box to the AVScreenCapture server to determine whether to start screen capture. Screen capture starts only when the user touches a button to continue the operation. 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ciThis API is called by the system application that creates the dialog box. 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci**System API**: This is a system API. 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci**Parameters** 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 117e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ------------------------------------------------------------ | 118e41f4b71Sopenharmony_ci| sessionId | number | Yes | Session ID of the AVScreenCapture service, which is sent to the application when the AVScreenCapture server starts the privacy dialog box.| 119e41f4b71Sopenharmony_ci| choice | string | Yes | User selection result. The value **false** means that the user touches a button to cancel the operation, and **true** means that the user touches a button to continue the operation. | 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci**Error codes** 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci| ID| Error Message | 124e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 125e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 126e41f4b71Sopenharmony_ci| 5400101 | No memory. Return by promise. | 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci**Example** 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci```ts 131e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_cilet sessionId: number = 0; // Use the ID of the session that starts the process. 134e41f4b71Sopenharmony_cilet choice: string = 'false'; // Use the user selection result. 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_citry { 137e41f4b71Sopenharmony_ci await media.reportAVScreenCaptureUserChoice(sessionId, choice); 138e41f4b71Sopenharmony_ci} catch (error: BusinessError) { 139e41f4b71Sopenharmony_ci console.error(`reportAVScreenCaptureUserChoice error, error message: ${error.message}`); 140e41f4b71Sopenharmony_ci} 141e41f4b71Sopenharmony_ci``` 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci## PixelMapParams<sup>11+</sup> 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ciDefines the format parameters of the video thumbnail to be obtained. 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVImageGenerator 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci| Name | Type | Readable | Writable | Description | 150e41f4b71Sopenharmony_ci| -------- | ------ | ------| ------ | ---------------------- | 151e41f4b71Sopenharmony_ci| colorFormat | [PixelFormat](#pixelformat11) | Yes | Yes | Color format of the thumbnail.<br>**System API**: This is a system API. | 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci## PixelFormat<sup>11+</sup> 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ciEnumerates the color formats supported by the video thumbnail. 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVImageGenerator 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci**System API**: This is a system API. 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci| Name | Value | Description | 162e41f4b71Sopenharmony_ci| ------------------------ | --------------- | ------------------------------------------------------------ | 163e41f4b71Sopenharmony_ci| RGB_565 | 2 | RGB_565. | 164e41f4b71Sopenharmony_ci| RGBA_8888 | 3 | RGBA_8888.| 165e41f4b71Sopenharmony_ci| RGB_888 | 5 | RGB_888. | 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci## AvPlayer<sup>9+</sup> 168e41f4b71Sopenharmony_ci> **NOTE** 169e41f4b71Sopenharmony_ci> 170e41f4b71Sopenharmony_ci> A playback management class that provides APIs to manage and play media assets. Before calling any API in **AVPlayer**, you must use [createAVPlayer()](js-apis-media.md#mediacreateavplayer9) to create an [AVPlayer](js-apis-media.md#avplayer9) instance. 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci### setPlaybackRange<sup>12+</sup> 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_cisetPlaybackRange(startTimeMs: number, endTimeMs: number, mode?: SeekMode) : Promise\<void> 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ciSets the playback range and seeks to the start position of the range based on the specified [SeekMode](js-apis-media.md#seekmode8). After the setting, only the content in the specified range of the audio or video file is played. This API uses a promise to return the result. It can be used when the AVPlayer is in the initialized, prepared, paused, stopped, or completed state. 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AvPlayer 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci**System API**: This is a system API. 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci**Parameters** 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 185e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | --------------------------- | 186e41f4b71Sopenharmony_ci| startTimeMs | number | Yes | Start position of the range, in ms. The value range is [0, duration). If **-1** is passed in, the system starts playing from position 0.| 187e41f4b71Sopenharmony_ci| endTimeMs | number | Yes | End position of the range, in ms. The value range is (startTimeMs, duration]. If **-1** is passed in, the system plays the content until it reaches the final part of the asset.| 188e41f4b71Sopenharmony_ci| mode | [SeekMode](js-apis-media.md#seekmode8) | No | Seek mode, which can be **SeekMode.SEEK_PREV_SYNC** or **SeekMode.SEEK_CLOSEST**.<br>The default value is **SeekMode.SEEK_PREV_SYNC**.| 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci**Error codes** 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci| ID| Error Message | 195e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ | 196e41f4b71Sopenharmony_ci| 202 | Called from Non-System applications. Return by promise. | 197e41f4b71Sopenharmony_ci| 401 | The parameter check failed. Return by promise. | 198e41f4b71Sopenharmony_ci| 5400102 | Operation not allowed. Return by promise. | 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci**Example** 201e41f4b71Sopenharmony_ci 202e41f4b71Sopenharmony_ci```ts 203e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit'; 204e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ciavPlayer.setPlaybackRange(0, 6000, media.SeekMode.SEEK_CLOSEST).then(() => { 207e41f4b71Sopenharmony_ci console.info('Succeeded setPlaybackRange'); 208e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 209e41f4b71Sopenharmony_ci console.error('Failed to setPlaybackRange' + err.message); 210e41f4b71Sopenharmony_ci}); 211e41f4b71Sopenharmony_ci``` 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci## AVMetadataExtractor<sup>11+</sup> 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ciProvides APIs to obtain metadata from media assets. Before calling any API of **AVMetadataExtractor**, you must use [createAVMetadataExtractor()](js-apis-media.md#mediacreateavmetadataextractor11) to create an **AVMetadataExtractor** instance. 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci### getTimeByFrameIndex<sup>12+</sup> 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_cigetTimeByFrameIndex(index: number): Promise\<number> 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ciObtains the video timestamp corresponding to a video frame number. Only MP4 video files are supported. 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci**System API**: This is a system API. 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci**Parameters** 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 230e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------- | 231e41f4b71Sopenharmony_ci| index | number | Yes | Video frame number.| 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci**Return value** 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ci| Type | Description | 236e41f4b71Sopenharmony_ci| ---------------- | ----------------------------------- | 237e41f4b71Sopenharmony_ci| Promise\<number> | Promise used to return the timestamp, in microseconds.| 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ci**Error codes** 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_ci| ID| Error Message | 244e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------- | 245e41f4b71Sopenharmony_ci| 401 | The parameter check failed. Return by promise. | 246e41f4b71Sopenharmony_ci| 5400102 | Operation not allowed. Returned by promise. | 247e41f4b71Sopenharmony_ci| 5400106 | Unsupported format. Returned by promise. | 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci**Example** 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ci```ts 252e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit'; 253e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ciavMetadataExtractor.getTimeByFrameIndex(0).then((timeUs: number) => { 256e41f4b71Sopenharmony_ci console.info(`Succeeded getTimeByFrameIndex timeUs: ${timeUs}`); 257e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 258e41f4b71Sopenharmony_ci console.error(`Failed to getTimeByFrameIndex ${err.message}`); 259e41f4b71Sopenharmony_ci}) 260e41f4b71Sopenharmony_ci``` 261e41f4b71Sopenharmony_ci 262e41f4b71Sopenharmony_ci### getFrameIndexByTime<sup>12+</sup> 263e41f4b71Sopenharmony_ci 264e41f4b71Sopenharmony_cigetFrameIndexByTime(timeUs: number): Promise\<number> 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ciObtains the video frame number corresponding to a video timestamp. Only MP4 video files are supported. 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 269e41f4b71Sopenharmony_ci 270e41f4b71Sopenharmony_ci**System API**: This is a system API. 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_ci**Parameters** 273e41f4b71Sopenharmony_ci 274e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 275e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------ | 276e41f4b71Sopenharmony_ci| timeUs | number | Yes | Video timestamp, in microseconds.| 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_ci**Return value** 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci| Type | Description | 281e41f4b71Sopenharmony_ci| ---------------- | ------------------------- | 282e41f4b71Sopenharmony_ci| Promise\<number> | Promise used to return the video frame number.| 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_ci**Error codes** 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_ci| ID| Error Message | 289e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------- | 290e41f4b71Sopenharmony_ci| 401 | The parameter check failed. Return by promise. | 291e41f4b71Sopenharmony_ci| 5400102 | Operation not allowed. Returned by promise. | 292e41f4b71Sopenharmony_ci| 5400106 | Unsupported format. Returned by promise. | 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci**Example** 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci```ts 297e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit'; 298e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ciavMetadataExtractor.getFrameIndexByTime(0).then((index: number) => { 301e41f4b71Sopenharmony_ci console.info(`Succeeded getFrameIndexByTime index: ${index}`); 302e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 303e41f4b71Sopenharmony_ci console.error(`Failed to getFrameIndexByTime ${err.message}`); 304e41f4b71Sopenharmony_ci}) 305e41f4b71Sopenharmony_ci``` 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ci## AVRecorder<sup>9+</sup> 308e41f4b71Sopenharmony_ci 309e41f4b71Sopenharmony_ciA recording management class that provides APIs to record media assets. Before calling any API in **AVRecorder**, you must use [createAVRecorder()](js-apis-media.md#mediacreateavrecorder9) to create an **AVRecorder** instance. 310e41f4b71Sopenharmony_ci 311e41f4b71Sopenharmony_ci> **NOTE** 312e41f4b71Sopenharmony_ci> 313e41f4b71Sopenharmony_ci> To use the camera to record videos, the camera module is required. For details about how to use the APIs provided by the camera module, see [Camera Management](../apis-camera-kit/js-apis-camera.md). 314e41f4b71Sopenharmony_ci 315e41f4b71Sopenharmony_ci### isWatermarkSupported<sup>12+</sup> 316e41f4b71Sopenharmony_ci 317e41f4b71Sopenharmony_ciisWatermarkSupported(): Promise\<boolean> 318e41f4b71Sopenharmony_ci 319e41f4b71Sopenharmony_ciChecks whether the device supports the hardware digital watermark. This API uses a promise to return the result. 320e41f4b71Sopenharmony_ci 321e41f4b71Sopenharmony_ciThis API can be called after the [prepare()](js-apis-media.md#prepare9-3), [start()](js-apis-media.md#start9), or [paused()](js-apis-media.md#pause9) event is triggered. 322e41f4b71Sopenharmony_ci 323e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder 324e41f4b71Sopenharmony_ci 325e41f4b71Sopenharmony_ci**System API**: This is a system API. 326e41f4b71Sopenharmony_ci 327e41f4b71Sopenharmony_ci**Return value** 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_ci| Type | Description | 330e41f4b71Sopenharmony_ci| ---------------- | -------------------------------- | 331e41f4b71Sopenharmony_ci| Promise\<boolean> | Promise used to return the check result.| 332e41f4b71Sopenharmony_ci 333e41f4b71Sopenharmony_ci**Example** 334e41f4b71Sopenharmony_ci 335e41f4b71Sopenharmony_ci```ts 336e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ciavRecorder.isWatermarkSupported().then((isWatermarkSupported: boolean) => { 339e41f4b71Sopenharmony_ci console.info(`Succeeded in get, isWatermarkSupported: ${isWatermarkSupported}`); 340e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 341e41f4b71Sopenharmony_ci console.error(`Failed to get and catch error is ${error.message}`); 342e41f4b71Sopenharmony_ci}); 343e41f4b71Sopenharmony_ci``` 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ci### setWatermark<sup>12+</sup> 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_cisetWatermark(watermark: image.PixelMap, config: WatermarkConfig): Promise\<void> 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ciSets a watermark for the AVRecorder. This API uses a promise to return the result. 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_ciThis API can be called only after the [prepare()](js-apis-media.md#prepare9-3) event is triggered and before the [start()](js-apis-media.md#start9) event is triggered. 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder 354e41f4b71Sopenharmony_ci 355e41f4b71Sopenharmony_ci**System API**: This is a system API. 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci**Parameters** 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 360e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | --------------------------- | 361e41f4b71Sopenharmony_ci| watermark | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes | PixelMap data.<br>Currently, the following specifications are supported:<br>- Only RGBA8888 is supported.<br>- If the original image is 8 KB, the watermark resolution is 3072 x 288; if the original image is 4 KB, the watermark resolution is 1536 x 144.| 362e41f4b71Sopenharmony_ci| config | [WatermarkConfig](#watermarkconfig12) | Yes | Watermark configuration.| 363e41f4b71Sopenharmony_ci 364e41f4b71Sopenharmony_ci**Return value** 365e41f4b71Sopenharmony_ci 366e41f4b71Sopenharmony_ci| Type | Description | 367e41f4b71Sopenharmony_ci| ---------------- | -------------------------------- | 368e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.| 369e41f4b71Sopenharmony_ci 370e41f4b71Sopenharmony_ci**Error codes** 371e41f4b71Sopenharmony_ci 372e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 373e41f4b71Sopenharmony_ci 374e41f4b71Sopenharmony_ci| ID| Error Message | 375e41f4b71Sopenharmony_ci| -------- | -------------------------------------- | 376e41f4b71Sopenharmony_ci| 401 | The parameter check failed. Return by promise. | 377e41f4b71Sopenharmony_ci| 801 | Capability not supported. Return by promise. | 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci**Example** 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_ci```ts 382e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 383e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit'; 384e41f4b71Sopenharmony_ci 385e41f4b71Sopenharmony_cilet watermark: image.PixelMap|undefined = undefined; // need data 386e41f4b71Sopenharmony_cilet watermarkConfig: media.WatermarkConfig = { top: 100, left: 100 } 387e41f4b71Sopenharmony_ci 388e41f4b71Sopenharmony_ciavRecorder.setWatermark(watermark, watermarkConfig).then(() => { 389e41f4b71Sopenharmony_ci console.info('Succeeded in setWatermark'); 390e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 391e41f4b71Sopenharmony_ci console.error(`Failed to setWatermark and catch error is ${error.message}`); 392e41f4b71Sopenharmony_ci}); 393e41f4b71Sopenharmony_ci``` 394e41f4b71Sopenharmony_ci 395e41f4b71Sopenharmony_ci## VideoRecorder<sup>9+</sup> 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ci> **NOTE** 398e41f4b71Sopenharmony_ci> This class is deprecated after AVRecorder<sup>9+</sup> is released. You are advised to use [AVRecorder](js-apis-media.md#avrecorder9) instead. 399e41f4b71Sopenharmony_ci 400e41f4b71Sopenharmony_ciImplements video recording. Before calling any API in the **VideoRecorder** class, you must use [createVideoRecorder()](#mediacreatevideorecorder9) to create a [VideoRecorder](#videorecorder9) instance. 401e41f4b71Sopenharmony_ci 402e41f4b71Sopenharmony_ci### Attributes 403e41f4b71Sopenharmony_ci 404e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 405e41f4b71Sopenharmony_ci 406e41f4b71Sopenharmony_ci**System API**: This is a system API. 407e41f4b71Sopenharmony_ci 408e41f4b71Sopenharmony_ci| Name | Type | Readable| Writable| Description | 409e41f4b71Sopenharmony_ci| ------------------ | -------------------------------------- | ---- | ---- | ---------------- | 410e41f4b71Sopenharmony_ci| state<sup>9+</sup> | [VideoRecordState](#videorecordstate9) | Yes | No | Video recording state.| 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci### prepare<sup>9+</sup> 413e41f4b71Sopenharmony_ci 414e41f4b71Sopenharmony_ciprepare(config: VideoRecorderConfig, callback: AsyncCallback\<void>): void 415e41f4b71Sopenharmony_ci 416e41f4b71Sopenharmony_ciSets video recording parameters. This API uses an asynchronous callback to return the result. 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_ci**Required permissions:** ohos.permission.MICROPHONE 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 421e41f4b71Sopenharmony_ci 422e41f4b71Sopenharmony_ci**System API**: This is a system API. 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ci**Parameters** 425e41f4b71Sopenharmony_ci 426e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 427e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | ----------------------------------- | 428e41f4b71Sopenharmony_ci| config | [VideoRecorderConfig](#videorecorderconfig9) | Yes | Video recording parameters to set. | 429e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 430e41f4b71Sopenharmony_ci 431e41f4b71Sopenharmony_ci**Error codes** 432e41f4b71Sopenharmony_ci 433e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 434e41f4b71Sopenharmony_ci 435e41f4b71Sopenharmony_ci| ID| Error Message | 436e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ | 437e41f4b71Sopenharmony_ci| 201 | Permission denied. Return by callback. | 438e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 439e41f4b71Sopenharmony_ci| 5400102 | Operation not allowed. Return by callback. | 440e41f4b71Sopenharmony_ci| 5400105 | Service died. Return by callback. | 441e41f4b71Sopenharmony_ci 442e41f4b71Sopenharmony_ci**Example** 443e41f4b71Sopenharmony_ci 444e41f4b71Sopenharmony_ci```ts 445e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 446e41f4b71Sopenharmony_ci 447e41f4b71Sopenharmony_ci// Configure the parameters based on those supported by the hardware device. 448e41f4b71Sopenharmony_cilet videoProfile: media.VideoRecorderProfile = { 449e41f4b71Sopenharmony_ci audioBitrate : 48000, 450e41f4b71Sopenharmony_ci audioChannels : 2, 451e41f4b71Sopenharmony_ci audioCodec : media.CodecMimeType.AUDIO_AAC, 452e41f4b71Sopenharmony_ci audioSampleRate : 48000, 453e41f4b71Sopenharmony_ci fileFormat : media.ContainerFormatType.CFT_MPEG_4, 454e41f4b71Sopenharmony_ci videoBitrate : 2000000, 455e41f4b71Sopenharmony_ci videoCodec : media.CodecMimeType.VIDEO_AVC, 456e41f4b71Sopenharmony_ci videoFrameWidth : 640, 457e41f4b71Sopenharmony_ci videoFrameHeight : 480, 458e41f4b71Sopenharmony_ci videoFrameRate : 30 459e41f4b71Sopenharmony_ci} 460e41f4b71Sopenharmony_ci 461e41f4b71Sopenharmony_cilet videoConfig: media.VideoRecorderConfig = { 462e41f4b71Sopenharmony_ci audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC, 463e41f4b71Sopenharmony_ci videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV, 464e41f4b71Sopenharmony_ci profile : videoProfile, 465e41f4b71Sopenharmony_ci url : 'fd://xx', // The file must be created by the caller and granted with proper permissions. 466e41f4b71Sopenharmony_ci rotation : 0, 467e41f4b71Sopenharmony_ci location : { latitude : 30, longitude : 130 } 468e41f4b71Sopenharmony_ci} 469e41f4b71Sopenharmony_ci 470e41f4b71Sopenharmony_ci// asyncallback 471e41f4b71Sopenharmony_civideoRecorder.prepare(videoConfig, (err: BusinessError) => { 472e41f4b71Sopenharmony_ci if (err == null) { 473e41f4b71Sopenharmony_ci console.info('prepare success'); 474e41f4b71Sopenharmony_ci } else { 475e41f4b71Sopenharmony_ci console.error('prepare failed and error is ' + err.message); 476e41f4b71Sopenharmony_ci } 477e41f4b71Sopenharmony_ci}) 478e41f4b71Sopenharmony_ci``` 479e41f4b71Sopenharmony_ci 480e41f4b71Sopenharmony_ci### prepare<sup>9+</sup> 481e41f4b71Sopenharmony_ci 482e41f4b71Sopenharmony_ciprepare(config: VideoRecorderConfig): Promise\<void> 483e41f4b71Sopenharmony_ci 484e41f4b71Sopenharmony_ciSets video recording parameters. This API uses a promise to return the result. 485e41f4b71Sopenharmony_ci 486e41f4b71Sopenharmony_ci**Required permissions:** ohos.permission.MICROPHONE 487e41f4b71Sopenharmony_ci 488e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 489e41f4b71Sopenharmony_ci 490e41f4b71Sopenharmony_ci**System API**: This is a system API. 491e41f4b71Sopenharmony_ci 492e41f4b71Sopenharmony_ci**Parameters** 493e41f4b71Sopenharmony_ci 494e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 495e41f4b71Sopenharmony_ci| ------ | -------------------------------------------- | ---- | ------------------------ | 496e41f4b71Sopenharmony_ci| config | [VideoRecorderConfig](#videorecorderconfig9) | Yes | Video recording parameters to set.| 497e41f4b71Sopenharmony_ci 498e41f4b71Sopenharmony_ci**Return value** 499e41f4b71Sopenharmony_ci 500e41f4b71Sopenharmony_ci| Type | Description | 501e41f4b71Sopenharmony_ci| -------------- | ---------------------------------------- | 502e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result.| 503e41f4b71Sopenharmony_ci 504e41f4b71Sopenharmony_ci**Error codes** 505e41f4b71Sopenharmony_ci 506e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 507e41f4b71Sopenharmony_ci 508e41f4b71Sopenharmony_ci| ID| Error Message | 509e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- | 510e41f4b71Sopenharmony_ci| 201 | Permission denied. Return by promise. | 511e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 512e41f4b71Sopenharmony_ci| 5400102 | Operation not allowed. Return by promise. | 513e41f4b71Sopenharmony_ci| 5400105 | Service died. Return by promise. | 514e41f4b71Sopenharmony_ci 515e41f4b71Sopenharmony_ci**Example** 516e41f4b71Sopenharmony_ci 517e41f4b71Sopenharmony_ci```ts 518e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 519e41f4b71Sopenharmony_ci 520e41f4b71Sopenharmony_ci// Configure the parameters based on those supported by the hardware device. 521e41f4b71Sopenharmony_cilet videoProfile: media.VideoRecorderProfile = { 522e41f4b71Sopenharmony_ci audioBitrate : 48000, 523e41f4b71Sopenharmony_ci audioChannels : 2, 524e41f4b71Sopenharmony_ci audioCodec : media.CodecMimeType.AUDIO_AAC, 525e41f4b71Sopenharmony_ci audioSampleRate : 48000, 526e41f4b71Sopenharmony_ci fileFormat : media.ContainerFormatType.CFT_MPEG_4, 527e41f4b71Sopenharmony_ci videoBitrate : 2000000, 528e41f4b71Sopenharmony_ci videoCodec : media.CodecMimeType.VIDEO_AVC, 529e41f4b71Sopenharmony_ci videoFrameWidth : 640, 530e41f4b71Sopenharmony_ci videoFrameHeight : 480, 531e41f4b71Sopenharmony_ci videoFrameRate : 30 532e41f4b71Sopenharmony_ci} 533e41f4b71Sopenharmony_ci 534e41f4b71Sopenharmony_cilet videoConfig: media.VideoRecorderConfig = { 535e41f4b71Sopenharmony_ci audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC, 536e41f4b71Sopenharmony_ci videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV, 537e41f4b71Sopenharmony_ci profile : videoProfile, 538e41f4b71Sopenharmony_ci url : 'fd://xx', // The file must be created by the caller and granted with proper permissions. 539e41f4b71Sopenharmony_ci rotation : 0, 540e41f4b71Sopenharmony_ci location : { latitude : 30, longitude : 130 } 541e41f4b71Sopenharmony_ci} 542e41f4b71Sopenharmony_ci 543e41f4b71Sopenharmony_ci// promise 544e41f4b71Sopenharmony_civideoRecorder.prepare(videoConfig).then(() => { 545e41f4b71Sopenharmony_ci console.info('prepare success'); 546e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 547e41f4b71Sopenharmony_ci console.error('prepare failed and catch error is ' + err.message); 548e41f4b71Sopenharmony_ci}); 549e41f4b71Sopenharmony_ci``` 550e41f4b71Sopenharmony_ci 551e41f4b71Sopenharmony_ci### getInputSurface<sup>9+</sup> 552e41f4b71Sopenharmony_ci 553e41f4b71Sopenharmony_cigetInputSurface(callback: AsyncCallback\<string>): void 554e41f4b71Sopenharmony_ci 555e41f4b71Sopenharmony_ciObtains the surface required for recording. This API uses an asynchronous callback to return the result. The caller obtains the **surfaceBuffer** from this surface and fills in the corresponding data. 556e41f4b71Sopenharmony_ci 557e41f4b71Sopenharmony_ciNote that the video data must carry the timestamp (in ns) and buffer size, and the start time of the timestamp must be based on the system startup time. 558e41f4b71Sopenharmony_ci 559e41f4b71Sopenharmony_ciThis API can be called only after [prepare()](#prepare9) is called. 560e41f4b71Sopenharmony_ci 561e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 562e41f4b71Sopenharmony_ci 563e41f4b71Sopenharmony_ci**System API**: This is a system API. 564e41f4b71Sopenharmony_ci 565e41f4b71Sopenharmony_ci**Parameters** 566e41f4b71Sopenharmony_ci 567e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 568e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | --------------------------- | 569e41f4b71Sopenharmony_ci| callback | AsyncCallback\<string> | Yes | Callback used to return the result.| 570e41f4b71Sopenharmony_ci 571e41f4b71Sopenharmony_ci**Error codes** 572e41f4b71Sopenharmony_ci 573e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 574e41f4b71Sopenharmony_ci 575e41f4b71Sopenharmony_ci| ID| Error Message | 576e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ | 577e41f4b71Sopenharmony_ci| 5400102 | Operation not allowed. Return by callback. | 578e41f4b71Sopenharmony_ci| 5400103 | I/O error. Return by callback. | 579e41f4b71Sopenharmony_ci| 5400105 | Service died. Return by callback. | 580e41f4b71Sopenharmony_ci 581e41f4b71Sopenharmony_ci**Example** 582e41f4b71Sopenharmony_ci 583e41f4b71Sopenharmony_ci```ts 584e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 585e41f4b71Sopenharmony_ci 586e41f4b71Sopenharmony_ci// asyncallback 587e41f4b71Sopenharmony_cilet surfaceID: string; // Surface ID passed to the external system. 588e41f4b71Sopenharmony_civideoRecorder.getInputSurface((err: BusinessError, surfaceId: string) => { 589e41f4b71Sopenharmony_ci if (err == null) { 590e41f4b71Sopenharmony_ci console.info('getInputSurface success'); 591e41f4b71Sopenharmony_ci surfaceID = surfaceId; 592e41f4b71Sopenharmony_ci } else { 593e41f4b71Sopenharmony_ci console.error('getInputSurface failed and error is ' + err.message); 594e41f4b71Sopenharmony_ci } 595e41f4b71Sopenharmony_ci}); 596e41f4b71Sopenharmony_ci``` 597e41f4b71Sopenharmony_ci 598e41f4b71Sopenharmony_ci### getInputSurface<sup>9+</sup> 599e41f4b71Sopenharmony_ci 600e41f4b71Sopenharmony_cigetInputSurface(): Promise\<string>; 601e41f4b71Sopenharmony_ci 602e41f4b71Sopenharmony_ci Obtains the surface required for recording. This API uses a promise to return the result. The caller obtains the **surfaceBuffer** from this surface and fills in the corresponding data. 603e41f4b71Sopenharmony_ci 604e41f4b71Sopenharmony_ciNote that the video data must carry the timestamp (in ns) and buffer size, and the start time of the timestamp must be based on the system startup time. 605e41f4b71Sopenharmony_ci 606e41f4b71Sopenharmony_ciThis API can be called only after [prepare()](#prepare9-1) is called. 607e41f4b71Sopenharmony_ci 608e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 609e41f4b71Sopenharmony_ci 610e41f4b71Sopenharmony_ci**System API**: This is a system API. 611e41f4b71Sopenharmony_ci 612e41f4b71Sopenharmony_ci**Return value** 613e41f4b71Sopenharmony_ci 614e41f4b71Sopenharmony_ci| Type | Description | 615e41f4b71Sopenharmony_ci| ---------------- | -------------------------------- | 616e41f4b71Sopenharmony_ci| Promise\<string> | Promise used to return the result.| 617e41f4b71Sopenharmony_ci 618e41f4b71Sopenharmony_ci**Error codes** 619e41f4b71Sopenharmony_ci 620e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 621e41f4b71Sopenharmony_ci 622e41f4b71Sopenharmony_ci| ID| Error Message | 623e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- | 624e41f4b71Sopenharmony_ci| 5400102 | Operation not allowed. Return by promise. | 625e41f4b71Sopenharmony_ci| 5400103 | I/O error. Return by promise. | 626e41f4b71Sopenharmony_ci| 5400105 | Service died. Return by promise. | 627e41f4b71Sopenharmony_ci 628e41f4b71Sopenharmony_ci**Example** 629e41f4b71Sopenharmony_ci 630e41f4b71Sopenharmony_ci```ts 631e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 632e41f4b71Sopenharmony_ci 633e41f4b71Sopenharmony_ci// promise 634e41f4b71Sopenharmony_cilet surfaceID: string; // Surface ID passed to the external system. 635e41f4b71Sopenharmony_civideoRecorder.getInputSurface().then((surfaceId: string) => { 636e41f4b71Sopenharmony_ci console.info('getInputSurface success'); 637e41f4b71Sopenharmony_ci surfaceID = surfaceId; 638e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 639e41f4b71Sopenharmony_ci console.error('getInputSurface failed and catch error is ' + err.message); 640e41f4b71Sopenharmony_ci}); 641e41f4b71Sopenharmony_ci``` 642e41f4b71Sopenharmony_ci 643e41f4b71Sopenharmony_ci### start<sup>9+</sup> 644e41f4b71Sopenharmony_ci 645e41f4b71Sopenharmony_cistart(callback: AsyncCallback\<void>): void 646e41f4b71Sopenharmony_ci 647e41f4b71Sopenharmony_ciStarts recording. This API uses an asynchronous callback to return the result. 648e41f4b71Sopenharmony_ci 649e41f4b71Sopenharmony_ciThis API can be called only after [prepare()](#prepare9) and [getInputSurface()](#getinputsurface9) are called, because the data source must pass data to the surface first. 650e41f4b71Sopenharmony_ci 651e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 652e41f4b71Sopenharmony_ci 653e41f4b71Sopenharmony_ci**System API**: This is a system API. 654e41f4b71Sopenharmony_ci 655e41f4b71Sopenharmony_ci**Parameters** 656e41f4b71Sopenharmony_ci 657e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 658e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------- | 659e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 660e41f4b71Sopenharmony_ci 661e41f4b71Sopenharmony_ci**Error codes** 662e41f4b71Sopenharmony_ci 663e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 664e41f4b71Sopenharmony_ci 665e41f4b71Sopenharmony_ci| ID| Error Message | 666e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ | 667e41f4b71Sopenharmony_ci| 5400102 | Operation not allowed. Return by callback. | 668e41f4b71Sopenharmony_ci| 5400103 | I/O error. Return by callback. | 669e41f4b71Sopenharmony_ci| 5400105 | Service died. Return by callback. | 670e41f4b71Sopenharmony_ci 671e41f4b71Sopenharmony_ci**Example** 672e41f4b71Sopenharmony_ci 673e41f4b71Sopenharmony_ci```ts 674e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 675e41f4b71Sopenharmony_ci 676e41f4b71Sopenharmony_ci// asyncallback 677e41f4b71Sopenharmony_civideoRecorder.start((err: BusinessError) => { 678e41f4b71Sopenharmony_ci if (err == null) { 679e41f4b71Sopenharmony_ci console.info('start videorecorder success'); 680e41f4b71Sopenharmony_ci } else { 681e41f4b71Sopenharmony_ci console.error('start videorecorder failed and error is ' + err.message); 682e41f4b71Sopenharmony_ci } 683e41f4b71Sopenharmony_ci}); 684e41f4b71Sopenharmony_ci``` 685e41f4b71Sopenharmony_ci 686e41f4b71Sopenharmony_ci### start<sup>9+</sup> 687e41f4b71Sopenharmony_ci 688e41f4b71Sopenharmony_cistart(): Promise\<void> 689e41f4b71Sopenharmony_ci 690e41f4b71Sopenharmony_ciStarts recording. This API uses a promise to return the result. 691e41f4b71Sopenharmony_ci 692e41f4b71Sopenharmony_ciThis API can be called only after [prepare()](#prepare9-1) and [getInputSurface()](#getinputsurface9-1) are called, because the data source must pass data to the surface first. 693e41f4b71Sopenharmony_ci 694e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 695e41f4b71Sopenharmony_ci 696e41f4b71Sopenharmony_ci**System API**: This is a system API. 697e41f4b71Sopenharmony_ci 698e41f4b71Sopenharmony_ci**Return value** 699e41f4b71Sopenharmony_ci 700e41f4b71Sopenharmony_ci| Type | Description | 701e41f4b71Sopenharmony_ci| -------------- | ------------------------------------- | 702e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result.| 703e41f4b71Sopenharmony_ci 704e41f4b71Sopenharmony_ci**Error codes** 705e41f4b71Sopenharmony_ci 706e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 707e41f4b71Sopenharmony_ci 708e41f4b71Sopenharmony_ci| ID| Error Message | 709e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- | 710e41f4b71Sopenharmony_ci| 5400102 | Operation not allowed. Return by promise. | 711e41f4b71Sopenharmony_ci| 5400103 | I/O error. Return by promise. | 712e41f4b71Sopenharmony_ci| 5400105 | Service died. Return by promise. | 713e41f4b71Sopenharmony_ci 714e41f4b71Sopenharmony_ci**Example** 715e41f4b71Sopenharmony_ci 716e41f4b71Sopenharmony_ci```ts 717e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 718e41f4b71Sopenharmony_ci 719e41f4b71Sopenharmony_ci// promise 720e41f4b71Sopenharmony_civideoRecorder.start().then(() => { 721e41f4b71Sopenharmony_ci console.info('start videorecorder success'); 722e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 723e41f4b71Sopenharmony_ci console.error('start videorecorder failed and catch error is ' + err.message); 724e41f4b71Sopenharmony_ci}); 725e41f4b71Sopenharmony_ci``` 726e41f4b71Sopenharmony_ci 727e41f4b71Sopenharmony_ci### pause<sup>9+</sup> 728e41f4b71Sopenharmony_ci 729e41f4b71Sopenharmony_cipause(callback: AsyncCallback\<void>): void 730e41f4b71Sopenharmony_ci 731e41f4b71Sopenharmony_ciPauses recording. This API uses an asynchronous callback to return the result. 732e41f4b71Sopenharmony_ci 733e41f4b71Sopenharmony_ciThis API can be called only after [start()](#start9) is called. You can resume recording by calling [resume()](#resume9). 734e41f4b71Sopenharmony_ci 735e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 736e41f4b71Sopenharmony_ci 737e41f4b71Sopenharmony_ci**System API**: This is a system API. 738e41f4b71Sopenharmony_ci 739e41f4b71Sopenharmony_ci**Parameters** 740e41f4b71Sopenharmony_ci 741e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 742e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------- | 743e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 744e41f4b71Sopenharmony_ci 745e41f4b71Sopenharmony_ci**Error codes** 746e41f4b71Sopenharmony_ci 747e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 748e41f4b71Sopenharmony_ci 749e41f4b71Sopenharmony_ci| ID| Error Message | 750e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ | 751e41f4b71Sopenharmony_ci| 5400102 | Operation not allowed. Return by callback. | 752e41f4b71Sopenharmony_ci| 5400103 | I/O error. Return by callback. | 753e41f4b71Sopenharmony_ci| 5400105 | Service died. Return by callback. | 754e41f4b71Sopenharmony_ci 755e41f4b71Sopenharmony_ci**Example** 756e41f4b71Sopenharmony_ci 757e41f4b71Sopenharmony_ci```ts 758e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 759e41f4b71Sopenharmony_ci 760e41f4b71Sopenharmony_ci// asyncallback 761e41f4b71Sopenharmony_civideoRecorder.pause((err: BusinessError) => { 762e41f4b71Sopenharmony_ci if (err == null) { 763e41f4b71Sopenharmony_ci console.info('pause videorecorder success'); 764e41f4b71Sopenharmony_ci } else { 765e41f4b71Sopenharmony_ci console.error('pause videorecorder failed and error is ' + err.message); 766e41f4b71Sopenharmony_ci } 767e41f4b71Sopenharmony_ci}); 768e41f4b71Sopenharmony_ci``` 769e41f4b71Sopenharmony_ci 770e41f4b71Sopenharmony_ci### pause<sup>9+</sup> 771e41f4b71Sopenharmony_ci 772e41f4b71Sopenharmony_cipause(): Promise\<void> 773e41f4b71Sopenharmony_ci 774e41f4b71Sopenharmony_ciPauses recording. This API uses a promise to return the result. 775e41f4b71Sopenharmony_ci 776e41f4b71Sopenharmony_ciThis API can be called only after [start()](#start9-1) is called. You can resume recording by calling [resume()](#resume9-1). 777e41f4b71Sopenharmony_ci 778e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 779e41f4b71Sopenharmony_ci 780e41f4b71Sopenharmony_ci**System API**: This is a system API. 781e41f4b71Sopenharmony_ci 782e41f4b71Sopenharmony_ci**Return value** 783e41f4b71Sopenharmony_ci 784e41f4b71Sopenharmony_ci| Type | Description | 785e41f4b71Sopenharmony_ci| -------------- | ------------------------------------- | 786e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result.| 787e41f4b71Sopenharmony_ci 788e41f4b71Sopenharmony_ci**Error codes** 789e41f4b71Sopenharmony_ci 790e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 791e41f4b71Sopenharmony_ci 792e41f4b71Sopenharmony_ci| ID| Error Message | 793e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- | 794e41f4b71Sopenharmony_ci| 5400102 | Operation not allowed. Return by promise. | 795e41f4b71Sopenharmony_ci| 5400103 | I/O error. Return by promise. | 796e41f4b71Sopenharmony_ci| 5400105 | Service died. Return by promise. | 797e41f4b71Sopenharmony_ci 798e41f4b71Sopenharmony_ci**Example** 799e41f4b71Sopenharmony_ci 800e41f4b71Sopenharmony_ci```ts 801e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 802e41f4b71Sopenharmony_ci 803e41f4b71Sopenharmony_ci// promise 804e41f4b71Sopenharmony_civideoRecorder.pause().then(() => { 805e41f4b71Sopenharmony_ci console.info('pause videorecorder success'); 806e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 807e41f4b71Sopenharmony_ci console.error('pause videorecorder failed and catch error is ' + err.message); 808e41f4b71Sopenharmony_ci}); 809e41f4b71Sopenharmony_ci``` 810e41f4b71Sopenharmony_ci 811e41f4b71Sopenharmony_ci### resume<sup>9+</sup> 812e41f4b71Sopenharmony_ci 813e41f4b71Sopenharmony_ciresume(callback: AsyncCallback\<void>): void 814e41f4b71Sopenharmony_ci 815e41f4b71Sopenharmony_ciResumes recording. This API uses an asynchronous callback to return the result. 816e41f4b71Sopenharmony_ci 817e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 818e41f4b71Sopenharmony_ci 819e41f4b71Sopenharmony_ci**System API**: This is a system API. 820e41f4b71Sopenharmony_ci 821e41f4b71Sopenharmony_ci**Parameters** 822e41f4b71Sopenharmony_ci 823e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 824e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------- | 825e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 826e41f4b71Sopenharmony_ci 827e41f4b71Sopenharmony_ci**Error codes** 828e41f4b71Sopenharmony_ci 829e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 830e41f4b71Sopenharmony_ci 831e41f4b71Sopenharmony_ci| ID| Error Message | 832e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ | 833e41f4b71Sopenharmony_ci| 5400102 | Operation not allowed. Return by callback. | 834e41f4b71Sopenharmony_ci| 5400103 | I/O error. Return by callback. | 835e41f4b71Sopenharmony_ci| 5400105 | Service died. Return by callback. | 836e41f4b71Sopenharmony_ci 837e41f4b71Sopenharmony_ci**Example** 838e41f4b71Sopenharmony_ci 839e41f4b71Sopenharmony_ci```ts 840e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 841e41f4b71Sopenharmony_ci 842e41f4b71Sopenharmony_ci// asyncallback 843e41f4b71Sopenharmony_civideoRecorder.resume((err: BusinessError) => { 844e41f4b71Sopenharmony_ci if (err == null) { 845e41f4b71Sopenharmony_ci console.info('resume videorecorder success'); 846e41f4b71Sopenharmony_ci } else { 847e41f4b71Sopenharmony_ci console.error('resume videorecorder failed and error is ' + err.message); 848e41f4b71Sopenharmony_ci } 849e41f4b71Sopenharmony_ci}); 850e41f4b71Sopenharmony_ci``` 851e41f4b71Sopenharmony_ci 852e41f4b71Sopenharmony_ci### resume<sup>9+</sup> 853e41f4b71Sopenharmony_ci 854e41f4b71Sopenharmony_ciresume(): Promise\<void> 855e41f4b71Sopenharmony_ci 856e41f4b71Sopenharmony_ciResumes recording. This API uses a promise to return the result. 857e41f4b71Sopenharmony_ci 858e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 859e41f4b71Sopenharmony_ci 860e41f4b71Sopenharmony_ci**System API**: This is a system API. 861e41f4b71Sopenharmony_ci 862e41f4b71Sopenharmony_ci**Return value** 863e41f4b71Sopenharmony_ci 864e41f4b71Sopenharmony_ci| Type | Description | 865e41f4b71Sopenharmony_ci| -------------- | ------------------------------------- | 866e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result.| 867e41f4b71Sopenharmony_ci 868e41f4b71Sopenharmony_ci**Error codes** 869e41f4b71Sopenharmony_ci 870e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 871e41f4b71Sopenharmony_ci 872e41f4b71Sopenharmony_ci| ID| Error Message | 873e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- | 874e41f4b71Sopenharmony_ci| 5400102 | Operation not allowed. Return by promise. | 875e41f4b71Sopenharmony_ci| 5400103 | I/O error. Return by promise. | 876e41f4b71Sopenharmony_ci| 5400105 | Service died. Return by promise. | 877e41f4b71Sopenharmony_ci 878e41f4b71Sopenharmony_ci**Example** 879e41f4b71Sopenharmony_ci 880e41f4b71Sopenharmony_ci```ts 881e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 882e41f4b71Sopenharmony_ci 883e41f4b71Sopenharmony_ci// promise 884e41f4b71Sopenharmony_civideoRecorder.resume().then(() => { 885e41f4b71Sopenharmony_ci console.info('resume videorecorder success'); 886e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 887e41f4b71Sopenharmony_ci console.error('resume videorecorder failed and catch error is ' + err.message); 888e41f4b71Sopenharmony_ci}); 889e41f4b71Sopenharmony_ci``` 890e41f4b71Sopenharmony_ci 891e41f4b71Sopenharmony_ci### stop<sup>9+</sup> 892e41f4b71Sopenharmony_ci 893e41f4b71Sopenharmony_cistop(callback: AsyncCallback\<void>): void 894e41f4b71Sopenharmony_ci 895e41f4b71Sopenharmony_ciStops recording. This API uses an asynchronous callback to return the result. 896e41f4b71Sopenharmony_ci 897e41f4b71Sopenharmony_ciTo start another recording, you must call [prepare()](#prepare9) and [getInputSurface()](#getinputsurface9) again. 898e41f4b71Sopenharmony_ci 899e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 900e41f4b71Sopenharmony_ci 901e41f4b71Sopenharmony_ci**System API**: This is a system API. 902e41f4b71Sopenharmony_ci 903e41f4b71Sopenharmony_ci**Parameters** 904e41f4b71Sopenharmony_ci 905e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 906e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------- | 907e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 908e41f4b71Sopenharmony_ci 909e41f4b71Sopenharmony_ci**Error codes** 910e41f4b71Sopenharmony_ci 911e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 912e41f4b71Sopenharmony_ci 913e41f4b71Sopenharmony_ci| ID| Error Message | 914e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ | 915e41f4b71Sopenharmony_ci| 5400102 | Operation not allowed. Return by callback. | 916e41f4b71Sopenharmony_ci| 5400103 | I/O error. Return by callback. | 917e41f4b71Sopenharmony_ci| 5400105 | Service died. Return by callback. | 918e41f4b71Sopenharmony_ci 919e41f4b71Sopenharmony_ci**Example** 920e41f4b71Sopenharmony_ci 921e41f4b71Sopenharmony_ci```ts 922e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 923e41f4b71Sopenharmony_ci 924e41f4b71Sopenharmony_ci// asyncallback 925e41f4b71Sopenharmony_civideoRecorder.stop((err: BusinessError) => { 926e41f4b71Sopenharmony_ci if (err == null) { 927e41f4b71Sopenharmony_ci console.info('stop videorecorder success'); 928e41f4b71Sopenharmony_ci } else { 929e41f4b71Sopenharmony_ci console.error('stop videorecorder failed and error is ' + err.message); 930e41f4b71Sopenharmony_ci } 931e41f4b71Sopenharmony_ci}); 932e41f4b71Sopenharmony_ci``` 933e41f4b71Sopenharmony_ci 934e41f4b71Sopenharmony_ci### stop<sup>9+</sup> 935e41f4b71Sopenharmony_ci 936e41f4b71Sopenharmony_cistop(): Promise\<void> 937e41f4b71Sopenharmony_ci 938e41f4b71Sopenharmony_ciStops recording. This API uses a promise to return the result. 939e41f4b71Sopenharmony_ci 940e41f4b71Sopenharmony_ciTo start another recording, you must call [prepare()](#prepare9-1) and [getInputSurface()](#getinputsurface9-1) again. 941e41f4b71Sopenharmony_ci 942e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 943e41f4b71Sopenharmony_ci 944e41f4b71Sopenharmony_ci**System API**: This is a system API. 945e41f4b71Sopenharmony_ci 946e41f4b71Sopenharmony_ci**Return value** 947e41f4b71Sopenharmony_ci 948e41f4b71Sopenharmony_ci| Type | Description | 949e41f4b71Sopenharmony_ci| -------------- | ------------------------------------- | 950e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result.| 951e41f4b71Sopenharmony_ci 952e41f4b71Sopenharmony_ci**Error codes** 953e41f4b71Sopenharmony_ci 954e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 955e41f4b71Sopenharmony_ci 956e41f4b71Sopenharmony_ci| ID| Error Message | 957e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- | 958e41f4b71Sopenharmony_ci| 5400102 | Operation not allowed. Return by promise. | 959e41f4b71Sopenharmony_ci| 5400103 | I/O error. Return by promise. | 960e41f4b71Sopenharmony_ci| 5400105 | Service died. Return by promise. | 961e41f4b71Sopenharmony_ci 962e41f4b71Sopenharmony_ci**Example** 963e41f4b71Sopenharmony_ci 964e41f4b71Sopenharmony_ci```ts 965e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 966e41f4b71Sopenharmony_ci 967e41f4b71Sopenharmony_ci// promise 968e41f4b71Sopenharmony_civideoRecorder.stop().then(() => { 969e41f4b71Sopenharmony_ci console.info('stop videorecorder success'); 970e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 971e41f4b71Sopenharmony_ci console.error('stop videorecorder failed and catch error is ' + err.message); 972e41f4b71Sopenharmony_ci}); 973e41f4b71Sopenharmony_ci``` 974e41f4b71Sopenharmony_ci 975e41f4b71Sopenharmony_ci### release<sup>9+</sup> 976e41f4b71Sopenharmony_ci 977e41f4b71Sopenharmony_cirelease(callback: AsyncCallback\<void>): void 978e41f4b71Sopenharmony_ci 979e41f4b71Sopenharmony_ciReleases the video recording resources. This API uses an asynchronous callback to return the result. 980e41f4b71Sopenharmony_ci 981e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 982e41f4b71Sopenharmony_ci 983e41f4b71Sopenharmony_ci**System API**: This is a system API. 984e41f4b71Sopenharmony_ci 985e41f4b71Sopenharmony_ci**Parameters** 986e41f4b71Sopenharmony_ci 987e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 988e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | -------------------------------- | 989e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 990e41f4b71Sopenharmony_ci 991e41f4b71Sopenharmony_ci**Error codes** 992e41f4b71Sopenharmony_ci 993e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 994e41f4b71Sopenharmony_ci 995e41f4b71Sopenharmony_ci| ID| Error Message | 996e41f4b71Sopenharmony_ci| -------- | --------------------------------- | 997e41f4b71Sopenharmony_ci| 5400105 | Service died. Return by callback. | 998e41f4b71Sopenharmony_ci 999e41f4b71Sopenharmony_ci**Example** 1000e41f4b71Sopenharmony_ci 1001e41f4b71Sopenharmony_ci```ts 1002e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1003e41f4b71Sopenharmony_ci 1004e41f4b71Sopenharmony_ci// asyncallback 1005e41f4b71Sopenharmony_civideoRecorder.release((err: BusinessError) => { 1006e41f4b71Sopenharmony_ci if (err == null) { 1007e41f4b71Sopenharmony_ci console.info('release videorecorder success'); 1008e41f4b71Sopenharmony_ci } else { 1009e41f4b71Sopenharmony_ci console.error('release videorecorder failed and error is ' + err.message); 1010e41f4b71Sopenharmony_ci } 1011e41f4b71Sopenharmony_ci}); 1012e41f4b71Sopenharmony_ci``` 1013e41f4b71Sopenharmony_ci 1014e41f4b71Sopenharmony_ci### release<sup>9+</sup> 1015e41f4b71Sopenharmony_ci 1016e41f4b71Sopenharmony_cirelease(): Promise\<void> 1017e41f4b71Sopenharmony_ci 1018e41f4b71Sopenharmony_ciReleases the video recording resources. This API uses a promise to return the result. 1019e41f4b71Sopenharmony_ci 1020e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 1021e41f4b71Sopenharmony_ci 1022e41f4b71Sopenharmony_ci**System API**: This is a system API. 1023e41f4b71Sopenharmony_ci 1024e41f4b71Sopenharmony_ci**Return value** 1025e41f4b71Sopenharmony_ci 1026e41f4b71Sopenharmony_ci| Type | Description | 1027e41f4b71Sopenharmony_ci| -------------- | ----------------------------------------- | 1028e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result.| 1029e41f4b71Sopenharmony_ci 1030e41f4b71Sopenharmony_ci**Error codes** 1031e41f4b71Sopenharmony_ci 1032e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 1033e41f4b71Sopenharmony_ci 1034e41f4b71Sopenharmony_ci| ID| Error Message | 1035e41f4b71Sopenharmony_ci| -------- | --------------------------------- | 1036e41f4b71Sopenharmony_ci| 5400105 | Service died. Return by callback. | 1037e41f4b71Sopenharmony_ci 1038e41f4b71Sopenharmony_ci**Example** 1039e41f4b71Sopenharmony_ci 1040e41f4b71Sopenharmony_ci```ts 1041e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1042e41f4b71Sopenharmony_ci 1043e41f4b71Sopenharmony_ci// promise 1044e41f4b71Sopenharmony_civideoRecorder.release().then(() => { 1045e41f4b71Sopenharmony_ci console.info('release videorecorder success'); 1046e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1047e41f4b71Sopenharmony_ci console.error('release videorecorder failed and catch error is ' + err.message); 1048e41f4b71Sopenharmony_ci}); 1049e41f4b71Sopenharmony_ci``` 1050e41f4b71Sopenharmony_ci 1051e41f4b71Sopenharmony_ci### reset<sup>9+</sup> 1052e41f4b71Sopenharmony_ci 1053e41f4b71Sopenharmony_cireset(callback: AsyncCallback\<void>): void 1054e41f4b71Sopenharmony_ci 1055e41f4b71Sopenharmony_ciResets video recording. This API uses an asynchronous callback to return the result. 1056e41f4b71Sopenharmony_ci 1057e41f4b71Sopenharmony_ciTo start another recording, you must call [prepare()](#prepare9) and [getInputSurface()](#getinputsurface9) again. 1058e41f4b71Sopenharmony_ci 1059e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 1060e41f4b71Sopenharmony_ci 1061e41f4b71Sopenharmony_ci**System API**: This is a system API. 1062e41f4b71Sopenharmony_ci 1063e41f4b71Sopenharmony_ci**Parameters** 1064e41f4b71Sopenharmony_ci 1065e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1066e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------- | 1067e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 1068e41f4b71Sopenharmony_ci 1069e41f4b71Sopenharmony_ci**Error codes** 1070e41f4b71Sopenharmony_ci 1071e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 1072e41f4b71Sopenharmony_ci 1073e41f4b71Sopenharmony_ci| ID| Error Message | 1074e41f4b71Sopenharmony_ci| -------- | --------------------------------- | 1075e41f4b71Sopenharmony_ci| 5400103 | I/O error. Return by callback. | 1076e41f4b71Sopenharmony_ci| 5400105 | Service died. Return by callback. | 1077e41f4b71Sopenharmony_ci 1078e41f4b71Sopenharmony_ci**Example** 1079e41f4b71Sopenharmony_ci 1080e41f4b71Sopenharmony_ci```ts 1081e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1082e41f4b71Sopenharmony_ci 1083e41f4b71Sopenharmony_ci// asyncallback 1084e41f4b71Sopenharmony_civideoRecorder.reset((err: BusinessError) => { 1085e41f4b71Sopenharmony_ci if (err == null) { 1086e41f4b71Sopenharmony_ci console.info('reset videorecorder success'); 1087e41f4b71Sopenharmony_ci } else { 1088e41f4b71Sopenharmony_ci console.error('reset videorecorder failed and error is ' + err.message); 1089e41f4b71Sopenharmony_ci } 1090e41f4b71Sopenharmony_ci}); 1091e41f4b71Sopenharmony_ci``` 1092e41f4b71Sopenharmony_ci 1093e41f4b71Sopenharmony_ci### reset<sup>9+</sup> 1094e41f4b71Sopenharmony_ci 1095e41f4b71Sopenharmony_cireset(): Promise\<void> 1096e41f4b71Sopenharmony_ci 1097e41f4b71Sopenharmony_ciResets video recording. This API uses a promise to return the result. 1098e41f4b71Sopenharmony_ci 1099e41f4b71Sopenharmony_ciTo start another recording, you must call [prepare()](#prepare9-1) and [getInputSurface()](#getinputsurface9-1) again. 1100e41f4b71Sopenharmony_ci 1101e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 1102e41f4b71Sopenharmony_ci 1103e41f4b71Sopenharmony_ci**System API**: This is a system API. 1104e41f4b71Sopenharmony_ci 1105e41f4b71Sopenharmony_ci**Return value** 1106e41f4b71Sopenharmony_ci 1107e41f4b71Sopenharmony_ci| Type | Description | 1108e41f4b71Sopenharmony_ci| -------------- | ------------------------------------- | 1109e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result.| 1110e41f4b71Sopenharmony_ci 1111e41f4b71Sopenharmony_ci**Error codes** 1112e41f4b71Sopenharmony_ci 1113e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 1114e41f4b71Sopenharmony_ci 1115e41f4b71Sopenharmony_ci| ID| Error Message | 1116e41f4b71Sopenharmony_ci| -------- | -------------------------------- | 1117e41f4b71Sopenharmony_ci| 5400103 | I/O error. Return by promise. | 1118e41f4b71Sopenharmony_ci| 5400105 | Service died. Return by promise. | 1119e41f4b71Sopenharmony_ci 1120e41f4b71Sopenharmony_ci**Example** 1121e41f4b71Sopenharmony_ci 1122e41f4b71Sopenharmony_ci```ts 1123e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1124e41f4b71Sopenharmony_ci 1125e41f4b71Sopenharmony_ci// promise 1126e41f4b71Sopenharmony_civideoRecorder.reset().then(() => { 1127e41f4b71Sopenharmony_ci console.info('reset videorecorder success'); 1128e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1129e41f4b71Sopenharmony_ci console.error('reset videorecorder failed and catch error is ' + err.message); 1130e41f4b71Sopenharmony_ci}); 1131e41f4b71Sopenharmony_ci``` 1132e41f4b71Sopenharmony_ci 1133e41f4b71Sopenharmony_ci### on('error')<sup>9+</sup> 1134e41f4b71Sopenharmony_ci 1135e41f4b71Sopenharmony_cion(type: 'error', callback: ErrorCallback): void 1136e41f4b71Sopenharmony_ci 1137e41f4b71Sopenharmony_ciSubscribes to video recording error events. After an error event is reported, you must handle the event and exit the recording. 1138e41f4b71Sopenharmony_ci 1139e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 1140e41f4b71Sopenharmony_ci 1141e41f4b71Sopenharmony_ci**System API**: This is a system API. 1142e41f4b71Sopenharmony_ci 1143e41f4b71Sopenharmony_ci**Parameters** 1144e41f4b71Sopenharmony_ci 1145e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1146e41f4b71Sopenharmony_ci| -------- | ------------- | ---- | ------------------------------------------------------------ | 1147e41f4b71Sopenharmony_ci| type | string | Yes | Event type, which is **'error'** in this case.<br>This event is triggered when an error occurs during video recording.| 1148e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback invoked when the event is triggered. | 1149e41f4b71Sopenharmony_ci 1150e41f4b71Sopenharmony_ci**Error codes** 1151e41f4b71Sopenharmony_ci 1152e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md). 1153e41f4b71Sopenharmony_ci 1154e41f4b71Sopenharmony_ci| ID| Error Message | 1155e41f4b71Sopenharmony_ci| -------- | --------------------------------- | 1156e41f4b71Sopenharmony_ci| 5400103 | I/O error. Return by callback. | 1157e41f4b71Sopenharmony_ci| 5400105 | Service died. Return by callback. | 1158e41f4b71Sopenharmony_ci 1159e41f4b71Sopenharmony_ci**Example** 1160e41f4b71Sopenharmony_ci 1161e41f4b71Sopenharmony_ci```ts 1162e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1163e41f4b71Sopenharmony_ci 1164e41f4b71Sopenharmony_ci// This event is reported when an error occurs during the retrieval of videoRecordState. 1165e41f4b71Sopenharmony_civideoRecorder.on('error', (error: BusinessError) => { // Set the 'error' event callback. 1166e41f4b71Sopenharmony_ci console.error(`audio error called, error: ${error}`); 1167e41f4b71Sopenharmony_ci}) 1168e41f4b71Sopenharmony_ci``` 1169e41f4b71Sopenharmony_ci 1170e41f4b71Sopenharmony_ci## VideoRecordState<sup>9+</sup> 1171e41f4b71Sopenharmony_ci 1172e41f4b71Sopenharmony_ciEnumerates the video recording states. You can obtain the state through the **state** attribute. 1173e41f4b71Sopenharmony_ci 1174e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 1175e41f4b71Sopenharmony_ci 1176e41f4b71Sopenharmony_ci**System API**: This is a system API. 1177e41f4b71Sopenharmony_ci 1178e41f4b71Sopenharmony_ci| Name | Type | Description | 1179e41f4b71Sopenharmony_ci| -------- | ------ | ---------------------- | 1180e41f4b71Sopenharmony_ci| idle | string | The video recorder is idle. | 1181e41f4b71Sopenharmony_ci| prepared | string | The video recording parameters are set.| 1182e41f4b71Sopenharmony_ci| playing | string | Video recording is in progress. | 1183e41f4b71Sopenharmony_ci| paused | string | Video recording is paused. | 1184e41f4b71Sopenharmony_ci| stopped | string | Video recording is stopped. | 1185e41f4b71Sopenharmony_ci| error | string | Video recording is in the error state. | 1186e41f4b71Sopenharmony_ci 1187e41f4b71Sopenharmony_ci## VideoRecorderConfig<sup>9+</sup> 1188e41f4b71Sopenharmony_ci 1189e41f4b71Sopenharmony_ciDescribes the video recording parameters. 1190e41f4b71Sopenharmony_ci 1191e41f4b71Sopenharmony_ciThe **audioSourceType** and **videoSourceType** parameters are used to distinguish video-only recording from audio and video recording. (For audio-only recording, use [AVRecorder](js-apis-media.md#avrecorder9) or [AudioRecorder](js-apis-media.md#audiorecorderdeprecated).) For video-only recording, set only **videoSourceType**. For audio and video recording, set both **audioSourceType** and **videoSourceType**. 1192e41f4b71Sopenharmony_ci 1193e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 1194e41f4b71Sopenharmony_ci 1195e41f4b71Sopenharmony_ci**System API**: This is a system API. 1196e41f4b71Sopenharmony_ci 1197e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1198e41f4b71Sopenharmony_ci| --------------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ | 1199e41f4b71Sopenharmony_ci| audioSourceType | [AudioSourceType](js-apis-media.md#audiosourcetype9) | No | Type of the audio source for video recording. This parameter is mandatory for audio recording. | 1200e41f4b71Sopenharmony_ci| videoSourceType | [VideoSourceType](js-apis-media.md#videosourcetype9) | Yes | Type of the video source for video recording. | 1201e41f4b71Sopenharmony_ci| profile | [VideoRecorderProfile](#videorecorderprofile9) | Yes | Video recording profile. | 1202e41f4b71Sopenharmony_ci| rotation | number | No | Rotation angle of the recorded video. The value can only be 0 (default), 90, 180, or 270. | 1203e41f4b71Sopenharmony_ci| location | [Location](js-apis-media.md#location) | No | Geographical location of the recorded video. By default, the geographical location information is not recorded. | 1204e41f4b71Sopenharmony_ci| url | string | Yes | Video output URL. Supported: fd://xx (fd number)<br> | 1205e41f4b71Sopenharmony_ci 1206e41f4b71Sopenharmony_ci## VideoRecorderProfile<sup>9+</sup> 1207e41f4b71Sopenharmony_ci 1208e41f4b71Sopenharmony_ciDescribes the video recording profile. 1209e41f4b71Sopenharmony_ci 1210e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 1211e41f4b71Sopenharmony_ci 1212e41f4b71Sopenharmony_ci**System API**: This is a system API. 1213e41f4b71Sopenharmony_ci 1214e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1215e41f4b71Sopenharmony_ci| ---------------- | -------------------------------------------- | ---- | ---------------- | 1216e41f4b71Sopenharmony_ci| audioBitrate | number | No | Audio encoding bit rate. This parameter is mandatory for audio recording.| 1217e41f4b71Sopenharmony_ci| audioChannels | number | No | Number of audio channels. This parameter is mandatory for audio recording.| 1218e41f4b71Sopenharmony_ci| audioCodec | [CodecMimeType](js-apis-media.md#codecmimetype8) | No | Audio encoding format. This parameter is mandatory for audio recording. | 1219e41f4b71Sopenharmony_ci| audioSampleRate | number | No | Audio sampling rate. This parameter is mandatory for audio recording. | 1220e41f4b71Sopenharmony_ci| fileFormat | [ContainerFormatType](js-apis-media.md#containerformattype8) | Yes | Container format of a file.| 1221e41f4b71Sopenharmony_ci| videoBitrate | number | Yes | Video encoding bit rate.| 1222e41f4b71Sopenharmony_ci| videoCodec | [CodecMimeType](js-apis-media.md#codecmimetype8) | Yes | Video encoding format. | 1223e41f4b71Sopenharmony_ci| videoFrameWidth | number | Yes | Width of the recorded video frame.| 1224e41f4b71Sopenharmony_ci| videoFrameHeight | number | Yes | Height of the recorded video frame.| 1225e41f4b71Sopenharmony_ci| videoFrameRate | number | Yes | Video frame rate. | 1226e41f4b71Sopenharmony_ci 1227e41f4b71Sopenharmony_ci## WatermarkConfig<sup>12+</sup> 1228e41f4b71Sopenharmony_ci 1229e41f4b71Sopenharmony_ciDescribes the watermark configuration set for the AVRecorder. The start point is the upper left corner of the image. 1230e41f4b71Sopenharmony_ci 1231e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core 1232e41f4b71Sopenharmony_ci 1233e41f4b71Sopenharmony_ci**System API**: This is a system API. 1234e41f4b71Sopenharmony_ci 1235e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1236e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ---------------- | 1237e41f4b71Sopenharmony_ci| top | number | Yes | Pixel offset from the top edge of the image.| 1238e41f4b71Sopenharmony_ci| left | number | Yes | Pixel offset from the left edge of the image.| 1239