1# @ohos.multimedia.media (Media) (System API) 2<!--Kit: Media Kit--> 3<!--Subsystem: Multimedia--> 4<!--Owner: @zzs_911--> 5<!--Designer: @stupig001--> 6<!--Tester: @xdlinc--> 7<!--Adviser: @zengyawen--> 8 9The multimedia subsystem provides a set of simple and easy-to-use APIs for you to access the system and use media resources. 10 11> **NOTE** 12> 13> - 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. 14> - This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.multimedia.media (Media)](arkts-apis-media.md). 15 16## Modules to Import 17 18```ts 19import { media } from '@kit.MediaKit'; 20``` 21 22## media.createVideoRecorder<sup>9+</sup> 23 24createVideoRecorder(callback: AsyncCallback\<VideoRecorder>): void 25 26Creates a VideoRecorder instance. This API uses an asynchronous callback to return the result. 27 28Only one VideoRecorder instance can be created per device. 29 30**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 31 32**System API**: This is a system API. 33 34**Parameters** 35 36| Name | Type | Mandatory| Description | 37| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 38| 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.| 39 40**Error codes** 41 42For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 43 44| ID| Error Message | 45| -------- | ------------------------------ | 46| 202 | Not system App. | 47| 5400101 | No memory. Return by callback. | 48 49**Example** 50 51```ts 52import { BusinessError } from '@kit.BasicServicesKit'; 53 54let videoRecorder: media.VideoRecorder; 55media.createVideoRecorder((error: BusinessError, video: media.VideoRecorder) => { 56 if (video != null) { 57 videoRecorder = video; 58 console.info('video createVideoRecorder success'); 59 } else { 60 console.error(`video createVideoRecorder fail, error message:${error.message}`); 61 } 62}); 63``` 64 65## media.createVideoRecorder<sup>9+</sup> 66 67createVideoRecorder(): Promise\<VideoRecorder> 68 69Creates a VideoRecorder instance. This API uses a promise to return the result. 70 71Only one VideoRecorder instance can be created per device. 72 73**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 74 75**System API**: This is a system API. 76 77**Return value** 78 79| Type | Description | 80| ----------------------------------------- | ------------------------------------------------------------ | 81| 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.| 82 83**Error codes** 84 85For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 86 87| ID| Error Message | 88| -------- | ----------------------------- | 89| 202 | Not system App. | 90| 5400101 | No memory. Return by promise. | 91 92**Example** 93 94```ts 95import { BusinessError } from '@kit.BasicServicesKit'; 96 97let videoRecorder: media.VideoRecorder; 98media.createVideoRecorder().then((video: media.VideoRecorder) => { 99 if (video != null) { 100 videoRecorder = video; 101 console.info('video createVideoRecorder success'); 102 } else { 103 console.error('video createVideoRecorder fail'); 104 } 105}).catch((error: BusinessError) => { 106 console.error(`video catchCallback, error message:${error.message}`); 107}); 108``` 109 110## media.reportAVScreenCaptureUserChoice<sup>12+</sup> 111 112reportAVScreenCaptureUserChoice(sessionId: number, choice: string): Promise\<void> 113 114Reports 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 the **Allow** button to continue the operation. 115 116This API is called by the system application that creates the dialog box. 117 118**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture 119 120**System API**: This is a system API. 121 122**Parameters** 123 124| Name | Type | Mandatory| Description | 125| --------- | ------ | ---- | ------------------------------------------------------------ | 126| sessionId | number | Yes | Session ID of the AVScreenCapture service, which is sent to the application when the AVScreenCapture server starts the privacy dialog box.| 127| choice | string | Yes | User choice, including whether screen capture is agreed, selected display ID, and window ID. For details, see JsonData in the example below.| 128 129**Return value** 130 131| Type | Description | 132| ---------------- | -------------------------------- | 133| Promise\<void> | Promise that returns no value.| 134 135**Error codes** 136 137| ID| Error Message | 138| -------- | ------------------------------------------- | 139| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 140| 5400101 | No memory. Return by promise. | 141 142**Example** 143 144```ts 145import { BusinessError } from '@kit.BasicServicesKit'; 146import { media } from '@kit.MediaKit'; 147 148class JsonData { 149 public choice: string = 'true'; 150 public displayId: number | null = -1; 151 public missionId: number | null = -1; 152 public checkBoxSelected: string = 'true'; 153 public isInnerAudioBoxSelected: string = 'true'; 154} 155let sessionId: number = 0; // Use the ID of the session that starts the process. 156 157try { 158 const jsonData: JsonData = { 159 choice: 'true', // Replace it with the user choice. 160 displayId: -1, // Replace it with the ID of the display selected by the user. 161 missionId: -1, // Replace it with the ID of the window selected by the user. 162 checkBoxSelected: 'true', // Replace it with the enabled status of screen protection. 163 isInnerAudioBoxSelected: 'true', // Replace it the enabled status of internal audio recording. 164 } 165 await media.reportAVScreenCaptureUserChoice(sessionId, JSON.stringify(jsonData)); 166} catch (error: BusinessError) { 167 console.error(`reportAVScreenCaptureUserChoice error, error message: ${error.message}`); 168} 169``` 170 171## media.getAVScreenCaptureConfigurableParameters<sup>20+</sup> 172 173getAVScreenCaptureConfigurableParameters(sessionId: number): Promise\<string> 174 175Obtains configuration parameters for system- and application-level privacy protection from the server. This API uses a promise to return the result. 176 177>**NOTE** 178> 179> This API is exclusively for the system application that creates the privacy dialog box. 180 181**System API**: This is a system API. 182 183**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture 184 185**Parameters** 186 187| Name | Type | Mandatory| Description | 188| --------- | ------ | ---- | ------------------------------------------------------------ | 189| sessionId | number | Yes | Session ID of the AVScreenCapture service, which is sent to the application when the AVScreenCapture server starts the privacy dialog box.| 190 191**Return value** 192 193| Type | Description | 194| ---------------- | -------------------------------- | 195| Promise\<string> | Promise used to return the result, which is a string containing the configuration parameters. If the operation fails, an empty string is returned.| 196 197**Error codes** 198 199For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 200| ID| Error Message | 201| -------- | ------------------------------------------- | 202| 202 | Called from Non-System applications. Return by promise. | 203| 5400109 | Sessions not exist. Return by promise. | 204 205**Example** 206 207```ts 208import { BusinessError } from '@kit.BasicServicesKit'; 209import { media } from '@kit.MediaKit'; 210 211let sessionId: number = 0; // Use the ID of the session that starts the process. 212 213try { 214 let privacyResult: string = await media.getAVScreenCaptureConfigurableParameters(sessionId); 215} catch (error: BusinessError) { 216 console.error(`getAVScreenCaptureConfigurableParameters error, error message: ${error.message}`); 217} 218``` 219 220## media.getScreenCaptureMonitor<sup>18+</sup> 221 222getScreenCaptureMonitor(): Promise\<ScreenCaptureMonitor> 223 224Obtains a ScreenCaptureMonitor instance. This API uses a promise to return the result. 225 226**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture 227 228**System API**: This is a system API. 229 230**Return value** 231 232| Type | Description | 233| ----------------------------------------- | ------------------------------------------------------------ | 234| Promise<[ScreenCaptureMonitor](#screencapturemonitor18)> | Promise used to return the result. The instance can be used to query and monitor the status of the system screen recorder.<br>If the operation is successful, a ScreenCaptureMonitor instance is returned; otherwise, **null** is returned.| 235 236**Error codes** 237 238For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 239 240| ID| Error Message | 241| -------- | ----------------------------- | 242| 202 | Not System App. | 243| 5400101 | No memory. Return by promise. | 244 245**Example** 246 247```ts 248let screenCaptureMonitor: media.ScreenCaptureMonitor; 249try { 250 screenCaptureMonitor = await media.getScreenCaptureMonitor(); 251} catch (err) { 252 console.error(`getScreenCaptureMonitor failed, error message:${err.message}`); 253} 254``` 255 256## media.createParallelSoundPool<sup>20+</sup> 257 258createParallelSoundPool(maxStreams: number, audioRenderInfo: audio.AudioRendererInfo): Promise\<SoundPool> 259 260Creates a SoundPool instance. This API uses a promise to return the result. 261 262If a SoundPool instance created using [createSoundPool](arkts-apis-media-f.md#mediacreatesoundpool10) is used to play the same sound again, it stops the current audio and restarts the audio. However, if the instance is created using **createParallelSoundPool**, it keeps playing the first audio and starts the new one alongside it. 263 264**System capability**: SystemCapability.Multimedia.Media.SoundPool 265 266**Parameters** 267 268| Name | Type | Mandatory| Description | 269| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 270| maxStreams | number | Yes | Maximum number of streams that can be played by the SoundPool instance. The value is an integer ranging from 1 to 32.| 271| audioRenderInfo | [audio.AudioRendererInfo](../apis-audio-kit/arkts-apis-audio-i.md#audiorendererinfo8) | Yes | Audio renderer parameters.| 272 273**Return value** 274 275| Type | Description | 276| ----------------------------------------- | ------------------------------------------------------------ | 277| Promise<[SoundPool](js-apis-inner-multimedia-soundPool.md)> | Promise used to return the result. If the operation is successful, a SoundPool instance is returned; otherwise, **null** is returned. The instance is used for loading and playback.| 278 279**Error codes** 280 281For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 282 283| ID| Error Message | 284| -------- | ----------------------------- | 285| 5400101 | No memory. Return by promise. | 286| 202| System API error. Return by promise. | 287 288**Example** 289 290```js 291import { audio } from '@kit.AudioKit'; 292import { BusinessError } from '@kit.BasicServicesKit'; 293 294let soundPool: media.SoundPool; 295let audioRendererInfo: audio.AudioRendererInfo = { 296 usage : audio.StreamUsage.STREAM_USAGE_MUSIC, 297 rendererFlags : 0 298} 299 300media.createParallelSoundPool(5, audioRendererInfo).then((soundpool_: media.SoundPool) => { 301 if (soundpool_ != null) { 302 soundPool = soundpool_; 303 console.info('Succceeded in creating SoundPool'); 304 } else { 305 console.error('Failed to create SoundPool'); 306 } 307}, (error: BusinessError) => { 308 console.error(`soundpool catchCallback, error message:${error.message}`); 309}); 310``` 311 312## PixelMapParams<sup>11+</sup> 313 314Defines the format parameters of the video thumbnail to be obtained. 315 316**System capability**: SystemCapability.Multimedia.Media.AVImageGenerator 317 318| Name | Type | Readable | Writable | Description | 319| -------- | ------ | ------| ------ | ---------------------- | 320| colorFormat | [PixelFormat](#pixelformat11) | No | Yes | Color format of the thumbnail.<br>**System API**: This is a system API. | 321 322## PixelFormat<sup>11+</sup> 323 324Enumerates the color formats supported by the video thumbnail. 325 326**System capability**: SystemCapability.Multimedia.Media.AVImageGenerator 327 328**System API**: This is a system API. 329 330| Name | Value | Description | 331| ------------------------ | --------------- | ------------------------------------------------------------ | 332| RGB_565 | 2 | RGB_565. | 333| RGBA_8888 | 3 | RGBA_8888.| 334| RGB_888 | 5 | RGB_888. | 335 336## AVMetadataExtractor<sup>11+</sup> 337 338Provides APIs to obtain metadata from media assets. Before calling any API of AVMetadataExtractor, you must use [createAVMetadataExtractor()](arkts-apis-media-f.md#mediacreateavmetadataextractor11) to create an AVMetadataExtractor instance. 339 340### getTimeByFrameIndex<sup>12+</sup> 341 342getTimeByFrameIndex(index: number): Promise\<number> 343 344Obtains the video timestamp corresponding to a video frame number. Only MP4 video files are supported. 345 346**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 347 348**System API**: This is a system API. 349 350**Parameters** 351 352| Name| Type | Mandatory| Description | 353| ------ | ------ | ---- | ---------- | 354| index | number | Yes | Video frame number.| 355 356**Return value** 357 358| Type | Description | 359| ---------------- | ----------------------------------- | 360| Promise\<number> | Promise used to return the timestamp, in microseconds.| 361 362**Error codes** 363 364For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 365 366| ID| Error Message | 367| -------- | ---------------------------------------------- | 368| 401 | The parameter check failed. Return by promise. | 369| 5400102 | Operation not allowed. Returned by promise. | 370| 5400106 | Unsupported format. Returned by promise. | 371 372**Example** 373 374```ts 375import { media } from '@kit.MediaKit'; 376import { BusinessError } from '@kit.BasicServicesKit'; 377 378avMetadataExtractor.getTimeByFrameIndex(0).then((timeUs: number) => { 379 console.info(`Succeeded getTimeByFrameIndex timeUs: ${timeUs}`); 380}).catch((err: BusinessError) => { 381 console.error(`Failed to getTimeByFrameIndex ${err.message}`); 382}) 383``` 384 385### getFrameIndexByTime<sup>12+</sup> 386 387getFrameIndexByTime(timeUs: number): Promise\<number> 388 389Obtains the video frame number corresponding to a video timestamp. Only MP4 video files are supported. 390 391**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 392 393**System API**: This is a system API. 394 395**Parameters** 396 397| Name| Type | Mandatory| Description | 398| ------ | ------ | ---- | ------------------------ | 399| timeUs | number | Yes | Video timestamp, in microseconds.| 400 401**Return value** 402 403| Type | Description | 404| ---------------- | ------------------------- | 405| Promise\<number> | Promise used to return the video frame number.| 406 407**Error codes** 408 409For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 410 411| ID| Error Message | 412| -------- | ---------------------------------------------- | 413| 401 | The parameter check failed. Return by promise. | 414| 5400102 | Operation not allowed. Returned by promise. | 415| 5400106 | Unsupported format. Returned by promise. | 416 417**Example** 418 419```ts 420import { media } from '@kit.MediaKit'; 421import { BusinessError } from '@kit.BasicServicesKit'; 422 423avMetadataExtractor.getFrameIndexByTime(0).then((index: number) => { 424 console.info(`Succeeded getFrameIndexByTime index: ${index}`); 425}).catch((err: BusinessError) => { 426 console.error(`Failed to getFrameIndexByTime ${err.message}`); 427}) 428``` 429 430## AVRecorder<sup>9+</sup> 431 432A recording management class that provides APIs to record media assets. Before calling any API in AVRecorder, you must use [createAVRecorder()](arkts-apis-media-f.md#mediacreateavrecorder9) to create an AVRecorder instance. 433 434> **NOTE** 435> 436> 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/arkts-apis-camera.md). 437 438### isWatermarkSupported<sup>13+</sup> 439 440isWatermarkSupported(): Promise\<boolean> 441 442Checks whether the device supports the hardware digital watermark. This API uses a promise to return the result. 443 444This API can be called after the [prepare()](arkts-apis-media-AVRecorder.md#prepare9-1), [start()](arkts-apis-media-AVRecorder.md#start9), or [paused()](arkts-apis-media-AVRecorder.md#pause9) event is triggered. 445 446**System capability**: SystemCapability.Multimedia.Media.AVRecorder 447 448**System API**: This is a system API. 449 450**Return value** 451 452| Type | Description | 453| ---------------- | -------------------------------- | 454| Promise\<boolean> | Promise used to return the check result, which indicates the support for the hardware digital watermark. **true** if supported, **false** otherwise.| 455 456**Example** 457 458```ts 459import { BusinessError } from '@kit.BasicServicesKit'; 460 461avRecorder.isWatermarkSupported().then((isWatermarkSupported: boolean) => { 462 console.info(`Succeeded in get, isWatermarkSupported: ${isWatermarkSupported}`); 463}).catch((error: BusinessError) => { 464 console.error(`Failed to get and catch error is ${error.message}`); 465}); 466``` 467 468### setWatermark<sup>13+</sup> 469 470setWatermark(watermark: image.PixelMap, config: WatermarkConfig): Promise\<void> 471 472Sets a watermark for the AVRecorder. This API uses a promise to return the result. 473 474This API can be called only after the [prepare()](arkts-apis-media-AVRecorder.md#prepare9-1) event is triggered and before the [start()](arkts-apis-media-AVRecorder.md#start9) event is triggered. 475 476**System capability**: SystemCapability.Multimedia.Media.AVRecorder 477 478**System API**: This is a system API. 479 480**Parameters** 481 482| Name | Type | Mandatory| Description | 483| -------- | -------------------- | ---- | --------------------------- | 484| watermark | [image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md) | Yes | PixelMap data.<br>Currently, the following specifications are supported:<br>- Only RGBA8888 is supported.<br>- If the original image is 8K, the watermark resolution should be limited to a size of 3072 x 288; if the original image is 4K, the watermark resolution should be limited to a size of 1536 x 144.| 485| config | [WatermarkConfig](#watermarkconfig13) | Yes | Watermark configuration.| 486 487**Return value** 488 489| Type | Description | 490| ---------------- | -------------------------------- | 491| Promise\<void> | Promise that returns no value.| 492 493**Error codes** 494 495For details about the error codes, see [Media Error Codes](errorcode-media.md). 496 497| ID| Error Message | 498| -------- | -------------------------------------- | 499| 401 | The parameter check failed. Return by promise. | 500| 801 | Capability not supported. Return by promise. | 501 502**Example** 503 504```ts 505import { BusinessError } from '@kit.BasicServicesKit'; 506import { image } from '@kit.ImageKit'; 507 508let watermark: image.PixelMap|undefined = undefined; // need data. 509let watermarkConfig: media.WatermarkConfig = { top: 100, left: 100 } 510 511avRecorder.setWatermark(watermark, watermarkConfig).then(() => { 512 console.info('Succeeded in setWatermark'); 513}).catch((error: BusinessError) => { 514 console.error(`Failed to setWatermark and catch error is ${error.message}`); 515}); 516``` 517 518### setMetadata<sup>18+</sup> 519setMetadata(metadata: Record\<string, string\>): void 520 521Sets custom metadata for the recording file of AVRecorder. 522 523This API can be called only after the [prepare()](arkts-apis-media-AVRecorder.md#prepare9-1) event is successfully triggered and before the [stop()](arkts-apis-media-AVRecorder.md#stop9) API is called. 524 525**System capability**: SystemCapability.Multimedia.Media.AVRecorder 526 527**System API**: This is a system API. 528 529**Parameters** 530 531| Name | Type | Mandatory| Description | 532| -------- | -------------------- | ---- |-------------------------------------------------------------------| 533| metadata | [Record<string, string>] | Yes | Tag and value of the metadata in key-value pairs.<br>- The first string is the tag.<br>- The second string is the value.| 534 535**Return value** 536 537| Type | Description | 538| --------------- |-----------| 539| void | No result.| 540 541**Error codes** 542 543For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 544 545| ID| Error Message | 546|-------|-----------------| 547| 202 | Not System App. | 548 549**Example** 550 551```ts 552import { BusinessError } from '@kit.BasicServicesKit'; 553 554let meta : Record<string, string> = { 555 'com.openharmony.userdefine':'10', 556 'com.openharmony.userdefine2':'20' 557}; 558 559avRecorder.setMetadata(meta); 560``` 561 562## AVRecorderProfile<sup>9+</sup> 563 564Describes the audio and video recording profile. 565 566**System capability**: SystemCapability.Multimedia.Media.AVRecorder 567 568| Name | Type | Mandatory| Description | 569| ---------------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | 570| enableStableQualityMode<sup>18+</sup> | boolean | No | Whether to enable stable quality mode for video recording. This parameter is optional for video recording. The default value is **false**. If this parameter is set to **true**, the system will use a video encoding strategy designed to maintain stable quality.<br>**System API**: This is a system API.| 571 572## VideoRecorder<sup>9+</sup> 573 574> **NOTE** 575> This class is deprecated after AVRecorder<sup>9+</sup> is released. You are advised to use [AVRecorder](arkts-apis-media-AVRecorder.md) instead. 576 577Implements video recording. Before calling any API in the **VideoRecorder** class, you must use [createVideoRecorder()](#mediacreatevideorecorder9) to create a [VideoRecorder](#videorecorder9) instance. 578 579### Properties 580 581**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 582 583**System API**: This is a system API. 584 585| Name | Type | Read-Only| Optional| Description | 586| ------------------ | -------------------------------------- | ---- | ---- | ---------------- | 587| state<sup>9+</sup> | [VideoRecordState](#videorecordstate9) | Yes | No | Video recording state.| 588 589### prepare<sup>9+</sup> 590 591prepare(config: VideoRecorderConfig, callback: AsyncCallback\<void>): void 592 593Sets video recording parameters. This API uses an asynchronous callback to return the result. 594 595**Required permissions:** ohos.permission.MICROPHONE 596 597**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 598 599**System API**: This is a system API. 600 601**Parameters** 602 603| Name | Type | Mandatory| Description | 604| -------- | -------------------------------------------- | ---- | ----------------------------------- | 605| config | [VideoRecorderConfig](#videorecorderconfig9) | Yes | Video recording parameters to set. | 606| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 607 608**Error codes** 609 610For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 611 612| ID| Error Message | 613| -------- | ------------------------------------------ | 614| 201 | Permission denied. Return by callback. | 615| 202 | Not system App. | 616| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 617| 5400102 | Operation not allowed. Return by callback. | 618| 5400105 | Service died. Return by callback. | 619 620**Example** 621 622```ts 623import { BusinessError } from '@kit.BasicServicesKit'; 624 625// Configure the parameters based on those supported by the hardware device. 626let videoProfile: media.VideoRecorderProfile = { 627 audioBitrate : 48000, 628 audioChannels : 2, 629 audioCodec : media.CodecMimeType.AUDIO_AAC, 630 audioSampleRate : 48000, 631 fileFormat : media.ContainerFormatType.CFT_MPEG_4, 632 videoBitrate : 2000000, 633 videoCodec : media.CodecMimeType.VIDEO_AVC, 634 videoFrameWidth : 640, 635 videoFrameHeight : 480, 636 videoFrameRate : 30 637} 638 639let videoConfig: media.VideoRecorderConfig = { 640 audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC, 641 videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV, 642 profile : videoProfile, 643 url : 'fd://xx', // The file must be created by the caller and granted with proper permissions. 644 rotation : 0, 645 location : { latitude : 30, longitude : 130 } 646} 647 648// asyncallback. 649videoRecorder.prepare(videoConfig, (err: BusinessError) => { 650 if (err == null) { 651 console.info('prepare success'); 652 } else { 653 console.error('prepare failed and error is ' + err.message); 654 } 655}) 656``` 657 658### prepare<sup>9+</sup> 659 660prepare(config: VideoRecorderConfig): Promise\<void> 661 662Sets video recording parameters. This API uses a promise to return the result. 663 664**Required permissions:** ohos.permission.MICROPHONE 665 666**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 667 668**System API**: This is a system API. 669 670**Parameters** 671 672| Name| Type | Mandatory| Description | 673| ------ | -------------------------------------------- | ---- | ------------------------ | 674| config | [VideoRecorderConfig](#videorecorderconfig9) | Yes | Video recording parameters to set.| 675 676**Return value** 677 678| Type | Description | 679| -------------- | ---------------------------------------- | 680| Promise\<void> | Promise used to return the result.| 681 682**Error codes** 683 684For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 685 686| ID| Error Message | 687| -------- | ----------------------------------------- | 688| 201 | Permission denied. Return by promise. | 689| 202 | Not system App. | 690| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 691| 5400102 | Operation not allowed. Return by promise. | 692| 5400105 | Service died. Return by promise. | 693 694**Example** 695 696```ts 697import { BusinessError } from '@kit.BasicServicesKit'; 698 699// Configure the parameters based on those supported by the hardware device. 700let videoProfile: media.VideoRecorderProfile = { 701 audioBitrate : 48000, 702 audioChannels : 2, 703 audioCodec : media.CodecMimeType.AUDIO_AAC, 704 audioSampleRate : 48000, 705 fileFormat : media.ContainerFormatType.CFT_MPEG_4, 706 videoBitrate : 2000000, 707 videoCodec : media.CodecMimeType.VIDEO_AVC, 708 videoFrameWidth : 640, 709 videoFrameHeight : 480, 710 videoFrameRate : 30 711} 712 713let videoConfig: media.VideoRecorderConfig = { 714 audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC, 715 videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV, 716 profile : videoProfile, 717 url : 'fd://xx', // The file must be created by the caller and granted with proper permissions. 718 rotation : 0, 719 location : { latitude : 30, longitude : 130 } 720} 721 722// promise. 723videoRecorder.prepare(videoConfig).then(() => { 724 console.info('prepare success'); 725}).catch((err: BusinessError) => { 726 console.error('prepare failed and catch error is ' + err.message); 727}); 728``` 729 730### getInputSurface<sup>9+</sup> 731 732getInputSurface(callback: AsyncCallback\<string>): void 733 734Obtains 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. 735 736Note 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. 737 738This API can be called only after [prepare()](#prepare9) is called. 739 740**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 741 742**System API**: This is a system API. 743 744**Parameters** 745 746| Name | Type | Mandatory| Description | 747| -------- | ---------------------- | ---- | --------------------------- | 748| callback | AsyncCallback\<string> | Yes | Callback used to return the result.| 749 750**Error codes** 751 752For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 753 754| ID| Error Message | 755| -------- | ------------------------------------------ | 756| 202 | Not system App. | 757| 5400102 | Operation not allowed. Return by callback. | 758| 5400103 | I/O error. Return by callback. | 759| 5400105 | Service died. Return by callback. | 760 761**Example** 762 763```ts 764import { BusinessError } from '@kit.BasicServicesKit'; 765 766// asyncallback. 767let surfaceID: string; // Surface ID passed to the external system. 768videoRecorder.getInputSurface((err: BusinessError, surfaceId: string) => { 769 if (err == null) { 770 console.info('getInputSurface success'); 771 surfaceID = surfaceId; 772 } else { 773 console.error('getInputSurface failed and error is ' + err.message); 774 } 775}); 776``` 777 778### getInputSurface<sup>9+</sup> 779 780getInputSurface(): Promise\<string>; 781 782 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. 783 784Note 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. 785 786This API can be called only after [prepare()](#prepare9-1) is called. 787 788**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 789 790**System API**: This is a system API. 791 792**Return value** 793 794| Type | Description | 795| ---------------- | -------------------------------- | 796| Promise\<string> | Promise used to return the result.| 797 798**Error codes** 799 800For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 801 802| ID| Error Message | 803| -------- | ----------------------------------------- | 804| 202 | Not system App. | 805| 5400102 | Operation not allowed. Return by promise. | 806| 5400103 | I/O error. Return by promise. | 807| 5400105 | Service died. Return by promise. | 808 809**Example** 810 811```ts 812import { BusinessError } from '@kit.BasicServicesKit'; 813 814// promise. 815let surfaceID: string; // Surface ID passed to the external system. 816videoRecorder.getInputSurface().then((surfaceId: string) => { 817 console.info('getInputSurface success'); 818 surfaceID = surfaceId; 819}).catch((err: BusinessError) => { 820 console.error('getInputSurface failed and catch error is ' + err.message); 821}); 822``` 823 824### start<sup>9+</sup> 825 826start(callback: AsyncCallback\<void>): void 827 828Starts recording. This API uses an asynchronous callback to return the result. 829 830This API can be called only after [prepare()](#prepare9) and [getInputSurface()](#getinputsurface9) are called, because the data source must pass data to the surface first. 831 832**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 833 834**System API**: This is a system API. 835 836**Parameters** 837 838| Name | Type | Mandatory| Description | 839| -------- | -------------------- | ---- | ---------------------------- | 840| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 841 842**Error codes** 843 844For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 845 846| ID| Error Message | 847| -------- | ------------------------------------------ | 848| 202 | Not system App. | 849| 5400102 | Operation not allowed. Return by callback. | 850| 5400103 | I/O error. Return by callback. | 851| 5400105 | Service died. Return by callback. | 852 853**Example** 854 855```ts 856import { BusinessError } from '@kit.BasicServicesKit'; 857 858// asyncallback. 859videoRecorder.start((err: BusinessError) => { 860 if (err == null) { 861 console.info('start videorecorder success'); 862 } else { 863 console.error('start videorecorder failed and error is ' + err.message); 864 } 865}); 866``` 867 868### start<sup>9+</sup> 869 870start(): Promise\<void> 871 872Starts recording. This API uses a promise to return the result. 873 874This 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. 875 876**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 877 878**System API**: This is a system API. 879 880**Return value** 881 882| Type | Description | 883| -------------- | ------------------------------------- | 884| Promise\<void> | Promise used to return the result.| 885 886**Error codes** 887 888For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 889 890| ID| Error Message | 891| -------- | ----------------------------------------- | 892| 202 | Not system App. | 893| 5400102 | Operation not allowed. Return by promise. | 894| 5400103 | I/O error. Return by promise. | 895| 5400105 | Service died. Return by promise. | 896 897**Example** 898 899```ts 900import { BusinessError } from '@kit.BasicServicesKit'; 901 902// promise. 903videoRecorder.start().then(() => { 904 console.info('start videorecorder success'); 905}).catch((err: BusinessError) => { 906 console.error('start videorecorder failed and catch error is ' + err.message); 907}); 908``` 909 910### pause<sup>9+</sup> 911 912pause(callback: AsyncCallback\<void>): void 913 914Pauses recording. This API uses an asynchronous callback to return the result. 915 916This API can be called only after [start()](#start9) is called. You can resume recording by calling [resume()](#resume9). 917 918**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 919 920**System API**: This is a system API. 921 922**Parameters** 923 924| Name | Type | Mandatory| Description | 925| -------- | -------------------- | ---- | ---------------------------- | 926| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 927 928**Error codes** 929 930For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 931 932| ID| Error Message | 933| -------- | ------------------------------------------ | 934| 202 | Not system App. | 935| 5400102 | Operation not allowed. Return by callback. | 936| 5400103 | I/O error. Return by callback. | 937| 5400105 | Service died. Return by callback. | 938 939**Example** 940 941```ts 942import { BusinessError } from '@kit.BasicServicesKit'; 943 944// asyncallback. 945videoRecorder.pause((err: BusinessError) => { 946 if (err == null) { 947 console.info('pause videorecorder success'); 948 } else { 949 console.error('pause videorecorder failed and error is ' + err.message); 950 } 951}); 952``` 953 954### pause<sup>9+</sup> 955 956pause(): Promise\<void> 957 958Pauses recording. This API uses a promise to return the result. 959 960This API can be called only after [start()](#start9-1) is called. You can resume recording by calling [resume()](#resume9-1). 961 962**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 963 964**System API**: This is a system API. 965 966**Return value** 967 968| Type | Description | 969| -------------- | ------------------------------------- | 970| Promise\<void> | Promise used to return the result.| 971 972**Error codes** 973 974For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 975 976| ID| Error Message | 977| -------- | ----------------------------------------- | 978| 202 | Not system App. | 979| 5400102 | Operation not allowed. Return by promise. | 980| 5400103 | I/O error. Return by promise. | 981| 5400105 | Service died. Return by promise. | 982 983**Example** 984 985```ts 986import { BusinessError } from '@kit.BasicServicesKit'; 987 988// promise. 989videoRecorder.pause().then(() => { 990 console.info('pause videorecorder success'); 991}).catch((err: BusinessError) => { 992 console.error('pause videorecorder failed and catch error is ' + err.message); 993}); 994``` 995 996### resume<sup>9+</sup> 997 998resume(callback: AsyncCallback\<void>): void 999 1000Resumes recording. This API uses an asynchronous callback to return the result. 1001 1002**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 1003 1004**System API**: This is a system API. 1005 1006**Parameters** 1007 1008| Name | Type | Mandatory| Description | 1009| -------- | -------------------- | ---- | ---------------------------- | 1010| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 1011 1012**Error codes** 1013 1014For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 1015 1016| ID| Error Message | 1017| -------- | ------------------------------------------ | 1018| 202 | Not system App. | 1019| 5400102 | Operation not allowed. Return by callback. | 1020| 5400103 | I/O error. Return by callback. | 1021| 5400105 | Service died. Return by callback. | 1022 1023**Example** 1024 1025```ts 1026import { BusinessError } from '@kit.BasicServicesKit'; 1027 1028// asyncallback. 1029videoRecorder.resume((err: BusinessError) => { 1030 if (err == null) { 1031 console.info('resume videorecorder success'); 1032 } else { 1033 console.error('resume videorecorder failed and error is ' + err.message); 1034 } 1035}); 1036``` 1037 1038### resume<sup>9+</sup> 1039 1040resume(): Promise\<void> 1041 1042Resumes recording. This API uses a promise to return the result. 1043 1044**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 1045 1046**System API**: This is a system API. 1047 1048**Return value** 1049 1050| Type | Description | 1051| -------------- | ------------------------------------- | 1052| Promise\<void> | Promise used to return the result.| 1053 1054**Error codes** 1055 1056For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 1057 1058| ID| Error Message | 1059| -------- | ----------------------------------------- | 1060| 202 | Not system App. | 1061| 5400102 | Operation not allowed. Return by promise. | 1062| 5400103 | I/O error. Return by promise. | 1063| 5400105 | Service died. Return by promise. | 1064 1065**Example** 1066 1067```ts 1068import { BusinessError } from '@kit.BasicServicesKit'; 1069 1070// promise. 1071videoRecorder.resume().then(() => { 1072 console.info('resume videorecorder success'); 1073}).catch((err: BusinessError) => { 1074 console.error('resume videorecorder failed and catch error is ' + err.message); 1075}); 1076``` 1077 1078### stop<sup>9+</sup> 1079 1080stop(callback: AsyncCallback\<void>): void 1081 1082Stops recording. This API uses an asynchronous callback to return the result. 1083 1084To start another recording, you must call [prepare()](#prepare9) and [getInputSurface()](#getinputsurface9) again. 1085 1086**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 1087 1088**System API**: This is a system API. 1089 1090**Parameters** 1091 1092| Name | Type | Mandatory| Description | 1093| -------- | -------------------- | ---- | ---------------------------- | 1094| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 1095 1096**Error codes** 1097 1098For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 1099 1100| ID| Error Message | 1101| -------- | ------------------------------------------ | 1102| 202 | Not system App. | 1103| 5400102 | Operation not allowed. Return by callback. | 1104| 5400103 | I/O error. Return by callback. | 1105| 5400105 | Service died. Return by callback. | 1106 1107**Example** 1108 1109```ts 1110import { BusinessError } from '@kit.BasicServicesKit'; 1111 1112// asyncallback. 1113videoRecorder.stop((err: BusinessError) => { 1114 if (err == null) { 1115 console.info('stop videorecorder success'); 1116 } else { 1117 console.error('stop videorecorder failed and error is ' + err.message); 1118 } 1119}); 1120``` 1121 1122### stop<sup>9+</sup> 1123 1124stop(): Promise\<void> 1125 1126Stops recording. This API uses a promise to return the result. 1127 1128To start another recording, you must call [prepare()](#prepare9-1) and [getInputSurface()](#getinputsurface9-1) again. 1129 1130**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 1131 1132**System API**: This is a system API. 1133 1134**Return value** 1135 1136| Type | Description | 1137| -------------- | ------------------------------------- | 1138| Promise\<void> | Promise used to return the result.| 1139 1140**Error codes** 1141 1142For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 1143 1144| ID| Error Message | 1145| -------- | ----------------------------------------- | 1146| 202 | Not system App. | 1147| 5400102 | Operation not allowed. Return by promise. | 1148| 5400103 | I/O error. Return by promise. | 1149| 5400105 | Service died. Return by promise. | 1150 1151**Example** 1152 1153```ts 1154import { BusinessError } from '@kit.BasicServicesKit'; 1155 1156// promise. 1157videoRecorder.stop().then(() => { 1158 console.info('stop videorecorder success'); 1159}).catch((err: BusinessError) => { 1160 console.error('stop videorecorder failed and catch error is ' + err.message); 1161}); 1162``` 1163 1164### release<sup>9+</sup> 1165 1166release(callback: AsyncCallback\<void>): void 1167 1168Releases the video recording resources. This API uses an asynchronous callback to return the result. 1169 1170**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 1171 1172**System API**: This is a system API. 1173 1174**Parameters** 1175 1176| Name | Type | Mandatory| Description | 1177| -------- | -------------------- | ---- | -------------------------------- | 1178| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 1179 1180**Error codes** 1181 1182For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 1183 1184| ID| Error Message | 1185| -------- | --------------------------------- | 1186| 202 | Not system App. | 1187| 5400105 | Service died. Return by callback. | 1188 1189**Example** 1190 1191```ts 1192import { BusinessError } from '@kit.BasicServicesKit'; 1193 1194// asyncallback. 1195videoRecorder.release((err: BusinessError) => { 1196 if (err == null) { 1197 console.info('release videorecorder success'); 1198 } else { 1199 console.error('release videorecorder failed and error is ' + err.message); 1200 } 1201}); 1202``` 1203 1204### release<sup>9+</sup> 1205 1206release(): Promise\<void> 1207 1208Releases the video recording resources. This API uses a promise to return the result. 1209 1210**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 1211 1212**System API**: This is a system API. 1213 1214**Return value** 1215 1216| Type | Description | 1217| -------------- | ----------------------------------------- | 1218| Promise\<void> | Promise used to return the result.| 1219 1220**Error codes** 1221 1222For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 1223 1224| ID| Error Message | 1225| -------- | --------------------------------- | 1226| 202 | Not system App. | 1227| 5400105 | Service died. Return by callback. | 1228 1229**Example** 1230 1231```ts 1232import { BusinessError } from '@kit.BasicServicesKit'; 1233 1234// promise. 1235videoRecorder.release().then(() => { 1236 console.info('release videorecorder success'); 1237}).catch((err: BusinessError) => { 1238 console.error('release videorecorder failed and catch error is ' + err.message); 1239}); 1240``` 1241 1242### reset<sup>9+</sup> 1243 1244reset(callback: AsyncCallback\<void>): void 1245 1246Resets video recording. This API uses an asynchronous callback to return the result. 1247 1248To start another recording, you must call [prepare()](#prepare9) and [getInputSurface()](#getinputsurface9) again. 1249 1250**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 1251 1252**System API**: This is a system API. 1253 1254**Parameters** 1255 1256| Name | Type | Mandatory| Description | 1257| -------- | -------------------- | ---- | ---------------------------- | 1258| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 1259 1260**Error codes** 1261 1262For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 1263 1264| ID| Error Message | 1265| -------- | --------------------------------- | 1266| 202 | Not system App. | 1267| 5400103 | I/O error. Return by callback. | 1268| 5400105 | Service died. Return by callback. | 1269 1270**Example** 1271 1272```ts 1273import { BusinessError } from '@kit.BasicServicesKit'; 1274 1275// asyncallback. 1276videoRecorder.reset((err: BusinessError) => { 1277 if (err == null) { 1278 console.info('reset videorecorder success'); 1279 } else { 1280 console.error('reset videorecorder failed and error is ' + err.message); 1281 } 1282}); 1283``` 1284 1285### reset<sup>9+</sup> 1286 1287reset(): Promise\<void> 1288 1289Resets video recording. This API uses a promise to return the result. 1290 1291To start another recording, you must call [prepare()](#prepare9-1) and [getInputSurface()](#getinputsurface9-1) again. 1292 1293**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 1294 1295**System API**: This is a system API. 1296 1297**Return value** 1298 1299| Type | Description | 1300| -------------- | ------------------------------------- | 1301| Promise\<void> | Promise used to return the result.| 1302 1303**Error codes** 1304 1305For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 1306 1307| ID| Error Message | 1308| -------- | -------------------------------- | 1309| 202 | Not system App. | 1310| 5400103 | I/O error. Return by promise. | 1311| 5400105 | Service died. Return by promise. | 1312 1313**Example** 1314 1315```ts 1316import { BusinessError } from '@kit.BasicServicesKit'; 1317 1318// promise. 1319videoRecorder.reset().then(() => { 1320 console.info('reset videorecorder success'); 1321}).catch((err: BusinessError) => { 1322 console.error('reset videorecorder failed and catch error is ' + err.message); 1323}); 1324``` 1325 1326### on('error')<sup>9+</sup> 1327 1328on(type: 'error', callback: ErrorCallback): void 1329 1330Subscribes to video recording error events. After an error event is reported, you must handle the event and exit the recording. 1331 1332**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 1333 1334**System API**: This is a system API. 1335 1336**Parameters** 1337 1338| Name | Type | Mandatory| Description | 1339| -------- | ------------- | ---- | ------------------------------------------------------------ | 1340| type | string | Yes | Event type, which is **'error'** in this case.<br>This event is triggered when an error occurs during video recording.| 1341| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback invoked when the event is triggered. | 1342 1343**Error codes** 1344 1345For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md). 1346 1347| ID| Error Message | 1348| -------- | --------------------------------- | 1349| 201 | permission denied. | 1350| 202 | Not system App. | 1351| 5400103 | I/O error. Return by callback. | 1352| 5400105 | Service died. Return by callback. | 1353 1354**Example** 1355 1356```ts 1357import { BusinessError } from '@kit.BasicServicesKit'; 1358 1359// This event is reported when an error occurs during the retrieval of videoRecordState. 1360videoRecorder.on('error', (error: BusinessError) => { // Set the 'error' event callback. 1361 console.error(`audio error called, error: ${error}`); 1362}) 1363``` 1364 1365## VideoRecordState<sup>9+</sup> 1366 1367Enumerates the video recording states. You can obtain the state through the **state** property. 1368 1369**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 1370 1371**System API**: This is a system API. 1372 1373| Name | Type | Description | 1374| -------- | ------ | ---------------------- | 1375| idle | string | The video recorder is idle. | 1376| prepared | string | The video recording parameters are set.| 1377| playing | string | Video recording is in progress. | 1378| paused | string | Video recording is paused. | 1379| stopped | string | Video recording is stopped. | 1380| error | string | Video recording is in the error state. | 1381 1382## VideoRecorderConfig<sup>9+</sup> 1383 1384Describes the video recording parameters. 1385 1386The **audioSourceType** and **videoSourceType** parameters are used to distinguish video-only recording from audio and video recording. (For audio-only recording, use [AVRecorder](arkts-apis-media-AVRecorder.md) or [AudioRecorder](arkts-apis-media-AudioRecorder.md).) For video-only recording, set only **videoSourceType**. For audio and video recording, set both **audioSourceType** and **videoSourceType**. 1387 1388**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 1389 1390**System API**: This is a system API. 1391 1392| Name | Type | Mandatory| Description | 1393| --------------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ | 1394| audioSourceType | [AudioSourceType](arkts-apis-media-e.md#audiosourcetype9) | No | Type of the audio source for video recording. This parameter is mandatory for audio recording. | 1395| videoSourceType | [VideoSourceType](arkts-apis-media-e.md#videosourcetype9) | Yes | Type of the video source for video recording. | 1396| profile | [VideoRecorderProfile](#videorecorderprofile9) | Yes | Video recording profile. | 1397| rotation | number | No | Rotation angle of the recorded video. The value can only be 0 (default), 90, 180, or 270. | 1398| location | [Location](arkts-apis-media-i.md#location) | No | Geographical location of the recorded video. By default, the geographical location information is not recorded. | 1399| url | string | Yes | Video output URL. Supported: fd://xx (fd number)<br> | 1400 1401## VideoRecorderProfile<sup>9+</sup> 1402 1403Describes the video recording profile. 1404 1405**System capability**: SystemCapability.Multimedia.Media.VideoRecorder 1406 1407**System API**: This is a system API. 1408 1409| Name | Type | Mandatory| Description | 1410| ---------------- | -------------------------------------------- | ---- | ---------------- | 1411| audioBitrate | number | No | Audio encoding bit rate. This parameter is mandatory for audio recording.| 1412| audioChannels | number | No | Audio channel count. This parameter is mandatory for audio recording.| 1413| audioCodec | [CodecMimeType](arkts-apis-media-e.md#codecmimetype8) | No | Audio encoding format. This parameter is mandatory for audio recording. | 1414| audioSampleRate | number | No | Audio sample rate. This parameter is mandatory for audio recording. | 1415| fileFormat | [ContainerFormatType](arkts-apis-media-e.md#containerformattype8) | Yes | Container format of a file.| 1416| videoBitrate | number | Yes | Video encoding bit rate.| 1417| videoCodec | [CodecMimeType](arkts-apis-media-e.md#codecmimetype8) | Yes | Video encoding format. | 1418| videoFrameWidth | number | Yes | Width of the recorded video frame.| 1419| videoFrameHeight | number | Yes | Height of the recorded video frame.| 1420| videoFrameRate | number | Yes | Video frame rate. | 1421 1422## WatermarkConfig<sup>13+</sup> 1423 1424Describes the watermark configuration set for the AVRecorder. The start point is the upper-left corner of the image. 1425 1426**System capability**: SystemCapability.Multimedia.Media.Core 1427 1428**System API**: This is a system API. 1429 1430| Name | Type | Mandatory| Description | 1431| --------- | ------ | ---- | ---------------- | 1432| top | number | Yes | Pixel offset from the top edge of the image.| 1433| left | number | Yes | Pixel offset from the left edge of the image.| 1434 1435## ScreenCaptureMonitor<sup>18+</sup> 1436 1437A class that provides APIs to query and monitor the system screen recorder status. Before calling any API, you must use [getScreenCaptureMonitor()](#mediagetscreencapturemonitor18) to obtain a [ScreenCaptureMonitor](#screencapturemonitor18) instance. 1438 1439### Properties 1440 1441**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture 1442 1443**System API**: This is a system API. 1444 1445| Name | Type | Read-Only| Optional| Description | 1446| ------------------ | -------------------------------------- | ---- | ---- | ---------------- | 1447| isSystemScreenRecorderWorking<sup>18+</sup> | boolean | Yes | No | Whether the system screen recorder is working.| 1448 1449### on('systemScreenRecorder')<sup>18+</sup> 1450 1451on(type: 'systemScreenRecorder', callback: Callback\<ScreenCaptureEvent>): void 1452 1453Subscribes to state change events of the system screen recorder. From the ScreenCaptureEvent event reported, you can determine whether the system screen recorder is working. 1454 1455**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture 1456 1457**System API**: This is a system API. 1458 1459**Parameters** 1460 1461| Name | Type | Mandatory| Description | 1462| -------- | ------------- | ---- | ------------------------------------------------------------ | 1463| type | string | Yes | Event type, which is **'systemScreenRecorder'** in this case.<br>This event is triggered when the state of the system screen recorder changes.| 1464| callback | function | Yes | Callback invoked when the event is triggered, where [ScreenCaptureEvent](#screencaptureevent18) indicates the new state. | 1465 1466**Error codes** 1467 1468For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1469 1470| ID| Error Message | 1471| -------- | --------------------------------- | 1472| 202 | Not System App. | 1473 1474**Example** 1475 1476```ts 1477 1478// This event is reported when the state of the system screen recorder changes. 1479screenCaptureMonitor.on('systemScreenRecorder', (event: media.ScreenCaptureEvent) => { 1480 // Set the 'systemScreenRecorder' event callback. 1481 console.info(`system ScreenRecorder event: ${event}`); 1482}) 1483``` 1484 1485### off('systemScreenRecorder')<sup>18+</sup> 1486 1487off(type: 'systemScreenRecorder', callback?: Callback\<ScreenCaptureEvent>): void 1488 1489Unsubscribes from state change events of the system screen recorder. 1490 1491**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture 1492 1493**System API**: This is a system API. 1494 1495**Parameters** 1496 1497| Name | Type | Mandatory| Description | 1498| -------- | ------------- | ---- | ------------------------------------------------------------ | 1499| type | string | Yes | Event type, which is **'systemScreenRecorder'** in this case.<br>This event is triggered when the state of the system screen recorder changes.| 1500| callback | function | No | Callback invoked when the event is triggered, where [ScreenCaptureEvent](#screencaptureevent18) indicates the new state. If this parameter is not specified, the last subscription event is canceled.| 1501 1502**Error codes** 1503 1504For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1505 1506| ID| Error Message | 1507| -------- | --------------------------------- | 1508| 202 | Not System App. | 1509 1510**Example** 1511 1512```ts 1513screenCaptureMonitor.off('systemScreenRecorder'); 1514``` 1515 1516## ScreenCaptureEvent<sup>18+</sup> 1517 1518Enumerates the states available for the system screen recorder. 1519 1520**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture 1521 1522**System API**: This is a system API. 1523 1524| Name | Value | Description | 1525| ------------------------ | --------------- | ------------------------------------------------------------ | 1526| SCREENCAPTURE_STARTED | 0 | The system screen recorder starts screen capture. | 1527| SCREENCAPTURE_STOPPED | 1 | The system screen recorder stops screen capture.| 1528 1529## enableDeviceLevelCapture<sup>20+</sup> 1530 1531Specifies whether to capture the entire screen or half of the screen when the foldable PC is in the folded state. 1532 1533**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture 1534 1535**System API**: This is a system API. 1536 1537**enableDeviceLevelCapture** is an optional parameter in the **AVScreenCaptureStrategy** API. Its default value is **false**. 1538 1539| Name | Type | Mandatory| Description| 1540| ------------------------ | ------- | ---- | ---- | 1541| enableDeviceLevelCapture | boolean | No | Whether to capture the entire screen when the foldable PC is folded. **true** to capture the entire screen, **false** to capture half of the screen.| 1542