• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Interface (AVRecorder)
2<!--Kit: Media Kit-->
3<!--Subsystem: Multimedia-->
4<!--Owner: @shiwei75-->
5<!--Designer: @HmQQQ-->
6<!--Tester: @xdlinc-->
7<!--Adviser: @zengyawen-->
8
9> **NOTE**
10>
11> - 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.
12> - The initial APIs of this interface are supported since API version 9.
13
14AVRecorder is a class for audio and video recording management. It 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.
15
16For details about the audio and video recording demo, see [Audio Recording](../../media/media/using-avrecorder-for-recording.md) and [Video Recording](../../media/media/video-recording.md).
17
18> **NOTE**
19>
20> 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).
21
22## Modules to Import
23
24```ts
25import { media } from '@kit.MediaKit';
26```
27
28## Properties
29
30**System capability**: SystemCapability.Multimedia.Media.AVRecorder
31
32| Name   | Type                                | Read-Only| Optional| Description              |
33| ------- | ------------------------------------ | ---- | ---- | ------------------ |
34| state9+ | [AVRecorderState](arkts-apis-media-t.md#avrecorderstate9) | Yes  | No  | AVRecorder state.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
35
36## prepare<sup>9+</sup>
37
38prepare(config: AVRecorderConfig, callback: AsyncCallback\<void>): void
39
40Sets audio and video recording parameters. This API uses an asynchronous callback to return the result.
41
42**Required permissions:** ohos.permission.MICROPHONE
43
44This permission is required only if audio recording is involved.
45
46To 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).
47
48**System capability**: SystemCapability.Multimedia.Media.AVRecorder
49
50**Parameters**
51
52| Name  | Type                                  | Mandatory| Description                                 |
53| -------- | -------------------------------------- | ---- | ------------------------------------- |
54| config   | [AVRecorderConfig](arkts-apis-media-i.md#avrecorderconfig9) | Yes  | Audio and video recording parameters to set.           |
55| callback | AsyncCallback\<void>                   | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
56
57**Error codes**
58
59For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md).
60
61| ID| Error Message                               |
62| -------- | --------------------------------------- |
63| 201      | Permission denied. Return by callback.  |
64| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.    |
65| 5400102  | Operate not permit. Return by callback. |
66| 5400105  | Service died. Return by callback.       |
67
68**Example**
69
70```ts
71import { BusinessError } from '@kit.BasicServicesKit';
72
73// Configure the parameters based on those supported by the hardware device.
74let avRecorderProfile: media.AVRecorderProfile = {
75  audioBitrate : 48000,
76  audioChannels : 2,
77  audioCodec : media.CodecMimeType.AUDIO_AAC,
78  audioSampleRate : 48000,
79  fileFormat : media.ContainerFormatType.CFT_MPEG_4,
80  videoBitrate : 2000000,
81  videoCodec : media.CodecMimeType.VIDEO_AVC,
82  videoFrameWidth : 640,
83  videoFrameHeight : 480,
84  videoFrameRate : 30
85};
86let videoMetaData: media.AVMetadata = {
87  videoOrientation: '0' // The value can be 0, 90, 180, or 270. If any other value is used, prepare() reports an error.
88};
89let avRecorderConfig: media.AVRecorderConfig = {
90  audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC,
91  videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV,
92  profile : avRecorderProfile,
93  url : 'fd://', // Before passing in an FD to this parameter, the file must be created by the caller and granted with the read and write permissions. Example value: fd://45.
94  metadata: videoMetaData,
95  location : { latitude : 30, longitude : 130 }
96};
97
98avRecorder.prepare(avRecorderConfig, (err: BusinessError) => {
99  if (err) {
100    console.error('Failed to prepare and error is: ' + err.message);
101  } else {
102    console.info('Succeeded in preparing');
103  }
104});
105```
106
107## prepare<sup>9+</sup>
108
109prepare(config: AVRecorderConfig): Promise\<void>
110
111Sets audio and video recording parameters. This API uses a promise to return the result.
112
113**Required permissions:** ohos.permission.MICROPHONE
114
115This permission is required only if audio recording is involved.
116
117To 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).
118
119**Atomic service API**: This API can be used in atomic services since API version 12.
120
121**System capability**: SystemCapability.Multimedia.Media.AVRecorder
122
123**Parameters**
124
125| Name| Type                                  | Mandatory| Description                      |
126| ------ | -------------------------------------- | ---- | -------------------------- |
127| config | [AVRecorderConfig](arkts-apis-media-i.md#avrecorderconfig9) | Yes  | Audio and video recording parameters to set.|
128
129**Return value**
130
131| Type          | Description                                      |
132| -------------- | ------------------------------------------ |
133| Promise\<void> | Promise that returns no value.|
134
135**Error codes**
136
137For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md).
138
139| ID| Error Message                              |
140| -------- | -------------------------------------- |
141| 201      | Permission denied. Return by promise.  |
142| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.    |
143| 5400102  | Operate not permit. Return by promise. |
144| 5400105  | Service died. Return by promise.       |
145
146**Example**
147
148```ts
149import { BusinessError } from '@kit.BasicServicesKit';
150
151// Configure the parameters based on those supported by the hardware device.
152let avRecorderProfile: media.AVRecorderProfile = {
153  audioBitrate : 48000,
154  audioChannels : 2,
155  audioCodec : media.CodecMimeType.AUDIO_AAC,
156  audioSampleRate : 48000,
157  fileFormat : media.ContainerFormatType.CFT_MPEG_4,
158  videoBitrate : 2000000,
159  videoCodec : media.CodecMimeType.VIDEO_AVC,
160  videoFrameWidth : 640,
161  videoFrameHeight : 480,
162  videoFrameRate : 30
163};
164let videoMetaData: media.AVMetadata = {
165  videoOrientation: '0' // The value can be 0, 90, 180, or 270. If any other value is used, prepare() reports an error.
166};
167let avRecorderConfig: media.AVRecorderConfig = {
168  audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC,
169  videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV,
170  profile : avRecorderProfile,
171  url : 'fd://', // Before passing in an FD to this parameter, the file must be created by the caller and granted with the read and write permissions. Example value: fd://45.
172  metadata : videoMetaData,
173  location : { latitude : 30, longitude : 130 }
174};
175
176avRecorder.prepare(avRecorderConfig).then(() => {
177  console.info('Succeeded in preparing');
178}).catch((err: Error) => {
179  let error: BusinessError = err as BusinessError;
180  console.error('Failed to prepare and error is: ' + error.message);
181});
182```
183
184## getInputSurface<sup>9+</sup>
185
186getInputSurface(callback: AsyncCallback\<string>): void
187
188Obtains 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 video data.
189
190Note 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.
191
192This API can be called only after the [prepare()](#prepare9) API is called.
193
194**System capability**: SystemCapability.Multimedia.Media.AVRecorder
195
196**Parameters**
197
198| Name  | Type                  | Mandatory| Description                       |
199| -------- | ---------------------- | ---- | --------------------------- |
200| callback | AsyncCallback\<string> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the surface ID obtained; otherwise, **err** is an error object.|
201
202**Error codes**
203
204For details about the error codes, see [Media Error Codes](errorcode-media.md).
205
206| ID| Error Message                               |
207| -------- | --------------------------------------- |
208| 5400102  | Operate not permit. Return by callback. |
209| 5400103  | IO error. Return by callback.           |
210| 5400105  | Service died. Return by callback.       |
211
212**Example**
213
214```ts
215import { BusinessError } from '@kit.BasicServicesKit';
216let surfaceID: string; // The surfaceID is transferred to the camera API to create a videoOutput instance.
217
218avRecorder.getInputSurface((err: BusinessError, surfaceId: string) => {
219  if (err) {
220    console.error('Failed to do getInputSurface and error is: ' + err.message);
221  } else {
222    console.info('Succeeded in doing getInputSurface');
223    surfaceID = surfaceId;
224  }
225});
226
227```
228
229## getInputSurface<sup>9+</sup>
230
231getInputSurface(): Promise\<string>
232
233Obtains 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 video data.
234
235Note 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.
236
237This API can be called only after the [prepare()](#prepare9-1) API is called.
238
239**System capability**: SystemCapability.Multimedia.Media.AVRecorder
240
241**Return value**
242
243| Type            | Description                            |
244| ---------------- | -------------------------------- |
245| Promise\<string> | Promise used to return the result.|
246
247**Error codes**
248
249For details about the error codes, see [Media Error Codes](errorcode-media.md).
250
251| ID| Error Message                              |
252| -------- | -------------------------------------- |
253| 5400102  | Operate not permit. Return by promise. |
254| 5400103  | IO error. Return by promise.           |
255| 5400105  | Service died. Return by promise.       |
256
257**Example**
258
259```ts
260import { BusinessError } from '@kit.BasicServicesKit';
261let surfaceID: string; // The surfaceID is transferred to the camera API to create a videoOutput instance.
262
263avRecorder.getInputSurface().then((surfaceId: string) => {
264  console.info('Succeeded in getting InputSurface');
265  surfaceID = surfaceId;
266}).catch((err: Error) => {
267  let error: BusinessError = err as BusinessError;
268  console.error('Failed to get InputSurface and error is: ' + error.message);
269});
270```
271
272## updateRotation<sup>12+</sup>
273
274updateRotation(rotation: number): Promise\<void>
275
276Updates the video rotation angle. This API uses a promise to return the result.
277
278This API can be called only after the [prepare()](#prepare9-1) event is triggered and before the [start()](#start9) API is called.
279
280**System capability**: SystemCapability.Multimedia.Media.AVRecorder
281
282**Parameters**
283
284| Name  | Type                | Mandatory| Description                       |
285| -------- | -------------------- | ---- | --------------------------- |
286| rotation | number | Yes  | Rotation angle, which can only be 0, 90, 180, or 270 degrees.|
287
288**Return value**
289
290| Type            | Description                            |
291| ---------------- | -------------------------------- |
292| Promise\<void> | Promise that returns no value.|
293
294**Error codes**
295
296For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md).
297
298| ID| Error Message                              |
299| -------- | -------------------------------------- |
300|   401    | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.   |
301| 5400102  | Operation not allowed. Return by promise. |
302| 5400103  | IO error. Return by promise.           |
303| 5400105  | Service died. Return by promise.       |
304
305**Example**
306
307```ts
308import { BusinessError } from '@kit.BasicServicesKit';
309
310let rotation = 90;
311
312avRecorder.updateRotation(rotation).then(() => {
313  console.info('Succeeded in doing updateRotation');
314}).catch((err: Error) => {
315  let error: BusinessError = err as BusinessError;
316  console.error('Failed to do updateRotation and error is: ' + error.message);
317});
318```
319
320## setWillMuteWhenInterrupted<sup>20+</sup>
321
322setWillMuteWhenInterrupted(muteWhenInterrupted: boolean): Promise&lt;void&gt;
323
324Sets whether to mute the current audio recording stream when an audio interruption occurs. This API uses a promise to return the result.
325
326**System capability**: SystemCapability.Multimedia.Media.AVRecorder
327
328**Parameters**
329
330| Name    | Type            | Mandatory  | Description                                                     |
331| ---------- |---------------- | ------ |---------------------------------------------------------|
332| muteWhenInterrupted | boolean | Yes | Whether to mute the current audio recording stream during an audio interruption. **true** to mute, **false** otherwise.|
333
334**Return value**
335
336| Type               | Description                         |
337| ------------------- | ----------------------------- |
338| Promise&lt;void&gt;| Promise that returns no value.|
339
340**Error codes**
341
342For details about the error codes, see [Media Error Codes](errorcode-media.md).
343
344| ID| Error Message                              |
345| -------- | -------------------------------------- |
346| 5400102  | Operation not allowed. Return by promise. |
347| 5400105  | Service died. Return by promise.       |
348
349**Example**
350
351```ts
352import { BusinessError } from '@kit.BasicServicesKit';
353
354avRecorder.setWillMuteWhenInterrupted(true).then(() => {
355  console.info('Succeeded in doing setWillMuteWhenInterrupted');
356}).catch((err: Error) => {
357  let error: BusinessError = err as BusinessError;
358  console.error('Failed to do setWillMuteWhenInterrupted and error is: ' + error.message);
359});
360```
361
362## start<sup>9+</sup>
363
364start(callback: AsyncCallback\<void>): void
365
366Starts recording. This API uses an asynchronous callback to return the result.
367
368For audio-only recording, this API can be called only after the [prepare()](#prepare9) API is called. For video-only recording, this API can be called only after the [getInputSurface()](#getinputsurface9) API is called.
369
370**System capability**: SystemCapability.Multimedia.Media.AVRecorder
371
372**Parameters**
373
374| Name  | Type                | Mandatory| Description                        |
375| -------- | -------------------- | ---- | ---------------------------- |
376| callback | AsyncCallback\<void> | Yes  |Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
377
378**Error codes**
379
380For details about the error codes, see [Media Error Codes](errorcode-media.md).
381
382| ID| Error Message                               |
383| -------- | --------------------------------------- |
384| 5400102  | Operate not permit. Return by callback. |
385| 5400103  | IO error. Return by callback.           |
386| 5400105  | Service died. Return by callback.       |
387
388**Example**
389
390```ts
391import { BusinessError } from '@kit.BasicServicesKit';
392
393avRecorder.start((err: BusinessError) => {
394  if (err) {
395    console.error('Failed to start AVRecorder and error is: ' + err.message);
396  } else {
397    console.info('Succeeded in starting AVRecorder');
398  }
399});
400```
401
402## start<sup>9+</sup>
403
404start(): Promise\<void>
405
406Starts recording. This API uses a promise to return the result.
407
408For audio-only recording, this API can be called only after the [prepare()](#prepare9-1) API is called. For video-only recording, this API can be called only after the [getInputSurface()](#getinputsurface9-1) API is called.
409
410**Atomic service API**: This API can be used in atomic services since API version 12.
411
412**System capability**: SystemCapability.Multimedia.Media.AVRecorder
413
414**Return value**
415
416| Type          | Description                                 |
417| -------------- | ------------------------------------- |
418| Promise\<void> | Promise that returns no value.|
419
420**Error codes**
421
422For details about the error codes, see [Media Error Codes](errorcode-media.md).
423
424| ID| Error Message                              |
425| -------- | -------------------------------------- |
426| 5400102  | Operate not permit. Return by promise. |
427| 5400103  | IO error. Return by promise.           |
428| 5400105  | Service died. Return by promise.       |
429
430**Example**
431
432```ts
433import { BusinessError } from '@kit.BasicServicesKit';
434
435avRecorder.start().then(() => {
436  console.info('Succeeded in starting AVRecorder');
437}).catch((err: Error) => {
438  let error: BusinessError = err as BusinessError;
439  console.error('Failed to start AVRecorder and error is: ' + error.message);
440});
441```
442
443## pause<sup>9+</sup>
444
445pause(callback: AsyncCallback\<void>): void
446
447Pauses recording. This API uses an asynchronous callback to return the result.
448
449This API can be called only after the [start()](#start9) API is called. You can call [resume()](#resume9) to resume recording.
450
451**System capability**: SystemCapability.Multimedia.Media.AVRecorder
452
453**Parameters**
454
455| Name  | Type                | Mandatory| Description                       |
456| -------- | -------------------- | ---- | --------------------------- |
457| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
458
459**Error codes**
460
461For details about the error codes, see [Media Error Codes](errorcode-media.md).
462
463| ID| Error Message                               |
464| -------- | --------------------------------------- |
465| 5400102  | Operate not permit. Return by callback. |
466| 5400103  | IO error. Return by callback.           |
467| 5400105  | Service died. Return by callback.       |
468
469**Example**
470
471```ts
472import { BusinessError } from '@kit.BasicServicesKit';
473
474avRecorder.pause((err: BusinessError) => {
475  if (err) {
476    console.error('Failed to pause AVRecorder and error is: ' + err.message);
477  } else {
478    console.info('Succeeded in pausing');
479  }
480});
481```
482
483## pause<sup>9+</sup>
484
485pause(): Promise\<void>
486
487Pauses recording. This API uses a promise to return the result.
488
489This API can be called only after the [start()](#start9-1) API is called. You can call [resume()](#resume9-1) to resume recording.
490
491**Atomic service API**: This API can be used in atomic services since API version 12.
492
493**System capability**: SystemCapability.Multimedia.Media.AVRecorder
494
495**Return value**
496
497| Type          | Description                                 |
498| -------------- | ------------------------------------- |
499| Promise\<void> | Promise that returns no value.|
500
501**Error codes**
502
503For details about the error codes, see [Media Error Codes](errorcode-media.md).
504
505| ID| Error Message                              |
506| -------- | -------------------------------------- |
507| 5400102  | Operate not permit. Return by promise. |
508| 5400103  | IO error. Return by promise.           |
509| 5400105  | Service died. Return by promise.       |
510
511**Example**
512
513```ts
514import { BusinessError } from '@kit.BasicServicesKit';
515
516avRecorder.pause().then(() => {
517  console.info('Succeeded in pausing');
518}).catch((err: Error) => {
519  let error: BusinessError = err as BusinessError;
520  console.error('Failed to pause AVRecorder and error is: ' + error.message);
521});
522```
523
524## resume<sup>9+</sup>
525
526resume(callback: AsyncCallback\<void>): void
527
528Resumes recording. This API uses an asynchronous callback to return the result.
529
530This API can be called only after the [pause()](#pause9) API is called.
531
532**System capability**: SystemCapability.Multimedia.Media.AVRecorder
533
534**Parameters**
535
536| Name  | Type                | Mandatory| Description                        |
537| -------- | -------------------- | ---- | ---------------------------- |
538| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
539
540**Error codes**
541
542For details about the error codes, see [Media Error Codes](errorcode-media.md).
543
544| ID| Error Message                               |
545| -------- | --------------------------------------- |
546| 5400102  | Operate not permit. Return by callback. |
547| 5400103  | IO error. Return by callback.           |
548| 5400105  | Service died. Return by callback.       |
549
550**Example**
551
552```ts
553import { BusinessError } from '@kit.BasicServicesKit';
554
555avRecorder.resume((err: BusinessError) => {
556  if (err) {
557    console.error('Failed to resume AVRecorder and error is: ' + err.message);
558  } else {
559    console.info('Succeeded in resuming AVRecorder');
560  }
561});
562```
563
564## resume<sup>9+</sup>
565
566resume(): Promise\<void>
567
568Resumes recording. This API uses a promise to return the result.
569
570This API can be called only after the [pause()](#pause9-1) API is called.
571
572**Atomic service API**: This API can be used in atomic services since API version 12.
573
574**System capability**: SystemCapability.Multimedia.Media.AVRecorder
575
576**Return value**
577
578| Type          | Description                                 |
579| -------------- | ------------------------------------- |
580| Promise\<void> | Promise that returns no value.|
581
582**Error codes**
583
584For details about the error codes, see [Media Error Codes](errorcode-media.md).
585
586| ID| Error Message                              |
587| -------- | -------------------------------------- |
588| 5400102  | Operate not permit. Return by promise. |
589| 5400103  | IO error. Return by promise.           |
590| 5400105  | Service died. Return by promise.       |
591
592**Example**
593
594```ts
595import { BusinessError } from '@kit.BasicServicesKit';
596
597avRecorder.resume().then(() => {
598  console.info('Succeeded in resuming AVRecorder');
599}).catch((err: Error) => {
600  let error: BusinessError = err as BusinessError;
601  console.error('Failed to resume AVRecorder failed and error is: ' + error.message);
602});
603```
604
605## stop<sup>9+</sup>
606
607stop(callback: AsyncCallback\<void>): void
608
609Stops recording. This API uses an asynchronous callback to return the result.
610
611This API can be called only after the [start()](#start9) or [pause()](#pause9) API is called.
612
613For audio-only recording, you can call [prepare()](#prepare9) again for re-recording. For video-only recording or audio and video recording, you can call [prepare()](#prepare9) and [getInputSurface()](#getinputsurface9) again for re-recording.
614
615**System capability**: SystemCapability.Multimedia.Media.AVRecorder
616
617**Parameters**
618
619| Name  | Type                | Mandatory| Description                        |
620| -------- | -------------------- | ---- | ---------------------------- |
621| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
622
623**Error codes**
624
625For details about the error codes, see [Media Error Codes](errorcode-media.md).
626
627| ID| Error Message                               |
628| -------- | --------------------------------------- |
629| 5400102  | Operate not permit. Return by callback. |
630| 5400103  | IO error. Return by callback.           |
631| 5400105  | Service died. Return by callback.       |
632
633**Example**
634
635```ts
636import { BusinessError } from '@kit.BasicServicesKit';
637
638avRecorder.stop((err: BusinessError) => {
639  if (err) {
640    console.error('Failed to stop AVRecorder and error is: ' + err.message);
641  } else {
642    console.info('Succeeded in stopping AVRecorder');
643  }
644});
645```
646
647## stop<sup>9+</sup>
648
649stop(): Promise\<void>
650
651Stops recording. This API uses a promise to return the result.
652
653This API can be called only after the [start()](#start9-1) or [pause()](#pause9-1) API is called.
654
655For audio-only recording, you can call [prepare()](#prepare9-1) again for re-recording. For video-only recording or audio and video recording, you can call [prepare()](#prepare9-1) and [getInputSurface()](#getinputsurface9-1) again for re-recording.
656
657**Atomic service API**: This API can be used in atomic services since API version 12.
658
659**System capability**: SystemCapability.Multimedia.Media.AVRecorder
660
661**Return value**
662
663| Type          | Description                                 |
664| -------------- | ------------------------------------- |
665| Promise\<void> | Promise that returns no value.|
666
667**Error codes**
668
669For details about the error codes, see [Media Error Codes](errorcode-media.md).
670
671| ID| Error Message                              |
672| -------- | -------------------------------------- |
673| 5400102  | Operate not permit. Return by promise. |
674| 5400103  | IO error. Return by promise.           |
675| 5400105  | Service died. Return by promise.       |
676
677**Example**
678
679```ts
680import { BusinessError } from '@kit.BasicServicesKit';
681
682avRecorder.stop().then(() => {
683  console.info('Succeeded in stopping AVRecorder');
684}).catch((err: Error) => {
685  let error: BusinessError = err as BusinessError;
686  console.error('Failed to stop AVRecorder and error is: ' + error.message);
687});
688```
689
690## reset<sup>9+</sup>
691
692reset(callback: AsyncCallback\<void>): void
693
694Resets audio and video recording. This API uses an asynchronous callback to return the result.
695
696For audio-only recording, you can call [prepare()](#prepare9) again for re-recording. For video-only recording or audio and video recording, you can call [prepare()](#prepare9) and [getInputSurface()](#getinputsurface9) again for re-recording.
697
698**System capability**: SystemCapability.Multimedia.Media.AVRecorder
699
700**Parameters**
701
702| Name  | Type                | Mandatory| Description                          |
703| -------- | -------------------- | ---- | ------------------------------ |
704| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
705
706**Error codes**
707
708For details about the error codes, see [Media Error Codes](errorcode-media.md).
709
710| ID| Error Message                         |
711| -------- | --------------------------------- |
712| 5400103  | IO error. Return by callback.     |
713| 5400105  | Service died. Return by callback. |
714
715**Example**
716
717```ts
718import { BusinessError } from '@kit.BasicServicesKit';
719
720avRecorder.reset((err: BusinessError) => {
721  if (err) {
722    console.error('Failed to reset AVRecorder and error is: ' + err.message);
723  } else {
724    console.info('Succeeded in resetting AVRecorder');
725  }
726});
727```
728
729## reset<sup>9+</sup>
730
731reset(): Promise\<void>
732
733Resets audio and video recording. This API uses a promise to return the result.
734
735For audio-only recording, you can call [prepare()](#prepare9-1) again for re-recording. For video-only recording or audio and video recording, you can call [prepare()](#prepare9-1) and [getInputSurface()](#getinputsurface9-1) again for re-recording.
736
737**System capability**: SystemCapability.Multimedia.Media.AVRecorder
738
739**Return value**
740
741| Type          | Description                                   |
742| -------------- | --------------------------------------- |
743| Promise\<void> | Promise that returns no value.|
744
745**Error codes**
746
747For details about the error codes, see [Media Error Codes](errorcode-media.md).
748
749| ID| Error Message                        |
750| -------- | -------------------------------- |
751| 5400103  | IO error. Return by promise.     |
752| 5400105  | Service died. Return by promise. |
753
754**Example**
755
756```ts
757import { BusinessError } from '@kit.BasicServicesKit';
758
759avRecorder.reset().then(() => {
760  console.info('Succeeded in resetting AVRecorder');
761}).catch((err: Error) => {
762  let error: BusinessError = err as BusinessError;
763  console.error('Failed to reset AVRecorder and error is: ' + error.message);
764});
765```
766
767## release<sup>9+</sup>
768
769release(callback: AsyncCallback\<void>): void
770
771Releases the audio and video recording resources. This API uses an asynchronous callback to return the result.
772
773After the resources are released, you can no longer perform any operation on the AVRecorder instance.
774
775**System capability**: SystemCapability.Multimedia.Media.AVRecorder
776
777**Parameters**
778
779| Name  | Type                | Mandatory| Description                              |
780| -------- | -------------------- | ---- | ---------------------------------- |
781| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
782
783**Error codes**
784
785For details about the error codes, see [Media Error Codes](errorcode-media.md).
786
787| ID| Error Message                         |
788| -------- | --------------------------------- |
789| 5400105  | Service died. Return by callback. |
790
791**Example**
792
793```ts
794import { BusinessError } from '@kit.BasicServicesKit';
795
796avRecorder.release((err: BusinessError) => {
797  if (err) {
798    console.error('Failed to release AVRecorder and error is: ' + err.message);
799  } else {
800    console.info('Succeeded in releasing AVRecorder');
801  }
802});
803```
804
805## release<sup>9+</sup>
806
807release(): Promise\<void>
808
809Releases the audio and video recording resources. This API uses a promise to return the result.
810
811After the resources are released, you can no longer perform any operation on the AVRecorder instance.
812
813**Atomic service API**: This API can be used in atomic services since API version 12.
814
815**System capability**: SystemCapability.Multimedia.Media.AVRecorder
816
817**Return value**
818
819| Type          | Description                                       |
820| -------------- | ------------------------------------------- |
821| Promise\<void> | Promise that returns no value.|
822
823**Error codes**
824
825For details about the error codes, see [Media Error Codes](errorcode-media.md).
826
827| ID| Error Message                         |
828| -------- | --------------------------------- |
829| 5400105  | Service died. Return by callback. |
830
831**Example**
832
833```ts
834import { BusinessError } from '@kit.BasicServicesKit';
835
836avRecorder.release().then(() => {
837  console.info('Succeeded in releasing AVRecorder');
838}).catch((err: Error) => {
839  let error: BusinessError = err as BusinessError;
840  console.error('Failed to release AVRecorder and error is: ' + error.message);
841});
842```
843
844## getCurrentAudioCapturerInfo<sup>11+</sup>
845
846getCurrentAudioCapturerInfo(callback: AsyncCallback\<audio.AudioCapturerChangeInfo>): void
847
848Obtains the information about the current audio capturer. This API uses an asynchronous callback to return the result.
849
850This API can be called only after the **prepare()** API is called. If this API is called after **stop()** is successfully called, an error is reported.
851
852**System capability**: SystemCapability.Multimedia.Media.AVRecorder
853
854**Parameters**
855
856| Name  | Type                                                        | Mandatory| Description                                |
857| -------- | ------------------------------------------------------------ | ---- | ------------------------------------ |
858| callback | AsyncCallback\<[audio.AudioCapturerChangeInfo](../apis-audio-kit/arkts-apis-audio-i.md#audiocapturerchangeinfo9)> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the audio.AudioCapturerChangeInfo object obtained; otherwise, **err** is an error object.|
859
860**Error codes**
861
862For details about the error codes, see [Media Error Codes](errorcode-media.md).
863
864| ID| Error Message                                  |
865| -------- | ------------------------------------------ |
866| 5400102  | Operation not allowed. |
867| 5400103  | I/O error.             |
868| 5400105  | Service died. Return by callback.          |
869
870**Example**
871
872```ts
873import { BusinessError } from '@kit.BasicServicesKit';
874import { audio } from '@kit.AudioKit';
875
876let currentCapturerInfo: audio.AudioCapturerChangeInfo;
877
878avRecorder.getCurrentAudioCapturerInfo((err: BusinessError, capturerInfo: audio.AudioCapturerChangeInfo) => {
879  if (err) {
880    console.error('Failed to get CurrentAudioCapturerInfo and error is: ' + err.message);
881  } else {
882    console.info('Succeeded in getting CurrentAudioCapturerInfo');
883    currentCapturerInfo = capturerInfo;
884  }
885});
886```
887
888## getCurrentAudioCapturerInfo<sup>11+</sup>
889
890getCurrentAudioCapturerInfo(): Promise\<audio.AudioCapturerChangeInfo>
891
892Obtains the information about the current audio capturer. This API uses a promise to return the result.
893
894This API can be called only after the **prepare()** API is called. If this API is called after **stop()** is successfully called, an error is reported.
895
896**System capability**: SystemCapability.Multimedia.Media.AVRecorder
897
898**Return value**
899
900| Type                                                        | Description                                             |
901| ------------------------------------------------------------ | ------------------------------------------------- |
902| Promise\<[audio.AudioCapturerChangeInfo](../apis-audio-kit/arkts-apis-audio-i.md#audiocapturerchangeinfo9)> | Promise used to return the audio capturer information.|
903
904**Error codes**
905
906For details about the error codes, see [Media Error Codes](errorcode-media.md).
907
908| ID| Error Message                        |
909| -------- | -------------------------------- |
910| 5400102  | Operation not allowed.           |
911| 5400103  | I/O error.                       |
912| 5400105  | Service died. Return by promise. |
913
914**Example**
915
916```ts
917import { BusinessError } from '@kit.BasicServicesKit';
918import { audio } from '@kit.AudioKit';
919
920let currentCapturerInfo: audio.AudioCapturerChangeInfo;
921
922avRecorder.getCurrentAudioCapturerInfo().then((capturerInfo: audio.AudioCapturerChangeInfo) => {
923  console.info('Succeeded in getting CurrentAudioCapturerInfo');
924  currentCapturerInfo = capturerInfo;
925}).catch((err: Error) => {
926  let error: BusinessError = err as BusinessError;
927  console.error('Failed to get CurrentAudioCapturerInfo and error is: ' + error.message);
928});
929```
930
931## getAudioCapturerMaxAmplitude<sup>11+</sup>
932
933getAudioCapturerMaxAmplitude(callback: AsyncCallback\<number>): void
934
935Obtains the maximum amplitude of the current audio capturer. This API uses an asynchronous callback to return the result.
936
937This API can be called only after the **prepare()** API is called. If this API is called after **stop()** is successfully called, an error is reported.
938
939The return value is the maximum amplitude within the duration from the time the maximum amplitude is obtained last time to the current time. For example, if you have obtained the maximum amplitude at 1s and you call this API again at 2s, then the return value is the maximum amplitude within the duration from 1s to 2s.
940
941**System capability**: SystemCapability.Multimedia.Media.AVRecorder
942
943**Parameters**
944
945| Name  | Type                  | Mandatory| Description                                |
946| -------- | ---------------------- | ---- | ------------------------------------ |
947| callback | AsyncCallback\<number> | Yes  |  Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the maximum amplitude obtained; otherwise, **err** is an error object.|
948
949**Error codes**
950
951For details about the error codes, see [Media Error Codes](errorcode-media.md).
952
953| ID| Error Message                                  |
954| -------- | ------------------------------------------ |
955| 5400102  | Operation not allowed. |
956| 5400105  | Service died. Return by callback.          |
957
958**Example**
959
960```ts
961import { BusinessError } from '@kit.BasicServicesKit';
962
963let maxAmplitude: number;
964
965avRecorder.getAudioCapturerMaxAmplitude((err: BusinessError, amplitude: number) => {
966  if (err) {
967    console.error('Failed to get AudioCapturerMaxAmplitude and error is: ' + err.message);
968  } else {
969    console.info('Succeeded in getting AudioCapturerMaxAmplitude');
970    maxAmplitude = amplitude;
971  }
972});
973```
974
975## getAudioCapturerMaxAmplitude<sup>11+</sup>
976
977getAudioCapturerMaxAmplitude(): Promise\<number>
978
979Obtains the maximum amplitude of the current audio capturer. This API uses a promise to return the result.
980
981This API can be called only after the **prepare()** API is called. If this API is called after **stop()** is successfully called, an error is reported.
982
983The return value is the maximum amplitude within the duration from the time the maximum amplitude is obtained last time to the current time. For example, if you have obtained the maximum amplitude at 1s and you call this API again at 2s, then the return value is the maximum amplitude within the duration from 1s to 2s.
984
985**System capability**: SystemCapability.Multimedia.Media.AVRecorder
986
987**Return value**
988
989| Type            | Description                                             |
990| ---------------- | ------------------------------------------------- |
991| Promise\<number>| Promise used to return the maximum amplitude obtained.|
992
993**Error codes**
994
995For details about the error codes, see [Media Error Codes](errorcode-media.md).
996
997| ID| Error Message                        |
998| -------- | -------------------------------- |
999| 5400102  | Operation not allowed.           |
1000| 5400105  | Service died. Return by promise. |
1001
1002**Example**
1003
1004```ts
1005import { BusinessError } from '@kit.BasicServicesKit';
1006
1007let maxAmplitude: number;
1008
1009avRecorder.getAudioCapturerMaxAmplitude().then((amplitude: number) => {
1010  console.info('Succeeded in getting AudioCapturerMaxAmplitude');
1011  maxAmplitude = amplitude;
1012}).catch((err: Error) => {
1013  let error: BusinessError = err as BusinessError;
1014  console.error('Failed to get AudioCapturerMaxAmplitude and error is: ' + error.message);
1015});
1016```
1017
1018## getAvailableEncoder<sup>11+</sup>
1019
1020getAvailableEncoder(callback: AsyncCallback\<Array\<EncoderInfo>>): void
1021
1022Obtains available encoders. This API uses an asynchronous callback to return the result.
1023
1024**System capability**: SystemCapability.Multimedia.Media.AVRecorder
1025
1026**Parameters**
1027
1028| Name  | Type                                                 | Mandatory| Description                                |
1029| -------- | ----------------------------------------------------- | ---- | ------------------------------------ |
1030| callback | AsyncCallback\<Array\<[EncoderInfo](arkts-apis-media-i.md#encoderinfo11)>> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the available encoders obtained; otherwise, **err** is an error object.|
1031
1032**Error codes**
1033
1034For details about the error codes, see [Media Error Codes](errorcode-media.md).
1035
1036| ID| Error Message                                  |
1037| -------- | ------------------------------------------ |
1038| 5400102  | Operation not allowed. |
1039| 5400105  | Service died. Return by callback.          |
1040
1041**Example**
1042
1043```ts
1044import { BusinessError } from '@kit.BasicServicesKit';
1045
1046let encoderInfo: media.EncoderInfo;
1047
1048avRecorder.getAvailableEncoder((err: BusinessError, info: media.EncoderInfo[]) => {
1049  if (err) {
1050    console.error('Failed to get AvailableEncoder and error is: ' + err.message);
1051  } else {
1052    console.info('Succeeded in getting AvailableEncoder');
1053    if (info.length > 0) {
1054      encoderInfo = info[0];
1055    } else {
1056      console.error('No available encoder');
1057    }
1058  }
1059});
1060```
1061
1062## getAvailableEncoder<sup>11+</sup>
1063
1064getAvailableEncoder(): Promise\<Array\<EncoderInfo>>
1065
1066Obtains available encoders. This API uses a promise to return the result.
1067
1068**System capability**: SystemCapability.Multimedia.Media.AVRecorder
1069
1070**Return value**
1071
1072| Type                                           | Description                                           |
1073| ----------------------------------------------- | ----------------------------------------------- |
1074| Promise\<Array\<[EncoderInfo](arkts-apis-media-i.md#encoderinfo11)>> | Promise used to return the information about the available encoders.|
1075
1076**Error codes**
1077
1078For details about the error codes, see [Media Error Codes](errorcode-media.md).
1079
1080| ID| Error Message                        |
1081| -------- | -------------------------------- |
1082| 5400102  | Operation not allowed.           |
1083| 5400105  | Service died. Return by promise. |
1084
1085**Example**
1086
1087```ts
1088import { BusinessError } from '@kit.BasicServicesKit';
1089
1090let encoderInfo: media.EncoderInfo;
1091
1092avRecorder.getAvailableEncoder().then((info: media.EncoderInfo[]) => {
1093  console.info('Succeeded in getting AvailableEncoder');
1094    if (info.length > 0) {
1095      encoderInfo = info[0];
1096    } else {
1097      console.error('No available encoder');
1098    }
1099}).catch((err: Error) => {
1100  let error: BusinessError = err as BusinessError;
1101  console.error('Failed to get AvailableEncoder and error is: ' + error.message);
1102});
1103```
1104
1105## getAVRecorderConfig<sup>11+</sup>
1106
1107getAVRecorderConfig(callback: AsyncCallback\<AVRecorderConfig>): void
1108
1109Obtains the real-time configuration of this AVRecorder. This API uses an asynchronous callback to return the result.
1110
1111This API can be called only after [prepare()](#prepare9) is called.
1112
1113**System capability**: SystemCapability.Multimedia.Media.AVRecorder
1114
1115**Parameters**
1116
1117| Name  | Type                  | Mandatory| Description                       |
1118| -------- | ---------------------- | ---- | --------------------------- |
1119| callback | AsyncCallback\<[AVRecorderConfig](arkts-apis-media-i.md#avrecorderconfig9)> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the real-time configuration obtained; otherwise, **err** is an error object.|
1120
1121**Error codes**
1122
1123For details about the error codes, see [Media Error Codes](errorcode-media.md).
1124
1125| ID| Error Message                                  |
1126| -------- | ------------------------------------------ |
1127| 5400102  | Operate not permit. Return by callback. |
1128| 5400103  | IO error. Return by callback.             |
1129| 5400105  | Service died. Return by callback.          |
1130
1131**Example**
1132
1133```ts
1134import { BusinessError } from '@kit.BasicServicesKit';
1135
1136let avConfig: media.AVRecorderConfig;
1137
1138avRecorder.getAVRecorderConfig((err: BusinessError, config: media.AVRecorderConfig) => {
1139  if (err) {
1140    console.error('Failed to get avConfig and error is: ' + err.message);
1141  } else {
1142    console.info('Succeeded in getting AVRecorderConfig');
1143    avConfig = config;
1144  }
1145});
1146```
1147
1148## getAVRecorderConfig<sup>11+</sup>
1149
1150getAVRecorderConfig(): Promise\<AVRecorderConfig>;
1151
1152Obtains the real-time configuration of this AVRecorder. This API uses a promise to return the result.
1153
1154This API can be called only after [prepare()](#prepare9-1) is called.
1155
1156**System capability**: SystemCapability.Multimedia.Media.AVRecorder
1157
1158**Return value**
1159
1160| Type            | Description                            |
1161| ---------------- | -------------------------------- |
1162| Promise\<[AVRecorderConfig](arkts-apis-media-i.md#avrecorderconfig9)> | Promise used to return the real-time configuration.|
1163
1164**Error codes**
1165
1166For details about the error codes, see [Media Error Codes](errorcode-media.md).
1167
1168| ID| Error Message                                 |
1169| -------- | ----------------------------------------- |
1170| 5400102  | Operate not permit. Return by promise. |
1171| 5400103  | IO error. Return by promise.             |
1172| 5400105  | Service died. Return by promise.          |
1173
1174**Example**
1175
1176```ts
1177import { BusinessError } from '@kit.BasicServicesKit';
1178
1179let avConfig: media.AVRecorderConfig;
1180
1181avRecorder.getAVRecorderConfig().then((config: media.AVRecorderConfig) => {
1182  console.info('Succeeded in getting AVRecorderConfig');
1183  avConfig = config;
1184}).catch((err: Error) => {
1185  let error: BusinessError = err as BusinessError;
1186  console.error('Failed to get AVRecorderConfig and error is: ' + error.message);
1187});
1188```
1189
1190## on('stateChange')<sup>9+</sup>
1191
1192on(type: 'stateChange', callback: OnAVRecorderStateChangeHandler): void
1193
1194Subscribes to AVRecorder state changes. An application can subscribe to only one AVRecorder state change event. When the application initiates multiple subscriptions to this event, the last subscription is applied.
1195
1196**Atomic service API**: This API can be used in atomic services since API version 12.
1197
1198**System capability**: SystemCapability.Multimedia.Media.AVRecorder
1199
1200**Parameters**
1201
1202| Name  | Type    | Mandatory| Description                                                        |
1203| -------- | -------- | ---- | ------------------------------------------------------------ |
1204| type     | string   | Yes  | Event type, which is **'stateChange'** in this case. This event can be triggered by both user operations and the system.|
1205| callback | [OnAVRecorderStateChangeHandler](arkts-apis-media-t.md#onavrecorderstatechangehandler12) | Yes  | Callback invoked when the event is triggered.|
1206
1207**Error codes**
1208
1209For details about the error codes, see [Media Error Codes](errorcode-media.md).
1210
1211| ID| Error Message                         |
1212| -------- | --------------------------------- |
1213| 5400103  | IO error. Return by callback.     |
1214| 5400105  | Service died. Return by callback. |
1215
1216**Example**
1217
1218```ts
1219avRecorder.on('stateChange', async (state: media.AVRecorderState, reason: media.StateChangeReason) => {
1220  console.info('case state has changed, new state is: ' + state + ', and reason is: ' + reason);
1221});
1222```
1223
1224## off('stateChange')<sup>9+</sup>
1225
1226off(type: 'stateChange', callback?: OnAVRecorderStateChangeHandler): void
1227
1228Unsubscribes from AVRecorder state changes.
1229
1230**Atomic service API**: This API can be used in atomic services since API version 12.
1231
1232**System capability**: SystemCapability.Multimedia.Media.AVRecorder
1233
1234**Parameters**
1235
1236| Name| Type  | Mandatory| Description                                                        |
1237| ------ | ------ | ---- | ------------------------------------------------------------ |
1238| type   | string | Yes  | Event type, which is **'stateChange'** in this case. This event can be triggered by both user operations and the system.|
1239| callback | [OnAVRecorderStateChangeHandler](arkts-apis-media-t.md#onavrecorderstatechangehandler12) | No  | Callback invoked when the event is triggered.<br>This parameter is supported since API version 12.|
1240
1241**Example**
1242
1243```ts
1244avRecorder.off('stateChange');
1245```
1246
1247## on('error')<sup>9+</sup>
1248
1249on(type: 'error', callback: ErrorCallback): void
1250
1251Subscribes to AVRecorder errors. This event is used only for error prompt and does not require the user to stop recording control. If the [AVRecorderState](arkts-apis-media-t.md#avrecorderstate9) is also switched to error, call [reset()](#reset9) or [release()][release()](#release9) to exit the recording.
1252
1253An application can subscribe to only one AVRecorder error event. When the application initiates multiple subscriptions to this event, the last subscription is applied.
1254
1255**Atomic service API**: This API can be used in atomic services since API version 12.
1256
1257**System capability**: SystemCapability.Multimedia.Media.AVRecorder
1258
1259**Parameters**
1260
1261| Name  | Type         | Mandatory| Description                                                        |
1262| -------- | ------------- | ---- | ------------------------------------------------------------ |
1263| type     | string        | Yes  | Event type, which is **'error'** in this case.<br>This event is triggered when an error occurs during recording.|
1264| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes  | Callback invoked when the event is triggered.                                      |
1265
1266**Error codes**
1267
1268For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Error Codes](errorcode-media.md).
1269
1270| ID| Error Message                                  |
1271| -------- | ------------------------------------------ |
1272| 201      | Permission denied.     |
1273| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. |
1274| 801      | Capability not supported. |
1275| 5400101  | No memory.             |
1276| 5400102  | Operation not allowed. |
1277| 5400103  | I/O error.             |
1278| 5400104  | Time out.              |
1279| 5400105  | Service died.          |
1280| 5400106  | Unsupported format.    |
1281| 5400107  | Audio interrupted.     |
1282
1283**Example**
1284
1285```ts
1286import { BusinessError } from '@kit.BasicServicesKit';
1287
1288avRecorder.on('error', (err: BusinessError) => {
1289  console.info('case avRecorder.on(error) called, errMessage is ' + err.message);
1290});
1291```
1292
1293## off('error')<sup>9+</sup>
1294
1295off(type: 'error', callback?: ErrorCallback): void
1296
1297Unsubscribes from AVRecorder errors. After the unsubscription, your application can no longer receive AVRecorder errors.
1298
1299**Atomic service API**: This API can be used in atomic services since API version 12.
1300
1301**System capability**: SystemCapability.Multimedia.Media.AVRecorder
1302
1303**Parameters**
1304
1305| Name| Type  | Mandatory| Description                                                        |
1306| ------ | ------ | ---- | ------------------------------------------------------------ |
1307| type   | string | Yes  | Event type, which is **'error'** in this case.<br>This event is triggered when an error occurs during recording.|
1308| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | No  | Callback invoked when the event is triggered.<br>This parameter is supported since API version 12.                  |
1309
1310**Example**
1311
1312```ts
1313avRecorder.off('error');
1314```
1315
1316## on('audioCapturerChange')<sup>11+</sup>
1317
1318on(type: 'audioCapturerChange', callback: Callback<audio.AudioCapturerChangeInfo>): void
1319
1320Subscribes to audio capturer configuration changes. Any configuration change triggers the callback that returns the entire configuration information.
1321
1322When the application initiates multiple subscriptions to this event, the last subscription is applied.
1323
1324**System capability**: SystemCapability.Multimedia.Media.AVRecorder
1325
1326**Parameters**
1327
1328| Name  | Type    | Mandatory| Description                                                        |
1329| -------- | -------- | ---- | ------------------------------------------------------------ |
1330| type     | string   | Yes  |Event type, which is **'audioCapturerChange'** in this case.|
1331| callback | Callback<[audio.AudioCapturerChangeInfo](../apis-audio-kit/arkts-apis-audio-i.md#audiocapturerchangeinfo9)> | Yes| Callback used to return the entire configuration information about the audio capturer.|
1332
1333**Error codes**
1334
1335For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1336
1337| ID| Error Message                                  |
1338| -------- | ------------------------------------------ |
1339| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
1340
1341**Example**
1342
1343```ts
1344import { audio } from '@kit.AudioKit'
1345
1346let capturerChangeInfo: audio.AudioCapturerChangeInfo;
1347
1348avRecorder.on('audioCapturerChange',  (audioCapturerChangeInfo: audio.AudioCapturerChangeInfo) => {
1349  console.info('audioCapturerChange called');
1350  capturerChangeInfo = audioCapturerChangeInfo;
1351});
1352```
1353
1354## off('audioCapturerChange')<sup>11+</sup>
1355
1356off(type: 'audioCapturerChange', callback?: Callback<audio.AudioCapturerChangeInfo>): void
1357
1358Subscribes to audio capturer configuration changes.
1359
1360**System capability**: SystemCapability.Multimedia.Media.AVRecorder
1361
1362**Parameters**
1363
1364| Name| Type  | Mandatory| Description                                                        |
1365| ------ | ------ | ---- | ------------------------------------------------------------ |
1366| type   | string | Yes  | Event type, which is **'audioCapturerChange'** in this case.|
1367| callback | Callback<[audio.AudioCapturerChangeInfo](../apis-audio-kit/arkts-apis-audio-i.md#audiocapturerchangeinfo9)> | No| Callback used to return the entire configuration information about the audio capturer.<br>This parameter is supported since API version 12.|
1368
1369**Example**
1370
1371```ts
1372avRecorder.off('audioCapturerChange');
1373```
1374
1375## on('photoAssetAvailable')<sup>12+</sup>
1376
1377on(type: 'photoAssetAvailable', callback: Callback\<photoAccessHelper.PhotoAsset>): void
1378
1379Subscribes to media asset callback events. When [FileGenerationMode](arkts-apis-media-e.md#filegenerationmode12) is used during media file creation, the [PhotoAsset](../apis-media-library-kit/arkts-apis-photoAccessHelper-PhotoAsset.md) object is called back to the application after the [stop](#stop9) operation is complete.
1380
1381When the application initiates multiple subscriptions to this event, the last subscription is applied.
1382
1383**System capability**: SystemCapability.Multimedia.Media.AVRecorder
1384
1385**Parameters**
1386
1387| Name  | Type    | Mandatory| Description                                                        |
1388| -------- | -------- | ---- | ------------------------------------------------------------ |
1389| type     | string   | Yes  |Event type, which is **'photoAssetAvailable'** in this case. The event is triggered when a photo asset is available.|
1390| callback | Callback<[photoAccessHelper.PhotoAsset](../apis-media-library-kit/arkts-apis-photoAccessHelper-PhotoAsset.md)> | Yes| Callback used to return the PhotoAsset object corresponding to the resource file created by the system.|
1391
1392**Error codes**
1393
1394For details about the error codes, see [Media Error Codes](errorcode-media.md).
1395
1396| ID| Error Message                                  |
1397| -------- | ------------------------------------------ |
1398| 5400103  | IO error. Return by callback.             |
1399| 5400105  | Service died. Return by callback.          |
1400
1401**Example**
1402
1403<!--code_no_check-->
1404```ts
1405import { photoAccessHelper } from '@kit.MediaLibraryKit';
1406import { common } from '@kit.AbilityKit'
1407let photoAsset: photoAccessHelper.PhotoAsset;
1408let context: Context | undefined;
1409constructor(context: Context) {
1410  this.context = context; // this.getUIContext().getHostContext();
1411}
1412
1413// Example: Process the photoAsset callback and save the video.
1414async function saveVideo(asset: photoAccessHelper.PhotoAsset) {
1415  console.info("saveVideo called");
1416  if (!this.context) {
1417    console.error('context is undefined');
1418    return;
1419  }
1420  try {
1421    let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(this.context);
1422    let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset);
1423    assetChangeRequest.saveCameraPhoto();
1424    await phAccessHelper.applyChanges(assetChangeRequest);
1425    console.info('apply saveVideo successfully');
1426  } catch (err) {
1427    console.error(`apply saveVideo failed with error: ${err.code}, ${err.message}`);
1428  }
1429}
1430// Subscribe to the photoAsset event.
1431avRecorder.on('photoAssetAvailable',  (asset: photoAccessHelper.PhotoAsset) => {
1432  console.info('photoAssetAvailable called');
1433  if (asset != undefined) {
1434    photoAsset = asset;
1435    // Process the photoAsset callback.
1436    // Example: this.saveVideo (asset);
1437  } else {
1438    console.error('photoAsset is undefined');
1439  }
1440});
1441```
1442
1443## off('photoAssetAvailable')<sup>12+</sup>
1444
1445off(type: 'photoAssetAvailable', callback?: Callback<photoAccessHelper.PhotoAsset>): void
1446
1447Unsubscribes from media asset callback events.
1448
1449**System capability**: SystemCapability.Multimedia.Media.AVRecorder
1450
1451**Parameters**
1452
1453| Name| Type  | Mandatory| Description                                                        |
1454| ------ | ------ | ---- | ------------------------------------------------------------ |
1455| type   | string | Yes  | Event type, which is **'photoAssetAvailable'** in this case.|
1456| callback | Callback<[photoAccessHelper.PhotoAsset](../apis-media-library-kit/arkts-apis-photoAccessHelper-PhotoAsset.md)> | No| Callback used to return the PhotoAsset object corresponding to the resource file created by the system.|
1457
1458**Example**
1459
1460```ts
1461avRecorder.off('photoAssetAvailable');
1462```
1463