1e41f4b71Sopenharmony_ci# @ohos.multimedia.media (Media)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci> **NOTE**
4e41f4b71Sopenharmony_ci>
5e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciThe multimedia subsystem provides a set of simple and easy-to-use APIs for you to access the system and use media resources.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ciThis subsystem offers the following audio and video services:
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci- Audio and video playback ([AVPlayer](#avplayer9)<sup>9+</sup>)
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci- Audio and video recording [AVRecorder](#avrecorder9)<sup>9+</sup>)
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci- Video transcoding ([AVTranscoder](#avtranscoder12)<sup>12+</sup>)
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci- Obtaining audio and video metadata ([AVMetadataExtractor](#avmetadataextractor11)<sup>11+</sup>)
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci- Obtaining video thumbnails ([AVImageGenerator](#avimagegenerator12)<sup>12+</sup>)
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci## Modules to Import
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci```ts
24e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit';
25e41f4b71Sopenharmony_ci```
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci## media.createAVPlayer<sup>9+</sup>
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_cicreateAVPlayer(callback: AsyncCallback\<AVPlayer>): void
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ciCreates an **AVPlayer** instance. This API uses an asynchronous callback to return the result.
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci> **NOTE**
34e41f4b71Sopenharmony_ci>
35e41f4b71Sopenharmony_ci> You are advised to create a maximum of 16 **AVPlayer** instances for an application in both audio and video playback scenarios.<!--Del-->
36e41f4b71Sopenharmony_ci> The actual number of instances that can be created may be different. It depends on the specifications of the device chip in use. For example, in the case of RK3568, you are advised to create a maximum of 6 **AVPlayer** instances for an application in audio and video playback scenarios.<!--DelEnd-->
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci**Parameters**
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci| Name  | Type                                 | Mandatory| Description                                                        |
45e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ------------------------------------------------------------ |
46e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[AVPlayer](#avplayer9)> | Yes  | Callback used to return the result. If the operation is successful, an **AVPlayer** instance is returned; otherwise, **null** is returned. The instance can be used to play audio and video.|
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci**Error codes**
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci| ID| Error Message                      |
53e41f4b71Sopenharmony_ci| -------- | ------------------------------ |
54e41f4b71Sopenharmony_ci| 5400101  | No memory. Return by callback. |
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci**Example**
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci```ts
59e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_cilet avPlayer: media.AVPlayer;
62e41f4b71Sopenharmony_cimedia.createAVPlayer((error: BusinessError, video: media.AVPlayer) => {
63e41f4b71Sopenharmony_ci  if (video != null) {
64e41f4b71Sopenharmony_ci    avPlayer = video;
65e41f4b71Sopenharmony_ci    console.info('Succeeded in creating AVPlayer');
66e41f4b71Sopenharmony_ci  } else {
67e41f4b71Sopenharmony_ci    console.error(`Failed to create AVPlayer, error message:${error.message}`);
68e41f4b71Sopenharmony_ci  }
69e41f4b71Sopenharmony_ci});
70e41f4b71Sopenharmony_ci```
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci## media.createAVPlayer<sup>9+</sup>
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_cicreateAVPlayer(): Promise\<AVPlayer>
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ciCreates an **AVPlayer** instance. This API uses a promise to return the result.
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci> **NOTE**
79e41f4b71Sopenharmony_ci>
80e41f4b71Sopenharmony_ci> You are advised to create a maximum of 16 **AVPlayer** instances for an application in both audio and video playback scenarios.<!--Del-->
81e41f4b71Sopenharmony_ci> The actual number of instances that can be created may be different. It depends on the specifications of the device chip in use. For example, in the case of RK3568, you are advised to create a maximum of 6 **AVPlayer** instances for an application in audio and video playback scenarios.<!--DelEnd-->
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci**Return value**
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ci| Type                           | Description                                                        |
90e41f4b71Sopenharmony_ci| ------------------------------- | ------------------------------------------------------------ |
91e41f4b71Sopenharmony_ci| Promise\<[AVPlayer](#avplayer9)> | Promise used to return the result. If the operation is successful, an **AVPlayer** instance is returned; otherwise, **null** is returned. The instance can be used to play audio and video.|
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci**Error codes**
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci| ID| Error Message                     |
98e41f4b71Sopenharmony_ci| -------- | ----------------------------- |
99e41f4b71Sopenharmony_ci| 5400101  | No memory. Return by promise. |
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci**Example**
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci```ts
104e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_cilet avPlayer: media.AVPlayer;
107e41f4b71Sopenharmony_cimedia.createAVPlayer().then((video: media.AVPlayer) => {
108e41f4b71Sopenharmony_ci  if (video != null) {
109e41f4b71Sopenharmony_ci    avPlayer = video;
110e41f4b71Sopenharmony_ci    console.info('Succeeded in creating AVPlayer');
111e41f4b71Sopenharmony_ci  } else {
112e41f4b71Sopenharmony_ci    console.error('Failed to create AVPlayer');
113e41f4b71Sopenharmony_ci  }
114e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
115e41f4b71Sopenharmony_ci  console.error(`Failed to create AVPlayer, error message:${error.message}`);
116e41f4b71Sopenharmony_ci});
117e41f4b71Sopenharmony_ci```
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci## media.createAVRecorder<sup>9+</sup>
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_cicreateAVRecorder(callback: AsyncCallback\<AVRecorder>): void
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ciCreates an **AVRecorder** instance. This API uses an asynchronous callback to return the result.
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci> **NOTE**
126e41f4b71Sopenharmony_ci>
127e41f4b71Sopenharmony_ci> - A maximum of 2 **AVRecorder** instances can be created.
128e41f4b71Sopenharmony_ci> - Only one instance can perform audio recording on a device at one time, since all the applications share the audio channel. Any attempt to create the second instance for audio recording fails due to audio channel conflicts.
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci**Parameters**
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci| Name  | Type                                      | Mandatory| Description                                                        |
135e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ |
136e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[AVRecorder](#avrecorder9)> | Yes  | Callback used to return the result. If the operation is successful, an **AVRecorder** instance is returned; otherwise, **null** is returned. The instance can be used to record audio and video.|
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci**Error codes**
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci| ID| Error Message                      |
143e41f4b71Sopenharmony_ci| -------- | ------------------------------ |
144e41f4b71Sopenharmony_ci| 5400101  | No memory. Return by callback. |
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ci**Example**
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci```ts
149e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
150e41f4b71Sopenharmony_cilet avRecorder: media.AVRecorder;
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_cimedia.createAVRecorder((error: BusinessError, recorder: media.AVRecorder) => {
153e41f4b71Sopenharmony_ci  if (recorder != null) {
154e41f4b71Sopenharmony_ci    avRecorder = recorder;
155e41f4b71Sopenharmony_ci    console.info('Succeeded in creating AVRecorder');
156e41f4b71Sopenharmony_ci  } else {
157e41f4b71Sopenharmony_ci    console.error(`Failed to create AVRecorder, error message:${error.message}`);
158e41f4b71Sopenharmony_ci  }
159e41f4b71Sopenharmony_ci});
160e41f4b71Sopenharmony_ci```
161e41f4b71Sopenharmony_ci
162e41f4b71Sopenharmony_ci## media.createAVRecorder<sup>9+</sup>
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_cicreateAVRecorder(): Promise\<AVRecorder>
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ciCreates an **AVRecorder** instance. This API uses a promise to return the result.
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci> **NOTE**
169e41f4b71Sopenharmony_ci>
170e41f4b71Sopenharmony_ci> - A maximum of 2 **AVRecorder** instances can be created.
171e41f4b71Sopenharmony_ci> - Only one instance can perform audio recording on a device at one time, since all the applications share the audio channel. Any attempt to create the second instance for audio recording fails due to audio channel conflicts.
172e41f4b71Sopenharmony_ci
173e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
174e41f4b71Sopenharmony_ci
175e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
176e41f4b71Sopenharmony_ci
177e41f4b71Sopenharmony_ci**Return value**
178e41f4b71Sopenharmony_ci
179e41f4b71Sopenharmony_ci| Type                                | Description                                                        |
180e41f4b71Sopenharmony_ci| ------------------------------------ | ------------------------------------------------------------ |
181e41f4b71Sopenharmony_ci| Promise\<[AVRecorder](#avrecorder9)> | Promise used to return the result. If the operation is successful, an **AVRecorder** instance is returned; otherwise, **null** is returned. The instance can be used to record audio and video.|
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ci**Error codes**
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ci| ID| Error Message                     |
188e41f4b71Sopenharmony_ci| -------- | ----------------------------- |
189e41f4b71Sopenharmony_ci| 5400101  | No memory. Return by promise. |
190e41f4b71Sopenharmony_ci
191e41f4b71Sopenharmony_ci**Example**
192e41f4b71Sopenharmony_ci
193e41f4b71Sopenharmony_ci```ts
194e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_cilet avRecorder: media.AVRecorder;
197e41f4b71Sopenharmony_cimedia.createAVRecorder().then((recorder: media.AVRecorder) => {
198e41f4b71Sopenharmony_ci  if (recorder != null) {
199e41f4b71Sopenharmony_ci    avRecorder = recorder;
200e41f4b71Sopenharmony_ci    console.info('Succeeded in creating AVRecorder');
201e41f4b71Sopenharmony_ci  } else {
202e41f4b71Sopenharmony_ci    console.error('Failed to create AVRecorder');
203e41f4b71Sopenharmony_ci  }
204e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
205e41f4b71Sopenharmony_ci  console.error(`Failed to create AVRecorder, error message:${error.message}`);
206e41f4b71Sopenharmony_ci});
207e41f4b71Sopenharmony_ci```
208e41f4b71Sopenharmony_ci
209e41f4b71Sopenharmony_ci## media.createAVTranscoder<sup>12+</sup>
210e41f4b71Sopenharmony_ci
211e41f4b71Sopenharmony_cicreateAVTranscoder(): Promise\<AVTranscoder>
212e41f4b71Sopenharmony_ci
213e41f4b71Sopenharmony_ciCreates an **AVTranscoder** instance. This API uses a promise to return the result.
214e41f4b71Sopenharmony_ci
215e41f4b71Sopenharmony_ci> **NOTE**
216e41f4b71Sopenharmony_ci
217e41f4b71Sopenharmony_ci> A maximum of 2 **AVTranscoder** instances can be created.
218e41f4b71Sopenharmony_ci
219e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVTranscoder
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci**Return value**
222e41f4b71Sopenharmony_ci
223e41f4b71Sopenharmony_ci| Type                           | Description                                                        |
224e41f4b71Sopenharmony_ci| ------------------------------- | ------------------------------------------------------------ |
225e41f4b71Sopenharmony_ci| Promise\<[AVTranscoder](#avtranscoder12)> | Promise used to return the result. If the operation is successful, an **AVTranscoder** instance is returned; otherwise, **null** is returned. The instance can be used for video transcoding.|
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_ci**Error codes**
228e41f4b71Sopenharmony_ci
229e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
230e41f4b71Sopenharmony_ci
231e41f4b71Sopenharmony_ci| ID| Error Message                     |
232e41f4b71Sopenharmony_ci| -------- | ----------------------------- |
233e41f4b71Sopenharmony_ci| 5400101  | No memory. Return by promise. |
234e41f4b71Sopenharmony_ci
235e41f4b71Sopenharmony_ci**Example**
236e41f4b71Sopenharmony_ci
237e41f4b71Sopenharmony_ci```ts
238e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
239e41f4b71Sopenharmony_ci
240e41f4b71Sopenharmony_cilet avTranscoder: media.AVTranscoder;
241e41f4b71Sopenharmony_cimedia.createAVTranscoder().then((transcoder: media.AVTranscoder) => {
242e41f4b71Sopenharmony_ci  if (transcoder != null) {
243e41f4b71Sopenharmony_ci    avTranscoder = transcoder;
244e41f4b71Sopenharmony_ci    console.info('Succeeded in creating AVTranscoder');
245e41f4b71Sopenharmony_ci  } else {
246e41f4b71Sopenharmony_ci    console.error('Failed to create AVTranscoder');
247e41f4b71Sopenharmony_ci  }
248e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
249e41f4b71Sopenharmony_ci  console.error(`Failed to create AVTranscoder, error message:${error.message}`);
250e41f4b71Sopenharmony_ci});
251e41f4b71Sopenharmony_ci```
252e41f4b71Sopenharmony_ci
253e41f4b71Sopenharmony_ci## media.createAVMetadataExtractor<sup>11+</sup>
254e41f4b71Sopenharmony_ci
255e41f4b71Sopenharmony_cicreateAVMetadataExtractor(callback: AsyncCallback\<AVMetadataExtractor>): void
256e41f4b71Sopenharmony_ci
257e41f4b71Sopenharmony_ciCreates an **AVMetadataExtractor** instance. This API uses an asynchronous callback to return the result.
258e41f4b71Sopenharmony_ci
259e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor
260e41f4b71Sopenharmony_ci
261e41f4b71Sopenharmony_ci**Parameters**
262e41f4b71Sopenharmony_ci
263e41f4b71Sopenharmony_ci| Name  | Type                                 | Mandatory| Description                                                        |
264e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ------------------------------------------------------------ |
265e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[AVMetadataExtractor](#avmetadataextractor11)> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the **AVMetadataExtractor** instance created; otherwise, **err** is an error object.|
266e41f4b71Sopenharmony_ci
267e41f4b71Sopenharmony_ci**Error codes**
268e41f4b71Sopenharmony_ci
269e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
270e41f4b71Sopenharmony_ci
271e41f4b71Sopenharmony_ci| ID| Error Message                      |
272e41f4b71Sopenharmony_ci| -------- | ------------------------------ |
273e41f4b71Sopenharmony_ci| 5400101  | No memory. Returned by callback. |
274e41f4b71Sopenharmony_ci
275e41f4b71Sopenharmony_ci**Example**
276e41f4b71Sopenharmony_ci
277e41f4b71Sopenharmony_ci```ts
278e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
279e41f4b71Sopenharmony_ci
280e41f4b71Sopenharmony_cilet avMetadataExtractor: media.AVMetadataExtractor;
281e41f4b71Sopenharmony_cimedia.createAVMetadataExtractor((error: BusinessError, extractor: media.AVMetadataExtractor) => {
282e41f4b71Sopenharmony_ci  if (extractor != null) {
283e41f4b71Sopenharmony_ci    avMetadataExtractor = extractor;
284e41f4b71Sopenharmony_ci    console.info('Succeeded in creating AVMetadataExtractor');
285e41f4b71Sopenharmony_ci  } else {
286e41f4b71Sopenharmony_ci    console.error(`Failed to create AVMetadataExtractor, error message:${error.message}`);
287e41f4b71Sopenharmony_ci  }
288e41f4b71Sopenharmony_ci});
289e41f4b71Sopenharmony_ci```
290e41f4b71Sopenharmony_ci
291e41f4b71Sopenharmony_ci## media.createAVMetadataExtractor<sup>11+</sup>
292e41f4b71Sopenharmony_ci
293e41f4b71Sopenharmony_cicreateAVMetadataExtractor(): Promise\<AVMetadataExtractor>
294e41f4b71Sopenharmony_ci
295e41f4b71Sopenharmony_ciCreates an **AVMetadataExtractor** instance. This API uses a promise to return the result.
296e41f4b71Sopenharmony_ci
297e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor
298e41f4b71Sopenharmony_ci
299e41f4b71Sopenharmony_ci**Error codes**
300e41f4b71Sopenharmony_ci
301e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
302e41f4b71Sopenharmony_ci
303e41f4b71Sopenharmony_ci| ID| Error Message                      |
304e41f4b71Sopenharmony_ci| -------- | ------------------------------ |
305e41f4b71Sopenharmony_ci| 5400101  | No memory. Returned by promise. |
306e41f4b71Sopenharmony_ci
307e41f4b71Sopenharmony_ci**Example**
308e41f4b71Sopenharmony_ci
309e41f4b71Sopenharmony_ci```ts
310e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
311e41f4b71Sopenharmony_ci
312e41f4b71Sopenharmony_cilet avMetadataExtractor: media.AVMetadataExtractor;
313e41f4b71Sopenharmony_cimedia.createAVMetadataExtractor().then((extractor: media.AVMetadataExtractor) => {
314e41f4b71Sopenharmony_ci  if (extractor != null) {
315e41f4b71Sopenharmony_ci    avMetadataExtractor = extractor;
316e41f4b71Sopenharmony_ci    console.info('Succeeded in creating AVMetadataExtractor');
317e41f4b71Sopenharmony_ci  } else {
318e41f4b71Sopenharmony_ci    console.error(`Failed to create AVMetadataExtractor`);
319e41f4b71Sopenharmony_ci  }
320e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
321e41f4b71Sopenharmony_ci  console.error(`Failed to create AVMetadataExtractor, error message:${error.message}`);
322e41f4b71Sopenharmony_ci});
323e41f4b71Sopenharmony_ci```
324e41f4b71Sopenharmony_ci
325e41f4b71Sopenharmony_ci## media.createSoundPool<sup>10+</sup>
326e41f4b71Sopenharmony_ci
327e41f4b71Sopenharmony_cicreateSoundPool(maxStreams: number, audioRenderInfo: audio.AudioRendererInfo, callback: AsyncCallback\<SoundPool>): void
328e41f4b71Sopenharmony_ci
329e41f4b71Sopenharmony_ciCreates a **SoundPool** instance. This API uses an asynchronous callback to return the result.
330e41f4b71Sopenharmony_ci
331e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.SoundPool
332e41f4b71Sopenharmony_ci
333e41f4b71Sopenharmony_ci**Parameters**
334e41f4b71Sopenharmony_ci
335e41f4b71Sopenharmony_ci| Name  | Type                                           | Mandatory| Description                                                        |
336e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
337e41f4b71Sopenharmony_ci| maxStreams | number | Yes  | Maximum number of streams that can be played by the **SoundPool** instance.|
338e41f4b71Sopenharmony_ci| audioRenderInfo | [audio.AudioRendererInfo](../apis-audio-kit/js-apis-audio.md#audiorendererinfo8)  | Yes  | Audio renderer parameters. When the **usage** parameter in **audioRenderInfo** is set to **STREAM_USAGE_UNKNOWN**, **STREAM_USAGE_MUSIC**, **STREAM_USAGE_MOVIE**, or **STREAM_USAGE_AUDIOBOOK**, the SoundPool uses the audio mixing mode when playing a short sound, without interrupting the playback of other audios.|
339e41f4b71Sopenharmony_ci| callback | AsyncCallback<[SoundPool](js-apis-inner-multimedia-soundPool.md)> | Yes  | Callback 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.|
340e41f4b71Sopenharmony_ci
341e41f4b71Sopenharmony_ci**Error codes**
342e41f4b71Sopenharmony_ci
343e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
344e41f4b71Sopenharmony_ci
345e41f4b71Sopenharmony_ci| ID| Error Message                      |
346e41f4b71Sopenharmony_ci| -------- | ------------------------------ |
347e41f4b71Sopenharmony_ci| 5400101  | No memory. Return by callback. |
348e41f4b71Sopenharmony_ci
349e41f4b71Sopenharmony_ci**Example**
350e41f4b71Sopenharmony_ci
351e41f4b71Sopenharmony_ci```js
352e41f4b71Sopenharmony_ciimport { audio } from '@kit.AudioKit';
353e41f4b71Sopenharmony_ci
354e41f4b71Sopenharmony_cilet soundPool: media.SoundPool;
355e41f4b71Sopenharmony_cilet audioRendererInfo: audio.AudioRendererInfo = {
356e41f4b71Sopenharmony_ci  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
357e41f4b71Sopenharmony_ci  rendererFlags : 0
358e41f4b71Sopenharmony_ci}
359e41f4b71Sopenharmony_ci
360e41f4b71Sopenharmony_cimedia.createSoundPool(5, audioRendererInfo, (error, soundPool_: media.SoundPool) => {
361e41f4b71Sopenharmony_ci  if (error) {
362e41f4b71Sopenharmony_ci    console.error(`Failed to createSoundPool`)
363e41f4b71Sopenharmony_ci    return;
364e41f4b71Sopenharmony_ci  } else {
365e41f4b71Sopenharmony_ci    soundPool = soundPool_;
366e41f4b71Sopenharmony_ci    console.info(`Succeeded in createSoundPool`)
367e41f4b71Sopenharmony_ci  }
368e41f4b71Sopenharmony_ci});
369e41f4b71Sopenharmony_ci```
370e41f4b71Sopenharmony_ci
371e41f4b71Sopenharmony_ci## media.createSoundPool<sup>10+</sup>
372e41f4b71Sopenharmony_ci
373e41f4b71Sopenharmony_cicreateSoundPool(maxStreams: number, audioRenderInfo: audio.AudioRendererInfo): Promise\<SoundPool>
374e41f4b71Sopenharmony_ci
375e41f4b71Sopenharmony_ciCreates a **SoundPool** instance. This API uses a promise to return the result.
376e41f4b71Sopenharmony_ci
377e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.SoundPool
378e41f4b71Sopenharmony_ci
379e41f4b71Sopenharmony_ci**Parameters**
380e41f4b71Sopenharmony_ci
381e41f4b71Sopenharmony_ci| Name  | Type                                           | Mandatory| Description                                                        |
382e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
383e41f4b71Sopenharmony_ci| maxStreams | number | Yes  | Maximum number of streams that can be played by the **SoundPool** instance.|
384e41f4b71Sopenharmony_ci| audioRenderInfo | [audio.AudioRendererInfo](../apis-audio-kit/js-apis-audio.md#audiorendererinfo8)  | Yes  | Audio renderer parameters.|
385e41f4b71Sopenharmony_ci
386e41f4b71Sopenharmony_ci**Return value**
387e41f4b71Sopenharmony_ci
388e41f4b71Sopenharmony_ci| Type                                     | Description                                                        |
389e41f4b71Sopenharmony_ci| ----------------------------------------- | ------------------------------------------------------------ |
390e41f4b71Sopenharmony_ci| 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.|
391e41f4b71Sopenharmony_ci
392e41f4b71Sopenharmony_ci**Error codes**
393e41f4b71Sopenharmony_ci
394e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
395e41f4b71Sopenharmony_ci
396e41f4b71Sopenharmony_ci| ID| Error Message                     |
397e41f4b71Sopenharmony_ci| -------- | ----------------------------- |
398e41f4b71Sopenharmony_ci| 5400101  | No memory. Return by promise. |
399e41f4b71Sopenharmony_ci
400e41f4b71Sopenharmony_ci**Example**
401e41f4b71Sopenharmony_ci
402e41f4b71Sopenharmony_ci```js
403e41f4b71Sopenharmony_ciimport { audio } from '@kit.AudioKit';
404e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
405e41f4b71Sopenharmony_ci
406e41f4b71Sopenharmony_cilet soundPool: media.SoundPool;
407e41f4b71Sopenharmony_cilet audioRendererInfo: audio.AudioRendererInfo = {
408e41f4b71Sopenharmony_ci  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
409e41f4b71Sopenharmony_ci  rendererFlags : 0
410e41f4b71Sopenharmony_ci}
411e41f4b71Sopenharmony_ci
412e41f4b71Sopenharmony_cimedia.createSoundPool(5, audioRendererInfo).then((soundpool_: media.SoundPool) => {
413e41f4b71Sopenharmony_ci  if (soundpool_ != null) {
414e41f4b71Sopenharmony_ci    soundPool = soundpool_;
415e41f4b71Sopenharmony_ci    console.info('Succceeded in creating SoundPool');
416e41f4b71Sopenharmony_ci  } else {
417e41f4b71Sopenharmony_ci    console.error('Failed to create SoundPool');
418e41f4b71Sopenharmony_ci  }
419e41f4b71Sopenharmony_ci}, (error: BusinessError) => {
420e41f4b71Sopenharmony_ci  console.error(`soundpool catchCallback, error message:${error.message}`);
421e41f4b71Sopenharmony_ci});
422e41f4b71Sopenharmony_ci```
423e41f4b71Sopenharmony_ci
424e41f4b71Sopenharmony_ci## media.createAVScreenCaptureRecorder<sup>12+</sup>
425e41f4b71Sopenharmony_ci
426e41f4b71Sopenharmony_cicreateAVScreenCaptureRecorder(): Promise\<AVScreenCaptureRecorder>
427e41f4b71Sopenharmony_ci
428e41f4b71Sopenharmony_ciCreates an **AVScreenCaptureRecorder** instance. This API uses a promise to return the result.
429e41f4b71Sopenharmony_ci
430e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
431e41f4b71Sopenharmony_ci
432e41f4b71Sopenharmony_ci**Return value**
433e41f4b71Sopenharmony_ci
434e41f4b71Sopenharmony_ci| Type                                                        | Description                                                        |
435e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------------------------------ |
436e41f4b71Sopenharmony_ci| Promise\<[AVScreenCaptureRecorder](#avscreencapturerecorder12)> | Promise used to return the result. If the operation is successful, an **AVScreenCaptureRecorder** instance is returned; otherwise, **null** is returned. The instance can be used for screen capture.|
437e41f4b71Sopenharmony_ci
438e41f4b71Sopenharmony_ci**Error codes**
439e41f4b71Sopenharmony_ci
440e41f4b71Sopenharmony_ci| ID| Error Message                      |
441e41f4b71Sopenharmony_ci| -------- | ------------------------------ |
442e41f4b71Sopenharmony_ci| 5400101  | No memory. Return by promise. |
443e41f4b71Sopenharmony_ci
444e41f4b71Sopenharmony_ci**Example**
445e41f4b71Sopenharmony_ci
446e41f4b71Sopenharmony_ci```ts
447e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
448e41f4b71Sopenharmony_ci
449e41f4b71Sopenharmony_cilet avScreenCaptureRecorder: media.AVScreenCaptureRecorder;
450e41f4b71Sopenharmony_cimedia.createAVScreenCaptureRecorder().then((captureRecorder: media.AVScreenCaptureRecorder) => {
451e41f4b71Sopenharmony_ci  if (captureRecorder != null) {
452e41f4b71Sopenharmony_ci    avScreenCaptureRecorder = captureRecorder;
453e41f4b71Sopenharmony_ci    console.info('Succeeded in createAVScreenCaptureRecorder');
454e41f4b71Sopenharmony_ci  } else {
455e41f4b71Sopenharmony_ci    console.error('Failed to createAVScreenCaptureRecorder');
456e41f4b71Sopenharmony_ci  }
457e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
458e41f4b71Sopenharmony_ci  console.error(`createAVScreenCaptureRecorder catchCallback, error message:${error.message}`);
459e41f4b71Sopenharmony_ci});
460e41f4b71Sopenharmony_ci```
461e41f4b71Sopenharmony_ci
462e41f4b71Sopenharmony_ci## AVErrorCode<sup>9+</sup>
463e41f4b71Sopenharmony_ci
464e41f4b71Sopenharmony_ciEnumerates the [media error codes](errorcode-media.md).
465e41f4b71Sopenharmony_ci
466e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
467e41f4b71Sopenharmony_ci
468e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
469e41f4b71Sopenharmony_ci
470e41f4b71Sopenharmony_ci| Name                                 | Value     | Description                                |
471e41f4b71Sopenharmony_ci| :------------------------------------ | ------- | ------------------------------------ |
472e41f4b71Sopenharmony_ci| AVERR_OK                              | 0       | The operation is successful.                      |
473e41f4b71Sopenharmony_ci| AVERR_NO_PERMISSION                   | 201     | No permission to perform the operation.              |
474e41f4b71Sopenharmony_ci| AVERR_INVALID_PARAMETER               | 401     | Invalid input parameter.                  |
475e41f4b71Sopenharmony_ci| AVERR_UNSUPPORT_CAPABILITY            | 801     | Unsupported API.       |
476e41f4b71Sopenharmony_ci| AVERR_NO_MEMORY                       | 5400101 | The system memory is insufficient or the number of services reaches the upper limit.|
477e41f4b71Sopenharmony_ci| AVERR_OPERATE_NOT_PERMIT              | 5400102 | The operation is not allowed in the current state or you do not have the permission to perform the operation.|
478e41f4b71Sopenharmony_ci| AVERR_IO                              | 5400103 | The data stream is abnormal.                |
479e41f4b71Sopenharmony_ci| AVERR_TIMEOUT                         | 5400104 | The system or network response times out.            |
480e41f4b71Sopenharmony_ci| AVERR_SERVICE_DIED                    | 5400105 | The service process is dead.                  |
481e41f4b71Sopenharmony_ci| AVERR_UNSUPPORT_FORMAT                | 5400106 | The format of the media asset is not supported.      |
482e41f4b71Sopenharmony_ci| AVERR_AUDIO_INTERRUPTED<sup>11+</sup> | 5400107 | The audio focus is interrupted.                  |
483e41f4b71Sopenharmony_ci
484e41f4b71Sopenharmony_ci## MediaType<sup>8+</sup>
485e41f4b71Sopenharmony_ci
486e41f4b71Sopenharmony_ciEnumerates the media types.
487e41f4b71Sopenharmony_ci
488e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
489e41f4b71Sopenharmony_ci
490e41f4b71Sopenharmony_ci| Name          | Value                   | Description                |
491e41f4b71Sopenharmony_ci| -------------- | --------------------- | ------------------- |
492e41f4b71Sopenharmony_ci| MEDIA_TYPE_AUD | 0                     | Media.<br> **Atomic service API**: This API can be used in atomic services since API version 11.          |
493e41f4b71Sopenharmony_ci| MEDIA_TYPE_VID | 1                     | Video.<br> **Atomic service API**: This API can be used in atomic services since API version 11.         |
494e41f4b71Sopenharmony_ci| MEDIA_TYPE_SUBTITLE<sup>12+</sup> | 2    | Subtitle.<br> **Atomic service API**: This API can be used in atomic services since API version 12.|
495e41f4b71Sopenharmony_ci
496e41f4b71Sopenharmony_ci## CodecMimeType<sup>8+</sup>
497e41f4b71Sopenharmony_ci
498e41f4b71Sopenharmony_ciEnumerates the codec MIME types.
499e41f4b71Sopenharmony_ci
500e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
501e41f4b71Sopenharmony_ci
502e41f4b71Sopenharmony_ci| Name        | Value                   | Description                    |
503e41f4b71Sopenharmony_ci| ------------ | --------------------- | ------------------------ |
504e41f4b71Sopenharmony_ci| VIDEO_H263   | 'video/h263'          | Video in H.263 format.     |
505e41f4b71Sopenharmony_ci| VIDEO_AVC    | 'video/avc'           | Video in AVC format.      |
506e41f4b71Sopenharmony_ci| VIDEO_MPEG2  | 'video/mpeg2'         | Video in MPEG-2 format.    |
507e41f4b71Sopenharmony_ci| VIDEO_MPEG4  | 'video/mp4v-es'         | Video in MPEG-4 format.    |
508e41f4b71Sopenharmony_ci| VIDEO_VP8    | 'video/x-vnd.on2.vp8' | Video in VP8 format.      |
509e41f4b71Sopenharmony_ci| VIDEO_HEVC<sup>11+</sup>   | 'video/hevc'          | Video in H.265 format.|
510e41f4b71Sopenharmony_ci| AUDIO_AAC    | 'audio/mp4a-latm'     | Audio in MP4A-LATM format.<br> **Atomic service API**: This API can be used in atomic services since API version 12.|
511e41f4b71Sopenharmony_ci| AUDIO_VORBIS | 'audio/vorbis'        | Audio in Vorbis format.   |
512e41f4b71Sopenharmony_ci| AUDIO_FLAC   | 'audio/flac'          | Audio in FLAC format.     |
513e41f4b71Sopenharmony_ci| AUDIO_MP3<sup>12+</sup>   | 'audio/mpeg'          | Audio in MPEG format.     |
514e41f4b71Sopenharmony_ci| AUDIO_G711MU<sup>12+</sup>   | 'audio/g711mu'     | Audio in G.711 μ-law format.|
515e41f4b71Sopenharmony_ci
516e41f4b71Sopenharmony_ci## MediaDescriptionKey<sup>8+</sup>
517e41f4b71Sopenharmony_ci
518e41f4b71Sopenharmony_ciEnumerates the media description keys.
519e41f4b71Sopenharmony_ci
520e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
521e41f4b71Sopenharmony_ci
522e41f4b71Sopenharmony_ci| Name                    | Value             | Description                                                        |
523e41f4b71Sopenharmony_ci| ------------------------ | --------------- | ------------------------------------------------------------ |
524e41f4b71Sopenharmony_ci| MD_KEY_TRACK_INDEX       | 'track_index'   | Track index, which is a number.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
525e41f4b71Sopenharmony_ci| MD_KEY_TRACK_TYPE        | 'track_type'    | Track type, which is a number. For details, see [MediaType](#mediatype8).<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
526e41f4b71Sopenharmony_ci| MD_KEY_CODEC_MIME        | 'codec_mime'    | Codec MIME type, which is a string.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
527e41f4b71Sopenharmony_ci| MD_KEY_DURATION          | 'duration'      | Media duration, which is a number, in units of ms.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
528e41f4b71Sopenharmony_ci| MD_KEY_BITRATE           | 'bitrate'       | Bit rate, which is a number, in units of bit/s.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
529e41f4b71Sopenharmony_ci| MD_KEY_WIDTH             | 'width'         | Video width, which is a number, in units of pixel.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
530e41f4b71Sopenharmony_ci| MD_KEY_HEIGHT            | 'height'        | Video height, which is a number, in units of pixel.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
531e41f4b71Sopenharmony_ci| MD_KEY_FRAME_RATE        | 'frame_rate'    | Video frame rate, which is a number, measured in frames per 100 seconds.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
532e41f4b71Sopenharmony_ci| MD_KEY_AUD_CHANNEL_COUNT | 'channel_count' | Number of audio channels, which is a number.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
533e41f4b71Sopenharmony_ci| MD_KEY_AUD_SAMPLE_RATE   | 'sample_rate'   | Sampling rate, which is a number, in units of Hz.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
534e41f4b71Sopenharmony_ci| MD_KEY_AUD_SAMPLE_DEPTH<sup>12+</sup>  | 'sample_depth'  | Bit depth, which is a number, in units of bits.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
535e41f4b71Sopenharmony_ci| MD_KEY_TRACK_NAME<sup>12+</sup>  | 'track_name'  | Track name, which is a string.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
536e41f4b71Sopenharmony_ci| MD_KEY_HDR_TYPE<sup>12+</sup>  | 'hdr_type'  | Codec track type, which is a string.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
537e41f4b71Sopenharmony_ci
538e41f4b71Sopenharmony_ci## PlaybackInfoKey<sup>12+</sup>
539e41f4b71Sopenharmony_ci
540e41f4b71Sopenharmony_ciEnumerates the playback description keys.
541e41f4b71Sopenharmony_ci
542e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
543e41f4b71Sopenharmony_ci
544e41f4b71Sopenharmony_ci| Name                    | Value             | Description                                                        |
545e41f4b71Sopenharmony_ci| ------------------------ | --------------- | ------------------------------------------------------------ |
546e41f4b71Sopenharmony_ci| SERVER_IP_ADDRESS        | 'server_ip_address'    | IP address of the server, which is a string. |
547e41f4b71Sopenharmony_ci| AVG_DOWNLOAD_RATE        | 'average_download_rate'| Average download rate, which is a number, in units of bit/s.|
548e41f4b71Sopenharmony_ci| DOWNLOAD_RATE            | 'download_rate'        | Download rate in one second, which is a number, in units of bit/s.|
549e41f4b71Sopenharmony_ci| IS_DOWNLOADING           | 'is_downloading'       | Download status, which is a number. The value **1** means that the downloaded is in progress, and **0** means that the download is complete.|
550e41f4b71Sopenharmony_ci| BUFFER_DURATION          | 'buffer_duration'      | Duration that the cached data can be played, which is a number, in units of seconds.|
551e41f4b71Sopenharmony_ci
552e41f4b71Sopenharmony_ci## BufferingInfoType<sup>8+</sup>
553e41f4b71Sopenharmony_ci
554e41f4b71Sopenharmony_ciEnumerates the buffering event types.
555e41f4b71Sopenharmony_ci
556e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
557e41f4b71Sopenharmony_ci
558e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
559e41f4b71Sopenharmony_ci
560e41f4b71Sopenharmony_ci| Name             | Value  | Description                            |
561e41f4b71Sopenharmony_ci| ----------------- | ---- | -------------------------------- |
562e41f4b71Sopenharmony_ci| BUFFERING_START   | 1    | Buffering starts.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                  |
563e41f4b71Sopenharmony_ci| BUFFERING_END     | 2    | Buffering ends.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                  |
564e41f4b71Sopenharmony_ci| BUFFERING_PERCENT | 3    | Buffering progress, in percent.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                |
565e41f4b71Sopenharmony_ci| CACHED_DURATION   | 4    | Cache duration, in ms.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
566e41f4b71Sopenharmony_ci
567e41f4b71Sopenharmony_ci## StateChangeReason<sup>9+</sup>
568e41f4b71Sopenharmony_ci
569e41f4b71Sopenharmony_ciEnumerates the reasons for the state transition of the **AVPlayer** or **AVRecorder** instance. The enum value is reported together with **state**.
570e41f4b71Sopenharmony_ci
571e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
572e41f4b71Sopenharmony_ci
573e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
574e41f4b71Sopenharmony_ci
575e41f4b71Sopenharmony_ci| Name      | Value  | Description                                                        |
576e41f4b71Sopenharmony_ci| ---------- | ---- | ------------------------------------------------------------ |
577e41f4b71Sopenharmony_ci| USER       | 1    | State transition triggered by user behavior. It happens when a user or the client calls an API.|
578e41f4b71Sopenharmony_ci| BACKGROUND | 2    | State transition caused by background system behavior. For example, if an application does not have the permission of Media Controller, the application is forcibly suspended or stopped by the system when it switches to the background.|
579e41f4b71Sopenharmony_ci
580e41f4b71Sopenharmony_ci## AVPlayer<sup>9+</sup>
581e41f4b71Sopenharmony_ci
582e41f4b71Sopenharmony_ciA playback management class that provides APIs to manage and play media assets. Before calling any API in **AVPlayer**, you must use [createAVPlayer()](#mediacreateavplayer9) to create an **AVPlayer** instance.
583e41f4b71Sopenharmony_ci
584e41f4b71Sopenharmony_ciFor details about the audio and video playback demo, see [Audio Playback](../../media/media/using-avplayer-for-playback.md) and [Video Playback](../../media/media/video-playback.md).
585e41f4b71Sopenharmony_ci
586e41f4b71Sopenharmony_ci> **NOTE**
587e41f4b71Sopenharmony_ci>
588e41f4b71Sopenharmony_ci> When using the **AVPlayer** instance, you are advised to register the following callbacks to proactively obtain status changes:
589e41f4b71Sopenharmony_ci> - [on('stateChange')](#onstatechange9): listens for AVPlayer state changes.
590e41f4b71Sopenharmony_ci> - [on('error')](#onerror9): listens for error events.
591e41f4b71Sopenharmony_ci
592e41f4b71Sopenharmony_ci### Attributes
593e41f4b71Sopenharmony_ci
594e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
595e41f4b71Sopenharmony_ci
596e41f4b71Sopenharmony_ci| Name                                               | Type                                                        | Read-Only| Optional| Description                                                        |
597e41f4b71Sopenharmony_ci| --------------------------------------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
598e41f4b71Sopenharmony_ci| url<sup>9+</sup>                                    | string                                                       | No  | Yes  | URL of the media asset. It can be set only when the AVPlayer is in the idle state. <br>The video formats MP4, MPEG-TS, and MKV are supported.<br>The audio formats M4A, AAC, MP3, OGG, WAV, FLAC, and AMR are supported.<br>**Example of supported URLs**:<br>1. FD: fd://xx<br>![](figures/en-us_image_url.png)<br>2. HTTP: http\://xx<br>3. HTTPS: https\://xx<br>4. HLS: http\://xx or https\://xx<br>**NOTE**<br>- To set a network playback path, you must declare the [ohos.permission.INTERNET](../../security/AccessToken/permissions-for-all.md#ohospermissioninternet) permission by following the instructions provided in [Declaring Permissions](../../security/AccessToken/declare-permissions.md). The error code [201](../errorcode-universal.md) may be reported.<br>- WebM is no longer supported since API version 11.<br> - After the resource handle (FD) is transferred to an **AVPlayer** instance, do not use the resource handle to perform other read and write operations, including but not limited to transferring this handle to other **AVPlayer**, **AVMetadataExtractor**, **AVImageGenerator**, or **AVTranscoder** instance. Competition occurs when multiple AVPlayers use the same resource handle to read and write files at the same time, resulting in errors in obtaining data.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
599e41f4b71Sopenharmony_ci| fdSrc<sup>9+</sup>                                  | [AVFileDescriptor](#avfiledescriptor9)                       | No  | Yes  | FD of the media asset. It can be set only when the AVPlayer is in the idle state.<br>This attribute is required when media assets of an application are continuously stored in a file.<br>The video formats MP4, MPEG-TS, and MKV are supported.<br>The audio formats M4A, AAC, MP3, OGG, WAV, FLAC, and AMR are supported.<br>**Example:**<br>Assume that a media file that stores continuous assets consists of the following:<br>Video 1 (address offset: 0, byte length: 100)<br>Video 2 (address offset: 101; byte length: 50)<br>Video 3 (address offset: 151, byte length: 150)<br>1. To play video 1: AVFileDescriptor {fd = resource handle; offset = 0; length = 100; }<br>2. To play video 2: AVFileDescriptor {fd = resource handle; offset = 101; length = 50; }<br>3. To play video 3: AVFileDescriptor {fd = resource handle; offset = 151; length = 150; }<br>To play an independent media file, use **src=fd://xx**.<br>**NOTE**<br>WebM is no longer supported since API version 11.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
600e41f4b71Sopenharmony_ci| dataSrc<sup>10+</sup>                               | [AVDataSrcDescriptor](#avdatasrcdescriptor10)                | No  | Yes  | Descriptor of a streaming media asset. It can be set only when the AVPlayer is in the idle state.<br>Use scenario: An application starts playing a media file while the file is still being downloaded from the remote to the local host.<br>The video formats MP4, MPEG-TS, and MKV are supported.<br>The audio formats M4A, AAC, MP3, OGG, WAV, FLAC, and AMR are supported.<br>**Example:**<br>A user is obtaining an audio and video file from a remote server and wants to play the downloaded file content. To implement this scenario, do as follows:<br>1. Obtain the total file size, in bytes. If the total size cannot be obtained, set **fileSize** to **-1**.<br>2. Implement the **func** callback to fill in data. If **fileSize** is **-1**, the format of **func** is **func(buffer: ArrayBuffer, length: number)**, and the AVPlayer obtains data in sequence; otherwise, the format is **func(buffer: ArrayBuffer, length: number, pos: number)**, and the AVPlayer seeks and obtains data in the required positions.<br>3. Set **AVDataSrcDescriptor {fileSize = size, callback = func}**.<br>**Notes:**<br>If the media file to play is in MP4/M4A format, ensure that the **moov** field (specifying the media information) is before the **mdat** field (specifying the media data) or the fields before the **moov** field is less than 10 MB. Otherwise, the parsing fails and the media file cannot be played.<br>**NOTE**<br>WebM is no longer supported since API version 11.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
601e41f4b71Sopenharmony_ci| surfaceId<sup>9+</sup>                              | string                                                       | No  | Yes  | Video window ID. By default, there is no video window.<br>This parameter can be set when the AVPlayer is in the initialized state.<br>It can be set again when the AVPlayer is in the prepared, playing, paused, completed, or stopped state, in the prerequisite that the video window ID has been set in the initialized state. After the new setting is performed, the video is played in the new window.<br>It is used to render the window for video playback and therefore is not required in audio-only playback scenarios.<br>**Example:**<br>[Create a surface ID through XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md#getxcomponentsurfaceid).<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
602e41f4b71Sopenharmony_ci| loop<sup>9+</sup>                                   | boolean                                                      | No  | No  | Whether to loop playback. The value **true** means to loop playback, and **false** (default) means the opposite. It is a dynamic attribute<br>and can be set only when the AVPlayer is in the prepared, playing, paused, or completed state.<br>This setting is not supported in live mode.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
603e41f4b71Sopenharmony_ci| videoScaleType<sup>9+</sup>                         | [VideoScaleType](#videoscaletype9)                           | No  | Yes  | Video scale type. The default value is **VIDEO_SCALE_TYPE_FIT**. It is a dynamic attribute<br>and can be set only when the AVPlayer is in the prepared, playing, paused, or completed state.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
604e41f4b71Sopenharmony_ci| audioInterruptMode<sup>9+</sup>                     | [audio.InterruptMode](../apis-audio-kit/js-apis-audio.md#interruptmode9)       | No  | Yes  | Audio interruption mode. The default value is **SHARE_MODE**. It is a dynamic attribute<br>and can be set only when the AVPlayer is in the prepared, playing, paused, or completed state.<br>To take effect, this attribute must be set before [play()](#play9) is called for the first time.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
605e41f4b71Sopenharmony_ci| audioRendererInfo<sup>10+</sup>                     | [audio.AudioRendererInfo](../apis-audio-kit/js-apis-audio.md#audiorendererinfo8) | No  | Yes  | Audio renderer information. If the media source contains videos, the default value of **usage** is **STREAM_USAGE_MOVIE**. Otherwise, the default value of **usage** is **STREAM_USAGE_MUSIC**. The default value of **rendererFlags** is 0. If the default value of **usage** does not meet the requirements, configure [audio.AudioRendererInfo](../apis-audio-kit/js-apis-audio.md#audiorendererinfo8).<br>This parameter can be set only when the AVPlayer is in the initialized state.<br>To take effect, this attribute must be set before [prepare()](#prepare9) is called for the first time.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
606e41f4b71Sopenharmony_ci| audioEffectMode<sup>10+</sup>                       | [audio.AudioEffectMode](../apis-audio-kit/js-apis-audio.md#audioeffectmode10)  | No  | Yes  | Audio effect mode. The audio effect mode is a dynamic attribute and is restored to the default value **EFFECT_DEFAULT** when **usage** of **audioRendererInfo** is changed. It can be set only when the AVPlayer is in the prepared, playing, paused, or completed state.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
607e41f4b71Sopenharmony_ci| state<sup>9+</sup>                                  | [AVPlayerState](#avplayerstate9)                             | Yes  | No  | AVPlayer state. It can be used as a query parameter when the AVPlayer is in any state.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                 |
608e41f4b71Sopenharmony_ci| currentTime<sup>9+</sup>                            | number                                                       | Yes  | No  | Current video playback position, in ms. It can be used as a query parameter when the AVPlayer is in the prepared, playing, paused, or completed state.<br>The value **-1** indicates an invalid value.<br>In live mode, **-1** is returned by default.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
609e41f4b71Sopenharmony_ci| duration<sup>9+</sup> | number                                                       | Yes  | No  | Video duration, in ms. It can be used as a query parameter when the AVPlayer is in the prepared, playing, paused, or completed state.<br>The value **-1** indicates an invalid value.<br>In live mode, **-1** is returned by default.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
610e41f4b71Sopenharmony_ci| width<sup>9+</sup>                                  | number                                                       | Yes  | No  | Video width, in px. It can be used as a query parameter when the AVPlayer is in the prepared, playing, paused, or completed state.<br>The value **0** indicates an invalid value.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
611e41f4b71Sopenharmony_ci| height<sup>9+</sup>                                 | number                                                       | Yes  | No  | Video height, in px. It can be used as a query parameter when the AVPlayer is in the prepared, playing, paused, or completed state.<br>The value **0** indicates an invalid value.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
612e41f4b71Sopenharmony_ci
613e41f4b71Sopenharmony_ci### on('stateChange')<sup>9+</sup>
614e41f4b71Sopenharmony_ci
615e41f4b71Sopenharmony_cion(type: 'stateChange', callback: OnAVPlayerStateChangeHandle): void
616e41f4b71Sopenharmony_ci
617e41f4b71Sopenharmony_ciSubscribes to AVPlayer state changes.
618e41f4b71Sopenharmony_ci
619e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
620e41f4b71Sopenharmony_ci
621e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
622e41f4b71Sopenharmony_ci
623e41f4b71Sopenharmony_ci**Parameters**
624e41f4b71Sopenharmony_ci
625e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
626e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
627e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'stateChange'** in this case. This event can be triggered by both user operations and the system.|
628e41f4b71Sopenharmony_ci| callback | [OnAVPlayerStateChangeHandle](#onavplayerstatechangehandle12) | Yes  | Callback invoked when the event is triggered.|
629e41f4b71Sopenharmony_ci
630e41f4b71Sopenharmony_ci**Example**
631e41f4b71Sopenharmony_ci
632e41f4b71Sopenharmony_ci```ts
633e41f4b71Sopenharmony_ciavPlayer.on('stateChange', async (state: string, reason: media.StateChangeReason) => {
634e41f4b71Sopenharmony_ci  switch (state) {
635e41f4b71Sopenharmony_ci    case 'idle':
636e41f4b71Sopenharmony_ci      console.info('state idle called');
637e41f4b71Sopenharmony_ci      break;
638e41f4b71Sopenharmony_ci    case 'initialized':
639e41f4b71Sopenharmony_ci      console.info('initialized prepared called');
640e41f4b71Sopenharmony_ci      break;
641e41f4b71Sopenharmony_ci    case 'prepared':
642e41f4b71Sopenharmony_ci      console.info('state prepared called');
643e41f4b71Sopenharmony_ci      break;
644e41f4b71Sopenharmony_ci    case 'playing':
645e41f4b71Sopenharmony_ci      console.info('state playing called');
646e41f4b71Sopenharmony_ci      break;
647e41f4b71Sopenharmony_ci    case 'paused':
648e41f4b71Sopenharmony_ci      console.info('state paused called');
649e41f4b71Sopenharmony_ci      break;
650e41f4b71Sopenharmony_ci    case 'completed':
651e41f4b71Sopenharmony_ci      console.info('state completed called');
652e41f4b71Sopenharmony_ci      break;
653e41f4b71Sopenharmony_ci    case 'stopped':
654e41f4b71Sopenharmony_ci      console.info('state stopped called');
655e41f4b71Sopenharmony_ci      break;
656e41f4b71Sopenharmony_ci    case 'released':
657e41f4b71Sopenharmony_ci      console.info('state released called');
658e41f4b71Sopenharmony_ci      break;
659e41f4b71Sopenharmony_ci    case 'error':
660e41f4b71Sopenharmony_ci      console.info('state error called');
661e41f4b71Sopenharmony_ci      break;
662e41f4b71Sopenharmony_ci    default:
663e41f4b71Sopenharmony_ci      console.info('unknown state :' + state);
664e41f4b71Sopenharmony_ci      break;
665e41f4b71Sopenharmony_ci  }
666e41f4b71Sopenharmony_ci})
667e41f4b71Sopenharmony_ci```
668e41f4b71Sopenharmony_ci
669e41f4b71Sopenharmony_ci### off('stateChange')<sup>9+</sup>
670e41f4b71Sopenharmony_ci
671e41f4b71Sopenharmony_cioff(type: 'stateChange', callback?: OnAVPlayerStateChangeHandle): void
672e41f4b71Sopenharmony_ci
673e41f4b71Sopenharmony_ciUnsubscribes from AVPlayer state changes.
674e41f4b71Sopenharmony_ci
675e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
676e41f4b71Sopenharmony_ci
677e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
678e41f4b71Sopenharmony_ci
679e41f4b71Sopenharmony_ci**Parameters**
680e41f4b71Sopenharmony_ci
681e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                 |
682e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------------------------------------- |
683e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'stateChange'** in this case.|
684e41f4b71Sopenharmony_ci| callback   | [OnAVPlayerStateChangeHandle](#onavplayerstatechangehandle12) | No  | Callback invoked when the event is triggered.<br>This parameter is supported since API version 12.|
685e41f4b71Sopenharmony_ci
686e41f4b71Sopenharmony_ci**Example**
687e41f4b71Sopenharmony_ci
688e41f4b71Sopenharmony_ci```ts
689e41f4b71Sopenharmony_ciavPlayer.off('stateChange')
690e41f4b71Sopenharmony_ci```
691e41f4b71Sopenharmony_ci
692e41f4b71Sopenharmony_ci### on('error')<sup>9+</sup>
693e41f4b71Sopenharmony_ci
694e41f4b71Sopenharmony_cion(type: 'error', callback: ErrorCallback): void
695e41f4b71Sopenharmony_ci
696e41f4b71Sopenharmony_ciSubscribes to AVPlayer errors. This event is used only for error prompt and does not require the user to stop playback control. If [AVPlayerState](#avplayerstate9) is also switched to error, call [reset()](#reset9) or [release()](#release9) to exit the playback.
697e41f4b71Sopenharmony_ci
698e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
699e41f4b71Sopenharmony_ci
700e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
701e41f4b71Sopenharmony_ci
702e41f4b71Sopenharmony_ci**Parameters**
703e41f4b71Sopenharmony_ci
704e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
705e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
706e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'error'** in this case. This event can be triggered by both user operations and the system.|
707e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes  | Callback used to return the error code ID and error message.|
708e41f4b71Sopenharmony_ci
709e41f4b71Sopenharmony_ci**Error codes**
710e41f4b71Sopenharmony_ci
711e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
712e41f4b71Sopenharmony_ci
713e41f4b71Sopenharmony_ci| ID| Error Message             |
714e41f4b71Sopenharmony_ci| -------- | --------------------- |
715e41f4b71Sopenharmony_ci| 201      | Permission denied     |
716e41f4b71Sopenharmony_ci| 401      | The parameter check failed. |
717e41f4b71Sopenharmony_ci| 801      | Capability not supported. |
718e41f4b71Sopenharmony_ci| 5400101  | No memory. |
719e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed.|
720e41f4b71Sopenharmony_ci| 5400103  | I/O error             |
721e41f4b71Sopenharmony_ci| 5400104  | Time out              |
722e41f4b71Sopenharmony_ci| 5400105  | Service died.         |
723e41f4b71Sopenharmony_ci| 5400106  | Unsupport format.     |
724e41f4b71Sopenharmony_ci
725e41f4b71Sopenharmony_ci**Example**
726e41f4b71Sopenharmony_ci
727e41f4b71Sopenharmony_ci```ts
728e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
729e41f4b71Sopenharmony_ci
730e41f4b71Sopenharmony_ciavPlayer.on('error', (error: BusinessError) => {
731e41f4b71Sopenharmony_ci  console.info('error happened,and error message is :' + error.message)
732e41f4b71Sopenharmony_ci  console.info('error happened,and error code is :' + error.code)
733e41f4b71Sopenharmony_ci})
734e41f4b71Sopenharmony_ci```
735e41f4b71Sopenharmony_ci
736e41f4b71Sopenharmony_ci### off('error')<sup>9+</sup>
737e41f4b71Sopenharmony_ci
738e41f4b71Sopenharmony_cioff(type: 'error', callback?: ErrorCallback): void
739e41f4b71Sopenharmony_ci
740e41f4b71Sopenharmony_ciUnsubscribes from AVPlayer errors.
741e41f4b71Sopenharmony_ci
742e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
743e41f4b71Sopenharmony_ci
744e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
745e41f4b71Sopenharmony_ci
746e41f4b71Sopenharmony_ci**Parameters**
747e41f4b71Sopenharmony_ci
748e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                     |
749e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------------------------- |
750e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'error'** in this case.|
751e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | No  | Callback used to return the error code ID and error message.<br>This parameter is supported since API version 12.|
752e41f4b71Sopenharmony_ci
753e41f4b71Sopenharmony_ci**Example**
754e41f4b71Sopenharmony_ci
755e41f4b71Sopenharmony_ci```ts
756e41f4b71Sopenharmony_ciavPlayer.off('error')
757e41f4b71Sopenharmony_ci```
758e41f4b71Sopenharmony_ci
759e41f4b71Sopenharmony_ci### setMediaSource<sup>12+</sup>
760e41f4b71Sopenharmony_ci
761e41f4b71Sopenharmony_cisetMediaSource(src:MediaSource, strategy?: PlaybackStrategy): Promise\<void>
762e41f4b71Sopenharmony_ci
763e41f4b71Sopenharmony_ciSets a source of streaming media that can be pre-downloaded, downloads the media data, and temporarily stores the data in the memory. For details about how to use the API, see [Video Playback](../../media/media/video-playback.md) This API uses a promise to return the result.
764e41f4b71Sopenharmony_ci
765e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
766e41f4b71Sopenharmony_ci
767e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
768e41f4b71Sopenharmony_ci
769e41f4b71Sopenharmony_ci**Parameters**
770e41f4b71Sopenharmony_ci
771e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                |
772e41f4b71Sopenharmony_ci| -------- | -------- | ---- | -------------------- |
773e41f4b71Sopenharmony_ci| src | [MediaSource](#mediasource12) | Yes  | Source of the streaming media to pre-download.|
774e41f4b71Sopenharmony_ci| strategy | [PlaybackStrategy](#playbackstrategy12) | No  | strategy for playing the pre-downloaded streaming media.|
775e41f4b71Sopenharmony_ci
776e41f4b71Sopenharmony_ci**Return value**
777e41f4b71Sopenharmony_ci
778e41f4b71Sopenharmony_ci| Type          | Description                                      |
779e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------ |
780e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
781e41f4b71Sopenharmony_ci
782e41f4b71Sopenharmony_ci**Error codes**
783e41f4b71Sopenharmony_ci
784e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
785e41f4b71Sopenharmony_ci
786e41f4b71Sopenharmony_ci| ID| Error Message                                 |
787e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
788e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
789e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
790e41f4b71Sopenharmony_ci
791e41f4b71Sopenharmony_ci**Example**
792e41f4b71Sopenharmony_ci
793e41f4b71Sopenharmony_ci```ts
794e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit';
795e41f4b71Sopenharmony_ci
796e41f4b71Sopenharmony_cilet player = await media.createAVPlayer();
797e41f4b71Sopenharmony_cilet headers: Record<string, string> = {"User-Agent" : "User-Agent-Value"};
798e41f4b71Sopenharmony_cilet mediaSource : media.MediaSource = media.createMediaSourceWithUrl("http://xxx",  headers);
799e41f4b71Sopenharmony_cilet playStrategy : media.PlaybackStrategy = {preferredWidth: 1, preferredHeight: 2, preferredBufferDuration: 3, preferredHdr: false};
800e41f4b71Sopenharmony_ciplayer.setMediaSource(mediaSource, playStrategy);
801e41f4b71Sopenharmony_ci```
802e41f4b71Sopenharmony_ci
803e41f4b71Sopenharmony_ci### setPlaybackStrategy<sup>12+</sup>
804e41f4b71Sopenharmony_ci
805e41f4b71Sopenharmony_cisetPlaybackStrategy(strategy: PlaybackStrategy): Promise\<void>
806e41f4b71Sopenharmony_ci
807e41f4b71Sopenharmony_ciSets a playback strategy. This API can be called only when the AVPlayer is in the initialized state.
808e41f4b71Sopenharmony_ci
809e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
810e41f4b71Sopenharmony_ci
811e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
812e41f4b71Sopenharmony_ci
813e41f4b71Sopenharmony_ci**Parameters**
814e41f4b71Sopenharmony_ci
815e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                |
816e41f4b71Sopenharmony_ci| -------- | -------- | ---- | -------------------- |
817e41f4b71Sopenharmony_ci| strategy | [PlaybackStrategy](#playbackstrategy12) | Yes  | Playback strategy.|
818e41f4b71Sopenharmony_ci
819e41f4b71Sopenharmony_ci**Return value**
820e41f4b71Sopenharmony_ci
821e41f4b71Sopenharmony_ci| Type          | Description                                 |
822e41f4b71Sopenharmony_ci| -------------- | ------------------------------------ |
823e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
824e41f4b71Sopenharmony_ci
825e41f4b71Sopenharmony_ci**Error codes**
826e41f4b71Sopenharmony_ci
827e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
828e41f4b71Sopenharmony_ci
829e41f4b71Sopenharmony_ci| ID| Error Message                                 |
830e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
831e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Incorrect parameter types. 2. Parameter verification failed. |
832e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
833e41f4b71Sopenharmony_ci
834e41f4b71Sopenharmony_ci**Example**
835e41f4b71Sopenharmony_ci
836e41f4b71Sopenharmony_ci```ts
837e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit';
838e41f4b71Sopenharmony_ci
839e41f4b71Sopenharmony_cilet player = await media.createAVPlayer();
840e41f4b71Sopenharmony_cilet fileDescriptor = await context.resourceManager.getRawFd('xxx.mp4')
841e41f4b71Sopenharmony_ciplayer.fdSrc = fileDescriptor
842e41f4b71Sopenharmony_cilet playStrategy : media.PlaybackStrategy = {preferredWidth: 1, preferredHeight: 2, preferredBufferDuration: 3,
843e41f4b71Sopenharmony_ci  preferredHdr: false, mutedMediaType: media.MediaType.MEDIA_TYPE_AUD};
844e41f4b71Sopenharmony_ciplayer.setPlaybackStrategy(playStrategy);
845e41f4b71Sopenharmony_ci```
846e41f4b71Sopenharmony_ci
847e41f4b71Sopenharmony_ci### prepare<sup>9+</sup>
848e41f4b71Sopenharmony_ci
849e41f4b71Sopenharmony_ciprepare(callback: AsyncCallback\<void>): void
850e41f4b71Sopenharmony_ci
851e41f4b71Sopenharmony_ciPrepares for audio and video playback. This API can be called only when the AVPlayer is in the initialized state. The state changes can be detected by subscribing to the [stateChange](#onstatechange9) event. This API uses an asynchronous callback to return the result.
852e41f4b71Sopenharmony_ci
853e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
854e41f4b71Sopenharmony_ci
855e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
856e41f4b71Sopenharmony_ci
857e41f4b71Sopenharmony_ci**Parameters**
858e41f4b71Sopenharmony_ci
859e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                |
860e41f4b71Sopenharmony_ci| -------- | -------- | ---- | -------------------- |
861e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
862e41f4b71Sopenharmony_ci
863e41f4b71Sopenharmony_ci**Error codes**
864e41f4b71Sopenharmony_ci
865e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
866e41f4b71Sopenharmony_ci
867e41f4b71Sopenharmony_ci| ID| Error Message                                  |
868e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
869e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by callback. |
870e41f4b71Sopenharmony_ci| 5400106  | Unsupport format. Return by callback.      |
871e41f4b71Sopenharmony_ci
872e41f4b71Sopenharmony_ci**Example**
873e41f4b71Sopenharmony_ci
874e41f4b71Sopenharmony_ci```ts
875e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
876e41f4b71Sopenharmony_ci
877e41f4b71Sopenharmony_ciavPlayer.prepare((err: BusinessError) => {
878e41f4b71Sopenharmony_ci  if (err) {
879e41f4b71Sopenharmony_ci    console.error('Failed to prepare,error message is :' + err.message)
880e41f4b71Sopenharmony_ci  } else {
881e41f4b71Sopenharmony_ci    console.info('Succeeded in preparing');
882e41f4b71Sopenharmony_ci  }
883e41f4b71Sopenharmony_ci})
884e41f4b71Sopenharmony_ci```
885e41f4b71Sopenharmony_ci
886e41f4b71Sopenharmony_ci### prepare<sup>9+</sup>
887e41f4b71Sopenharmony_ci
888e41f4b71Sopenharmony_ciprepare(): Promise\<void>
889e41f4b71Sopenharmony_ci
890e41f4b71Sopenharmony_ciPrepares for audio and video playback. This API can be called only when the AVPlayer is in the initialized state. The state changes can be detected by subscribing to the [stateChange](#onstatechange9) event. This API uses a promise to return the result.
891e41f4b71Sopenharmony_ci
892e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
893e41f4b71Sopenharmony_ci
894e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
895e41f4b71Sopenharmony_ci
896e41f4b71Sopenharmony_ci**Return value**
897e41f4b71Sopenharmony_ci
898e41f4b71Sopenharmony_ci| Type          | Description                     |
899e41f4b71Sopenharmony_ci| -------------- | ------------------------- |
900e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
901e41f4b71Sopenharmony_ci
902e41f4b71Sopenharmony_ci**Error codes**
903e41f4b71Sopenharmony_ci
904e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
905e41f4b71Sopenharmony_ci
906e41f4b71Sopenharmony_ci| ID| Error Message                                 |
907e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
908e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
909e41f4b71Sopenharmony_ci| 5400106  | Unsupport format. Return by promise.      |
910e41f4b71Sopenharmony_ci
911e41f4b71Sopenharmony_ci**Example**
912e41f4b71Sopenharmony_ci
913e41f4b71Sopenharmony_ci```ts
914e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
915e41f4b71Sopenharmony_ci
916e41f4b71Sopenharmony_ciavPlayer.prepare().then(() => {
917e41f4b71Sopenharmony_ci  console.info('Succeeded in preparing');
918e41f4b71Sopenharmony_ci}, (err: BusinessError) => {
919e41f4b71Sopenharmony_ci  console.error('Failed to prepare,error message is :' + err.message)
920e41f4b71Sopenharmony_ci})
921e41f4b71Sopenharmony_ci```
922e41f4b71Sopenharmony_ci
923e41f4b71Sopenharmony_ci### setMediaMuted<sup>12+</sup>
924e41f4b71Sopenharmony_ci
925e41f4b71Sopenharmony_cisetMediaMuted(mediaType: MediaType,  muted: boolean ): Promise\<void>
926e41f4b71Sopenharmony_ci
927e41f4b71Sopenharmony_ciMutes or unmutes the audio. This API can be called only when the AVPlayer is in the prepared, playing, paused, or completed state. The **mediaType** parameter can be set only to the audio format.
928e41f4b71Sopenharmony_ci
929e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
930e41f4b71Sopenharmony_ci
931e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
932e41f4b71Sopenharmony_ci
933e41f4b71Sopenharmony_ci**Parameters**
934e41f4b71Sopenharmony_ci
935e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                |
936e41f4b71Sopenharmony_ci| -------- | -------- | ---- | -------------------- |
937e41f4b71Sopenharmony_ci| mediaType | [MediaType](#mediatype8) | Yes  | Media type.|
938e41f4b71Sopenharmony_ci| muted | boolean | Yes  | Whether to mute the audio.|
939e41f4b71Sopenharmony_ci
940e41f4b71Sopenharmony_ci**Return value**
941e41f4b71Sopenharmony_ci
942e41f4b71Sopenharmony_ci| Type          | Description                     |
943e41f4b71Sopenharmony_ci| -------------- | ------------------------- |
944e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
945e41f4b71Sopenharmony_ci
946e41f4b71Sopenharmony_ci**Error codes**
947e41f4b71Sopenharmony_ci
948e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
949e41f4b71Sopenharmony_ci
950e41f4b71Sopenharmony_ci| ID| Error Message|
951e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
952e41f4b71Sopenharmony_ci| 401 | The parameter check failed. Return by promise. |
953e41f4b71Sopenharmony_ci| 5400102 | Operation not allowed. Return by promise. |
954e41f4b71Sopenharmony_ci
955e41f4b71Sopenharmony_ci**Example**
956e41f4b71Sopenharmony_ci
957e41f4b71Sopenharmony_ci```ts
958e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
959e41f4b71Sopenharmony_ci
960e41f4b71Sopenharmony_ciavPlayer.prepare().then(() => {
961e41f4b71Sopenharmony_ci  console.info('Succeeded in preparing');
962e41f4b71Sopenharmony_ci  avPlayer.setMediaMuted(media.MediaType.MEDIA_TYPE_AUD, true)
963e41f4b71Sopenharmony_ci}, (err: BusinessError) => {
964e41f4b71Sopenharmony_ci  console.error('Failed to prepare,error message is :' + err.message)
965e41f4b71Sopenharmony_ci})
966e41f4b71Sopenharmony_ci```
967e41f4b71Sopenharmony_ci
968e41f4b71Sopenharmony_ci### play<sup>9+</sup>
969e41f4b71Sopenharmony_ci
970e41f4b71Sopenharmony_ciplay(callback: AsyncCallback\<void>): void
971e41f4b71Sopenharmony_ci
972e41f4b71Sopenharmony_ciStarts to play an audio and video asset. This API can be called only when the AVPlayer is in the prepared, paused, or completed state. This API uses an asynchronous callback to return the result.
973e41f4b71Sopenharmony_ci
974e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
975e41f4b71Sopenharmony_ci
976e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
977e41f4b71Sopenharmony_ci
978e41f4b71Sopenharmony_ci**Parameters**
979e41f4b71Sopenharmony_ci
980e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                |
981e41f4b71Sopenharmony_ci| -------- | -------- | ---- | -------------------- |
982e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
983e41f4b71Sopenharmony_ci
984e41f4b71Sopenharmony_ci**Error codes**
985e41f4b71Sopenharmony_ci
986e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
987e41f4b71Sopenharmony_ci
988e41f4b71Sopenharmony_ci| ID| Error Message                                  |
989e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
990e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by callback. |
991e41f4b71Sopenharmony_ci
992e41f4b71Sopenharmony_ci**Example**
993e41f4b71Sopenharmony_ci
994e41f4b71Sopenharmony_ci```ts
995e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
996e41f4b71Sopenharmony_ci
997e41f4b71Sopenharmony_ciavPlayer.play((err: BusinessError) => {
998e41f4b71Sopenharmony_ci  if (err) {
999e41f4b71Sopenharmony_ci    console.error('Failed to play,error message is :' + err.message)
1000e41f4b71Sopenharmony_ci  } else {
1001e41f4b71Sopenharmony_ci    console.info('Succeeded in playing');
1002e41f4b71Sopenharmony_ci  }
1003e41f4b71Sopenharmony_ci})
1004e41f4b71Sopenharmony_ci```
1005e41f4b71Sopenharmony_ci
1006e41f4b71Sopenharmony_ci### play<sup>9+</sup>
1007e41f4b71Sopenharmony_ci
1008e41f4b71Sopenharmony_ciplay(): Promise\<void>
1009e41f4b71Sopenharmony_ci
1010e41f4b71Sopenharmony_ciStarts to play an audio and video asset. This API can be called only when the AVPlayer is in the prepared, paused, or completed state. This API uses a promise to return the result.
1011e41f4b71Sopenharmony_ci
1012e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1013e41f4b71Sopenharmony_ci
1014e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1015e41f4b71Sopenharmony_ci
1016e41f4b71Sopenharmony_ci**Return value**
1017e41f4b71Sopenharmony_ci
1018e41f4b71Sopenharmony_ci| Type          | Description                     |
1019e41f4b71Sopenharmony_ci| -------------- | ------------------------- |
1020e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
1021e41f4b71Sopenharmony_ci
1022e41f4b71Sopenharmony_ci**Error codes**
1023e41f4b71Sopenharmony_ci
1024e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
1025e41f4b71Sopenharmony_ci
1026e41f4b71Sopenharmony_ci| ID| Error Message                                 |
1027e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
1028e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
1029e41f4b71Sopenharmony_ci
1030e41f4b71Sopenharmony_ci**Example**
1031e41f4b71Sopenharmony_ci
1032e41f4b71Sopenharmony_ci```ts
1033e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1034e41f4b71Sopenharmony_ci
1035e41f4b71Sopenharmony_ciavPlayer.play().then(() => {
1036e41f4b71Sopenharmony_ci  console.info('Succeeded in playing');
1037e41f4b71Sopenharmony_ci}, (err: BusinessError) => {
1038e41f4b71Sopenharmony_ci  console.error('Failed to play,error message is :' + err.message)
1039e41f4b71Sopenharmony_ci})
1040e41f4b71Sopenharmony_ci```
1041e41f4b71Sopenharmony_ci
1042e41f4b71Sopenharmony_ci### pause<sup>9+</sup>
1043e41f4b71Sopenharmony_ci
1044e41f4b71Sopenharmony_cipause(callback: AsyncCallback\<void>): void
1045e41f4b71Sopenharmony_ci
1046e41f4b71Sopenharmony_ciPauses audio and video playback. This API can be called only when the AVPlayer is in the playing state. This API uses an asynchronous callback to return the result.
1047e41f4b71Sopenharmony_ci
1048e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1049e41f4b71Sopenharmony_ci
1050e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1051e41f4b71Sopenharmony_ci
1052e41f4b71Sopenharmony_ci**Parameters**
1053e41f4b71Sopenharmony_ci
1054e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                |
1055e41f4b71Sopenharmony_ci| -------- | -------- | ---- | -------------------- |
1056e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
1057e41f4b71Sopenharmony_ci
1058e41f4b71Sopenharmony_ci**Error codes**
1059e41f4b71Sopenharmony_ci
1060e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
1061e41f4b71Sopenharmony_ci
1062e41f4b71Sopenharmony_ci| ID| Error Message                                  |
1063e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
1064e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by callback. |
1065e41f4b71Sopenharmony_ci
1066e41f4b71Sopenharmony_ci**Example**
1067e41f4b71Sopenharmony_ci
1068e41f4b71Sopenharmony_ci```ts
1069e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1070e41f4b71Sopenharmony_ci
1071e41f4b71Sopenharmony_ciavPlayer.pause((err: BusinessError) => {
1072e41f4b71Sopenharmony_ci  if (err) {
1073e41f4b71Sopenharmony_ci    console.error('Failed to pause,error message is :' + err.message)
1074e41f4b71Sopenharmony_ci  } else {
1075e41f4b71Sopenharmony_ci    console.info('Succeeded in pausing');
1076e41f4b71Sopenharmony_ci  }
1077e41f4b71Sopenharmony_ci})
1078e41f4b71Sopenharmony_ci```
1079e41f4b71Sopenharmony_ci
1080e41f4b71Sopenharmony_ci### pause<sup>9+</sup>
1081e41f4b71Sopenharmony_ci
1082e41f4b71Sopenharmony_cipause(): Promise\<void>
1083e41f4b71Sopenharmony_ci
1084e41f4b71Sopenharmony_ciPauses audio and video playback. This API can be called only when the AVPlayer is in the playing state. This API uses a promise to return the result.
1085e41f4b71Sopenharmony_ci
1086e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1087e41f4b71Sopenharmony_ci
1088e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1089e41f4b71Sopenharmony_ci
1090e41f4b71Sopenharmony_ci**Return value**
1091e41f4b71Sopenharmony_ci
1092e41f4b71Sopenharmony_ci| Type          | Description                     |
1093e41f4b71Sopenharmony_ci| -------------- | ------------------------- |
1094e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
1095e41f4b71Sopenharmony_ci
1096e41f4b71Sopenharmony_ci**Error codes**
1097e41f4b71Sopenharmony_ci
1098e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
1099e41f4b71Sopenharmony_ci
1100e41f4b71Sopenharmony_ci| ID| Error Message                                 |
1101e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
1102e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
1103e41f4b71Sopenharmony_ci
1104e41f4b71Sopenharmony_ci**Example**
1105e41f4b71Sopenharmony_ci
1106e41f4b71Sopenharmony_ci```ts
1107e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1108e41f4b71Sopenharmony_ci
1109e41f4b71Sopenharmony_ciavPlayer.pause().then(() => {
1110e41f4b71Sopenharmony_ci  console.info('Succeeded in pausing');
1111e41f4b71Sopenharmony_ci}, (err: BusinessError) => {
1112e41f4b71Sopenharmony_ci  console.error('Failed to pause,error message is :' + err.message)
1113e41f4b71Sopenharmony_ci})
1114e41f4b71Sopenharmony_ci```
1115e41f4b71Sopenharmony_ci
1116e41f4b71Sopenharmony_ci### stop<sup>9+</sup>
1117e41f4b71Sopenharmony_ci
1118e41f4b71Sopenharmony_cistop(callback: AsyncCallback\<void>): void
1119e41f4b71Sopenharmony_ci
1120e41f4b71Sopenharmony_ciStops audio and video playback. This API can be called only when the AVPlayer is in the prepared, playing, paused, or completed state. This API uses an asynchronous callback to return the result.
1121e41f4b71Sopenharmony_ci
1122e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1123e41f4b71Sopenharmony_ci
1124e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1125e41f4b71Sopenharmony_ci
1126e41f4b71Sopenharmony_ci**Parameters**
1127e41f4b71Sopenharmony_ci
1128e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                |
1129e41f4b71Sopenharmony_ci| -------- | -------- | ---- | -------------------- |
1130e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
1131e41f4b71Sopenharmony_ci
1132e41f4b71Sopenharmony_ci**Error codes**
1133e41f4b71Sopenharmony_ci
1134e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
1135e41f4b71Sopenharmony_ci
1136e41f4b71Sopenharmony_ci| ID| Error Message                                  |
1137e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
1138e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by callback. |
1139e41f4b71Sopenharmony_ci
1140e41f4b71Sopenharmony_ci**Example**
1141e41f4b71Sopenharmony_ci
1142e41f4b71Sopenharmony_ci```ts
1143e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1144e41f4b71Sopenharmony_ci
1145e41f4b71Sopenharmony_ciavPlayer.stop((err: BusinessError) => {
1146e41f4b71Sopenharmony_ci  if (err) {
1147e41f4b71Sopenharmony_ci    console.error('Failed to stop,error message is :' + err.message)
1148e41f4b71Sopenharmony_ci  } else {
1149e41f4b71Sopenharmony_ci    console.info('Succeeded in stopping');
1150e41f4b71Sopenharmony_ci  }
1151e41f4b71Sopenharmony_ci})
1152e41f4b71Sopenharmony_ci```
1153e41f4b71Sopenharmony_ci
1154e41f4b71Sopenharmony_ci### stop<sup>9+</sup>
1155e41f4b71Sopenharmony_ci
1156e41f4b71Sopenharmony_cistop(): Promise\<void>
1157e41f4b71Sopenharmony_ci
1158e41f4b71Sopenharmony_ciStops audio and video playback. This API can be called only when the AVPlayer is in the prepared, playing, paused, or completed state. This API uses a promise to return the result.
1159e41f4b71Sopenharmony_ci
1160e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1161e41f4b71Sopenharmony_ci
1162e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1163e41f4b71Sopenharmony_ci
1164e41f4b71Sopenharmony_ci**Return value**
1165e41f4b71Sopenharmony_ci
1166e41f4b71Sopenharmony_ci| Type          | Description                     |
1167e41f4b71Sopenharmony_ci| -------------- | ------------------------- |
1168e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
1169e41f4b71Sopenharmony_ci
1170e41f4b71Sopenharmony_ci**Error codes**
1171e41f4b71Sopenharmony_ci
1172e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
1173e41f4b71Sopenharmony_ci
1174e41f4b71Sopenharmony_ci| ID| Error Message                                 |
1175e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
1176e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
1177e41f4b71Sopenharmony_ci
1178e41f4b71Sopenharmony_ci**Example**
1179e41f4b71Sopenharmony_ci
1180e41f4b71Sopenharmony_ci```ts
1181e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1182e41f4b71Sopenharmony_ci
1183e41f4b71Sopenharmony_ciavPlayer.stop().then(() => {
1184e41f4b71Sopenharmony_ci  console.info('Succeeded in stopping');
1185e41f4b71Sopenharmony_ci}, (err: BusinessError) => {
1186e41f4b71Sopenharmony_ci  console.error('Failed to stop,error message is :' + err.message)
1187e41f4b71Sopenharmony_ci})
1188e41f4b71Sopenharmony_ci```
1189e41f4b71Sopenharmony_ci
1190e41f4b71Sopenharmony_ci### reset<sup>9+</sup>
1191e41f4b71Sopenharmony_ci
1192e41f4b71Sopenharmony_cireset(callback: AsyncCallback\<void>): void
1193e41f4b71Sopenharmony_ci
1194e41f4b71Sopenharmony_ciResets audio and video playback. This API can be called only when the AVPlayer is in the initialized, prepared, playing, paused, completed, stopped, or error state. This API uses an asynchronous callback to return the result.
1195e41f4b71Sopenharmony_ci
1196e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1197e41f4b71Sopenharmony_ci
1198e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1199e41f4b71Sopenharmony_ci
1200e41f4b71Sopenharmony_ci**Parameters**
1201e41f4b71Sopenharmony_ci
1202e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                |
1203e41f4b71Sopenharmony_ci| -------- | -------- | ---- | -------------------- |
1204e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
1205e41f4b71Sopenharmony_ci
1206e41f4b71Sopenharmony_ci**Error codes**
1207e41f4b71Sopenharmony_ci
1208e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
1209e41f4b71Sopenharmony_ci
1210e41f4b71Sopenharmony_ci| ID| Error Message                                  |
1211e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
1212e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by callback. |
1213e41f4b71Sopenharmony_ci
1214e41f4b71Sopenharmony_ci**Example**
1215e41f4b71Sopenharmony_ci
1216e41f4b71Sopenharmony_ci```ts
1217e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1218e41f4b71Sopenharmony_ci
1219e41f4b71Sopenharmony_ciavPlayer.reset((err: BusinessError) => {
1220e41f4b71Sopenharmony_ci  if (err) {
1221e41f4b71Sopenharmony_ci    console.error('Failed to reset,error message is :' + err.message)
1222e41f4b71Sopenharmony_ci  } else {
1223e41f4b71Sopenharmony_ci    console.info('Succeeded in resetting');
1224e41f4b71Sopenharmony_ci  }
1225e41f4b71Sopenharmony_ci})
1226e41f4b71Sopenharmony_ci```
1227e41f4b71Sopenharmony_ci
1228e41f4b71Sopenharmony_ci### reset<sup>9+</sup>
1229e41f4b71Sopenharmony_ci
1230e41f4b71Sopenharmony_cireset(): Promise\<void>
1231e41f4b71Sopenharmony_ci
1232e41f4b71Sopenharmony_ciResets audio and video playback. This API can be called only when the AVPlayer is in the initialized, prepared, playing, paused, completed, stopped, or error state. This API uses a promise to return the result.
1233e41f4b71Sopenharmony_ci
1234e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1235e41f4b71Sopenharmony_ci
1236e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1237e41f4b71Sopenharmony_ci
1238e41f4b71Sopenharmony_ci**Return value**
1239e41f4b71Sopenharmony_ci
1240e41f4b71Sopenharmony_ci| Type          | Description                     |
1241e41f4b71Sopenharmony_ci| -------------- | ------------------------- |
1242e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
1243e41f4b71Sopenharmony_ci
1244e41f4b71Sopenharmony_ci**Error codes**
1245e41f4b71Sopenharmony_ci
1246e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
1247e41f4b71Sopenharmony_ci
1248e41f4b71Sopenharmony_ci| ID| Error Message                                 |
1249e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
1250e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
1251e41f4b71Sopenharmony_ci
1252e41f4b71Sopenharmony_ci**Example**
1253e41f4b71Sopenharmony_ci
1254e41f4b71Sopenharmony_ci```ts
1255e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1256e41f4b71Sopenharmony_ci
1257e41f4b71Sopenharmony_ciavPlayer.reset().then(() => {
1258e41f4b71Sopenharmony_ci  console.info('Succeeded in resetting');
1259e41f4b71Sopenharmony_ci}, (err: BusinessError) => {
1260e41f4b71Sopenharmony_ci  console.error('Failed to reset,error message is :' + err.message)
1261e41f4b71Sopenharmony_ci})
1262e41f4b71Sopenharmony_ci```
1263e41f4b71Sopenharmony_ci
1264e41f4b71Sopenharmony_ci### release<sup>9+</sup>
1265e41f4b71Sopenharmony_ci
1266e41f4b71Sopenharmony_cirelease(callback: AsyncCallback\<void>): void
1267e41f4b71Sopenharmony_ci
1268e41f4b71Sopenharmony_ciReleases the playback resources. This API can be called when the AVPlayer is in any state except released. This API uses an asynchronous callback to return the result.
1269e41f4b71Sopenharmony_ci
1270e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1271e41f4b71Sopenharmony_ci
1272e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1273e41f4b71Sopenharmony_ci
1274e41f4b71Sopenharmony_ci**Parameters**
1275e41f4b71Sopenharmony_ci
1276e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                |
1277e41f4b71Sopenharmony_ci| -------- | -------- | ---- | -------------------- |
1278e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
1279e41f4b71Sopenharmony_ci
1280e41f4b71Sopenharmony_ci**Error codes**
1281e41f4b71Sopenharmony_ci
1282e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
1283e41f4b71Sopenharmony_ci
1284e41f4b71Sopenharmony_ci| ID| Error Message                                  |
1285e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
1286e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by callback. |
1287e41f4b71Sopenharmony_ci
1288e41f4b71Sopenharmony_ci**Example**
1289e41f4b71Sopenharmony_ci
1290e41f4b71Sopenharmony_ci```ts
1291e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1292e41f4b71Sopenharmony_ci
1293e41f4b71Sopenharmony_ciavPlayer.release((err: BusinessError) => {
1294e41f4b71Sopenharmony_ci  if (err) {
1295e41f4b71Sopenharmony_ci    console.error('Failed to release,error message is :' + err.message)
1296e41f4b71Sopenharmony_ci  } else {
1297e41f4b71Sopenharmony_ci    console.info('Succeeded in releasing');
1298e41f4b71Sopenharmony_ci  }
1299e41f4b71Sopenharmony_ci})
1300e41f4b71Sopenharmony_ci```
1301e41f4b71Sopenharmony_ci
1302e41f4b71Sopenharmony_ci### release<sup>9+</sup>
1303e41f4b71Sopenharmony_ci
1304e41f4b71Sopenharmony_cirelease(): Promise\<void>
1305e41f4b71Sopenharmony_ci
1306e41f4b71Sopenharmony_ciReleases the playback resources. This API can be called when the AVPlayer is in any state except released. This API uses a promise to return the result.
1307e41f4b71Sopenharmony_ci
1308e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1309e41f4b71Sopenharmony_ci
1310e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1311e41f4b71Sopenharmony_ci
1312e41f4b71Sopenharmony_ci**Return value**
1313e41f4b71Sopenharmony_ci
1314e41f4b71Sopenharmony_ci| Type          | Description                     |
1315e41f4b71Sopenharmony_ci| -------------- | ------------------------- |
1316e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
1317e41f4b71Sopenharmony_ci
1318e41f4b71Sopenharmony_ci**Error codes**
1319e41f4b71Sopenharmony_ci
1320e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
1321e41f4b71Sopenharmony_ci
1322e41f4b71Sopenharmony_ci| ID| Error Message                                 |
1323e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
1324e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
1325e41f4b71Sopenharmony_ci
1326e41f4b71Sopenharmony_ci**Example**
1327e41f4b71Sopenharmony_ci
1328e41f4b71Sopenharmony_ci```ts
1329e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1330e41f4b71Sopenharmony_ci
1331e41f4b71Sopenharmony_ciavPlayer.release().then(() => {
1332e41f4b71Sopenharmony_ci  console.info('Succeeded in releasing');
1333e41f4b71Sopenharmony_ci}, (err: BusinessError) => {
1334e41f4b71Sopenharmony_ci  console.error('Failed to release,error message is :' + err.message)
1335e41f4b71Sopenharmony_ci})
1336e41f4b71Sopenharmony_ci```
1337e41f4b71Sopenharmony_ci
1338e41f4b71Sopenharmony_ci### getTrackDescription<sup>9+</sup>
1339e41f4b71Sopenharmony_ci
1340e41f4b71Sopenharmony_cigetTrackDescription(callback: AsyncCallback\<Array\<MediaDescription>>): void
1341e41f4b71Sopenharmony_ci
1342e41f4b71Sopenharmony_ciObtains the audio and video track information. This API can be called only when the AVPlayer is in the prepared, playing, or paused state. To obtain information about all audio and video tracks, this API must be called after the data loading callback is triggered. This API uses an asynchronous callback to return the result.
1343e41f4b71Sopenharmony_ci
1344e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1345e41f4b71Sopenharmony_ci
1346e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1347e41f4b71Sopenharmony_ci
1348e41f4b71Sopenharmony_ci**Parameters**
1349e41f4b71Sopenharmony_ci
1350e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory| Description                                        |
1351e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------- |
1352e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<[MediaDescription](#mediadescription8)>> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the MediaDescription array obtained; otherwise, **err** is an error object.|
1353e41f4b71Sopenharmony_ci
1354e41f4b71Sopenharmony_ci**Error codes**
1355e41f4b71Sopenharmony_ci
1356e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
1357e41f4b71Sopenharmony_ci
1358e41f4b71Sopenharmony_ci| ID| Error Message                                  |
1359e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
1360e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by callback. |
1361e41f4b71Sopenharmony_ci
1362e41f4b71Sopenharmony_ci**Example**
1363e41f4b71Sopenharmony_ci
1364e41f4b71Sopenharmony_ci```ts
1365e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1366e41f4b71Sopenharmony_ci
1367e41f4b71Sopenharmony_ciavPlayer.getTrackDescription((error: BusinessError, arrList: Array<media.MediaDescription>) => {
1368e41f4b71Sopenharmony_ci  if ((arrList) != null) {
1369e41f4b71Sopenharmony_ci    console.info('Succeeded in doing getTrackDescription');
1370e41f4b71Sopenharmony_ci  } else {
1371e41f4b71Sopenharmony_ci    console.error(`Failed to do getTrackDescription, error:${error}`);
1372e41f4b71Sopenharmony_ci  }
1373e41f4b71Sopenharmony_ci});
1374e41f4b71Sopenharmony_ci```
1375e41f4b71Sopenharmony_ci
1376e41f4b71Sopenharmony_ci### getTrackDescription<sup>9+</sup>
1377e41f4b71Sopenharmony_ci
1378e41f4b71Sopenharmony_cigetTrackDescription(): Promise\<Array\<MediaDescription>>
1379e41f4b71Sopenharmony_ci
1380e41f4b71Sopenharmony_ciObtains the audio and video track information. This API can be called only when the AVPlayer is in the prepared, playing, or paused state. This API uses a promise to return the result.
1381e41f4b71Sopenharmony_ci
1382e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1383e41f4b71Sopenharmony_ci
1384e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1385e41f4b71Sopenharmony_ci
1386e41f4b71Sopenharmony_ci**Return value**
1387e41f4b71Sopenharmony_ci
1388e41f4b71Sopenharmony_ci| Type                                                  | Description                                             |
1389e41f4b71Sopenharmony_ci| ------------------------------------------------------ | ------------------------------------------------- |
1390e41f4b71Sopenharmony_ci| Promise<Array<[MediaDescription](#mediadescription8)>> | Promise used to return the MediaDescription array that holds the audio and video track information.|
1391e41f4b71Sopenharmony_ci
1392e41f4b71Sopenharmony_ci**Error codes**
1393e41f4b71Sopenharmony_ci
1394e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
1395e41f4b71Sopenharmony_ci
1396e41f4b71Sopenharmony_ci| ID| Error Message                                 |
1397e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
1398e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
1399e41f4b71Sopenharmony_ci
1400e41f4b71Sopenharmony_ci**Example**
1401e41f4b71Sopenharmony_ci
1402e41f4b71Sopenharmony_ci```ts
1403e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1404e41f4b71Sopenharmony_ci
1405e41f4b71Sopenharmony_ciavPlayer.getTrackDescription().then((arrList: Array<media.MediaDescription>) => {
1406e41f4b71Sopenharmony_ci  console.info('Succeeded in getting TrackDescription');
1407e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
1408e41f4b71Sopenharmony_ci  console.error(`Failed to get TrackDescription, error:${error}`);
1409e41f4b71Sopenharmony_ci});
1410e41f4b71Sopenharmony_ci```
1411e41f4b71Sopenharmony_ci
1412e41f4b71Sopenharmony_ci### getSelectedTracks<sup>12+</sup>
1413e41f4b71Sopenharmony_ci
1414e41f4b71Sopenharmony_cigetSelectedTracks(): Promise\<Array\<number>>
1415e41f4b71Sopenharmony_ci
1416e41f4b71Sopenharmony_ciObtains the indexes of the selected audio or video tracks. This API can be called only when the AVPlayer is in the prepared, playing, or paused state. This API uses a promise to return the result.
1417e41f4b71Sopenharmony_ci
1418e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1419e41f4b71Sopenharmony_ci
1420e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1421e41f4b71Sopenharmony_ci
1422e41f4b71Sopenharmony_ci**Return value**
1423e41f4b71Sopenharmony_ci
1424e41f4b71Sopenharmony_ci| Type                                                  | Description                                             |
1425e41f4b71Sopenharmony_ci| ------------------------------------------------------ | ------------------------------------------------- |
1426e41f4b71Sopenharmony_ci| Promise<Array<[number]>> | Promise used to return the index array.|
1427e41f4b71Sopenharmony_ci
1428e41f4b71Sopenharmony_ci**Error codes**
1429e41f4b71Sopenharmony_ci
1430e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
1431e41f4b71Sopenharmony_ci
1432e41f4b71Sopenharmony_ci| ID| Error Message                                 |
1433e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
1434e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. |
1435e41f4b71Sopenharmony_ci
1436e41f4b71Sopenharmony_ci**Example**
1437e41f4b71Sopenharmony_ci
1438e41f4b71Sopenharmony_ci```ts
1439e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1440e41f4b71Sopenharmony_ci
1441e41f4b71Sopenharmony_ciavPlayer.getSelectedTracks().then((arrList: Array<number>) => {
1442e41f4b71Sopenharmony_ci  console.info('Succeeded in getting SelectedTracks');
1443e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
1444e41f4b71Sopenharmony_ci  console.error(`Failed to get SelectedTracks, error:${error}`);
1445e41f4b71Sopenharmony_ci});
1446e41f4b71Sopenharmony_ci```
1447e41f4b71Sopenharmony_ci
1448e41f4b71Sopenharmony_ci### getPlaybackInfo<sup>12+</sup>
1449e41f4b71Sopenharmony_ci
1450e41f4b71Sopenharmony_cigetPlaybackInfo(): Promise\<PlaybackInfo>
1451e41f4b71Sopenharmony_ci
1452e41f4b71Sopenharmony_ciObtains the playback information. This API can be called only when the AVPlayer is in the prepared, playing, or paused state. This API uses a promise to return the result.
1453e41f4b71Sopenharmony_ci
1454e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1455e41f4b71Sopenharmony_ci
1456e41f4b71Sopenharmony_ci**Return value**
1457e41f4b71Sopenharmony_ci
1458e41f4b71Sopenharmony_ci| Type                                                  | Description                                             |
1459e41f4b71Sopenharmony_ci| ------------------------------------------------------ | ------------------------------------------------- |
1460e41f4b71Sopenharmony_ci| Promise<[PlaybackInfo](#playbackinfo12)> | Promise used to return **PlaybackInfo**.|
1461e41f4b71Sopenharmony_ci
1462e41f4b71Sopenharmony_ci**Example**
1463e41f4b71Sopenharmony_ci
1464e41f4b71Sopenharmony_ci```ts
1465e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1466e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit';
1467e41f4b71Sopenharmony_ci
1468e41f4b71Sopenharmony_cilet avPlayer: media.AVPlayer | undefined = undefined;
1469e41f4b71Sopenharmony_cilet playbackInfo: media.PlaybackInfo | undefined = undefined;
1470e41f4b71Sopenharmony_cimedia.createAVPlayer(async (err: BusinessError, player: media.AVPlayer) => {
1471e41f4b71Sopenharmony_ci  if (player != null) {
1472e41f4b71Sopenharmony_ci    avPlayer = player;
1473e41f4b71Sopenharmony_ci    console.info(`Succeeded in creating AVPlayer`);
1474e41f4b71Sopenharmony_ci    if (avPlayer) {
1475e41f4b71Sopenharmony_ci      try {
1476e41f4b71Sopenharmony_ci        playbackInfo = await avPlayer.getPlaybackInfo();
1477e41f4b71Sopenharmony_ci        console.info(`AVPlayer getPlaybackInfo = ${JSON.stringify(playbackInfo)}`); // Print PlaybackInfo.
1478e41f4b71Sopenharmony_ci      } catch (error) {
1479e41f4b71Sopenharmony_ci        console.error(`error = ${error}`);
1480e41f4b71Sopenharmony_ci      }
1481e41f4b71Sopenharmony_ci    }
1482e41f4b71Sopenharmony_ci  } else {
1483e41f4b71Sopenharmony_ci    console.error(`Failed to create AVPlayer, error message:${err.message}`);
1484e41f4b71Sopenharmony_ci  }
1485e41f4b71Sopenharmony_ci});
1486e41f4b71Sopenharmony_ci```
1487e41f4b71Sopenharmony_ci
1488e41f4b71Sopenharmony_ci### selectTrack<sup>12+</sup>
1489e41f4b71Sopenharmony_ci
1490e41f4b71Sopenharmony_ciselectTrack(index: number, mode?: SwitchMode): Promise\<void>
1491e41f4b71Sopenharmony_ci
1492e41f4b71Sopenharmony_ciSelects an audio track when the AVPlayer is used to play a video with multiple audio tracks. This API uses a promise to return the result.
1493e41f4b71Sopenharmony_ci
1494e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1495e41f4b71Sopenharmony_ci
1496e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1497e41f4b71Sopenharmony_ci
1498e41f4b71Sopenharmony_ci**Parameters**
1499e41f4b71Sopenharmony_ci
1500e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                |
1501e41f4b71Sopenharmony_ci| -------- | -------- | ---- | -------------------- |
1502e41f4b71Sopenharmony_ci| index | number | Yes  | Index of the audio track, which is obtained from [MediaDescription](#mediadescription8).|
1503e41f4b71Sopenharmony_ci| mode   | [SwitchMode](#switchmode12) | No  | Video track switch mode. The default mode is **SMOOTH**. Only the DASH protocol is supported. **This parameter is valid only for video playback.**|
1504e41f4b71Sopenharmony_ci
1505e41f4b71Sopenharmony_ci**Return value**
1506e41f4b71Sopenharmony_ci
1507e41f4b71Sopenharmony_ci| Type          | Description                     |
1508e41f4b71Sopenharmony_ci| -------------- | ------------------------- |
1509e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
1510e41f4b71Sopenharmony_ci
1511e41f4b71Sopenharmony_ci**Error codes**
1512e41f4b71Sopenharmony_ci
1513e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
1514e41f4b71Sopenharmony_ci
1515e41f4b71Sopenharmony_ci| ID| Error Message                                 |
1516e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
1517e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Return by promise.       |
1518e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
1519e41f4b71Sopenharmony_ci
1520e41f4b71Sopenharmony_ci**Example**
1521e41f4b71Sopenharmony_ci
1522e41f4b71Sopenharmony_ci```ts
1523e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1524e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit';
1525e41f4b71Sopenharmony_ci
1526e41f4b71Sopenharmony_cilet avPlayer: media.AVPlayer = await media.createAVPlayer();
1527e41f4b71Sopenharmony_cilet audioTrackIndex: Object = 0;
1528e41f4b71Sopenharmony_ciavPlayer.getTrackDescription((error: BusinessError, arrList: Array<media.MediaDescription>) => {
1529e41f4b71Sopenharmony_ci  if (arrList != null) {
1530e41f4b71Sopenharmony_ci    for (let i = 0; i < arrList.length; i++) {
1531e41f4b71Sopenharmony_ci      if (i != 0) {
1532e41f4b71Sopenharmony_ci        // Obtain the audio track list.
1533e41f4b71Sopenharmony_ci        audioTrackIndex = arrList[i][media.MediaDescriptionKey.MD_KEY_TRACK_INDEX];
1534e41f4b71Sopenharmony_ci      }
1535e41f4b71Sopenharmony_ci    }
1536e41f4b71Sopenharmony_ci  } else {
1537e41f4b71Sopenharmony_ci    console.error(`Failed to get TrackDescription, error:${error}`);
1538e41f4b71Sopenharmony_ci  }
1539e41f4b71Sopenharmony_ci});
1540e41f4b71Sopenharmony_ci
1541e41f4b71Sopenharmony_ci// Select an audio track.
1542e41f4b71Sopenharmony_ciavPlayer.selectTrack(parseInt(audioTrackIndex.toString()));
1543e41f4b71Sopenharmony_ci```
1544e41f4b71Sopenharmony_ci
1545e41f4b71Sopenharmony_ci### deselectTrack<sup>12+</sup>
1546e41f4b71Sopenharmony_ci
1547e41f4b71Sopenharmony_cideselectTrack(index: number): Promise\<void>
1548e41f4b71Sopenharmony_ci
1549e41f4b71Sopenharmony_ciDeselects an audio track when the AVPlayer is used to play a video with multiple audio tracks. This API uses a promise to return the result.
1550e41f4b71Sopenharmony_ci
1551e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1552e41f4b71Sopenharmony_ci
1553e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1554e41f4b71Sopenharmony_ci
1555e41f4b71Sopenharmony_ci**Parameters**
1556e41f4b71Sopenharmony_ci
1557e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                |
1558e41f4b71Sopenharmony_ci| -------- | -------- | ---- | -------------------- |
1559e41f4b71Sopenharmony_ci| index | number | Yes  | Index of the audio track, which is obtained from [MediaDescription](#mediadescription8).|
1560e41f4b71Sopenharmony_ci
1561e41f4b71Sopenharmony_ci**Return value**
1562e41f4b71Sopenharmony_ci
1563e41f4b71Sopenharmony_ci| Type          | Description                     |
1564e41f4b71Sopenharmony_ci| -------------- | ------------------------- |
1565e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
1566e41f4b71Sopenharmony_ci
1567e41f4b71Sopenharmony_ci**Error codes**
1568e41f4b71Sopenharmony_ci
1569e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
1570e41f4b71Sopenharmony_ci
1571e41f4b71Sopenharmony_ci| ID| Error Message                                 |
1572e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
1573e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Return by promise.       |
1574e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
1575e41f4b71Sopenharmony_ci
1576e41f4b71Sopenharmony_ci**Example**
1577e41f4b71Sopenharmony_ci
1578e41f4b71Sopenharmony_ci```ts
1579e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1580e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit';
1581e41f4b71Sopenharmony_ci
1582e41f4b71Sopenharmony_cilet avPlayer: media.AVPlayer = await media.createAVPlayer();
1583e41f4b71Sopenharmony_cilet audioTrackIndex: Object = 0;
1584e41f4b71Sopenharmony_ciavPlayer.getTrackDescription((error: BusinessError, arrList: Array<media.MediaDescription>) => {
1585e41f4b71Sopenharmony_ci  if (arrList != null) {
1586e41f4b71Sopenharmony_ci    for (let i = 0; i < arrList.length; i++) {
1587e41f4b71Sopenharmony_ci      if (i != 0) {
1588e41f4b71Sopenharmony_ci        // Obtain the audio track list.
1589e41f4b71Sopenharmony_ci        audioTrackIndex = arrList[i][media.MediaDescriptionKey.MD_KEY_TRACK_INDEX];
1590e41f4b71Sopenharmony_ci      }
1591e41f4b71Sopenharmony_ci    }
1592e41f4b71Sopenharmony_ci  } else {
1593e41f4b71Sopenharmony_ci    console.error(`Failed to get TrackDescription, error:${error}`);
1594e41f4b71Sopenharmony_ci  }
1595e41f4b71Sopenharmony_ci});
1596e41f4b71Sopenharmony_ci
1597e41f4b71Sopenharmony_ci// Select an audio track.
1598e41f4b71Sopenharmony_ciavPlayer.selectTrack(parseInt(audioTrackIndex.toString()));
1599e41f4b71Sopenharmony_ci// Deselect the audio track and restore to the default audio track.
1600e41f4b71Sopenharmony_ciavPlayer.deselectTrack(parseInt(audioTrackIndex.toString()));
1601e41f4b71Sopenharmony_ci```
1602e41f4b71Sopenharmony_ci
1603e41f4b71Sopenharmony_ci### setDecryptionConfig<sup>11+</sup>
1604e41f4b71Sopenharmony_ci
1605e41f4b71Sopenharmony_cisetDecryptionConfig(mediaKeySession: drm.MediaKeySession, secureVideoPath: boolean): void
1606e41f4b71Sopenharmony_ci
1607e41f4b71Sopenharmony_ciSets the decryption configuration. When receiving a [mediaKeySystemInfoUpdate event](#onmediakeysysteminfoupdate11), create the related configuration and set the decryption configuration based on the information in the reported event. Otherwise, the playback fails.
1608e41f4b71Sopenharmony_ci
1609e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1610e41f4b71Sopenharmony_ci
1611e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1612e41f4b71Sopenharmony_ci
1613e41f4b71Sopenharmony_ci**Parameters**
1614e41f4b71Sopenharmony_ci
1615e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory| Description                                        |
1616e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------- |
1617e41f4b71Sopenharmony_ci| mediaKeySession | [drm.MediaKeySession](../apis-drm-kit/js-apis-drm.md#mediakeysession) | Yes  | Decryption session.|
1618e41f4b71Sopenharmony_ci| secureVideoPath | boolean | Yes| Secure video channel. The value **true** means that a secure video channel is selected, and **false** means that a non-secure video channel is selected.|
1619e41f4b71Sopenharmony_ci
1620e41f4b71Sopenharmony_ci**Error codes**
1621e41f4b71Sopenharmony_ci
1622e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
1623e41f4b71Sopenharmony_ci
1624e41f4b71Sopenharmony_ci| ID| Error Message                                 |
1625e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
1626e41f4b71Sopenharmony_ci| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. |
1627e41f4b71Sopenharmony_ci
1628e41f4b71Sopenharmony_ci**Example**
1629e41f4b71Sopenharmony_ci
1630e41f4b71Sopenharmony_ciFor details about the DRM module, see [js-apis-drm.md](../apis-drm-kit/js-apis-drm.md).
1631e41f4b71Sopenharmony_ci```ts
1632e41f4b71Sopenharmony_ciimport { drm } from '@kit.DrmKit';
1633e41f4b71Sopenharmony_ci
1634e41f4b71Sopenharmony_ci// Create a media key system.
1635e41f4b71Sopenharmony_cilet keySystem:drm.MediaKeySystem = drm.createMediaKeySystem('com.clearplay.drm');
1636e41f4b71Sopenharmony_ci// Create a media key session.
1637e41f4b71Sopenharmony_cilet keySession:drm.MediaKeySession = keySystem.createMediaKeySession(drm.ContentProtectionLevel.CONTENT_PROTECTION_LEVEL_SW_CRYPTO);
1638e41f4b71Sopenharmony_ci// Generate a media key request and set the response to the media key request.
1639e41f4b71Sopenharmony_ci// Flag indicating whether a secure video channel is used.
1640e41f4b71Sopenharmony_cilet secureVideoPath:boolean = false;
1641e41f4b71Sopenharmony_ci// Set the decryption configuration.
1642e41f4b71Sopenharmony_ciavPlayer.setDecryptionConfig(keySession, secureVideoPath);
1643e41f4b71Sopenharmony_ci```
1644e41f4b71Sopenharmony_ci
1645e41f4b71Sopenharmony_ci### getMediaKeySystemInfos<sup>11+</sup>
1646e41f4b71Sopenharmony_ci
1647e41f4b71Sopenharmony_cigetMediaKeySystemInfos(): Array\<drm.MediaKeySystemInfo>
1648e41f4b71Sopenharmony_ci
1649e41f4b71Sopenharmony_ciObtains the media key system information of the media asset that is being played. This API must be called after the [mediaKeySystemInfoUpdate event](#onmediakeysysteminfoupdate11) is triggered.
1650e41f4b71Sopenharmony_ci
1651e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1652e41f4b71Sopenharmony_ci
1653e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1654e41f4b71Sopenharmony_ci
1655e41f4b71Sopenharmony_ci**Return value**
1656e41f4b71Sopenharmony_ci
1657e41f4b71Sopenharmony_ci| Type                                                  | Description                                             |
1658e41f4b71Sopenharmony_ci| ------------------------------------------------------ | ------------------------------------------------- |
1659e41f4b71Sopenharmony_ci|  Array<[drm.MediaKeySystemInfo](../apis-drm-kit/js-apis-drm.md#mediakeysysteminfo)> | Array of **MediaKeySystemInfo** objects, each of which contains the **uuid** and **pssh** attributes.|
1660e41f4b71Sopenharmony_ci
1661e41f4b71Sopenharmony_ci**Example**
1662e41f4b71Sopenharmony_ci
1663e41f4b71Sopenharmony_ci```ts
1664e41f4b71Sopenharmony_ciimport { drm } from '@kit.DrmKit';
1665e41f4b71Sopenharmony_ci
1666e41f4b71Sopenharmony_ciconst infos = avPlayer.getMediaKeySystemInfos();
1667e41f4b71Sopenharmony_ciconsole.info('GetMediaKeySystemInfos count: ' + infos.length);
1668e41f4b71Sopenharmony_cifor (let i = 0; i < infos.length; i++) {
1669e41f4b71Sopenharmony_ci  console.info('GetMediaKeySystemInfos uuid: ' + infos[i]["uuid"]);
1670e41f4b71Sopenharmony_ci  console.info('GetMediaKeySystemInfos pssh: ' + infos[i]["pssh"]);
1671e41f4b71Sopenharmony_ci}
1672e41f4b71Sopenharmony_ci```
1673e41f4b71Sopenharmony_ci
1674e41f4b71Sopenharmony_ci### seek<sup>9+</sup>
1675e41f4b71Sopenharmony_ci
1676e41f4b71Sopenharmony_ciseek(timeMs: number, mode?:SeekMode): void
1677e41f4b71Sopenharmony_ci
1678e41f4b71Sopenharmony_ciSeeks to the specified playback position. This API can be called only when the AVPlayer is in the prepared, playing, paused, or completed state. You can check whether the seek operation takes effect by subscribing to the [seekDone](#onseekdone9) event.
1679e41f4b71Sopenharmony_ciThis API is not supported in live mode.
1680e41f4b71Sopenharmony_ci
1681e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1682e41f4b71Sopenharmony_ci
1683e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1684e41f4b71Sopenharmony_ci
1685e41f4b71Sopenharmony_ci**Parameters**
1686e41f4b71Sopenharmony_ci
1687e41f4b71Sopenharmony_ci| Name| Type                  | Mandatory| Description                                                        |
1688e41f4b71Sopenharmony_ci| ------ | ---------------------- | ---- | ------------------------------------------------------------ |
1689e41f4b71Sopenharmony_ci| timeMs | number                 | Yes  | Position to seek to, in ms. The value range is [0, [duration](#attributes)].|
1690e41f4b71Sopenharmony_ci| mode   | [SeekMode](#seekmode8) | No  | Seek mode based on the video I frame. The default value is **SEEK_PREV_SYNC**. **Set this parameter only for video playback.**|
1691e41f4b71Sopenharmony_ci
1692e41f4b71Sopenharmony_ci**Example**
1693e41f4b71Sopenharmony_ci
1694e41f4b71Sopenharmony_ci```ts
1695e41f4b71Sopenharmony_cilet seekTime: number = 1000
1696e41f4b71Sopenharmony_ciavPlayer.seek(seekTime, media.SeekMode.SEEK_PREV_SYNC)
1697e41f4b71Sopenharmony_ci```
1698e41f4b71Sopenharmony_ci
1699e41f4b71Sopenharmony_ci### on('seekDone')<sup>9+</sup>
1700e41f4b71Sopenharmony_ci
1701e41f4b71Sopenharmony_cion(type: 'seekDone', callback: Callback\<number>): void
1702e41f4b71Sopenharmony_ci
1703e41f4b71Sopenharmony_ciSubscribes to the event to check whether the seek operation takes effect.
1704e41f4b71Sopenharmony_ci
1705e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1706e41f4b71Sopenharmony_ci
1707e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1708e41f4b71Sopenharmony_ci
1709e41f4b71Sopenharmony_ci**Parameters**
1710e41f4b71Sopenharmony_ci
1711e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
1712e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
1713e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'seekDone'** in this case. This event is triggered each time **seek()** is called.|
1714e41f4b71Sopenharmony_ci| callback | Callback\<number> | Yes  | Callback invoked when the event is triggered. It reports the time position requested by the user.<br>For video playback, [SeekMode](#seekmode8) may cause the actual position to be different from that requested by the user. The exact position can be obtained from the **currentTime** attribute. The time in this callback only means that the requested seek operation is complete.|
1715e41f4b71Sopenharmony_ci
1716e41f4b71Sopenharmony_ci**Example**
1717e41f4b71Sopenharmony_ci
1718e41f4b71Sopenharmony_ci```ts
1719e41f4b71Sopenharmony_ciavPlayer.on('seekDone', (seekDoneTime:number) => {
1720e41f4b71Sopenharmony_ci  console.info('seekDone called,and seek time is:' + seekDoneTime)
1721e41f4b71Sopenharmony_ci})
1722e41f4b71Sopenharmony_ci```
1723e41f4b71Sopenharmony_ci
1724e41f4b71Sopenharmony_ci### off('seekDone')<sup>9+</sup>
1725e41f4b71Sopenharmony_ci
1726e41f4b71Sopenharmony_cioff(type: 'seekDone', callback?: Callback\<number>): void
1727e41f4b71Sopenharmony_ci
1728e41f4b71Sopenharmony_ciUnsubscribes from the event that checks whether the seek operation takes effect.
1729e41f4b71Sopenharmony_ci
1730e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1731e41f4b71Sopenharmony_ci
1732e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1733e41f4b71Sopenharmony_ci
1734e41f4b71Sopenharmony_ci**Parameters**
1735e41f4b71Sopenharmony_ci
1736e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                |
1737e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------------------------------------------------- |
1738e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'seekDone'** in this case.|
1739e41f4b71Sopenharmony_ci| callback | Callback\<number> | No  | Callback invoked when the event is triggered. It reports the time position requested by the user.<br>For video playback, [SeekMode](#seekmode8) may cause the actual position to be different from that requested by the user. The exact position can be obtained from the **currentTime** attribute. The time in this callback only means that the requested seek operation is complete.<br>This parameter is supported since API version 12.|
1740e41f4b71Sopenharmony_ci
1741e41f4b71Sopenharmony_ci**Example**
1742e41f4b71Sopenharmony_ci
1743e41f4b71Sopenharmony_ci```ts
1744e41f4b71Sopenharmony_ciavPlayer.off('seekDone')
1745e41f4b71Sopenharmony_ci```
1746e41f4b71Sopenharmony_ci
1747e41f4b71Sopenharmony_ci### setSpeed<sup>9+</sup>
1748e41f4b71Sopenharmony_ci
1749e41f4b71Sopenharmony_cisetSpeed(speed: PlaybackSpeed): void
1750e41f4b71Sopenharmony_ci
1751e41f4b71Sopenharmony_ciSets the playback speed. This API can be called only when the AVPlayer is in the prepared, playing, paused, or completed state. You can check whether the setting takes effect by subscribing to the [speedDone](#onspeeddone9) event.
1752e41f4b71Sopenharmony_ciThis API is not supported in live mode.
1753e41f4b71Sopenharmony_ci
1754e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1755e41f4b71Sopenharmony_ci
1756e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1757e41f4b71Sopenharmony_ci
1758e41f4b71Sopenharmony_ci**Parameters**
1759e41f4b71Sopenharmony_ci
1760e41f4b71Sopenharmony_ci| Name| Type                            | Mandatory| Description              |
1761e41f4b71Sopenharmony_ci| ------ | -------------------------------- | ---- | ------------------ |
1762e41f4b71Sopenharmony_ci| speed  | [PlaybackSpeed](#playbackspeed8) | Yes  | Playback speed to set.|
1763e41f4b71Sopenharmony_ci
1764e41f4b71Sopenharmony_ci**Example**
1765e41f4b71Sopenharmony_ci
1766e41f4b71Sopenharmony_ci```ts
1767e41f4b71Sopenharmony_ciavPlayer.setSpeed(media.PlaybackSpeed.SPEED_FORWARD_2_00_X)
1768e41f4b71Sopenharmony_ci```
1769e41f4b71Sopenharmony_ci
1770e41f4b71Sopenharmony_ci### on('speedDone')<sup>9+</sup>
1771e41f4b71Sopenharmony_ci
1772e41f4b71Sopenharmony_cion(type: 'speedDone', callback: Callback\<number>): void
1773e41f4b71Sopenharmony_ci
1774e41f4b71Sopenharmony_ciSubscribes to the event to check whether the playback speed is successfully set.
1775e41f4b71Sopenharmony_ci
1776e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1777e41f4b71Sopenharmony_ci
1778e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1779e41f4b71Sopenharmony_ci
1780e41f4b71Sopenharmony_ci**Parameters**
1781e41f4b71Sopenharmony_ci
1782e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
1783e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
1784e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'speedDone'** in this case. This event is triggered each time **setSpeed()** is called.|
1785e41f4b71Sopenharmony_ci| callback | Callback\<number> | Yes  | Callback used to return the result. When the call of **setSpeed** is successful, the effective speed mode is reported. For details, see [PlaybackSpeed](#playbackspeed8).|
1786e41f4b71Sopenharmony_ci
1787e41f4b71Sopenharmony_ci**Example**
1788e41f4b71Sopenharmony_ci
1789e41f4b71Sopenharmony_ci```ts
1790e41f4b71Sopenharmony_ciavPlayer.on('speedDone', (speed:number) => {
1791e41f4b71Sopenharmony_ci  console.info('speedDone called,and speed value is:' + speed)
1792e41f4b71Sopenharmony_ci})
1793e41f4b71Sopenharmony_ci```
1794e41f4b71Sopenharmony_ci
1795e41f4b71Sopenharmony_ci### off('speedDone')<sup>9+</sup>
1796e41f4b71Sopenharmony_ci
1797e41f4b71Sopenharmony_cioff(type: 'speedDone', callback?: Callback\<number>): void
1798e41f4b71Sopenharmony_ci
1799e41f4b71Sopenharmony_ciUnsubscribes from the event that checks whether the playback speed is successfully set.
1800e41f4b71Sopenharmony_ci
1801e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1802e41f4b71Sopenharmony_ci
1803e41f4b71Sopenharmony_ci**Parameters**
1804e41f4b71Sopenharmony_ci
1805e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                     |
1806e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------------------------------------------------- |
1807e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'speedDone'** in this case.|
1808e41f4b71Sopenharmony_ci| callback | Callback\<number> | No  | Callback used to return the result. When the call of **setSpeed** is successful, the effective speed mode is reported. For details, see [PlaybackSpeed](#playbackspeed8).<br>This parameter is supported since API version 12.|
1809e41f4b71Sopenharmony_ci
1810e41f4b71Sopenharmony_ci**Example**
1811e41f4b71Sopenharmony_ci
1812e41f4b71Sopenharmony_ci```ts
1813e41f4b71Sopenharmony_ciavPlayer.off('speedDone')
1814e41f4b71Sopenharmony_ci```
1815e41f4b71Sopenharmony_ci
1816e41f4b71Sopenharmony_ci### setBitrate<sup>9+</sup>
1817e41f4b71Sopenharmony_ci
1818e41f4b71Sopenharmony_cisetBitrate(bitrate: number): void
1819e41f4b71Sopenharmony_ci
1820e41f4b71Sopenharmony_ciSets the bit rate, which is valid only for HTTP Live Streaming (HLS) streams. This API can be called only when the AVPlayer is in the prepared, playing, paused, or completed state. You can check whether the setting takes effect by subscribing to the [bitrateDone](#onbitratedone9) event. Note that the AVPlayer selects a proper bit rate based on the network connection speed.
1821e41f4b71Sopenharmony_ci
1822e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1823e41f4b71Sopenharmony_ci
1824e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1825e41f4b71Sopenharmony_ci
1826e41f4b71Sopenharmony_ci**Parameters**
1827e41f4b71Sopenharmony_ci
1828e41f4b71Sopenharmony_ci| Name | Type  | Mandatory| Description                                                        |
1829e41f4b71Sopenharmony_ci| ------- | ------ | ---- | ------------------------------------------------------------ |
1830e41f4b71Sopenharmony_ci| bitrate | number | Yes  | Bit rate to set. You can obtain the available bit rates of the current HLS stream by subscribing to the [availableBitrates](#onavailablebitrates9) event. If the bit rate to set is not in the list of the available bit rates, the AVPlayer selects from the list the minimum bit rate that is closed to the bit rate to set. If the length of the available bit rate list obtained through the event is 0, no bit rate can be set and the **bitrateDone** callback will not be triggered.|
1831e41f4b71Sopenharmony_ci
1832e41f4b71Sopenharmony_ci**Example**
1833e41f4b71Sopenharmony_ci
1834e41f4b71Sopenharmony_ci```ts
1835e41f4b71Sopenharmony_cilet bitrate: number = 96000
1836e41f4b71Sopenharmony_ciavPlayer.setBitrate(bitrate)
1837e41f4b71Sopenharmony_ci```
1838e41f4b71Sopenharmony_ci
1839e41f4b71Sopenharmony_ci### on('bitrateDone')<sup>9+</sup>
1840e41f4b71Sopenharmony_ci
1841e41f4b71Sopenharmony_cion(type: 'bitrateDone', callback: Callback\<number>): void
1842e41f4b71Sopenharmony_ci
1843e41f4b71Sopenharmony_ciSubscribes to the event to check whether the bit rate is successfully set.
1844e41f4b71Sopenharmony_ci
1845e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1846e41f4b71Sopenharmony_ci
1847e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1848e41f4b71Sopenharmony_ci
1849e41f4b71Sopenharmony_ci**Parameters**
1850e41f4b71Sopenharmony_ci
1851e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
1852e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
1853e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'bitrateDone'** in this case. This event is triggered each time **setBitrate()** is called.|
1854e41f4b71Sopenharmony_ci| callback | Callback\<number> | Yes  | Callback invoked when the event is triggered. It reports the effective bit rate.            |
1855e41f4b71Sopenharmony_ci
1856e41f4b71Sopenharmony_ci**Example**
1857e41f4b71Sopenharmony_ci
1858e41f4b71Sopenharmony_ci```ts
1859e41f4b71Sopenharmony_ciavPlayer.on('bitrateDone', (bitrate:number) => {
1860e41f4b71Sopenharmony_ci  console.info('bitrateDone called,and bitrate value is:' + bitrate)
1861e41f4b71Sopenharmony_ci})
1862e41f4b71Sopenharmony_ci```
1863e41f4b71Sopenharmony_ci
1864e41f4b71Sopenharmony_ci### off('bitrateDone')<sup>9+</sup>
1865e41f4b71Sopenharmony_ci
1866e41f4b71Sopenharmony_cioff(type: 'bitrateDone', callback?: Callback\<number>): void
1867e41f4b71Sopenharmony_ci
1868e41f4b71Sopenharmony_ciUnsubscribes from the event that checks whether the bit rate is successfully set.
1869e41f4b71Sopenharmony_ci
1870e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1871e41f4b71Sopenharmony_ci
1872e41f4b71Sopenharmony_ci**Parameters**
1873e41f4b71Sopenharmony_ci
1874e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
1875e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
1876e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'bitrateDone'** in this case.|
1877e41f4b71Sopenharmony_ci| callback | Callback\<number> | No  | Callback invoked when the event is triggered. It reports the effective bit rate.<br>This parameter is supported since API version 12.            |
1878e41f4b71Sopenharmony_ci
1879e41f4b71Sopenharmony_ci**Example**
1880e41f4b71Sopenharmony_ci
1881e41f4b71Sopenharmony_ci```ts
1882e41f4b71Sopenharmony_ciavPlayer.off('bitrateDone')
1883e41f4b71Sopenharmony_ci```
1884e41f4b71Sopenharmony_ci
1885e41f4b71Sopenharmony_ci### on('availableBitrates')<sup>9+</sup>
1886e41f4b71Sopenharmony_ci
1887e41f4b71Sopenharmony_cion(type: 'availableBitrates', callback: Callback\<Array\<number>>): void
1888e41f4b71Sopenharmony_ci
1889e41f4b71Sopenharmony_ciSubscribes to available bit rates of HLS streams. This event is reported only after the AVPlayer switches to the prepared state.
1890e41f4b71Sopenharmony_ci
1891e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1892e41f4b71Sopenharmony_ci
1893e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1894e41f4b71Sopenharmony_ci
1895e41f4b71Sopenharmony_ci**Parameters**
1896e41f4b71Sopenharmony_ci
1897e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
1898e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
1899e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'availableBitrates'** in this case. This event is triggered once after the AVPlayer switches to the prepared state.|
1900e41f4b71Sopenharmony_ci| callback | Callback\<Array\<number>> | Yes  | Callback invoked when the event is triggered. It returns an array that holds the available bit rates. If the array length is 0, no bit rate can be set.|
1901e41f4b71Sopenharmony_ci
1902e41f4b71Sopenharmony_ci**Example**
1903e41f4b71Sopenharmony_ci
1904e41f4b71Sopenharmony_ci```ts
1905e41f4b71Sopenharmony_ciavPlayer.on('availableBitrates', (bitrates: Array<number>) => {
1906e41f4b71Sopenharmony_ci  console.info('availableBitrates called,and availableBitrates length is:' + bitrates.length)
1907e41f4b71Sopenharmony_ci})
1908e41f4b71Sopenharmony_ci```
1909e41f4b71Sopenharmony_ci
1910e41f4b71Sopenharmony_ci### off('availableBitrates')<sup>9+</sup>
1911e41f4b71Sopenharmony_ci
1912e41f4b71Sopenharmony_cioff(type: 'availableBitrates', callback?: Callback\<Array\<number>>): void
1913e41f4b71Sopenharmony_ci
1914e41f4b71Sopenharmony_ciUnsubscribes from available bit rates of HLS streams. This event is reported after [prepare](#prepare9) is called.
1915e41f4b71Sopenharmony_ci
1916e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1917e41f4b71Sopenharmony_ci
1918e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1919e41f4b71Sopenharmony_ci
1920e41f4b71Sopenharmony_ci**Parameters**
1921e41f4b71Sopenharmony_ci
1922e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
1923e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
1924e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'availableBitrates'** in this case.|
1925e41f4b71Sopenharmony_ci| callback | Callback\<Array\<number>> | No  | Callback invoked when the event is triggered. It returns an array that holds the available bit rates. If the array length is 0, no bit rate can be set.<br>This parameter is supported since API version 12.|
1926e41f4b71Sopenharmony_ci
1927e41f4b71Sopenharmony_ci**Example**
1928e41f4b71Sopenharmony_ci
1929e41f4b71Sopenharmony_ci```ts
1930e41f4b71Sopenharmony_ciavPlayer.off('availableBitrates')
1931e41f4b71Sopenharmony_ci```
1932e41f4b71Sopenharmony_ci
1933e41f4b71Sopenharmony_ci
1934e41f4b71Sopenharmony_ci### on('mediaKeySystemInfoUpdate')<sup>11+</sup>
1935e41f4b71Sopenharmony_ci
1936e41f4b71Sopenharmony_cion(type: 'mediaKeySystemInfoUpdate', callback: Callback\<Array\<drm.MediaKeySystemInfo>>): void
1937e41f4b71Sopenharmony_ci
1938e41f4b71Sopenharmony_ciSubscribes to media key system information changes.
1939e41f4b71Sopenharmony_ci
1940e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1941e41f4b71Sopenharmony_ci
1942e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1943e41f4b71Sopenharmony_ci
1944e41f4b71Sopenharmony_ci**Parameters**
1945e41f4b71Sopenharmony_ci
1946e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
1947e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
1948e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'mediaKeySystemInfoUpdate'** in this case. This event is triggered when the copyright protection information of the media asset being played changes.|
1949e41f4b71Sopenharmony_ci| callback | Callback\<Array\<drm.[MediaKeySystemInfo](../apis-drm-kit/js-apis-drm.md#mediakeysysteminfo)>> | Yes  | Callback invoked when the event is triggered. It reports a **MediaKeySystemInfo** array.|
1950e41f4b71Sopenharmony_ci
1951e41f4b71Sopenharmony_ci**Example**
1952e41f4b71Sopenharmony_ci
1953e41f4b71Sopenharmony_ci```ts
1954e41f4b71Sopenharmony_ciimport { drm } from '@kit.DrmKit';
1955e41f4b71Sopenharmony_ci
1956e41f4b71Sopenharmony_ciavPlayer.on('mediaKeySystemInfoUpdate', (mediaKeySystemInfo: Array<drm.MediaKeySystemInfo>) => {
1957e41f4b71Sopenharmony_ci    for (let i = 0; i < mediaKeySystemInfo.length; i++) {
1958e41f4b71Sopenharmony_ci      console.info('mediaKeySystemInfoUpdate happened uuid: ' + mediaKeySystemInfo[i]["uuid"]);
1959e41f4b71Sopenharmony_ci      console.info('mediaKeySystemInfoUpdate happened pssh: ' + mediaKeySystemInfo[i]["pssh"]);
1960e41f4b71Sopenharmony_ci    }
1961e41f4b71Sopenharmony_ci})
1962e41f4b71Sopenharmony_ci```
1963e41f4b71Sopenharmony_ci
1964e41f4b71Sopenharmony_ci### off('mediaKeySystemInfoUpdate')<sup>11+</sup>
1965e41f4b71Sopenharmony_ci
1966e41f4b71Sopenharmony_cioff(type: 'mediaKeySystemInfoUpdate', callback?: Callback\<Array\<drm.MediaKeySystemInfo>>): void;
1967e41f4b71Sopenharmony_ci
1968e41f4b71Sopenharmony_ciUnsubscribes from media key system information changes.
1969e41f4b71Sopenharmony_ci
1970e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1971e41f4b71Sopenharmony_ci
1972e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1973e41f4b71Sopenharmony_ci
1974e41f4b71Sopenharmony_ci**Parameters**
1975e41f4b71Sopenharmony_ci
1976e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
1977e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
1978e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'mediaKeySystemInfoUpdate'** in this case.|
1979e41f4b71Sopenharmony_ci| callback | Callback\<Array\<drm.[MediaKeySystemInfo](../apis-drm-kit/js-apis-drm.md#mediakeysysteminfo)>> | No  | Callback invoked when the event is triggered. It reports a **MediaKeySystemInfo** array. If this parameter is specified, only the specified callback is unregistered. Otherwise, all callbacks associated with the specified event will be unregistered.|
1980e41f4b71Sopenharmony_ci
1981e41f4b71Sopenharmony_ci**Example**
1982e41f4b71Sopenharmony_ci
1983e41f4b71Sopenharmony_ci```ts
1984e41f4b71Sopenharmony_ciavPlayer.off('mediaKeySystemInfoUpdate')
1985e41f4b71Sopenharmony_ci```
1986e41f4b71Sopenharmony_ci
1987e41f4b71Sopenharmony_ci### setVolume<sup>9+</sup>
1988e41f4b71Sopenharmony_ci
1989e41f4b71Sopenharmony_cisetVolume(volume: number): void
1990e41f4b71Sopenharmony_ci
1991e41f4b71Sopenharmony_ciSets the volume. This API can be called only when the AVPlayer is in the prepared, playing, paused, or completed state. You can check whether the setting takes effect by subscribing to the [volumeChange](#onvolumechange9) event.
1992e41f4b71Sopenharmony_ci
1993e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1994e41f4b71Sopenharmony_ci
1995e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
1996e41f4b71Sopenharmony_ci
1997e41f4b71Sopenharmony_ci**Parameters**
1998e41f4b71Sopenharmony_ci
1999e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
2000e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
2001e41f4b71Sopenharmony_ci| volume | number | Yes  | Relative volume. The value ranges from 0.00 to 1.00. The value **1.00** indicates the maximum volume (100%).|
2002e41f4b71Sopenharmony_ci
2003e41f4b71Sopenharmony_ci**Example**
2004e41f4b71Sopenharmony_ci
2005e41f4b71Sopenharmony_ci```ts
2006e41f4b71Sopenharmony_cilet volume: number = 1.0
2007e41f4b71Sopenharmony_ciavPlayer.setVolume(volume)
2008e41f4b71Sopenharmony_ci```
2009e41f4b71Sopenharmony_ci
2010e41f4b71Sopenharmony_ci### on('volumeChange')<sup>9+</sup>
2011e41f4b71Sopenharmony_ci
2012e41f4b71Sopenharmony_cion(type: 'volumeChange', callback: Callback\<number>): void
2013e41f4b71Sopenharmony_ci
2014e41f4b71Sopenharmony_ciSubscribes to the event to check whether the volume is successfully set.
2015e41f4b71Sopenharmony_ci
2016e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2017e41f4b71Sopenharmony_ci
2018e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2019e41f4b71Sopenharmony_ci
2020e41f4b71Sopenharmony_ci**Parameters**
2021e41f4b71Sopenharmony_ci
2022e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
2023e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
2024e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'volumeChange'** in this case. This event is triggered each time **setVolume()** is called.|
2025e41f4b71Sopenharmony_ci| callback | Callback\<number> | Yes  | Callback invoked when the event is triggered. It reports the effective volume.           |
2026e41f4b71Sopenharmony_ci
2027e41f4b71Sopenharmony_ci**Example**
2028e41f4b71Sopenharmony_ci
2029e41f4b71Sopenharmony_ci```ts
2030e41f4b71Sopenharmony_ciavPlayer.on('volumeChange', (vol: number) => {
2031e41f4b71Sopenharmony_ci  console.info('volumeChange called,and new volume is :' + vol)
2032e41f4b71Sopenharmony_ci})
2033e41f4b71Sopenharmony_ci```
2034e41f4b71Sopenharmony_ci
2035e41f4b71Sopenharmony_ci### off('volumeChange')<sup>9+</sup>
2036e41f4b71Sopenharmony_ci
2037e41f4b71Sopenharmony_cioff(type: 'volumeChange', callback?: Callback\<number>): void
2038e41f4b71Sopenharmony_ci
2039e41f4b71Sopenharmony_ciUnsubscribes from the event that checks whether the volume is successfully set.
2040e41f4b71Sopenharmony_ci
2041e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2042e41f4b71Sopenharmony_ci
2043e41f4b71Sopenharmony_ci**Parameters**
2044e41f4b71Sopenharmony_ci
2045e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
2046e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
2047e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'volumeChange'** in this case.|
2048e41f4b71Sopenharmony_ci| callback | Callback\<number> | No  | Callback invoked when the event is triggered. It reports the effective volume.<br>This parameter is supported since API version 12.           |
2049e41f4b71Sopenharmony_ci
2050e41f4b71Sopenharmony_ci**Example**
2051e41f4b71Sopenharmony_ci
2052e41f4b71Sopenharmony_ci```ts
2053e41f4b71Sopenharmony_ciavPlayer.off('volumeChange')
2054e41f4b71Sopenharmony_ci```
2055e41f4b71Sopenharmony_ci
2056e41f4b71Sopenharmony_ci### on('endOfStream')<sup>9+</sup>
2057e41f4b71Sopenharmony_ci
2058e41f4b71Sopenharmony_cion(type: 'endOfStream', callback: Callback\<void>): void
2059e41f4b71Sopenharmony_ci
2060e41f4b71Sopenharmony_ciSubscribes to the event that indicates the end of the stream being played. If **[loop](#attributes) = true** is set, the AVPlayer seeks to the beginning of the stream and plays the stream again. If **loop** is not set, the completed state is reported through the [stateChange](#onstatechange9) event.
2061e41f4b71Sopenharmony_ci
2062e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2063e41f4b71Sopenharmony_ci
2064e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2065e41f4b71Sopenharmony_ci
2066e41f4b71Sopenharmony_ci**Parameters**
2067e41f4b71Sopenharmony_ci
2068e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
2069e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
2070e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'endOfStream'** in this case. This event is triggered when the AVPlayer finishes playing the media asset.|
2071e41f4b71Sopenharmony_ci| callback | Callback\<void> | Yes  | Callback invoked when the event is triggered.                              |
2072e41f4b71Sopenharmony_ci
2073e41f4b71Sopenharmony_ci**Example**
2074e41f4b71Sopenharmony_ci
2075e41f4b71Sopenharmony_ci```ts
2076e41f4b71Sopenharmony_ciavPlayer.on('endOfStream', () => {
2077e41f4b71Sopenharmony_ci  console.info('endOfStream called')
2078e41f4b71Sopenharmony_ci})
2079e41f4b71Sopenharmony_ci```
2080e41f4b71Sopenharmony_ci
2081e41f4b71Sopenharmony_ci### off('endOfStream')<sup>9+</sup>
2082e41f4b71Sopenharmony_ci
2083e41f4b71Sopenharmony_cioff(type: 'endOfStream', callback?: Callback\<void>): void
2084e41f4b71Sopenharmony_ci
2085e41f4b71Sopenharmony_ciUnsubscribes from the event that indicates the end of the stream being played.
2086e41f4b71Sopenharmony_ci
2087e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2088e41f4b71Sopenharmony_ci
2089e41f4b71Sopenharmony_ci**Parameters**
2090e41f4b71Sopenharmony_ci
2091e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
2092e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
2093e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'endOfStream'** in this case.|
2094e41f4b71Sopenharmony_ci| callback | Callback\<void> | No  | Callback invoked when the event is triggered.<br>This parameter is supported since API version 12.                              |
2095e41f4b71Sopenharmony_ci
2096e41f4b71Sopenharmony_ci**Example**
2097e41f4b71Sopenharmony_ci
2098e41f4b71Sopenharmony_ci```ts
2099e41f4b71Sopenharmony_ciavPlayer.off('endOfStream')
2100e41f4b71Sopenharmony_ci```
2101e41f4b71Sopenharmony_ci
2102e41f4b71Sopenharmony_ci### on('timeUpdate')<sup>9+</sup>
2103e41f4b71Sopenharmony_ci
2104e41f4b71Sopenharmony_cion(type: 'timeUpdate', callback: Callback\<number>): void
2105e41f4b71Sopenharmony_ci
2106e41f4b71Sopenharmony_ciSubscribes to playback position changes. It is used to refresh the current position of the progress bar. By default, this event is reported every 100 ms. However, it is reported immediately upon a successful seek operation.
2107e41f4b71Sopenharmony_ci
2108e41f4b71Sopenharmony_ciThe **'timeUpdate'** event is not supported in live mode.
2109e41f4b71Sopenharmony_ci
2110e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2111e41f4b71Sopenharmony_ci
2112e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2113e41f4b71Sopenharmony_ci
2114e41f4b71Sopenharmony_ci**Parameters**
2115e41f4b71Sopenharmony_ci
2116e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                          |
2117e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ---------------------------------------------- |
2118e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'timeUpdate'** in this case.|
2119e41f4b71Sopenharmony_ci| callback | Callback\<number> | Yes  | Callback used to return the current time.                                    |
2120e41f4b71Sopenharmony_ci
2121e41f4b71Sopenharmony_ci**Example**
2122e41f4b71Sopenharmony_ci
2123e41f4b71Sopenharmony_ci```ts
2124e41f4b71Sopenharmony_ciavPlayer.on('timeUpdate', (time:number) => {
2125e41f4b71Sopenharmony_ci  console.info('timeUpdate called,and new time is :' + time)
2126e41f4b71Sopenharmony_ci})
2127e41f4b71Sopenharmony_ci```
2128e41f4b71Sopenharmony_ci
2129e41f4b71Sopenharmony_ci### off('timeUpdate')<sup>9+</sup>
2130e41f4b71Sopenharmony_ci
2131e41f4b71Sopenharmony_cioff(type: 'timeUpdate', callback?: Callback\<number>): void
2132e41f4b71Sopenharmony_ci
2133e41f4b71Sopenharmony_ciUnsubscribes from playback position changes.
2134e41f4b71Sopenharmony_ci
2135e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2136e41f4b71Sopenharmony_ci
2137e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2138e41f4b71Sopenharmony_ci
2139e41f4b71Sopenharmony_ci**Parameters**
2140e41f4b71Sopenharmony_ci
2141e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                              |
2142e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------------------------------------- |
2143e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'timeUpdate'** in this case.|
2144e41f4b71Sopenharmony_ci| callback | Callback\<number> | No  | Callback used to return the current time.<br>This parameter is supported since API version 12.            |
2145e41f4b71Sopenharmony_ci
2146e41f4b71Sopenharmony_ci**Example**
2147e41f4b71Sopenharmony_ci
2148e41f4b71Sopenharmony_ci```ts
2149e41f4b71Sopenharmony_ciavPlayer.off('timeUpdate')
2150e41f4b71Sopenharmony_ci```
2151e41f4b71Sopenharmony_ci
2152e41f4b71Sopenharmony_ci### on('durationUpdate')<sup>9+</sup>
2153e41f4b71Sopenharmony_ci
2154e41f4b71Sopenharmony_ci
2155e41f4b71Sopenharmony_cion(type: 'durationUpdate', callback: Callback\<number>): void
2156e41f4b71Sopenharmony_ci
2157e41f4b71Sopenharmony_ciSubscribes to media asset duration changes. It is used to refresh the length of the progress bar. By default, this event is reported once in the prepared state. However, it can be repeatedly reported for special streams that trigger duration changes.
2158e41f4b71Sopenharmony_ciThe **'durationUpdate'** event is not supported in live mode.
2159e41f4b71Sopenharmony_ci
2160e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2161e41f4b71Sopenharmony_ci
2162e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2163e41f4b71Sopenharmony_ci
2164e41f4b71Sopenharmony_ci**Parameters**
2165e41f4b71Sopenharmony_ci
2166e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                              |
2167e41f4b71Sopenharmony_ci| -------- | -------- | ---- | -------------------------------------------------- |
2168e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'durationUpdate'** in this case.|
2169e41f4b71Sopenharmony_ci| callback | Callback\<number> | Yes  | Callback used to return the resource duration.       |
2170e41f4b71Sopenharmony_ci
2171e41f4b71Sopenharmony_ci**Example**
2172e41f4b71Sopenharmony_ci
2173e41f4b71Sopenharmony_ci```ts
2174e41f4b71Sopenharmony_ciavPlayer.on('durationUpdate', (duration: number) => {
2175e41f4b71Sopenharmony_ci  console.info('durationUpdate called,new duration is :' + duration)
2176e41f4b71Sopenharmony_ci})
2177e41f4b71Sopenharmony_ci```
2178e41f4b71Sopenharmony_ci
2179e41f4b71Sopenharmony_ci### off('durationUpdate')<sup>9+</sup>
2180e41f4b71Sopenharmony_ci
2181e41f4b71Sopenharmony_cioff(type: 'durationUpdate', callback?: Callback\<number>): void
2182e41f4b71Sopenharmony_ci
2183e41f4b71Sopenharmony_ciUnsubscribes from media asset duration changes.
2184e41f4b71Sopenharmony_ci
2185e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2186e41f4b71Sopenharmony_ci
2187e41f4b71Sopenharmony_ci**Parameters**
2188e41f4b71Sopenharmony_ci
2189e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                  |
2190e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------ |
2191e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'durationUpdate'** in this case.|
2192e41f4b71Sopenharmony_ci| callback | Callback\<number> | No  | Callback used to return the resource duration.<br>This parameter is supported since API version 12.       |
2193e41f4b71Sopenharmony_ci
2194e41f4b71Sopenharmony_ci**Example**
2195e41f4b71Sopenharmony_ci
2196e41f4b71Sopenharmony_ci```ts
2197e41f4b71Sopenharmony_ciavPlayer.off('durationUpdate')
2198e41f4b71Sopenharmony_ci```
2199e41f4b71Sopenharmony_ci
2200e41f4b71Sopenharmony_ci### on('bufferingUpdate')<sup>9+</sup>
2201e41f4b71Sopenharmony_ci
2202e41f4b71Sopenharmony_cion(type: 'bufferingUpdate', callback: OnBufferingUpdateHandler): void
2203e41f4b71Sopenharmony_ci
2204e41f4b71Sopenharmony_ciSubscribes to audio and video buffer changes. This subscription is supported only in network playback scenarios.
2205e41f4b71Sopenharmony_ci
2206e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2207e41f4b71Sopenharmony_ci
2208e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2209e41f4b71Sopenharmony_ci
2210e41f4b71Sopenharmony_ci**Parameters**
2211e41f4b71Sopenharmony_ci
2212e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
2213e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
2214e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'bufferingUpdate'** in this case.       |
2215e41f4b71Sopenharmony_ci| callback | [OnBufferingUpdateHandler](#onbufferingupdatehandler12) | Yes  | Callback invoked when the event is triggered.|
2216e41f4b71Sopenharmony_ci
2217e41f4b71Sopenharmony_ci**Example**
2218e41f4b71Sopenharmony_ci
2219e41f4b71Sopenharmony_ci```ts
2220e41f4b71Sopenharmony_ciavPlayer.on('bufferingUpdate', (infoType: media.BufferingInfoType, value: number) => {
2221e41f4b71Sopenharmony_ci  console.info('bufferingUpdate called,and infoType value is:' + infoType + ', value is :' + value)
2222e41f4b71Sopenharmony_ci})
2223e41f4b71Sopenharmony_ci```
2224e41f4b71Sopenharmony_ci
2225e41f4b71Sopenharmony_ci### off('bufferingUpdate')<sup>9+</sup>
2226e41f4b71Sopenharmony_ci
2227e41f4b71Sopenharmony_cioff(type: 'bufferingUpdate', callback?: OnBufferingUpdateHandler): void
2228e41f4b71Sopenharmony_ci
2229e41f4b71Sopenharmony_ciUnsubscribes from audio and video buffer changes. 
2230e41f4b71Sopenharmony_ci
2231e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2232e41f4b71Sopenharmony_ci
2233e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2234e41f4b71Sopenharmony_ci
2235e41f4b71Sopenharmony_ci**Parameters**
2236e41f4b71Sopenharmony_ci
2237e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                     |
2238e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------------------------------------------------- |
2239e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'bufferingUpdate'** in this case.|
2240e41f4b71Sopenharmony_ci| callback | [OnBufferingUpdateHandler](#onbufferingupdatehandler12) | No  | Callback invoked when the event is triggered.|
2241e41f4b71Sopenharmony_ci
2242e41f4b71Sopenharmony_ci**Example**
2243e41f4b71Sopenharmony_ci
2244e41f4b71Sopenharmony_ci```ts
2245e41f4b71Sopenharmony_ciavPlayer.off('bufferingUpdate')
2246e41f4b71Sopenharmony_ci```
2247e41f4b71Sopenharmony_ci
2248e41f4b71Sopenharmony_ci### on('startRenderFrame')<sup>9+</sup>
2249e41f4b71Sopenharmony_ci
2250e41f4b71Sopenharmony_cion(type: 'startRenderFrame', callback: Callback\<void>): void
2251e41f4b71Sopenharmony_ci
2252e41f4b71Sopenharmony_ciSubscribes to the event that indicates rendering starts for the first frame. This subscription is supported only in video playback scenarios. This event only means that the playback service sends the first frame to the display module. The actual rendering effect depends on the rendering performance of the display service.
2253e41f4b71Sopenharmony_ci
2254e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2255e41f4b71Sopenharmony_ci
2256e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2257e41f4b71Sopenharmony_ci
2258e41f4b71Sopenharmony_ci**Parameters**
2259e41f4b71Sopenharmony_ci
2260e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
2261e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
2262e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'startRenderFrame'** in this case.|
2263e41f4b71Sopenharmony_ci| callback | Callback\<void> | Yes  | Callback invoked when the event is triggered.                          |
2264e41f4b71Sopenharmony_ci
2265e41f4b71Sopenharmony_ci**Example**
2266e41f4b71Sopenharmony_ci
2267e41f4b71Sopenharmony_ci```ts
2268e41f4b71Sopenharmony_ciavPlayer.on('startRenderFrame', () => {
2269e41f4b71Sopenharmony_ci  console.info('startRenderFrame called')
2270e41f4b71Sopenharmony_ci})
2271e41f4b71Sopenharmony_ci```
2272e41f4b71Sopenharmony_ci
2273e41f4b71Sopenharmony_ci### off('startRenderFrame')<sup>9+</sup>
2274e41f4b71Sopenharmony_ci
2275e41f4b71Sopenharmony_cioff(type: 'startRenderFrame', callback?: Callback\<void>): void
2276e41f4b71Sopenharmony_ci
2277e41f4b71Sopenharmony_ciUnsubscribes from the event that indicates rendering starts for the first frame.
2278e41f4b71Sopenharmony_ci
2279e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2280e41f4b71Sopenharmony_ci
2281e41f4b71Sopenharmony_ci**Parameters**
2282e41f4b71Sopenharmony_ci
2283e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
2284e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
2285e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'startRenderFrame'** in this case.|
2286e41f4b71Sopenharmony_ci| callback | Callback\<void> | No  | Callback invoked when the event is triggered.<br>This parameter is supported since API version 12.                  |
2287e41f4b71Sopenharmony_ci
2288e41f4b71Sopenharmony_ci**Example**
2289e41f4b71Sopenharmony_ci
2290e41f4b71Sopenharmony_ci```ts
2291e41f4b71Sopenharmony_ciavPlayer.off('startRenderFrame')
2292e41f4b71Sopenharmony_ci```
2293e41f4b71Sopenharmony_ci
2294e41f4b71Sopenharmony_ci### on('videoSizeChange')<sup>9+</sup>
2295e41f4b71Sopenharmony_ci
2296e41f4b71Sopenharmony_cion(type: 'videoSizeChange', callback: OnVideoSizeChangeHandler): void
2297e41f4b71Sopenharmony_ci
2298e41f4b71Sopenharmony_ciSubscribes to video size (width and height) changes. This subscription is supported only in video playback scenarios. By default, this event is reported only once in the prepared state. However, it is also reported upon resolution changes in the case of HLS streams.
2299e41f4b71Sopenharmony_ci
2300e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2301e41f4b71Sopenharmony_ci
2302e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2303e41f4b71Sopenharmony_ci
2304e41f4b71Sopenharmony_ci**Parameters**
2305e41f4b71Sopenharmony_ci
2306e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
2307e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
2308e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'videoSizeChange'** in this case.|
2309e41f4b71Sopenharmony_ci| callback | [OnVideoSizeChangeHandler](#onvideosizechangehandler12) | Yes  | Callback invoked when the event is triggered.   |
2310e41f4b71Sopenharmony_ci
2311e41f4b71Sopenharmony_ci**Example**
2312e41f4b71Sopenharmony_ci
2313e41f4b71Sopenharmony_ci```ts
2314e41f4b71Sopenharmony_ciavPlayer.on('videoSizeChange', (width: number, height: number) => {
2315e41f4b71Sopenharmony_ci  console.info('videoSizeChange called,and width is:' + width + ', height is :' + height)
2316e41f4b71Sopenharmony_ci})
2317e41f4b71Sopenharmony_ci```
2318e41f4b71Sopenharmony_ci
2319e41f4b71Sopenharmony_ci### off('videoSizeChange')<sup>9+</sup>
2320e41f4b71Sopenharmony_ci
2321e41f4b71Sopenharmony_cioff(type: 'videoSizeChange', callback?: OnVideoSizeChangeHandler): void
2322e41f4b71Sopenharmony_ci
2323e41f4b71Sopenharmony_ciUnsubscribes from video size changes. 
2324e41f4b71Sopenharmony_ci
2325e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2326e41f4b71Sopenharmony_ci
2327e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2328e41f4b71Sopenharmony_ci
2329e41f4b71Sopenharmony_ci**Parameters**
2330e41f4b71Sopenharmony_ci
2331e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
2332e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
2333e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'videoSizeChange'** in this case.|
2334e41f4b71Sopenharmony_ci| callback | [OnVideoSizeChangeHandler](#onvideosizechangehandler12) | No  | Callback invoked when the event is triggered.<br>This parameter is supported since API version 12.   |
2335e41f4b71Sopenharmony_ci
2336e41f4b71Sopenharmony_ci**Example**
2337e41f4b71Sopenharmony_ci
2338e41f4b71Sopenharmony_ci```ts
2339e41f4b71Sopenharmony_ciavPlayer.off('videoSizeChange')
2340e41f4b71Sopenharmony_ci```
2341e41f4b71Sopenharmony_ci
2342e41f4b71Sopenharmony_ci### on('audioInterrupt')<sup>9+</sup>
2343e41f4b71Sopenharmony_ci
2344e41f4b71Sopenharmony_cion(type: 'audioInterrupt', callback: Callback\<audio.InterruptEvent>): void
2345e41f4b71Sopenharmony_ci
2346e41f4b71Sopenharmony_ciSubscribes to the audio interruption event. When multiple audio and video assets are played at the same time, this event is triggered based on the audio interruption mode [audio.InterruptMode](../apis-audio-kit/js-apis-audio.md#interruptmode9). The application needs to perform corresponding processing based on different audio interruption events. For details, see [Handling Audio Interruption Events](../../media/audio/audio-playback-concurrency.md).
2347e41f4b71Sopenharmony_ci
2348e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2349e41f4b71Sopenharmony_ci
2350e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2351e41f4b71Sopenharmony_ci
2352e41f4b71Sopenharmony_ci**Parameters**
2353e41f4b71Sopenharmony_ci
2354e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory| Description                                                    |
2355e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- |
2356e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type, which is **'audioInterrupt'** in this case.|
2357e41f4b71Sopenharmony_ci| callback | Callback\<[audio.InterruptEvent](../apis-audio-kit/js-apis-audio.md#interruptevent9)> | Yes  | Callback invoked when the event is triggered.                          |
2358e41f4b71Sopenharmony_ci
2359e41f4b71Sopenharmony_ci**Example**
2360e41f4b71Sopenharmony_ci
2361e41f4b71Sopenharmony_ci```ts
2362e41f4b71Sopenharmony_ciimport { audio } from '@kit.AudioKit';
2363e41f4b71Sopenharmony_ci
2364e41f4b71Sopenharmony_ciavPlayer.on('audioInterrupt', (info: audio.InterruptEvent) => {
2365e41f4b71Sopenharmony_ci  console.info('audioInterrupt called,and InterruptEvent info is:' + info)
2366e41f4b71Sopenharmony_ci})
2367e41f4b71Sopenharmony_ci```
2368e41f4b71Sopenharmony_ci
2369e41f4b71Sopenharmony_ci### off('audioInterrupt')<sup>9+</sup>
2370e41f4b71Sopenharmony_ci
2371e41f4b71Sopenharmony_cioff(type: 'audioInterrupt', callback?: Callback<audio.InterruptEvent>): void
2372e41f4b71Sopenharmony_ci
2373e41f4b71Sopenharmony_ciUnsubscribes from the audio interruption event.
2374e41f4b71Sopenharmony_ci
2375e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2376e41f4b71Sopenharmony_ci
2377e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2378e41f4b71Sopenharmony_ci
2379e41f4b71Sopenharmony_ci**Parameters**
2380e41f4b71Sopenharmony_ci
2381e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
2382e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
2383e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'audioInterrupt'** in this case.|
2384e41f4b71Sopenharmony_ci| callback | Callback\<[audio.InterruptEvent](../apis-audio-kit/js-apis-audio.md#interruptevent9)> | No  | Callback invoked when the event is triggered.<br>This parameter is supported since API version 12.            |
2385e41f4b71Sopenharmony_ci
2386e41f4b71Sopenharmony_ci**Example**
2387e41f4b71Sopenharmony_ci
2388e41f4b71Sopenharmony_ci```ts
2389e41f4b71Sopenharmony_ciavPlayer.off('audioInterrupt')
2390e41f4b71Sopenharmony_ci```
2391e41f4b71Sopenharmony_ci
2392e41f4b71Sopenharmony_ci### on('audioOutputDeviceChangeWithInfo')<sup>11+</sup>
2393e41f4b71Sopenharmony_ci
2394e41f4b71Sopenharmony_cion(type: 'audioOutputDeviceChangeWithInfo', callback: Callback\<audio.AudioStreamDeviceChangeInfo>): void
2395e41f4b71Sopenharmony_ci
2396e41f4b71Sopenharmony_ciSubscribes to audio stream output device changes and reasons. This API uses an asynchronous callback to return the result.
2397e41f4b71Sopenharmony_ci
2398e41f4b71Sopenharmony_ciWhen subscribing to this event, you are advised to implement the player behavior when the device is connected or disconnected by referring to [Responding to Audio Output Device Changes](../../media/audio/audio-output-device-change.md).
2399e41f4b71Sopenharmony_ci
2400e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2401e41f4b71Sopenharmony_ci
2402e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2403e41f4b71Sopenharmony_ci
2404e41f4b71Sopenharmony_ci**Parameters**
2405e41f4b71Sopenharmony_ci
2406e41f4b71Sopenharmony_ci| Name  | Type                      | Mandatory| Description                                       |
2407e41f4b71Sopenharmony_ci| :------- | :------------------------- | :--- | :------------------------------------------ |
2408e41f4b71Sopenharmony_ci| type     | string                     | Yes  | Event type, which is **'outputDeviceChangeWithInfo'** in this case. The event is triggered when the output device is changed.|
2409e41f4b71Sopenharmony_ci| callback | Callback\<[audio.AudioStreamDeviceChangeInfo](../apis-audio-kit/js-apis-audio.md#audiostreamdevicechangeinfo11)> | Yes  | Callback used to return the output device descriptor of the current audio stream and the change reason.|
2410e41f4b71Sopenharmony_ci
2411e41f4b71Sopenharmony_ci**Error codes**
2412e41f4b71Sopenharmony_ci
2413e41f4b71Sopenharmony_ci| ID| Error Message                                  |
2414e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
2415e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.       |
2416e41f4b71Sopenharmony_ci
2417e41f4b71Sopenharmony_ci**Example**
2418e41f4b71Sopenharmony_ci
2419e41f4b71Sopenharmony_ci```ts
2420e41f4b71Sopenharmony_ciimport { audio } from '@kit.AudioKit';
2421e41f4b71Sopenharmony_ci
2422e41f4b71Sopenharmony_ciavPlayer.on('audioOutputDeviceChangeWithInfo', (data: audio.AudioStreamDeviceChangeInfo) => {
2423e41f4b71Sopenharmony_ci  console.info(`${JSON.stringify(data)}`);
2424e41f4b71Sopenharmony_ci});
2425e41f4b71Sopenharmony_ci```
2426e41f4b71Sopenharmony_ci
2427e41f4b71Sopenharmony_ci### off('audioOutputDeviceChangeWithInfo')<sup>11+</sup>
2428e41f4b71Sopenharmony_ci
2429e41f4b71Sopenharmony_cioff(type: 'audioOutputDeviceChangeWithInfo', callback?: Callback\<audio.AudioStreamDeviceChangeInfo>): void
2430e41f4b71Sopenharmony_ci
2431e41f4b71Sopenharmony_ciUnsubscribes from audio stream output device changes and reasons. This API uses an asynchronous callback to return the result.
2432e41f4b71Sopenharmony_ci
2433e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2434e41f4b71Sopenharmony_ci
2435e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2436e41f4b71Sopenharmony_ci
2437e41f4b71Sopenharmony_ci**Parameters**
2438e41f4b71Sopenharmony_ci
2439e41f4b71Sopenharmony_ci| Name  | Type                      | Mandatory| Description                                       |
2440e41f4b71Sopenharmony_ci| :------- | :------------------------- | :--- | :------------------------------------------ |
2441e41f4b71Sopenharmony_ci| type     | string                     | Yes  | Event type, which is **'outputDeviceChange'** in this case. The event is triggered when the audio output device is changed.|
2442e41f4b71Sopenharmony_ci| callback | Callback\<[audio.AudioStreamDeviceChangeInfo](../apis-audio-kit/js-apis-audio.md#audiostreamdevicechangeinfo11)> | No  | Callback used to return the output device descriptor of the current audio stream and the change reason.|
2443e41f4b71Sopenharmony_ci
2444e41f4b71Sopenharmony_ci**Error codes**
2445e41f4b71Sopenharmony_ci
2446e41f4b71Sopenharmony_ci| ID| Error Message                                  |
2447e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
2448e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
2449e41f4b71Sopenharmony_ci
2450e41f4b71Sopenharmony_ci**Example**
2451e41f4b71Sopenharmony_ci
2452e41f4b71Sopenharmony_ci```ts
2453e41f4b71Sopenharmony_ciavPlayer.off('audioOutputDeviceChangeWithInfo');
2454e41f4b71Sopenharmony_ci```
2455e41f4b71Sopenharmony_ci
2456e41f4b71Sopenharmony_ci### addSubtitleFromFd<sup>12+</sup>
2457e41f4b71Sopenharmony_ci
2458e41f4b71Sopenharmony_ciaddSubtitleFromFd(fd: number, offset?: number, length?: number): Promise\<void>
2459e41f4b71Sopenharmony_ci
2460e41f4b71Sopenharmony_ciAdds an external subtitle to a video based on the FD. Currently, the external subtitle must be set after **fdSrc** of the video resource is set in an **AVPlayer** instance. This API uses a promise to return the result.
2461e41f4b71Sopenharmony_ci
2462e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2463e41f4b71Sopenharmony_ci
2464e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2465e41f4b71Sopenharmony_ci
2466e41f4b71Sopenharmony_ci**Parameters**
2467e41f4b71Sopenharmony_ci
2468e41f4b71Sopenharmony_ci| Name| Type                  | Mandatory| Description                                                        |
2469e41f4b71Sopenharmony_ci| ------ | ---------------------- | ---- | ------------------------------------------------------------ |
2470e41f4b71Sopenharmony_ci| fd | number   | Yes  | Resource handle, which is obtained by calling [resourceManager.getRawFd](../apis-localization-kit/js-apis-resource-manager.md#getrawfd9).|
2471e41f4b71Sopenharmony_ci| offset | number | No  | Resource offset, which needs to be entered based on the preset asset information. An invalid value causes a failure to parse subtitle assets.|
2472e41f4b71Sopenharmony_ci| length | number | No  | Resource length, which needs to be entered based on the preset asset information. The default value is the remaining bytes from the offset in the file. An invalid value causes a failure to parse subtitle assets.|
2473e41f4b71Sopenharmony_ci
2474e41f4b71Sopenharmony_ci**Return value**
2475e41f4b71Sopenharmony_ci
2476e41f4b71Sopenharmony_ci| Type          | Description                                      |
2477e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------ |
2478e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
2479e41f4b71Sopenharmony_ci
2480e41f4b71Sopenharmony_ci**Error codes**
2481e41f4b71Sopenharmony_ci
2482e41f4b71Sopenharmony_ci| ID| Error Message                                  |
2483e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
2484e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Return by promise. |
2485e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
2486e41f4b71Sopenharmony_ci
2487e41f4b71Sopenharmony_ci**Example**
2488e41f4b71Sopenharmony_ci
2489e41f4b71Sopenharmony_ci```ts
2490e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit'
2491e41f4b71Sopenharmony_ci
2492e41f4b71Sopenharmony_cilet context = getContext(this) as common.UIAbilityContext
2493e41f4b71Sopenharmony_cilet fileDescriptor = await context.resourceManager.getRawFd('xxx.srt')
2494e41f4b71Sopenharmony_ci
2495e41f4b71Sopenharmony_ciavPlayer.addSubtitleFromFd(fileDescriptor.fd, fileDescriptor.offset, fileDescriptor.length)
2496e41f4b71Sopenharmony_ci```
2497e41f4b71Sopenharmony_ci
2498e41f4b71Sopenharmony_ci### addSubtitleFromUrl<sup>12+</sup>
2499e41f4b71Sopenharmony_ci
2500e41f4b71Sopenharmony_ciaddSubtitleFromUrl(url: string): Promise\<void>
2501e41f4b71Sopenharmony_ci
2502e41f4b71Sopenharmony_ciAdds an external subtitle to a video based on the URL. Currently, the external subtitle must be set after **fdSrc** of the video resource is set in an **AVPlayer** instance. This API uses a promise to return the result.
2503e41f4b71Sopenharmony_ci
2504e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2505e41f4b71Sopenharmony_ci
2506e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2507e41f4b71Sopenharmony_ci
2508e41f4b71Sopenharmony_ci**Parameters**
2509e41f4b71Sopenharmony_ci
2510e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
2511e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
2512e41f4b71Sopenharmony_ci| url    | string | Yes  | Address of the external subtitle file.|
2513e41f4b71Sopenharmony_ci
2514e41f4b71Sopenharmony_ci**Return value**
2515e41f4b71Sopenharmony_ci
2516e41f4b71Sopenharmony_ci| Type          | Description                                      |
2517e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------ |
2518e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
2519e41f4b71Sopenharmony_ci
2520e41f4b71Sopenharmony_ci**Error codes**
2521e41f4b71Sopenharmony_ci
2522e41f4b71Sopenharmony_ci| ID| Error Message                                  |
2523e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
2524e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Return by promise. |
2525e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
2526e41f4b71Sopenharmony_ci
2527e41f4b71Sopenharmony_ci**Example**
2528e41f4b71Sopenharmony_ci
2529e41f4b71Sopenharmony_ci```ts
2530e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit'
2531e41f4b71Sopenharmony_ci
2532e41f4b71Sopenharmony_cilet fdUrl:string = 'http://xxx.xxx.xxx/xx/index.srt'
2533e41f4b71Sopenharmony_ci
2534e41f4b71Sopenharmony_cilet avPlayer: media.AVPlayer = await media.createAVPlayer()
2535e41f4b71Sopenharmony_ciavPlayer.addSubtitleFromUrl(fdUrl)
2536e41f4b71Sopenharmony_ci```
2537e41f4b71Sopenharmony_ci
2538e41f4b71Sopenharmony_ci### on('subtitleUpdate')<sup>12+</sup>
2539e41f4b71Sopenharmony_ci
2540e41f4b71Sopenharmony_cion(type: 'subtitleUpdate', callback: Callback\<SubtitleInfo>): void
2541e41f4b71Sopenharmony_ci
2542e41f4b71Sopenharmony_ciSubscribes to subtitle update events. When external subtitles exist, the system notifies the application through the subscribed-to callback. An application can subscribe to only one subtitle update event. When the application initiates multiple subscriptions to this event, the last subscription prevails.
2543e41f4b71Sopenharmony_ci
2544e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2545e41f4b71Sopenharmony_ci
2546e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2547e41f4b71Sopenharmony_ci
2548e41f4b71Sopenharmony_ci**Parameters**
2549e41f4b71Sopenharmony_ci
2550e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
2551e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
2552e41f4b71Sopenharmony_ci| type | string | Yes  | Event type, which is **'subtitleUpdate'** in this case. The event is triggered when the external subtitle is updated.|
2553e41f4b71Sopenharmony_ci| callback | function | Yes  | Callback invoked when the subtitle is updated.|
2554e41f4b71Sopenharmony_ci
2555e41f4b71Sopenharmony_ci**Example**
2556e41f4b71Sopenharmony_ci
2557e41f4b71Sopenharmony_ci```ts
2558e41f4b71Sopenharmony_ciavPlayer.on('subtitleUpdate', async (info: media.SubtitleInfo) => {
2559e41f4b71Sopenharmony_ci  if (info) {
2560e41f4b71Sopenharmony_ci    let text = (!info.text) ? '' : info.text
2561e41f4b71Sopenharmony_ci    let startTime = (!info.startTime) ? 0 : info.startTime
2562e41f4b71Sopenharmony_ci    let duration = (!info.duration) ? 0 : info.duration
2563e41f4b71Sopenharmony_ci    console.info('subtitleUpdate info: text=' + text + ' startTime=' + startTime +' duration=' + duration)
2564e41f4b71Sopenharmony_ci  } else {
2565e41f4b71Sopenharmony_ci    console.info('subtitleUpdate info is null')
2566e41f4b71Sopenharmony_ci  }
2567e41f4b71Sopenharmony_ci})
2568e41f4b71Sopenharmony_ci```
2569e41f4b71Sopenharmony_ci
2570e41f4b71Sopenharmony_ci### off('subtitleUpdate')<sup>12+</sup>
2571e41f4b71Sopenharmony_ci
2572e41f4b71Sopenharmony_cioff(type: 'subtitleUpdate', callback?: Callback\<SubtitleInfo>): void
2573e41f4b71Sopenharmony_ci
2574e41f4b71Sopenharmony_ciUnsubscribes from subtitle update events.
2575e41f4b71Sopenharmony_ci
2576e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2577e41f4b71Sopenharmony_ci
2578e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2579e41f4b71Sopenharmony_ci
2580e41f4b71Sopenharmony_ci**Parameters**
2581e41f4b71Sopenharmony_ci
2582e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
2583e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
2584e41f4b71Sopenharmony_ci| type | string | Yes  | Event type, which is **'subtitleUpdate'** in this case. The event is triggered when the external subtitle is updated.|
2585e41f4b71Sopenharmony_ci| callback | function | No  | Callback that has been registered to listen for subtitle update events.|
2586e41f4b71Sopenharmony_ci
2587e41f4b71Sopenharmony_ci**Example**
2588e41f4b71Sopenharmony_ci
2589e41f4b71Sopenharmony_ci```ts
2590e41f4b71Sopenharmony_ciavPlayer.off('subtitleUpdate')
2591e41f4b71Sopenharmony_ci```
2592e41f4b71Sopenharmony_ci
2593e41f4b71Sopenharmony_ci### on('trackChange')<sup>12+</sup>
2594e41f4b71Sopenharmony_ci
2595e41f4b71Sopenharmony_cion(type: 'trackChange', callback: OnTrackChangeHandler): void
2596e41f4b71Sopenharmony_ci
2597e41f4b71Sopenharmony_ciSubscribes to track change events. When the track changes, the system notifies the application through the subscribed-to callback. An application can subscribe to only one track change event. When the application initiates multiple subscriptions to this event, the last subscription prevails.
2598e41f4b71Sopenharmony_ci
2599e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2600e41f4b71Sopenharmony_ci
2601e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2602e41f4b71Sopenharmony_ci
2603e41f4b71Sopenharmony_ci**Parameters**
2604e41f4b71Sopenharmony_ci
2605e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
2606e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
2607e41f4b71Sopenharmony_ci| type | string | Yes  | Event type, which is **'trackChange'** in this case. The event is triggered when the track changes.|
2608e41f4b71Sopenharmony_ci| callback | [OnTrackChangeHandler](#ontrackchangehandler12) | Yes  | Callback invoked when the event is triggered.|
2609e41f4b71Sopenharmony_ci
2610e41f4b71Sopenharmony_ci**Example**
2611e41f4b71Sopenharmony_ci
2612e41f4b71Sopenharmony_ci```ts
2613e41f4b71Sopenharmony_ciavPlayer.on('trackChange', (index: number, isSelect: boolean) => {
2614e41f4b71Sopenharmony_ci  console.info('trackChange info: index=' + index + ' isSelect=' + isSelect)
2615e41f4b71Sopenharmony_ci})
2616e41f4b71Sopenharmony_ci```
2617e41f4b71Sopenharmony_ci
2618e41f4b71Sopenharmony_ci### off('trackChange')<sup>12+</sup>
2619e41f4b71Sopenharmony_ci
2620e41f4b71Sopenharmony_cioff(type: 'trackChange', callback?: OnTrackChangeHandler): void
2621e41f4b71Sopenharmony_ci
2622e41f4b71Sopenharmony_ciUnsubscribes from track change events.
2623e41f4b71Sopenharmony_ci
2624e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2625e41f4b71Sopenharmony_ci
2626e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2627e41f4b71Sopenharmony_ci
2628e41f4b71Sopenharmony_ci**Parameters**
2629e41f4b71Sopenharmony_ci
2630e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
2631e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
2632e41f4b71Sopenharmony_ci| type | string | Yes  | Event type, which is **'trackChange'** in this case. The event is triggered when the track changes.|
2633e41f4b71Sopenharmony_ci| callback | [OnTrackChangeHandler](#ontrackchangehandler12) | No  | Callback that has been registered to listen for track changes.|
2634e41f4b71Sopenharmony_ci
2635e41f4b71Sopenharmony_ci**Example**
2636e41f4b71Sopenharmony_ci
2637e41f4b71Sopenharmony_ci```ts
2638e41f4b71Sopenharmony_ciavPlayer.off('trackChange')
2639e41f4b71Sopenharmony_ci```
2640e41f4b71Sopenharmony_ci
2641e41f4b71Sopenharmony_ci### on('trackInfoUpdate')<sup>12+</sup>
2642e41f4b71Sopenharmony_ci
2643e41f4b71Sopenharmony_cion(type: 'trackInfoUpdate', callback: Callback\<Array\<MediaDescription>>): void
2644e41f4b71Sopenharmony_ci
2645e41f4b71Sopenharmony_ciSubscribes to track information update events. When the track information is updated, the system notifies the application through the subscribed-to callback. An application can subscribe to only one track change event. When the application initiates multiple subscriptions to this event, the last subscription prevails.
2646e41f4b71Sopenharmony_ci
2647e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2648e41f4b71Sopenharmony_ci
2649e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2650e41f4b71Sopenharmony_ci
2651e41f4b71Sopenharmony_ci**Parameters**
2652e41f4b71Sopenharmony_ci
2653e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
2654e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
2655e41f4b71Sopenharmony_ci| type | string | Yes  | Event type, which is **'trackInfoUpdate'** in this case. The event is triggered when the track information is updated.|
2656e41f4b71Sopenharmony_ci| callback | Callback\<Array\<[MediaDescription](#mediadescription8)>> | Yes  | Callback invoked when the event is triggered.|
2657e41f4b71Sopenharmony_ci
2658e41f4b71Sopenharmony_ci**Example**
2659e41f4b71Sopenharmony_ci
2660e41f4b71Sopenharmony_ci```ts
2661e41f4b71Sopenharmony_ciavPlayer.on('trackInfoUpdate', (info: Array<media.MediaDescription>) => {
2662e41f4b71Sopenharmony_ci  if (info) {
2663e41f4b71Sopenharmony_ci    for (let i = 0; i < info.length; i++) {
2664e41f4b71Sopenharmony_ci      let propertyIndex: Object = info[i][media.MediaDescriptionKey.MD_KEY_TRACK_INDEX];
2665e41f4b71Sopenharmony_ci      let propertyType: Object = info[i][media.MediaDescriptionKey.MD_KEY_TRACK_TYPE];
2666e41f4b71Sopenharmony_ci      console.info('track info: index=' + propertyIndex + ' tracktype=' + propertyType)
2667e41f4b71Sopenharmony_ci    }
2668e41f4b71Sopenharmony_ci  } else {
2669e41f4b71Sopenharmony_ci    console.info('track info is null')
2670e41f4b71Sopenharmony_ci  }
2671e41f4b71Sopenharmony_ci})
2672e41f4b71Sopenharmony_ci```
2673e41f4b71Sopenharmony_ci
2674e41f4b71Sopenharmony_ci### off('trackInfoUpdate')<sup>12+</sup>
2675e41f4b71Sopenharmony_ci
2676e41f4b71Sopenharmony_cioff(type: 'trackInfoUpdate', callback?: Callback\<Array\<MediaDescription>>): void
2677e41f4b71Sopenharmony_ci
2678e41f4b71Sopenharmony_ciUnsubscribes from track information update events.
2679e41f4b71Sopenharmony_ci
2680e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2681e41f4b71Sopenharmony_ci
2682e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2683e41f4b71Sopenharmony_ci
2684e41f4b71Sopenharmony_ci**Parameters**
2685e41f4b71Sopenharmony_ci
2686e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
2687e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
2688e41f4b71Sopenharmony_ci| type | string | Yes  | Event type, which is **'trackInfoUpdate'** in this case. The event is triggered when the track information is updated.|
2689e41f4b71Sopenharmony_ci| callback | Callback\<Array\<[MediaDescription](#mediadescription8)>> | No  | Callback that has been registered to listen for track information updates.|
2690e41f4b71Sopenharmony_ci
2691e41f4b71Sopenharmony_ci**Example**
2692e41f4b71Sopenharmony_ci
2693e41f4b71Sopenharmony_ci```ts
2694e41f4b71Sopenharmony_ciavPlayer.off('trackInfoUpdate')
2695e41f4b71Sopenharmony_ci```
2696e41f4b71Sopenharmony_ci
2697e41f4b71Sopenharmony_ci### on('amplitudeUpdate')<sup>13+</sup>
2698e41f4b71Sopenharmony_ci
2699e41f4b71Sopenharmony_cion(type: 'amplitudeUpdate', callback: Callback\<Array\<number>>): void
2700e41f4b71Sopenharmony_ci
2701e41f4b71Sopenharmony_ciSubscribes to update events of the maximum audio level value, which is periodically reported when audio resources are played.
2702e41f4b71Sopenharmony_ci
2703e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 13.
2704e41f4b71Sopenharmony_ci
2705e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2706e41f4b71Sopenharmony_ci
2707e41f4b71Sopenharmony_ci**Parameters**
2708e41f4b71Sopenharmony_ci
2709e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
2710e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
2711e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'amplitudeUpdate'** in this case. The event is triggered when the amplitude changes.|
2712e41f4b71Sopenharmony_ci| callback | Callback\<Array\<number>> | Yes  | Callback invoked when the event is triggered.|
2713e41f4b71Sopenharmony_ci
2714e41f4b71Sopenharmony_ci**Example**
2715e41f4b71Sopenharmony_ci
2716e41f4b71Sopenharmony_ci```ts
2717e41f4b71Sopenharmony_ciavPlayer.on('amplitudeUpdate', (value: Array<number>) => {
2718e41f4b71Sopenharmony_ci  console.info('amplitudeUpdate called,and amplitudeUpdate = ${value}')
2719e41f4b71Sopenharmony_ci})
2720e41f4b71Sopenharmony_ci```
2721e41f4b71Sopenharmony_ci
2722e41f4b71Sopenharmony_ci### off('amplitudeUpdate')<sup>13+</sup>
2723e41f4b71Sopenharmony_ci
2724e41f4b71Sopenharmony_cioff(type: 'amplitudeUpdate', callback?: Callback\<Array\<number>>): void
2725e41f4b71Sopenharmony_ci
2726e41f4b71Sopenharmony_ciUnsubscribes from update events of the maximum amplitude.
2727e41f4b71Sopenharmony_ci
2728e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 13.
2729e41f4b71Sopenharmony_ci
2730e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2731e41f4b71Sopenharmony_ci
2732e41f4b71Sopenharmony_ci**Parameters**
2733e41f4b71Sopenharmony_ci
2734e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
2735e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
2736e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'amplitudeUpdate'** in this case. The event is triggered when the amplitude changes.|
2737e41f4b71Sopenharmony_ci| callback | Callback\<Array\<number>> | No  | Callback that has been registered to listen for amplitude updates.|
2738e41f4b71Sopenharmony_ci
2739e41f4b71Sopenharmony_ci**Example**
2740e41f4b71Sopenharmony_ci
2741e41f4b71Sopenharmony_ci```ts
2742e41f4b71Sopenharmony_ciavPlayer.off('amplitudeUpdate')
2743e41f4b71Sopenharmony_ci```
2744e41f4b71Sopenharmony_ci
2745e41f4b71Sopenharmony_ci## AVPlayerState<sup>9+</sup>
2746e41f4b71Sopenharmony_ci
2747e41f4b71Sopenharmony_citype AVPlayerState = 'idle' | 'initialized' | 'prepared' | 'playing' | 'paused' | 'completed' | 'stopped' | 'released' | 'error'
2748e41f4b71Sopenharmony_ci
2749e41f4b71Sopenharmony_ciEnumerates the states of the [AVPlayer](#avplayer9). Your application can proactively obtain the AVPlayer state through the **state** attribute or obtain the reported AVPlayer state by subscribing to the [stateChange](#onstatechange9) event. For details about the rules for state transition, see [Audio Playback](../../media/media/using-avplayer-for-playback.md).
2750e41f4b71Sopenharmony_ci
2751e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2752e41f4b71Sopenharmony_ci
2753e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2754e41f4b71Sopenharmony_ci
2755e41f4b71Sopenharmony_ci|              Type              | Description                                                        |
2756e41f4b71Sopenharmony_ci| :-----------------------------: | :----------------------------------------------------------- |
2757e41f4b71Sopenharmony_ci|              'idle'               | The AVPlayer enters this state after [createAVPlayer()](#mediacreateavplayer9) or [reset()](#reset9) is called.<br>In case [createAVPlayer()](#mediacreateavplayer9) is used, all attributes are set to their default values.<br>In case [reset()](#reset9) is called, the **url<sup>9+</sup>**, **fdSrc<sup>9+</sup>**, or **dataSrc<sup>10+</sup>** attribute and the **loop** attribute are reset, and other attributes are retained.|
2758e41f4b71Sopenharmony_ci|           'initialized'           | The AVPlayer enters this state after **url<sup>9+</sup>** or **fdSrc<sup>9+</sup>** attribute is set in the idle state. In this case, you can configure static attributes such as the window and audio.|
2759e41f4b71Sopenharmony_ci|            'prepared'             | The AVPlayer enters this state when [prepare()](#prepare9) is called in the initialized state. In this case, the playback engine has prepared the resources.|
2760e41f4b71Sopenharmony_ci|             'playing'             | The AVPlayer enters this state when [play()](#play9) is called in the prepared, paused, or completed state.|
2761e41f4b71Sopenharmony_ci|             'paused'              | The AVPlayer enters this state when **pause()** is called in the playing state.|
2762e41f4b71Sopenharmony_ci|            'completed'            | The AVPlayer enters this state when a media asset finishes playing and loop playback is not set (no **loop = true**). In this case, if [play()](#play9) is called, the AVPlayer enters the playing state and replays the media asset; if [stop()](#stop9) is called, the AVPlayer enters the stopped state.|
2763e41f4b71Sopenharmony_ci|             'stopped'             | The AVPlayer enters this state when [stop()](#stop9) is called in the prepared, playing, paused, or completed state. In this case, the playback engine retains the attributes but releases the memory resources. You can call [prepare()](#prepare9) to prepare the resources again, call [reset()](#reset9) to reset the attributes, or call [release()](#release9) to destroy the playback engine.|
2764e41f4b71Sopenharmony_ci|            'released'             | The AVPlayer enters this state when [release()](#release9) is called. The playback engine associated with the **AVPlayer** instance is destroyed, and the playback process ends. This is the final state.|
2765e41f4b71Sopenharmony_ci| 'error' | The AVPlayer enters this state when an irreversible error occurs in the playback engine. You can call [reset()](#reset9) to reset the attributes or call [release()](#release9) to destroy the playback engine. For details about the error codes, see [Media Error Codes](errorcode-media.md).<br>**NOTE** Relationship between the error state and the [on('error')](#onerror9) event<br>1. When the AVPlayer enters the error state, the **on('error')** event is triggered. You can obtain the detailed error information through this event.<br>2. When the AVPlayer enters the error state, the playback service stops. This requires the client to design a fault tolerance mechanism to call [reset()](#reset9) or [release()](#release9).<br>3. The client receives **on('error')** event but the AVPlayer does not enter the error state. This situation occurs due to either of the following reasons:<br>Cause 1: The client calls an API in an incorrect state or passes in an incorrect parameter, and the AVPlayer intercepts the call. If this is the case, the client must correct its code logic.<br>Cause 2: A stream error is detected during playback. As a result, the container and decoding are abnormal for a short period of time, but continuous playback and playback control operations are not affected. If this is the case, the client does not need to design a fault tolerance mechanism.|
2766e41f4b71Sopenharmony_ci
2767e41f4b71Sopenharmony_ci## OnTrackChangeHandler<sup>12+</sup>
2768e41f4b71Sopenharmony_ci
2769e41f4b71Sopenharmony_citype OnTrackChangeHandler = (index: number, isSelected: boolean) => void
2770e41f4b71Sopenharmony_ci
2771e41f4b71Sopenharmony_ciDescribes the callback invoked for the track change event.
2772e41f4b71Sopenharmony_ci
2773e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2774e41f4b71Sopenharmony_ci
2775e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2776e41f4b71Sopenharmony_ci
2777e41f4b71Sopenharmony_ci| Name  | Type  | Mandatory| Description                                                        |
2778e41f4b71Sopenharmony_ci| ------ | ------ | ------ | ---------------------------------------------------------- |
2779e41f4b71Sopenharmony_ci| index  | number | Yes| Index of a track.    |
2780e41f4b71Sopenharmony_ci| isSelected | boolean | Yes| Status of the track, that is, whether the track is selected.|
2781e41f4b71Sopenharmony_ci
2782e41f4b71Sopenharmony_ci## OnAVPlayerStateChangeHandle<sup>12+</sup>
2783e41f4b71Sopenharmony_ci
2784e41f4b71Sopenharmony_citype OnAVPlayerStateChangeHandle = (state: AVPlayerState, reason: StateChangeReason) => void
2785e41f4b71Sopenharmony_ci
2786e41f4b71Sopenharmony_ciDescribes the callback invoked for the AVPlayer state change event.
2787e41f4b71Sopenharmony_ci
2788e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2789e41f4b71Sopenharmony_ci
2790e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2791e41f4b71Sopenharmony_ci
2792e41f4b71Sopenharmony_ci| Name  | Type  | Mandatory| Description                                                        |
2793e41f4b71Sopenharmony_ci| ------ | ------ | ------ | ---------------------------------------------------------- |
2794e41f4b71Sopenharmony_ci| state  | [AVPlayerState](#avplayerstate9) | Yes| State of the AVPlayer.    |
2795e41f4b71Sopenharmony_ci| reason | [StateChangeReason](#statechangereason9) | Yes| Reason for the state change.|
2796e41f4b71Sopenharmony_ci
2797e41f4b71Sopenharmony_ci## OnBufferingUpdateHandler<sup>12+</sup>
2798e41f4b71Sopenharmony_ci
2799e41f4b71Sopenharmony_citype OnBufferingUpdateHandler = (infoType: BufferingInfoType, value: number) => void
2800e41f4b71Sopenharmony_ci
2801e41f4b71Sopenharmony_ciDescribes the callback invoked for the buffering update event.
2802e41f4b71Sopenharmony_ci
2803e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2804e41f4b71Sopenharmony_ci
2805e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2806e41f4b71Sopenharmony_ci
2807e41f4b71Sopenharmony_ci| Name  | Type  | Mandatory| Description                                                        |
2808e41f4b71Sopenharmony_ci| ------ | ------ | ------ | ------------------------------------------------------------ |
2809e41f4b71Sopenharmony_ci| infoType  | [BufferingInfoType](#bufferinginfotype8) | Yes| Buffering information type.    |
2810e41f4b71Sopenharmony_ci| value | number | Yes| The value is fixed at **0**.|
2811e41f4b71Sopenharmony_ci
2812e41f4b71Sopenharmony_ci## OnVideoSizeChangeHandler<sup>12+</sup>
2813e41f4b71Sopenharmony_ci
2814e41f4b71Sopenharmony_citype OnVideoSizeChangeHandler = (width: number, height: number) => void
2815e41f4b71Sopenharmony_ci
2816e41f4b71Sopenharmony_ciDescribes the callback invoked for the video size change event.
2817e41f4b71Sopenharmony_ci
2818e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2819e41f4b71Sopenharmony_ci
2820e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2821e41f4b71Sopenharmony_ci
2822e41f4b71Sopenharmony_ci| Name  | Type  | Mandatory| Description                                                        |
2823e41f4b71Sopenharmony_ci| ------ | ------ | ------ | ------------------------------------------------------------ |
2824e41f4b71Sopenharmony_ci| width  | number | Yes| Video width.    |
2825e41f4b71Sopenharmony_ci| height | number | Yes| Video height.|
2826e41f4b71Sopenharmony_ci
2827e41f4b71Sopenharmony_ci## AVFileDescriptor<sup>9+</sup>
2828e41f4b71Sopenharmony_ci
2829e41f4b71Sopenharmony_ciDescribes an audio and video file asset. It is used to specify a particular asset for playback based on its offset and length within a file.
2830e41f4b71Sopenharmony_ci
2831e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2832e41f4b71Sopenharmony_ci
2833e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
2834e41f4b71Sopenharmony_ci
2835e41f4b71Sopenharmony_ci| Name  | Type  | Mandatory| Description                                                        |
2836e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
2837e41f4b71Sopenharmony_ci| fd     | number | Yes  | Resource handle, which is obtained by calling [resourceManager.getRawFd](../apis-localization-kit/js-apis-resource-manager.md#getrawfd9) or [fs.open](../apis-core-file-kit/js-apis-file-fs.md#fsopen).   |
2838e41f4b71Sopenharmony_ci| offset | number | No  | Resource offset, which needs to be entered based on the preset asset information. The default value is **0**. An invalid value causes a failure to parse audio and video assets.|
2839e41f4b71Sopenharmony_ci| length | number | No  | Resource length, which needs to be entered based on the preset asset information. The default value is the remaining bytes from the offset in the file. An invalid value causes a failure to parse audio and video assets.|
2840e41f4b71Sopenharmony_ci
2841e41f4b71Sopenharmony_ci## AVDataSrcDescriptor<sup>10+</sup>
2842e41f4b71Sopenharmony_ci
2843e41f4b71Sopenharmony_ciDefines the descriptor of an audio and video file, which is used in DataSource playback mode.<br>Use scenario: An application can create a playback instance and start playback before it finishes downloading the audio and video resources.
2844e41f4b71Sopenharmony_ci
2845e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2846e41f4b71Sopenharmony_ci
2847e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
2848e41f4b71Sopenharmony_ci
2849e41f4b71Sopenharmony_ci| Name  | Type  | Mandatory| Description                                                        |
2850e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
2851e41f4b71Sopenharmony_ci| fileSize     | number | Yes  | Size of the file to play, in bytes. The value **-1** indicates that the size is unknown. If **fileSize** is set to **-1**, the playback mode is similar to the live mode. In this mode, the **seek** and **setSpeed** operations cannot be performed, and the **loop** attribute cannot be set, indicating that loop playback is unavailable.|
2852e41f4b71Sopenharmony_ci| callback | (buffer: ArrayBuffer, length: number, pos?: number) => number | Yes  | Callback used to fill in data.<br>- Function: callback: (buffer: ArrayBuffer, length: number, pos?:number) => number;<br>- **buffer**: memory to be filled. The value is of the ArrayBuffer type. This parameter is mandatory.<br>- **length**: maximum length of the memory to be filled. The value is of the number type. This parameter is mandatory.<br>- **pos**: position of the data to be filled in the file. The value is of the number type. This parameter is optional. When **fileSize** is set to **-1**, this parameter cannot be used.<br>- Return value: length of the data to be filled, which is of the number type.|
2853e41f4b71Sopenharmony_ci
2854e41f4b71Sopenharmony_ci## SubtitleInfo<sup>12+</sup>
2855e41f4b71Sopenharmony_ci
2856e41f4b71Sopenharmony_ciDescribes the external subtitle information. When a subtitle update event is subscribed to, the information about the external subtitle is returned through a callback.
2857e41f4b71Sopenharmony_ci
2858e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2859e41f4b71Sopenharmony_ci
2860e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
2861e41f4b71Sopenharmony_ci
2862e41f4b71Sopenharmony_ci| Name  | Type  | Mandatory| Description                                                        |
2863e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
2864e41f4b71Sopenharmony_ci| text | string | No | Text information of the subtitle.|
2865e41f4b71Sopenharmony_ci| startTime | number | No | Start time for displaying the subtitle, in milliseconds.|
2866e41f4b71Sopenharmony_ci| duration | number | No| Duration for displaying the subtitle, in milliseconds.|
2867e41f4b71Sopenharmony_ci
2868e41f4b71Sopenharmony_ci## SeekMode<sup>8+</sup>
2869e41f4b71Sopenharmony_ci
2870e41f4b71Sopenharmony_ciEnumerates the video playback seek modes, which can be passed in the **seek** API.
2871e41f4b71Sopenharmony_ci
2872e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
2873e41f4b71Sopenharmony_ci
2874e41f4b71Sopenharmony_ci| Name          | Value  | Description                                                        |
2875e41f4b71Sopenharmony_ci| -------------- | ---- | ------------------------------------------------------------ |
2876e41f4b71Sopenharmony_ci| SEEK_NEXT_SYNC | 0    | Seeks to the next key frame at the specified position. You are advised to use this value for the rewind operation.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
2877e41f4b71Sopenharmony_ci| SEEK_PREV_SYNC | 1    | Seeks to the previous key frame at the specified position. You are advised to use this value for the fast-forward operation.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
2878e41f4b71Sopenharmony_ci| SEEK_CLOSEST<sup>12+</sup> | 2    | Seeks to the frame closest to the specified position. You are advised to use this value for accurate seek.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
2879e41f4b71Sopenharmony_ci
2880e41f4b71Sopenharmony_ci## SwitchMode<sup>12+</sup>
2881e41f4b71Sopenharmony_ci
2882e41f4b71Sopenharmony_ciEnumerates the track switching modes for video playback. The mode can be passed in to **selectTrack**. Currently, this enum is valid only for DASH video tracks.
2883e41f4b71Sopenharmony_ci
2884e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
2885e41f4b71Sopenharmony_ci
2886e41f4b71Sopenharmony_ci| Name          | Value  | Description                                                        |
2887e41f4b71Sopenharmony_ci| -------------- | ---- | ------------------------------------------------------------ |
2888e41f4b71Sopenharmony_ci| SMOOTH | 0    | Smooth playback is ensured after the switching. This mode has a delay, that is, the switching does not take effect immediately.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
2889e41f4b71Sopenharmony_ci| SEGMENT | 1    | The playback starts from the start position of the current segment after the switching. In this mode, the switching takes effect immediately and repeated playback may occur.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
2890e41f4b71Sopenharmony_ci| CLOSEST | 2    | The playback starts from the frame closest to the current playback time. In this mode, the switching takes effect immediately, and the playback is suspended for 3s to 5s and then resumed.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
2891e41f4b71Sopenharmony_ci
2892e41f4b71Sopenharmony_ci## PlaybackSpeed<sup>8+</sup>
2893e41f4b71Sopenharmony_ci
2894e41f4b71Sopenharmony_ciEnumerates the video playback speeds, which can be passed in the **setSpeed** API.
2895e41f4b71Sopenharmony_ci
2896e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2897e41f4b71Sopenharmony_ci
2898e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
2899e41f4b71Sopenharmony_ci
2900e41f4b71Sopenharmony_ci| Name                | Value  | Description                          |
2901e41f4b71Sopenharmony_ci| -------------------- | ---- | ------------------------------ |
2902e41f4b71Sopenharmony_ci| SPEED_FORWARD_0_75_X | 0    | Plays the video at 0.75 times the normal speed.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
2903e41f4b71Sopenharmony_ci| SPEED_FORWARD_1_00_X | 1    | Plays the video at the normal speed.<br>**Atomic service API**: This API can be used in atomic services since API version 12.        |
2904e41f4b71Sopenharmony_ci| SPEED_FORWARD_1_25_X | 2    | Plays the video at 1.25 times the normal speed.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
2905e41f4b71Sopenharmony_ci| SPEED_FORWARD_1_75_X | 3    | Plays the video at 1.75 times the normal speed.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
2906e41f4b71Sopenharmony_ci| SPEED_FORWARD_2_00_X | 4    | Plays the video at 2.00 times the normal speed.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
2907e41f4b71Sopenharmony_ci| SPEED_FORWARD_0_50_X<sup>12+</sup> | 5    | Plays the video at 0.50 times the normal speed.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
2908e41f4b71Sopenharmony_ci| SPEED_FORWARD_1_50_X<sup>12+</sup> | 6    | Plays the video at 1.50 times the normal speed.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
2909e41f4b71Sopenharmony_ci| SPEED_FORWARD_0_25_X<sup>12+</sup> | 8    | Plays the video at 0.25 times the normal speed.|
2910e41f4b71Sopenharmony_ci| SPEED_FORWARD_0_125_X<sup>12+</sup> | 9    | Plays the video at 0.125 times the normal speed.|
2911e41f4b71Sopenharmony_ci
2912e41f4b71Sopenharmony_ci## VideoScaleType<sup>9+</sup>
2913e41f4b71Sopenharmony_ci
2914e41f4b71Sopenharmony_ciEnumerates the video scale modes.
2915e41f4b71Sopenharmony_ci
2916e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2917e41f4b71Sopenharmony_ci
2918e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
2919e41f4b71Sopenharmony_ci
2920e41f4b71Sopenharmony_ci| Name                     | Value  | Description                                            |
2921e41f4b71Sopenharmony_ci| ------------------------- | ---- | ------------------------------------------------ |
2922e41f4b71Sopenharmony_ci| VIDEO_SCALE_TYPE_FIT      | 0    | Default mode. The video will be stretched to fit the window.             |
2923e41f4b71Sopenharmony_ci| VIDEO_SCALE_TYPE_FIT_CROP | 1    | The video will be stretched to fit the window, without changing its aspect ratio. The content may be cropped.|
2924e41f4b71Sopenharmony_ci
2925e41f4b71Sopenharmony_ci## MediaDescription<sup>8+</sup>
2926e41f4b71Sopenharmony_ci
2927e41f4b71Sopenharmony_ciDefines media information in key-value mode.
2928e41f4b71Sopenharmony_ci
2929e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2930e41f4b71Sopenharmony_ci
2931e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
2932e41f4b71Sopenharmony_ci
2933e41f4b71Sopenharmony_ci| Name         | Type  | Mandatory| Description                                                        |
2934e41f4b71Sopenharmony_ci| ------------- | ------ | ---- | ------------------------------------------------------------ |
2935e41f4b71Sopenharmony_ci| [key: string] | Object | Yes  | For details about the key range supported and the object type and range of each key, see [MediaDescriptionKey](#mediadescriptionkey8).|
2936e41f4b71Sopenharmony_ci
2937e41f4b71Sopenharmony_ci**Example**
2938e41f4b71Sopenharmony_ci
2939e41f4b71Sopenharmony_ci```ts
2940e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
2941e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit';
2942e41f4b71Sopenharmony_ci
2943e41f4b71Sopenharmony_cifunction printfItemDescription(obj: media.MediaDescription, key: string) {
2944e41f4b71Sopenharmony_ci  let property: Object = obj[key];
2945e41f4b71Sopenharmony_ci  console.info('audio key is ' + key); // Specify a key. For details about the keys, see [MediaDescriptionKey].
2946e41f4b71Sopenharmony_ci  console.info('audio value is ' + property); // Obtain the value of the key. The value can be any type. For details about the types, see [MediaDescriptionKey].
2947e41f4b71Sopenharmony_ci}
2948e41f4b71Sopenharmony_ci
2949e41f4b71Sopenharmony_cilet avPlayer: media.AVPlayer | undefined = undefined;
2950e41f4b71Sopenharmony_cimedia.createAVPlayer((err: BusinessError, player: media.AVPlayer) => {
2951e41f4b71Sopenharmony_ci  if(player != null) {
2952e41f4b71Sopenharmony_ci    avPlayer = player;
2953e41f4b71Sopenharmony_ci    console.info(`Succeeded in creating AVPlayer`);
2954e41f4b71Sopenharmony_ci    avPlayer.getTrackDescription((error: BusinessError, arrList: Array<media.MediaDescription>) => {
2955e41f4b71Sopenharmony_ci      if (arrList != null) {
2956e41f4b71Sopenharmony_ci        for (let i = 0; i < arrList.length; i++) {
2957e41f4b71Sopenharmony_ci          printfItemDescription(arrList[i], media.MediaDescriptionKey.MD_KEY_TRACK_TYPE);  // Print the MD_KEY_TRACK_TYPE value of each track.
2958e41f4b71Sopenharmony_ci        }
2959e41f4b71Sopenharmony_ci      } else {
2960e41f4b71Sopenharmony_ci        console.error(`Failed to get TrackDescription, error:${error}`);
2961e41f4b71Sopenharmony_ci      }
2962e41f4b71Sopenharmony_ci    });
2963e41f4b71Sopenharmony_ci  } else {
2964e41f4b71Sopenharmony_ci    console.error(`Failed to create AVPlayer, error message:${err.message}`);
2965e41f4b71Sopenharmony_ci  }
2966e41f4b71Sopenharmony_ci});
2967e41f4b71Sopenharmony_ci```
2968e41f4b71Sopenharmony_ci
2969e41f4b71Sopenharmony_ci## PlaybackInfo<sup>12+</sup>
2970e41f4b71Sopenharmony_ci
2971e41f4b71Sopenharmony_ciDefines the playback information in key-value pairs.
2972e41f4b71Sopenharmony_ci
2973e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
2974e41f4b71Sopenharmony_ci
2975e41f4b71Sopenharmony_ci| Name         | Type  | Mandatory| Description                                                        |
2976e41f4b71Sopenharmony_ci| ------------- | ------ | ---- | ------------------------------------------------------------ |
2977e41f4b71Sopenharmony_ci| [key: string] | Object | Yes  | For details about the key range supported and the object type and range of each key, see [PlaybackInfoKey](#playbackinfokey12).|
2978e41f4b71Sopenharmony_ci
2979e41f4b71Sopenharmony_ci**Example**
2980e41f4b71Sopenharmony_ci
2981e41f4b71Sopenharmony_ci```ts
2982e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
2983e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit';
2984e41f4b71Sopenharmony_ci
2985e41f4b71Sopenharmony_cifunction printfPlaybackInfo(obj: media.PlaybackInfo, key: string) {
2986e41f4b71Sopenharmony_ci  let property: Object = obj[key];
2987e41f4b71Sopenharmony_ci  console.info('key is ' + key); // // Specify a key. For details about the keys, see [PlaybackInfoKey].
2988e41f4b71Sopenharmony_ci  console.info('value is ' + property); // Obtain the value of the key. The value can be any type. For details about the types, see [PlaybackInfoKey].
2989e41f4b71Sopenharmony_ci}
2990e41f4b71Sopenharmony_ci
2991e41f4b71Sopenharmony_cilet avPlayer: media.AVPlayer | undefined = undefined;
2992e41f4b71Sopenharmony_cilet playbackInfo: media.PlaybackInfo | undefined = undefined;
2993e41f4b71Sopenharmony_cimedia.createAVPlayer(async (err: BusinessError, player: media.AVPlayer) => {
2994e41f4b71Sopenharmony_ci  if (player != null) {
2995e41f4b71Sopenharmony_ci    avPlayer = player;
2996e41f4b71Sopenharmony_ci    console.info(`Succeeded in creating AVPlayer`);
2997e41f4b71Sopenharmony_ci    if (avPlayer) {
2998e41f4b71Sopenharmony_ci      try {
2999e41f4b71Sopenharmony_ci        playbackInfo = await avPlayer.getPlaybackInfo();
3000e41f4b71Sopenharmony_ci        console.info(`AVPlayer getPlaybackInfo = ${JSON.stringify(playbackInfo)}`); // Print PlaybackInfo.
3001e41f4b71Sopenharmony_ci        printfPlaybackInfo(playbackInfo, media.PlaybackInfoKey.SERVER_IP_ADDRESS); // Print the IP address.
3002e41f4b71Sopenharmony_ci      } catch (error) {
3003e41f4b71Sopenharmony_ci        console.error(`error = ${error}`);
3004e41f4b71Sopenharmony_ci      }
3005e41f4b71Sopenharmony_ci    }
3006e41f4b71Sopenharmony_ci  } else {
3007e41f4b71Sopenharmony_ci    console.error(`Failed to create AVPlayer, error message:${err.message}`);
3008e41f4b71Sopenharmony_ci  }
3009e41f4b71Sopenharmony_ci});
3010e41f4b71Sopenharmony_ci```
3011e41f4b71Sopenharmony_ci
3012e41f4b71Sopenharmony_ci## AVRecorder<sup>9+</sup>
3013e41f4b71Sopenharmony_ci
3014e41f4b71Sopenharmony_ciA recording management class that provides APIs to record media assets. Before calling any API in **AVRecorder**, you must use [createAVRecorder()](#mediacreateavrecorder9) to create an **AVRecorder** instance.
3015e41f4b71Sopenharmony_ci
3016e41f4b71Sopenharmony_ciFor 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).
3017e41f4b71Sopenharmony_ci
3018e41f4b71Sopenharmony_ci> **NOTE**
3019e41f4b71Sopenharmony_ci>
3020e41f4b71Sopenharmony_ci> To use the camera to record videos, the camera module is required. For details about how to use the APIs provided by the camera module, see [Camera Management](../apis-camera-kit/js-apis-camera.md).
3021e41f4b71Sopenharmony_ci
3022e41f4b71Sopenharmony_ci### Attributes
3023e41f4b71Sopenharmony_ci
3024e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3025e41f4b71Sopenharmony_ci
3026e41f4b71Sopenharmony_ci| Name   | Type                                | Read-Only| Optional| Description              |
3027e41f4b71Sopenharmony_ci| ------- | ------------------------------------ | ---- | ---- | ------------------ |
3028e41f4b71Sopenharmony_ci| state9+ | [AVRecorderState](#avrecorderstate9) | Yes  | No  | AVRecorder state.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
3029e41f4b71Sopenharmony_ci
3030e41f4b71Sopenharmony_ci### prepare<sup>9+</sup>
3031e41f4b71Sopenharmony_ci
3032e41f4b71Sopenharmony_ciprepare(config: AVRecorderConfig, callback: AsyncCallback\<void>): void
3033e41f4b71Sopenharmony_ci
3034e41f4b71Sopenharmony_ciSets audio and video recording parameters. This API uses an asynchronous callback to return the result.
3035e41f4b71Sopenharmony_ci
3036e41f4b71Sopenharmony_ci**Required permissions:** ohos.permission.MICROPHONE
3037e41f4b71Sopenharmony_ci
3038e41f4b71Sopenharmony_ciThis permission is required only if audio recording is involved.
3039e41f4b71Sopenharmony_ci
3040e41f4b71Sopenharmony_ciTo use the camera to record videos, the camera module is required. For details about how to use the APIs provided by the camera module, see [Camera Management](../apis-camera-kit/js-apis-camera.md).
3041e41f4b71Sopenharmony_ci
3042e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3043e41f4b71Sopenharmony_ci
3044e41f4b71Sopenharmony_ci**Parameters**
3045e41f4b71Sopenharmony_ci
3046e41f4b71Sopenharmony_ci| Name  | Type                                  | Mandatory| Description                                 |
3047e41f4b71Sopenharmony_ci| -------- | -------------------------------------- | ---- | ------------------------------------- |
3048e41f4b71Sopenharmony_ci| config   | [AVRecorderConfig](#avrecorderconfig9) | Yes  | Audio and video recording parameters to set.           |
3049e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>                   | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
3050e41f4b71Sopenharmony_ci
3051e41f4b71Sopenharmony_ci**Error codes**
3052e41f4b71Sopenharmony_ci
3053e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3054e41f4b71Sopenharmony_ci
3055e41f4b71Sopenharmony_ci| ID| Error Message                               |
3056e41f4b71Sopenharmony_ci| -------- | --------------------------------------- |
3057e41f4b71Sopenharmony_ci| 201      | Permission denied. Return by callback.  |
3058e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.    |
3059e41f4b71Sopenharmony_ci| 5400102  | Operate not permit. Return by callback. |
3060e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by callback.       |
3061e41f4b71Sopenharmony_ci
3062e41f4b71Sopenharmony_ci**Example**
3063e41f4b71Sopenharmony_ci
3064e41f4b71Sopenharmony_ci```ts
3065e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3066e41f4b71Sopenharmony_ci
3067e41f4b71Sopenharmony_ci// Configure the parameters based on those supported by the hardware device.
3068e41f4b71Sopenharmony_cilet avRecorderProfile: media.AVRecorderProfile = {
3069e41f4b71Sopenharmony_ci  audioBitrate : 48000,
3070e41f4b71Sopenharmony_ci  audioChannels : 2,
3071e41f4b71Sopenharmony_ci  audioCodec : media.CodecMimeType.AUDIO_AAC,
3072e41f4b71Sopenharmony_ci  audioSampleRate : 48000,
3073e41f4b71Sopenharmony_ci  fileFormat : media.ContainerFormatType.CFT_MPEG_4,
3074e41f4b71Sopenharmony_ci  videoBitrate : 2000000,
3075e41f4b71Sopenharmony_ci  videoCodec : media.CodecMimeType.VIDEO_AVC,
3076e41f4b71Sopenharmony_ci  videoFrameWidth : 640,
3077e41f4b71Sopenharmony_ci  videoFrameHeight : 480,
3078e41f4b71Sopenharmony_ci  videoFrameRate : 30
3079e41f4b71Sopenharmony_ci}
3080e41f4b71Sopenharmony_cilet avRecorderConfig: media.AVRecorderConfig = {
3081e41f4b71Sopenharmony_ci  audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC,
3082e41f4b71Sopenharmony_ci  videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV,
3083e41f4b71Sopenharmony_ci  profile : avRecorderProfile,
3084e41f4b71Sopenharmony_ci  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.
3085e41f4b71Sopenharmony_ci  rotation: 0, // The value can be 0, 90, 180, or 270. If any other value is used, prepare() reports an error.
3086e41f4b71Sopenharmony_ci  location : { latitude : 30, longitude : 130 }
3087e41f4b71Sopenharmony_ci}
3088e41f4b71Sopenharmony_ci
3089e41f4b71Sopenharmony_ciavRecorder.prepare(avRecorderConfig, (err: BusinessError) => {
3090e41f4b71Sopenharmony_ci  if (err) {
3091e41f4b71Sopenharmony_ci    console.error('Failed to prepare and error is ' + err.message);
3092e41f4b71Sopenharmony_ci  } else {
3093e41f4b71Sopenharmony_ci    console.info('Succeeded in preparing');
3094e41f4b71Sopenharmony_ci  }
3095e41f4b71Sopenharmony_ci})
3096e41f4b71Sopenharmony_ci```
3097e41f4b71Sopenharmony_ci
3098e41f4b71Sopenharmony_ci### prepare<sup>9+</sup>
3099e41f4b71Sopenharmony_ci
3100e41f4b71Sopenharmony_ciprepare(config: AVRecorderConfig): Promise\<void>
3101e41f4b71Sopenharmony_ci
3102e41f4b71Sopenharmony_ciSets audio and video recording parameters. This API uses a promise to return the result.
3103e41f4b71Sopenharmony_ci
3104e41f4b71Sopenharmony_ci**Required permissions:** ohos.permission.MICROPHONE
3105e41f4b71Sopenharmony_ci
3106e41f4b71Sopenharmony_ciThis permission is required only if audio recording is involved.
3107e41f4b71Sopenharmony_ci
3108e41f4b71Sopenharmony_ciTo use the camera to record videos, the camera module is required. For details about how to use the APIs provided by the camera module, see [Camera Management](../apis-camera-kit/js-apis-camera.md).
3109e41f4b71Sopenharmony_ci
3110e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3111e41f4b71Sopenharmony_ci
3112e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3113e41f4b71Sopenharmony_ci
3114e41f4b71Sopenharmony_ci**Parameters**
3115e41f4b71Sopenharmony_ci
3116e41f4b71Sopenharmony_ci| Name| Type                                  | Mandatory| Description                      |
3117e41f4b71Sopenharmony_ci| ------ | -------------------------------------- | ---- | -------------------------- |
3118e41f4b71Sopenharmony_ci| config | [AVRecorderConfig](#avrecorderconfig9) | Yes  | Audio and video recording parameters to set.|
3119e41f4b71Sopenharmony_ci
3120e41f4b71Sopenharmony_ci**Return value**
3121e41f4b71Sopenharmony_ci
3122e41f4b71Sopenharmony_ci| Type          | Description                                      |
3123e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------ |
3124e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
3125e41f4b71Sopenharmony_ci
3126e41f4b71Sopenharmony_ci**Error codes**
3127e41f4b71Sopenharmony_ci
3128e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3129e41f4b71Sopenharmony_ci
3130e41f4b71Sopenharmony_ci| ID| Error Message                              |
3131e41f4b71Sopenharmony_ci| -------- | -------------------------------------- |
3132e41f4b71Sopenharmony_ci| 201      | Permission denied. Return by promise.  |
3133e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.    |
3134e41f4b71Sopenharmony_ci| 5400102  | Operate not permit. Return by promise. |
3135e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise.       |
3136e41f4b71Sopenharmony_ci
3137e41f4b71Sopenharmony_ci**Example**
3138e41f4b71Sopenharmony_ci
3139e41f4b71Sopenharmony_ci```ts
3140e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3141e41f4b71Sopenharmony_ci
3142e41f4b71Sopenharmony_ci// Configure the parameters based on those supported by the hardware device.
3143e41f4b71Sopenharmony_cilet avRecorderProfile: media.AVRecorderProfile = {
3144e41f4b71Sopenharmony_ci  audioBitrate : 48000,
3145e41f4b71Sopenharmony_ci  audioChannels : 2,
3146e41f4b71Sopenharmony_ci  audioCodec : media.CodecMimeType.AUDIO_AAC,
3147e41f4b71Sopenharmony_ci  audioSampleRate : 48000,
3148e41f4b71Sopenharmony_ci  fileFormat : media.ContainerFormatType.CFT_MPEG_4,
3149e41f4b71Sopenharmony_ci  videoBitrate : 2000000,
3150e41f4b71Sopenharmony_ci  videoCodec : media.CodecMimeType.VIDEO_AVC,
3151e41f4b71Sopenharmony_ci  videoFrameWidth : 640,
3152e41f4b71Sopenharmony_ci  videoFrameHeight : 480,
3153e41f4b71Sopenharmony_ci  videoFrameRate : 30
3154e41f4b71Sopenharmony_ci}
3155e41f4b71Sopenharmony_cilet avRecorderConfig: media.AVRecorderConfig = {
3156e41f4b71Sopenharmony_ci  audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC,
3157e41f4b71Sopenharmony_ci  videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV,
3158e41f4b71Sopenharmony_ci  profile : avRecorderProfile,
3159e41f4b71Sopenharmony_ci  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.
3160e41f4b71Sopenharmony_ci  rotation: 0, // The value can be 0, 90, 180, or 270. If any other value is used, prepare() reports an error.
3161e41f4b71Sopenharmony_ci  location : { latitude : 30, longitude : 130 }
3162e41f4b71Sopenharmony_ci}
3163e41f4b71Sopenharmony_ci
3164e41f4b71Sopenharmony_ciavRecorder.prepare(avRecorderConfig).then(() => {
3165e41f4b71Sopenharmony_ci  console.info('Succeeded in preparing');
3166e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
3167e41f4b71Sopenharmony_ci  console.error('Failed to prepare and catch error is ' + err.message);
3168e41f4b71Sopenharmony_ci});
3169e41f4b71Sopenharmony_ci```
3170e41f4b71Sopenharmony_ci
3171e41f4b71Sopenharmony_ci### getInputSurface<sup>9+</sup>
3172e41f4b71Sopenharmony_ci
3173e41f4b71Sopenharmony_cigetInputSurface(callback: AsyncCallback\<string>): void
3174e41f4b71Sopenharmony_ci
3175e41f4b71Sopenharmony_ciObtains the surface required for recording. This API uses an asynchronous callback to return the result. The caller obtains the **surfaceBuffer** from this surface and fills in the corresponding video data.
3176e41f4b71Sopenharmony_ci
3177e41f4b71Sopenharmony_ciNote that the video data must carry the timestamp (in ns) and buffer size, and the start time of the timestamp must be based on the system startup time.
3178e41f4b71Sopenharmony_ci
3179e41f4b71Sopenharmony_ciThis API can be called only after the [prepare()](#prepare9-2) API is called.
3180e41f4b71Sopenharmony_ci
3181e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3182e41f4b71Sopenharmony_ci
3183e41f4b71Sopenharmony_ci**Parameters**
3184e41f4b71Sopenharmony_ci
3185e41f4b71Sopenharmony_ci| Name  | Type                  | Mandatory| Description                       |
3186e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | --------------------------- |
3187e41f4b71Sopenharmony_ci| 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.|
3188e41f4b71Sopenharmony_ci
3189e41f4b71Sopenharmony_ci**Error codes**
3190e41f4b71Sopenharmony_ci
3191e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3192e41f4b71Sopenharmony_ci
3193e41f4b71Sopenharmony_ci| ID| Error Message                               |
3194e41f4b71Sopenharmony_ci| -------- | --------------------------------------- |
3195e41f4b71Sopenharmony_ci| 5400102  | Operate not permit. Return by callback. |
3196e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by callback.           |
3197e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by callback.       |
3198e41f4b71Sopenharmony_ci
3199e41f4b71Sopenharmony_ci**Example**
3200e41f4b71Sopenharmony_ci
3201e41f4b71Sopenharmony_ci```ts
3202e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3203e41f4b71Sopenharmony_cilet surfaceID: string; // The surfaceID is transferred to the camera API to create a videoOutput instance.
3204e41f4b71Sopenharmony_ci
3205e41f4b71Sopenharmony_ciavRecorder.getInputSurface((err: BusinessError, surfaceId: string) => {
3206e41f4b71Sopenharmony_ci  if (err) {
3207e41f4b71Sopenharmony_ci    console.error('Failed to do getInputSurface and error is ' + err.message);
3208e41f4b71Sopenharmony_ci  } else {
3209e41f4b71Sopenharmony_ci    console.info('Succeeded in doing getInputSurface');
3210e41f4b71Sopenharmony_ci    surfaceID = surfaceId;
3211e41f4b71Sopenharmony_ci  }
3212e41f4b71Sopenharmony_ci});
3213e41f4b71Sopenharmony_ci
3214e41f4b71Sopenharmony_ci```
3215e41f4b71Sopenharmony_ci
3216e41f4b71Sopenharmony_ci### getInputSurface<sup>9+</sup>
3217e41f4b71Sopenharmony_ci
3218e41f4b71Sopenharmony_cigetInputSurface(): Promise\<string>
3219e41f4b71Sopenharmony_ci
3220e41f4b71Sopenharmony_ciObtains 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.
3221e41f4b71Sopenharmony_ci
3222e41f4b71Sopenharmony_ciNote that the video data must carry the timestamp (in ns) and buffer size, and the start time of the timestamp must be based on the system startup time.
3223e41f4b71Sopenharmony_ci
3224e41f4b71Sopenharmony_ciThis API can be called only after the [prepare()](#prepare9-3) API is called.
3225e41f4b71Sopenharmony_ci
3226e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3227e41f4b71Sopenharmony_ci
3228e41f4b71Sopenharmony_ci**Return value**
3229e41f4b71Sopenharmony_ci
3230e41f4b71Sopenharmony_ci| Type            | Description                            |
3231e41f4b71Sopenharmony_ci| ---------------- | -------------------------------- |
3232e41f4b71Sopenharmony_ci| Promise\<string> | Promise used to return the result.|
3233e41f4b71Sopenharmony_ci
3234e41f4b71Sopenharmony_ci**Error codes**
3235e41f4b71Sopenharmony_ci
3236e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3237e41f4b71Sopenharmony_ci
3238e41f4b71Sopenharmony_ci| ID| Error Message                              |
3239e41f4b71Sopenharmony_ci| -------- | -------------------------------------- |
3240e41f4b71Sopenharmony_ci| 5400102  | Operate not permit. Return by promise. |
3241e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by promise.           |
3242e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise.       |
3243e41f4b71Sopenharmony_ci
3244e41f4b71Sopenharmony_ci**Example**
3245e41f4b71Sopenharmony_ci
3246e41f4b71Sopenharmony_ci```ts
3247e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3248e41f4b71Sopenharmony_cilet surfaceID: string; // The surfaceID is transferred to the camera API to create a videoOutput instance.
3249e41f4b71Sopenharmony_ci
3250e41f4b71Sopenharmony_ciavRecorder.getInputSurface().then((surfaceId: string) => {
3251e41f4b71Sopenharmony_ci  console.info('Succeeded in getting InputSurface');
3252e41f4b71Sopenharmony_ci  surfaceID = surfaceId;
3253e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
3254e41f4b71Sopenharmony_ci  console.error('Failed to get InputSurface and catch error is ' + err.message);
3255e41f4b71Sopenharmony_ci});
3256e41f4b71Sopenharmony_ci```
3257e41f4b71Sopenharmony_ci
3258e41f4b71Sopenharmony_ci### updateRotation<sup>12+</sup>
3259e41f4b71Sopenharmony_ci
3260e41f4b71Sopenharmony_ciupdateRotation(rotation: number): Promise\<void>
3261e41f4b71Sopenharmony_ci
3262e41f4b71Sopenharmony_ciUpdates the video rotation angle. This API uses a promise to return the result.
3263e41f4b71Sopenharmony_ci
3264e41f4b71Sopenharmony_ciThis API can be called only after the [prepare()](#prepare9-3) event is triggered and before the [start()](#start9) API is called.
3265e41f4b71Sopenharmony_ci
3266e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3267e41f4b71Sopenharmony_ci
3268e41f4b71Sopenharmony_ci**Parameters**
3269e41f4b71Sopenharmony_ci
3270e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                       |
3271e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | --------------------------- |
3272e41f4b71Sopenharmony_ci| rotation | number | Yes  | Rotation angle, which can only be 0, 90, 180, or 270 degrees.|
3273e41f4b71Sopenharmony_ci
3274e41f4b71Sopenharmony_ci**Return value**
3275e41f4b71Sopenharmony_ci
3276e41f4b71Sopenharmony_ci| Type            | Description                            |
3277e41f4b71Sopenharmony_ci| ---------------- | -------------------------------- |
3278e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
3279e41f4b71Sopenharmony_ci
3280e41f4b71Sopenharmony_ci**Error codes**
3281e41f4b71Sopenharmony_ci
3282e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3283e41f4b71Sopenharmony_ci
3284e41f4b71Sopenharmony_ci| ID| Error Message                              |
3285e41f4b71Sopenharmony_ci| -------- | -------------------------------------- |
3286e41f4b71Sopenharmony_ci|   401    | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.   |
3287e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
3288e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by promise.           |
3289e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise.       |
3290e41f4b71Sopenharmony_ci
3291e41f4b71Sopenharmony_ci**Example**
3292e41f4b71Sopenharmony_ci
3293e41f4b71Sopenharmony_ci```ts
3294e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3295e41f4b71Sopenharmony_ci
3296e41f4b71Sopenharmony_cilet rotation = 90
3297e41f4b71Sopenharmony_ci
3298e41f4b71Sopenharmony_ciavRecorder.updateRotation(rotation).then(() => {
3299e41f4b71Sopenharmony_ci  console.info('Succeeded in updateRotation');
3300e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
3301e41f4b71Sopenharmony_ci  console.error('Failed to updateRotation and catch error is ' + err.message);
3302e41f4b71Sopenharmony_ci});
3303e41f4b71Sopenharmony_ci```
3304e41f4b71Sopenharmony_ci
3305e41f4b71Sopenharmony_ci### start<sup>9+</sup>
3306e41f4b71Sopenharmony_ci
3307e41f4b71Sopenharmony_cistart(callback: AsyncCallback\<void>): void
3308e41f4b71Sopenharmony_ci
3309e41f4b71Sopenharmony_ciStarts recording. This API uses an asynchronous callback to return the result.
3310e41f4b71Sopenharmony_ci
3311e41f4b71Sopenharmony_ciFor audio-only recording, this API can be called only after the [prepare()](#prepare9-2) API is called. For video-only recording, this API can be called only after the [getInputSurface()](#getinputsurface9) API is called.
3312e41f4b71Sopenharmony_ci
3313e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3314e41f4b71Sopenharmony_ci
3315e41f4b71Sopenharmony_ci**Parameters**
3316e41f4b71Sopenharmony_ci
3317e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                        |
3318e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------- |
3319e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  |Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
3320e41f4b71Sopenharmony_ci
3321e41f4b71Sopenharmony_ci**Error codes**
3322e41f4b71Sopenharmony_ci
3323e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3324e41f4b71Sopenharmony_ci
3325e41f4b71Sopenharmony_ci| ID| Error Message                               |
3326e41f4b71Sopenharmony_ci| -------- | --------------------------------------- |
3327e41f4b71Sopenharmony_ci| 5400102  | Operate not permit. Return by callback. |
3328e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by callback.           |
3329e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by callback.       |
3330e41f4b71Sopenharmony_ci
3331e41f4b71Sopenharmony_ci**Example**
3332e41f4b71Sopenharmony_ci
3333e41f4b71Sopenharmony_ci```ts
3334e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3335e41f4b71Sopenharmony_ci
3336e41f4b71Sopenharmony_ciavRecorder.start((err: BusinessError) => {
3337e41f4b71Sopenharmony_ci  if (err) {
3338e41f4b71Sopenharmony_ci    console.error('Failed to start AVRecorder and error is ' + err.message);
3339e41f4b71Sopenharmony_ci  } else {
3340e41f4b71Sopenharmony_ci    console.info('Succeeded in starting AVRecorder');
3341e41f4b71Sopenharmony_ci  }
3342e41f4b71Sopenharmony_ci});
3343e41f4b71Sopenharmony_ci```
3344e41f4b71Sopenharmony_ci
3345e41f4b71Sopenharmony_ci### start<sup>9+</sup>
3346e41f4b71Sopenharmony_ci
3347e41f4b71Sopenharmony_cistart(): Promise\<void>
3348e41f4b71Sopenharmony_ci
3349e41f4b71Sopenharmony_ciStarts recording. This API uses a promise to return the result.
3350e41f4b71Sopenharmony_ci
3351e41f4b71Sopenharmony_ciFor audio-only recording, this API can be called only after the [prepare()](#prepare9-3) API is called. For video-only recording, this API can be called only after the [getInputSurface()](#getinputsurface9-1) API is called.
3352e41f4b71Sopenharmony_ci
3353e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3354e41f4b71Sopenharmony_ci
3355e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3356e41f4b71Sopenharmony_ci
3357e41f4b71Sopenharmony_ci**Return value**
3358e41f4b71Sopenharmony_ci
3359e41f4b71Sopenharmony_ci| Type          | Description                                 |
3360e41f4b71Sopenharmony_ci| -------------- | ------------------------------------- |
3361e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
3362e41f4b71Sopenharmony_ci
3363e41f4b71Sopenharmony_ci**Error codes**
3364e41f4b71Sopenharmony_ci
3365e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3366e41f4b71Sopenharmony_ci
3367e41f4b71Sopenharmony_ci| ID| Error Message                              |
3368e41f4b71Sopenharmony_ci| -------- | -------------------------------------- |
3369e41f4b71Sopenharmony_ci| 5400102  | Operate not permit. Return by promise. |
3370e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by promise.           |
3371e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise.       |
3372e41f4b71Sopenharmony_ci
3373e41f4b71Sopenharmony_ci**Example**
3374e41f4b71Sopenharmony_ci
3375e41f4b71Sopenharmony_ci```ts
3376e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3377e41f4b71Sopenharmony_ci
3378e41f4b71Sopenharmony_ciavRecorder.start().then(() => {
3379e41f4b71Sopenharmony_ci  console.info('Succeeded in starting AVRecorder');
3380e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
3381e41f4b71Sopenharmony_ci  console.error('Failed to start AVRecorder and catch error is ' + err.message);
3382e41f4b71Sopenharmony_ci});
3383e41f4b71Sopenharmony_ci```
3384e41f4b71Sopenharmony_ci
3385e41f4b71Sopenharmony_ci### pause<sup>9+</sup>
3386e41f4b71Sopenharmony_ci
3387e41f4b71Sopenharmony_cipause(callback: AsyncCallback\<void>): void
3388e41f4b71Sopenharmony_ci
3389e41f4b71Sopenharmony_ciPauses recording. This API uses an asynchronous callback to return the result.
3390e41f4b71Sopenharmony_ci
3391e41f4b71Sopenharmony_ciThis API can be called only after the [start()](#start9) API is called. You can call [resume()](#resume9) to resume recording.
3392e41f4b71Sopenharmony_ci
3393e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3394e41f4b71Sopenharmony_ci
3395e41f4b71Sopenharmony_ci**Parameters**
3396e41f4b71Sopenharmony_ci
3397e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                       |
3398e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | --------------------------- |
3399e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
3400e41f4b71Sopenharmony_ci
3401e41f4b71Sopenharmony_ci**Error codes**
3402e41f4b71Sopenharmony_ci
3403e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3404e41f4b71Sopenharmony_ci
3405e41f4b71Sopenharmony_ci| ID| Error Message                               |
3406e41f4b71Sopenharmony_ci| -------- | --------------------------------------- |
3407e41f4b71Sopenharmony_ci| 5400102  | Operate not permit. Return by callback. |
3408e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by callback.           |
3409e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by callback.       |
3410e41f4b71Sopenharmony_ci
3411e41f4b71Sopenharmony_ci**Example**
3412e41f4b71Sopenharmony_ci
3413e41f4b71Sopenharmony_ci```ts
3414e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3415e41f4b71Sopenharmony_ci
3416e41f4b71Sopenharmony_ciavRecorder.pause((err: BusinessError) => {
3417e41f4b71Sopenharmony_ci  if (err) {
3418e41f4b71Sopenharmony_ci    console.error('Failed to pause AVRecorder and error is ' + err.message);
3419e41f4b71Sopenharmony_ci  } else {
3420e41f4b71Sopenharmony_ci    console.info('Succeeded in pausing');
3421e41f4b71Sopenharmony_ci  }
3422e41f4b71Sopenharmony_ci});
3423e41f4b71Sopenharmony_ci```
3424e41f4b71Sopenharmony_ci
3425e41f4b71Sopenharmony_ci### pause<sup>9+</sup>
3426e41f4b71Sopenharmony_ci
3427e41f4b71Sopenharmony_cipause(): Promise\<void>
3428e41f4b71Sopenharmony_ci
3429e41f4b71Sopenharmony_ciPauses recording. This API uses a promise to return the result.
3430e41f4b71Sopenharmony_ci
3431e41f4b71Sopenharmony_ciThis API can be called only after the [start()](#start9-1) API is called. You can call [resume()](#resume9-1) to resume recording.
3432e41f4b71Sopenharmony_ci
3433e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3434e41f4b71Sopenharmony_ci
3435e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3436e41f4b71Sopenharmony_ci
3437e41f4b71Sopenharmony_ci**Return value**
3438e41f4b71Sopenharmony_ci
3439e41f4b71Sopenharmony_ci| Type          | Description                                 |
3440e41f4b71Sopenharmony_ci| -------------- | ------------------------------------- |
3441e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
3442e41f4b71Sopenharmony_ci
3443e41f4b71Sopenharmony_ci**Error codes**
3444e41f4b71Sopenharmony_ci
3445e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3446e41f4b71Sopenharmony_ci
3447e41f4b71Sopenharmony_ci| ID| Error Message                              |
3448e41f4b71Sopenharmony_ci| -------- | -------------------------------------- |
3449e41f4b71Sopenharmony_ci| 5400102  | Operate not permit. Return by promise. |
3450e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by promise.           |
3451e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise.       |
3452e41f4b71Sopenharmony_ci
3453e41f4b71Sopenharmony_ci**Example**
3454e41f4b71Sopenharmony_ci
3455e41f4b71Sopenharmony_ci```ts
3456e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3457e41f4b71Sopenharmony_ci
3458e41f4b71Sopenharmony_ciavRecorder.pause().then(() => {
3459e41f4b71Sopenharmony_ci  console.info('Succeeded in pausing');
3460e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
3461e41f4b71Sopenharmony_ci  console.error('Failed to pause AVRecorder and catch error is ' + err.message);
3462e41f4b71Sopenharmony_ci});
3463e41f4b71Sopenharmony_ci```
3464e41f4b71Sopenharmony_ci
3465e41f4b71Sopenharmony_ci### resume<sup>9+</sup>
3466e41f4b71Sopenharmony_ci
3467e41f4b71Sopenharmony_ciresume(callback: AsyncCallback\<void>): void
3468e41f4b71Sopenharmony_ci
3469e41f4b71Sopenharmony_ciResumes recording. This API uses an asynchronous callback to return the result.
3470e41f4b71Sopenharmony_ci
3471e41f4b71Sopenharmony_ciThis API can be called only after the [pause()](#pause9-2) API is called.
3472e41f4b71Sopenharmony_ci
3473e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3474e41f4b71Sopenharmony_ci
3475e41f4b71Sopenharmony_ci**Parameters**
3476e41f4b71Sopenharmony_ci
3477e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                        |
3478e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------- |
3479e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
3480e41f4b71Sopenharmony_ci
3481e41f4b71Sopenharmony_ci**Error codes**
3482e41f4b71Sopenharmony_ci
3483e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3484e41f4b71Sopenharmony_ci
3485e41f4b71Sopenharmony_ci| ID| Error Message                               |
3486e41f4b71Sopenharmony_ci| -------- | --------------------------------------- |
3487e41f4b71Sopenharmony_ci| 5400102  | Operate not permit. Return by callback. |
3488e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by callback.           |
3489e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by callback.       |
3490e41f4b71Sopenharmony_ci
3491e41f4b71Sopenharmony_ci**Example**
3492e41f4b71Sopenharmony_ci
3493e41f4b71Sopenharmony_ci```ts
3494e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3495e41f4b71Sopenharmony_ci
3496e41f4b71Sopenharmony_ciavRecorder.resume((err: BusinessError) => {
3497e41f4b71Sopenharmony_ci  if (err) {
3498e41f4b71Sopenharmony_ci    console.error('Failed to resume AVRecorder and error is ' + err.message);
3499e41f4b71Sopenharmony_ci  } else {
3500e41f4b71Sopenharmony_ci    console.info('Succeeded in resuming AVRecorder');
3501e41f4b71Sopenharmony_ci  }
3502e41f4b71Sopenharmony_ci});
3503e41f4b71Sopenharmony_ci```
3504e41f4b71Sopenharmony_ci
3505e41f4b71Sopenharmony_ci### resume<sup>9+</sup>
3506e41f4b71Sopenharmony_ci
3507e41f4b71Sopenharmony_ciresume(): Promise\<void>
3508e41f4b71Sopenharmony_ci
3509e41f4b71Sopenharmony_ciResumes recording. This API uses a promise to return the result.
3510e41f4b71Sopenharmony_ci
3511e41f4b71Sopenharmony_ciThis API can be called only after the [pause()](#pause9-3) API is called.
3512e41f4b71Sopenharmony_ci
3513e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3514e41f4b71Sopenharmony_ci
3515e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3516e41f4b71Sopenharmony_ci
3517e41f4b71Sopenharmony_ci**Return value**
3518e41f4b71Sopenharmony_ci
3519e41f4b71Sopenharmony_ci| Type          | Description                                 |
3520e41f4b71Sopenharmony_ci| -------------- | ------------------------------------- |
3521e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
3522e41f4b71Sopenharmony_ci
3523e41f4b71Sopenharmony_ci**Error codes**
3524e41f4b71Sopenharmony_ci
3525e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3526e41f4b71Sopenharmony_ci
3527e41f4b71Sopenharmony_ci| ID| Error Message                              |
3528e41f4b71Sopenharmony_ci| -------- | -------------------------------------- |
3529e41f4b71Sopenharmony_ci| 5400102  | Operate not permit. Return by promise. |
3530e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by promise.           |
3531e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise.       |
3532e41f4b71Sopenharmony_ci
3533e41f4b71Sopenharmony_ci**Example**
3534e41f4b71Sopenharmony_ci
3535e41f4b71Sopenharmony_ci```ts
3536e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3537e41f4b71Sopenharmony_ci
3538e41f4b71Sopenharmony_ciavRecorder.resume().then(() => {
3539e41f4b71Sopenharmony_ci  console.info('Succeeded in resuming AVRecorder');
3540e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
3541e41f4b71Sopenharmony_ci  console.error('Failed to resume  AVRecorder failed and catch error is ' + err.message);
3542e41f4b71Sopenharmony_ci});
3543e41f4b71Sopenharmony_ci```
3544e41f4b71Sopenharmony_ci
3545e41f4b71Sopenharmony_ci### stop<sup>9+</sup>
3546e41f4b71Sopenharmony_ci
3547e41f4b71Sopenharmony_cistop(callback: AsyncCallback\<void>): void
3548e41f4b71Sopenharmony_ci
3549e41f4b71Sopenharmony_ciStops recording. This API uses an asynchronous callback to return the result.
3550e41f4b71Sopenharmony_ci
3551e41f4b71Sopenharmony_ciThis API can be called only after the [start()](#start9) or [pause()](#pause9-2) API is called.
3552e41f4b71Sopenharmony_ci
3553e41f4b71Sopenharmony_ciFor audio-only recording, you can call [prepare()](#prepare9-2) again for re-recording. For video-only recording or audio and video recording, you can call [prepare()](#prepare9-2) and [getInputSurface()](#getinputsurface9) again for re-recording.
3554e41f4b71Sopenharmony_ci
3555e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3556e41f4b71Sopenharmony_ci
3557e41f4b71Sopenharmony_ci**Parameters**
3558e41f4b71Sopenharmony_ci
3559e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                        |
3560e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------- |
3561e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
3562e41f4b71Sopenharmony_ci
3563e41f4b71Sopenharmony_ci**Error codes**
3564e41f4b71Sopenharmony_ci
3565e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3566e41f4b71Sopenharmony_ci
3567e41f4b71Sopenharmony_ci| ID| Error Message                               |
3568e41f4b71Sopenharmony_ci| -------- | --------------------------------------- |
3569e41f4b71Sopenharmony_ci| 5400102  | Operate not permit. Return by callback. |
3570e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by callback.           |
3571e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by callback.       |
3572e41f4b71Sopenharmony_ci
3573e41f4b71Sopenharmony_ci**Example**
3574e41f4b71Sopenharmony_ci
3575e41f4b71Sopenharmony_ci```ts
3576e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3577e41f4b71Sopenharmony_ci
3578e41f4b71Sopenharmony_ciavRecorder.stop((err: BusinessError) => {
3579e41f4b71Sopenharmony_ci  if (err) {
3580e41f4b71Sopenharmony_ci    console.error('Failed to stop AVRecorder and error is ' + err.message);
3581e41f4b71Sopenharmony_ci  } else {
3582e41f4b71Sopenharmony_ci    console.info('Succeeded in stopping AVRecorder');
3583e41f4b71Sopenharmony_ci  }
3584e41f4b71Sopenharmony_ci});
3585e41f4b71Sopenharmony_ci```
3586e41f4b71Sopenharmony_ci
3587e41f4b71Sopenharmony_ci### stop<sup>9+</sup>
3588e41f4b71Sopenharmony_ci
3589e41f4b71Sopenharmony_cistop(): Promise\<void>
3590e41f4b71Sopenharmony_ci
3591e41f4b71Sopenharmony_ciStops recording. This API uses a promise to return the result.
3592e41f4b71Sopenharmony_ci
3593e41f4b71Sopenharmony_ciThis API can be called only after the [start()](#start9-1) or [pause()](#pause9-3) API is called.
3594e41f4b71Sopenharmony_ci
3595e41f4b71Sopenharmony_ciFor audio-only recording, you can call [prepare()](#prepare9-3) again for re-recording. For video-only recording or audio and video recording, you can call [prepare()](#prepare9-3) and [getInputSurface()](#getinputsurface9-1) again for re-recording.
3596e41f4b71Sopenharmony_ci
3597e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3598e41f4b71Sopenharmony_ci
3599e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3600e41f4b71Sopenharmony_ci
3601e41f4b71Sopenharmony_ci**Return value**
3602e41f4b71Sopenharmony_ci
3603e41f4b71Sopenharmony_ci| Type          | Description                                 |
3604e41f4b71Sopenharmony_ci| -------------- | ------------------------------------- |
3605e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
3606e41f4b71Sopenharmony_ci
3607e41f4b71Sopenharmony_ci**Error codes**
3608e41f4b71Sopenharmony_ci
3609e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3610e41f4b71Sopenharmony_ci
3611e41f4b71Sopenharmony_ci| ID| Error Message                              |
3612e41f4b71Sopenharmony_ci| -------- | -------------------------------------- |
3613e41f4b71Sopenharmony_ci| 5400102  | Operate not permit. Return by promise. |
3614e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by promise.           |
3615e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise.       |
3616e41f4b71Sopenharmony_ci
3617e41f4b71Sopenharmony_ci**Example**
3618e41f4b71Sopenharmony_ci
3619e41f4b71Sopenharmony_ci```ts
3620e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3621e41f4b71Sopenharmony_ci
3622e41f4b71Sopenharmony_ciavRecorder.stop().then(() => {
3623e41f4b71Sopenharmony_ci  console.info('Succeeded in stopping AVRecorder');
3624e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
3625e41f4b71Sopenharmony_ci  console.error('Failed to stop AVRecorder and catch error is ' + err.message);
3626e41f4b71Sopenharmony_ci});
3627e41f4b71Sopenharmony_ci```
3628e41f4b71Sopenharmony_ci
3629e41f4b71Sopenharmony_ci### reset<sup>9+</sup>
3630e41f4b71Sopenharmony_ci
3631e41f4b71Sopenharmony_cireset(callback: AsyncCallback\<void>): void
3632e41f4b71Sopenharmony_ci
3633e41f4b71Sopenharmony_ciResets audio and video recording. This API uses an asynchronous callback to return the result.
3634e41f4b71Sopenharmony_ci
3635e41f4b71Sopenharmony_ciFor audio-only recording, you can call [prepare()](#prepare9-2) again for re-recording. For video-only recording or audio and video recording, you can call [prepare()](#prepare9-2) and [getInputSurface()](#getinputsurface9) again for re-recording.
3636e41f4b71Sopenharmony_ci
3637e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3638e41f4b71Sopenharmony_ci
3639e41f4b71Sopenharmony_ci**Parameters**
3640e41f4b71Sopenharmony_ci
3641e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                          |
3642e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------ |
3643e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
3644e41f4b71Sopenharmony_ci
3645e41f4b71Sopenharmony_ci**Error codes**
3646e41f4b71Sopenharmony_ci
3647e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3648e41f4b71Sopenharmony_ci
3649e41f4b71Sopenharmony_ci| ID| Error Message                         |
3650e41f4b71Sopenharmony_ci| -------- | --------------------------------- |
3651e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by callback.     |
3652e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by callback. |
3653e41f4b71Sopenharmony_ci
3654e41f4b71Sopenharmony_ci**Example**
3655e41f4b71Sopenharmony_ci
3656e41f4b71Sopenharmony_ci```ts
3657e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3658e41f4b71Sopenharmony_ci
3659e41f4b71Sopenharmony_ciavRecorder.reset((err: BusinessError) => {
3660e41f4b71Sopenharmony_ci  if (err) {
3661e41f4b71Sopenharmony_ci    console.error('Failed to reset AVRecorder and error is ' + err.message);
3662e41f4b71Sopenharmony_ci  } else {
3663e41f4b71Sopenharmony_ci    console.info('Succeeded in resetting AVRecorder');
3664e41f4b71Sopenharmony_ci  }
3665e41f4b71Sopenharmony_ci});
3666e41f4b71Sopenharmony_ci```
3667e41f4b71Sopenharmony_ci
3668e41f4b71Sopenharmony_ci### reset<sup>9+</sup>
3669e41f4b71Sopenharmony_ci
3670e41f4b71Sopenharmony_cireset(): Promise\<void>
3671e41f4b71Sopenharmony_ci
3672e41f4b71Sopenharmony_ciResets audio and video recording. This API uses a promise to return the result.
3673e41f4b71Sopenharmony_ci
3674e41f4b71Sopenharmony_ciFor audio-only recording, you can call [prepare()](#prepare9-3) again for re-recording. For video-only recording or audio and video recording, you can call [prepare()](#prepare9-3) and [getInputSurface()](#getinputsurface9-1) again for re-recording.
3675e41f4b71Sopenharmony_ci
3676e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3677e41f4b71Sopenharmony_ci
3678e41f4b71Sopenharmony_ci**Return value**
3679e41f4b71Sopenharmony_ci
3680e41f4b71Sopenharmony_ci| Type          | Description                                   |
3681e41f4b71Sopenharmony_ci| -------------- | --------------------------------------- |
3682e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
3683e41f4b71Sopenharmony_ci
3684e41f4b71Sopenharmony_ci**Error codes**
3685e41f4b71Sopenharmony_ci
3686e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3687e41f4b71Sopenharmony_ci
3688e41f4b71Sopenharmony_ci| ID| Error Message                        |
3689e41f4b71Sopenharmony_ci| -------- | -------------------------------- |
3690e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by promise.     |
3691e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise. |
3692e41f4b71Sopenharmony_ci
3693e41f4b71Sopenharmony_ci**Example**
3694e41f4b71Sopenharmony_ci
3695e41f4b71Sopenharmony_ci```ts
3696e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3697e41f4b71Sopenharmony_ci
3698e41f4b71Sopenharmony_ciavRecorder.reset().then(() => {
3699e41f4b71Sopenharmony_ci  console.info('Succeeded in resetting AVRecorder');
3700e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
3701e41f4b71Sopenharmony_ci  console.error('Failed to reset and catch error is ' + err.message);
3702e41f4b71Sopenharmony_ci});
3703e41f4b71Sopenharmony_ci```
3704e41f4b71Sopenharmony_ci
3705e41f4b71Sopenharmony_ci### release<sup>9+</sup>
3706e41f4b71Sopenharmony_ci
3707e41f4b71Sopenharmony_cirelease(callback: AsyncCallback\<void>): void
3708e41f4b71Sopenharmony_ci
3709e41f4b71Sopenharmony_ciReleases the audio and video recording resources. This API uses an asynchronous callback to return the result.
3710e41f4b71Sopenharmony_ci
3711e41f4b71Sopenharmony_ciAfter the resources are released, you can no longer perform any operation on the **AVRecorder** instance.
3712e41f4b71Sopenharmony_ci
3713e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3714e41f4b71Sopenharmony_ci
3715e41f4b71Sopenharmony_ci**Parameters**
3716e41f4b71Sopenharmony_ci
3717e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                              |
3718e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------------- |
3719e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
3720e41f4b71Sopenharmony_ci
3721e41f4b71Sopenharmony_ci**Error codes**
3722e41f4b71Sopenharmony_ci
3723e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3724e41f4b71Sopenharmony_ci
3725e41f4b71Sopenharmony_ci| ID| Error Message                         |
3726e41f4b71Sopenharmony_ci| -------- | --------------------------------- |
3727e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by callback. |
3728e41f4b71Sopenharmony_ci
3729e41f4b71Sopenharmony_ci**Example**
3730e41f4b71Sopenharmony_ci
3731e41f4b71Sopenharmony_ci```ts
3732e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3733e41f4b71Sopenharmony_ci
3734e41f4b71Sopenharmony_ciavRecorder.release((err: BusinessError) => {
3735e41f4b71Sopenharmony_ci  if (err) {
3736e41f4b71Sopenharmony_ci    console.error('Failed to release AVRecorder and error is ' + err.message);
3737e41f4b71Sopenharmony_ci  } else {
3738e41f4b71Sopenharmony_ci    console.info('Succeeded in releasing AVRecorder');
3739e41f4b71Sopenharmony_ci  }
3740e41f4b71Sopenharmony_ci});
3741e41f4b71Sopenharmony_ci```
3742e41f4b71Sopenharmony_ci
3743e41f4b71Sopenharmony_ci### release<sup>9+</sup>
3744e41f4b71Sopenharmony_ci
3745e41f4b71Sopenharmony_cirelease(): Promise\<void>
3746e41f4b71Sopenharmony_ci
3747e41f4b71Sopenharmony_ciReleases the audio and video recording resources. This API uses a promise to return the result.
3748e41f4b71Sopenharmony_ci
3749e41f4b71Sopenharmony_ciAfter the resources are released, you can no longer perform any operation on the **AVRecorder** instance.
3750e41f4b71Sopenharmony_ci
3751e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3752e41f4b71Sopenharmony_ci
3753e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3754e41f4b71Sopenharmony_ci
3755e41f4b71Sopenharmony_ci**Return value**
3756e41f4b71Sopenharmony_ci
3757e41f4b71Sopenharmony_ci| Type          | Description                                       |
3758e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------- |
3759e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
3760e41f4b71Sopenharmony_ci
3761e41f4b71Sopenharmony_ci**Error codes**
3762e41f4b71Sopenharmony_ci
3763e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3764e41f4b71Sopenharmony_ci
3765e41f4b71Sopenharmony_ci| ID| Error Message                         |
3766e41f4b71Sopenharmony_ci| -------- | --------------------------------- |
3767e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by callback. |
3768e41f4b71Sopenharmony_ci
3769e41f4b71Sopenharmony_ci**Example**
3770e41f4b71Sopenharmony_ci
3771e41f4b71Sopenharmony_ci```ts
3772e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3773e41f4b71Sopenharmony_ci
3774e41f4b71Sopenharmony_ciavRecorder.release().then(() => {
3775e41f4b71Sopenharmony_ci  console.info('Succeeded in releasing AVRecorder');
3776e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
3777e41f4b71Sopenharmony_ci  console.error('Failed to release AVRecorder and catch error is ' + err.message);
3778e41f4b71Sopenharmony_ci});
3779e41f4b71Sopenharmony_ci```
3780e41f4b71Sopenharmony_ci
3781e41f4b71Sopenharmony_ci### getCurrentAudioCapturerInfo<sup>11+</sup>
3782e41f4b71Sopenharmony_ci
3783e41f4b71Sopenharmony_cigetCurrentAudioCapturerInfo(callback: AsyncCallback\<audio.AudioCapturerChangeInfo>): void
3784e41f4b71Sopenharmony_ci
3785e41f4b71Sopenharmony_ciObtains the information about the current audio capturer. This API uses an asynchronous callback to return the result.
3786e41f4b71Sopenharmony_ci
3787e41f4b71Sopenharmony_ciThis 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.
3788e41f4b71Sopenharmony_ci
3789e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3790e41f4b71Sopenharmony_ci
3791e41f4b71Sopenharmony_ci**Parameters**
3792e41f4b71Sopenharmony_ci
3793e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory| Description                                |
3794e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------ |
3795e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[audio.AudioCapturerChangeInfo](../apis-audio-kit/js-apis-audio.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.|
3796e41f4b71Sopenharmony_ci
3797e41f4b71Sopenharmony_ci**Error codes**
3798e41f4b71Sopenharmony_ci
3799e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3800e41f4b71Sopenharmony_ci
3801e41f4b71Sopenharmony_ci| ID| Error Message                                  |
3802e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
3803e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. |
3804e41f4b71Sopenharmony_ci| 5400103  | I/O error.             |
3805e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by callback.          |
3806e41f4b71Sopenharmony_ci
3807e41f4b71Sopenharmony_ci**Example**
3808e41f4b71Sopenharmony_ci
3809e41f4b71Sopenharmony_ci```ts
3810e41f4b71Sopenharmony_ciimport { audio } from '@kit.AudioKit';
3811e41f4b71Sopenharmony_ci
3812e41f4b71Sopenharmony_cilet currentCapturerInfo: audio.AudioCapturerChangeInfo;
3813e41f4b71Sopenharmony_ci
3814e41f4b71Sopenharmony_ciavRecorder.getCurrentAudioCapturerInfo((err: BusinessError, capturerInfo: audio.AudioCapturerChangeInfo) => {
3815e41f4b71Sopenharmony_ci  if (err) {
3816e41f4b71Sopenharmony_ci    console.error('Failed to get CurrentAudioCapturerInfo and error is ' + err.message);
3817e41f4b71Sopenharmony_ci  } else {
3818e41f4b71Sopenharmony_ci    console.info('Succeeded in getting CurrentAudioCapturerInfo');
3819e41f4b71Sopenharmony_ci    currentCapturerInfo = capturerInfo;
3820e41f4b71Sopenharmony_ci  }
3821e41f4b71Sopenharmony_ci});
3822e41f4b71Sopenharmony_ci```
3823e41f4b71Sopenharmony_ci
3824e41f4b71Sopenharmony_ci### getCurrentAudioCapturerInfo<sup>11+</sup>
3825e41f4b71Sopenharmony_ci
3826e41f4b71Sopenharmony_cigetCurrentAudioCapturerInfo(): Promise\<audio.AudioCapturerChangeInfo>
3827e41f4b71Sopenharmony_ci
3828e41f4b71Sopenharmony_ciObtains the information about the current audio capturer. This API uses a promise to return the result.
3829e41f4b71Sopenharmony_ci
3830e41f4b71Sopenharmony_ciThis 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.
3831e41f4b71Sopenharmony_ci
3832e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3833e41f4b71Sopenharmony_ci
3834e41f4b71Sopenharmony_ci**Return value**
3835e41f4b71Sopenharmony_ci
3836e41f4b71Sopenharmony_ci| Type                                                        | Description                                             |
3837e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------------------- |
3838e41f4b71Sopenharmony_ci| Promise\<[audio.AudioCapturerChangeInfo](../apis-audio-kit/js-apis-audio.md#audiocapturerchangeinfo9)> | Promise used to return the audio capturer information.|
3839e41f4b71Sopenharmony_ci
3840e41f4b71Sopenharmony_ci**Error codes**
3841e41f4b71Sopenharmony_ci
3842e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3843e41f4b71Sopenharmony_ci
3844e41f4b71Sopenharmony_ci| ID| Error Message                        |
3845e41f4b71Sopenharmony_ci| -------- | -------------------------------- |
3846e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed.           |
3847e41f4b71Sopenharmony_ci| 5400103  | I/O error.                       |
3848e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise. |
3849e41f4b71Sopenharmony_ci
3850e41f4b71Sopenharmony_ci**Example**
3851e41f4b71Sopenharmony_ci
3852e41f4b71Sopenharmony_ci```ts
3853e41f4b71Sopenharmony_ciimport { audio } from '@kit.AudioKit';
3854e41f4b71Sopenharmony_ci
3855e41f4b71Sopenharmony_cilet currentCapturerInfo: audio.AudioCapturerChangeInfo;
3856e41f4b71Sopenharmony_ci
3857e41f4b71Sopenharmony_ciavRecorder.getCurrentAudioCapturerInfo().then((capturerInfo: audio.AudioCapturerChangeInfo) => {
3858e41f4b71Sopenharmony_ci  console.info('Succeeded in getting CurrentAudioCapturerInfo');
3859e41f4b71Sopenharmony_ci  currentCapturerInfo = capturerInfo;
3860e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
3861e41f4b71Sopenharmony_ci  console.error('Failed to get CurrentAudioCapturerInfo and catch error is ' + err.message);
3862e41f4b71Sopenharmony_ci});
3863e41f4b71Sopenharmony_ci```
3864e41f4b71Sopenharmony_ci
3865e41f4b71Sopenharmony_ci### getAudioCapturerMaxAmplitude<sup>11+</sup>
3866e41f4b71Sopenharmony_ci
3867e41f4b71Sopenharmony_cigetAudioCapturerMaxAmplitude(callback: AsyncCallback\<number>): void
3868e41f4b71Sopenharmony_ci
3869e41f4b71Sopenharmony_ciObtains the maximum amplitude of the current audio capturer. This API uses an asynchronous callback to return the result.
3870e41f4b71Sopenharmony_ci
3871e41f4b71Sopenharmony_ciThis 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.
3872e41f4b71Sopenharmony_ci
3873e41f4b71Sopenharmony_ciThe 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.
3874e41f4b71Sopenharmony_ci
3875e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3876e41f4b71Sopenharmony_ci
3877e41f4b71Sopenharmony_ci**Parameters**
3878e41f4b71Sopenharmony_ci
3879e41f4b71Sopenharmony_ci| Name  | Type                  | Mandatory| Description                                |
3880e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------------------------ |
3881e41f4b71Sopenharmony_ci| 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.|
3882e41f4b71Sopenharmony_ci
3883e41f4b71Sopenharmony_ci**Error codes**
3884e41f4b71Sopenharmony_ci
3885e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3886e41f4b71Sopenharmony_ci
3887e41f4b71Sopenharmony_ci| ID| Error Message                                  |
3888e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
3889e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. |
3890e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by callback.          |
3891e41f4b71Sopenharmony_ci
3892e41f4b71Sopenharmony_ci**Example**
3893e41f4b71Sopenharmony_ci
3894e41f4b71Sopenharmony_ci```ts
3895e41f4b71Sopenharmony_cilet maxAmplitude: number;
3896e41f4b71Sopenharmony_ci
3897e41f4b71Sopenharmony_ciavRecorder.getAudioCapturerMaxAmplitude((err: BusinessError, amplitude: number) => {
3898e41f4b71Sopenharmony_ci  if (err) {
3899e41f4b71Sopenharmony_ci    console.error('Failed to get AudioCapturerMaxAmplitude and error is ' + err.message);
3900e41f4b71Sopenharmony_ci  } else {
3901e41f4b71Sopenharmony_ci    console.info('Succeeded in getting AudioCapturerMaxAmplitude');
3902e41f4b71Sopenharmony_ci    maxAmplitude = amplitude;
3903e41f4b71Sopenharmony_ci  }
3904e41f4b71Sopenharmony_ci});
3905e41f4b71Sopenharmony_ci```
3906e41f4b71Sopenharmony_ci
3907e41f4b71Sopenharmony_ci### getAudioCapturerMaxAmplitude<sup>11+</sup>
3908e41f4b71Sopenharmony_ci
3909e41f4b71Sopenharmony_cigetAudioCapturerMaxAmplitude(): Promise\<number>
3910e41f4b71Sopenharmony_ci
3911e41f4b71Sopenharmony_ciObtains the maximum amplitude of the current audio capturer. This API uses a promise to return the result.
3912e41f4b71Sopenharmony_ci
3913e41f4b71Sopenharmony_ciThis 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.
3914e41f4b71Sopenharmony_ci
3915e41f4b71Sopenharmony_ciThe 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.
3916e41f4b71Sopenharmony_ci
3917e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3918e41f4b71Sopenharmony_ci
3919e41f4b71Sopenharmony_ci**Return value**
3920e41f4b71Sopenharmony_ci
3921e41f4b71Sopenharmony_ci| Type            | Description                                             |
3922e41f4b71Sopenharmony_ci| ---------------- | ------------------------------------------------- |
3923e41f4b71Sopenharmony_ci| Promise\<number>| Promise used to return the maximum amplitude obtained.|
3924e41f4b71Sopenharmony_ci
3925e41f4b71Sopenharmony_ci**Error codes**
3926e41f4b71Sopenharmony_ci
3927e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3928e41f4b71Sopenharmony_ci
3929e41f4b71Sopenharmony_ci| ID| Error Message                        |
3930e41f4b71Sopenharmony_ci| -------- | -------------------------------- |
3931e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed.           |
3932e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise. |
3933e41f4b71Sopenharmony_ci
3934e41f4b71Sopenharmony_ci**Example**
3935e41f4b71Sopenharmony_ci
3936e41f4b71Sopenharmony_ci```ts
3937e41f4b71Sopenharmony_cilet maxAmplitude: number;
3938e41f4b71Sopenharmony_ci
3939e41f4b71Sopenharmony_ciavRecorder.getAudioCapturerMaxAmplitude().then((amplitude: number) => {
3940e41f4b71Sopenharmony_ci  console.info('Succeeded in getting AudioCapturerMaxAmplitude');
3941e41f4b71Sopenharmony_ci  maxAmplitude = amplitude;
3942e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
3943e41f4b71Sopenharmony_ci  console.error('Failed to get AudioCapturerMaxAmplitude and catch error is ' + err.message);
3944e41f4b71Sopenharmony_ci});
3945e41f4b71Sopenharmony_ci```
3946e41f4b71Sopenharmony_ci
3947e41f4b71Sopenharmony_ci### getAvailableEncoder<sup>11+</sup>
3948e41f4b71Sopenharmony_ci
3949e41f4b71Sopenharmony_cigetAvailableEncoder(callback: AsyncCallback\<Array\<EncoderInfo>>): void
3950e41f4b71Sopenharmony_ci
3951e41f4b71Sopenharmony_ciObtains available encoders. This API uses an asynchronous callback to return the result.
3952e41f4b71Sopenharmony_ci
3953e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3954e41f4b71Sopenharmony_ci
3955e41f4b71Sopenharmony_ci**Parameters**
3956e41f4b71Sopenharmony_ci
3957e41f4b71Sopenharmony_ci| Name  | Type                                                 | Mandatory| Description                                |
3958e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------------- | ---- | ------------------------------------ |
3959e41f4b71Sopenharmony_ci| callback | AsyncCallback\<Array\<[EncoderInfo](#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.|
3960e41f4b71Sopenharmony_ci
3961e41f4b71Sopenharmony_ci**Error codes**
3962e41f4b71Sopenharmony_ci
3963e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
3964e41f4b71Sopenharmony_ci
3965e41f4b71Sopenharmony_ci| ID| Error Message                                  |
3966e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
3967e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. |
3968e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by callback.          |
3969e41f4b71Sopenharmony_ci
3970e41f4b71Sopenharmony_ci**Example**
3971e41f4b71Sopenharmony_ci
3972e41f4b71Sopenharmony_ci```ts
3973e41f4b71Sopenharmony_cilet encoderInfo: media.EncoderInfo;
3974e41f4b71Sopenharmony_ci
3975e41f4b71Sopenharmony_ciavRecorder.getAvailableEncoder((err: BusinessError, info: media.EncoderInfo[]) => {
3976e41f4b71Sopenharmony_ci  if (err) {
3977e41f4b71Sopenharmony_ci    console.error('Failed to get AvailableEncoder and error is ' + err.message);
3978e41f4b71Sopenharmony_ci  } else {
3979e41f4b71Sopenharmony_ci    console.info('Succeeded in getting AvailableEncoder');
3980e41f4b71Sopenharmony_ci    encoderInfo = info[0];
3981e41f4b71Sopenharmony_ci  }
3982e41f4b71Sopenharmony_ci});
3983e41f4b71Sopenharmony_ci```
3984e41f4b71Sopenharmony_ci
3985e41f4b71Sopenharmony_ci### getAvailableEncoder<sup>11+</sup>
3986e41f4b71Sopenharmony_ci
3987e41f4b71Sopenharmony_cigetAvailableEncoder(): Promise\<Array\<EncoderInfo>>
3988e41f4b71Sopenharmony_ci
3989e41f4b71Sopenharmony_ciObtains available encoders. This API uses an asynchronous callback to return the result.
3990e41f4b71Sopenharmony_ci
3991e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
3992e41f4b71Sopenharmony_ci
3993e41f4b71Sopenharmony_ci**Return value**
3994e41f4b71Sopenharmony_ci
3995e41f4b71Sopenharmony_ci| Type                                           | Description                                           |
3996e41f4b71Sopenharmony_ci| ----------------------------------------------- | ----------------------------------------------- |
3997e41f4b71Sopenharmony_ci| Promise\<Array\<[EncoderInfo](#encoderinfo11)>> | Promise used to return the information about the available encoders.|
3998e41f4b71Sopenharmony_ci
3999e41f4b71Sopenharmony_ci**Error codes**
4000e41f4b71Sopenharmony_ci
4001e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
4002e41f4b71Sopenharmony_ci
4003e41f4b71Sopenharmony_ci| ID| Error Message                        |
4004e41f4b71Sopenharmony_ci| -------- | -------------------------------- |
4005e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed.           |
4006e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise. |
4007e41f4b71Sopenharmony_ci
4008e41f4b71Sopenharmony_ci**Example**
4009e41f4b71Sopenharmony_ci
4010e41f4b71Sopenharmony_ci```ts
4011e41f4b71Sopenharmony_cilet encoderInfo: media.EncoderInfo;
4012e41f4b71Sopenharmony_ci
4013e41f4b71Sopenharmony_ciavRecorder.getAvailableEncoder().then((info: media.EncoderInfo[]) => {
4014e41f4b71Sopenharmony_ci  console.info('Succeeded in getting AvailableEncoder');
4015e41f4b71Sopenharmony_ci  encoderInfo = info[0];
4016e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
4017e41f4b71Sopenharmony_ci  console.error('Failed to get AvailableEncoder and catch error is ' + err.message);
4018e41f4b71Sopenharmony_ci});
4019e41f4b71Sopenharmony_ci```
4020e41f4b71Sopenharmony_ci
4021e41f4b71Sopenharmony_ci### getAVRecorderConfig<sup>11+</sup>
4022e41f4b71Sopenharmony_ci
4023e41f4b71Sopenharmony_cigetAVRecorderConfig(callback: AsyncCallback\<AVRecorderConfig>): void
4024e41f4b71Sopenharmony_ci
4025e41f4b71Sopenharmony_ciObtains the real-time configuration of this AVRecorder. This API uses an asynchronous callback to return the result.
4026e41f4b71Sopenharmony_ci
4027e41f4b71Sopenharmony_ciThis API can be called only after [prepare()](#prepare9-2) is called.
4028e41f4b71Sopenharmony_ci
4029e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
4030e41f4b71Sopenharmony_ci
4031e41f4b71Sopenharmony_ci**Parameters**
4032e41f4b71Sopenharmony_ci
4033e41f4b71Sopenharmony_ci| Name  | Type                  | Mandatory| Description                       |
4034e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | --------------------------- |
4035e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[AVRecorderConfig](#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.|
4036e41f4b71Sopenharmony_ci
4037e41f4b71Sopenharmony_ci**Error codes**
4038e41f4b71Sopenharmony_ci
4039e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
4040e41f4b71Sopenharmony_ci
4041e41f4b71Sopenharmony_ci| ID| Error Message                                  |
4042e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
4043e41f4b71Sopenharmony_ci| 5400102  | Operate not permit. Return by callback. |
4044e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by callback.             |
4045e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by callback.          |
4046e41f4b71Sopenharmony_ci
4047e41f4b71Sopenharmony_ci**Example**
4048e41f4b71Sopenharmony_ci
4049e41f4b71Sopenharmony_ci```ts
4050e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4051e41f4b71Sopenharmony_ci
4052e41f4b71Sopenharmony_cilet avConfig: media.AVRecorderConfig;
4053e41f4b71Sopenharmony_ci
4054e41f4b71Sopenharmony_ciavRecorder.getAVRecorderConfig((err: BusinessError, config: media.AVRecorderConfig) => {
4055e41f4b71Sopenharmony_ci  if (err) {
4056e41f4b71Sopenharmony_ci    console.error('Failed to get avConfig and error is ' + err.message);
4057e41f4b71Sopenharmony_ci  } else {
4058e41f4b71Sopenharmony_ci    console.info('Succeeded in getting AVRecorderConfig');
4059e41f4b71Sopenharmony_ci    avConfig = config;
4060e41f4b71Sopenharmony_ci  }
4061e41f4b71Sopenharmony_ci});
4062e41f4b71Sopenharmony_ci```
4063e41f4b71Sopenharmony_ci
4064e41f4b71Sopenharmony_ci### getAVRecorderConfig<sup>11+</sup>
4065e41f4b71Sopenharmony_ci
4066e41f4b71Sopenharmony_cigetAVRecorderConfig(): Promise\<AVRecorderConfig>;
4067e41f4b71Sopenharmony_ci
4068e41f4b71Sopenharmony_ciObtains the real-time configuration of this AVRecorder. This API uses a promise to return the result.
4069e41f4b71Sopenharmony_ci
4070e41f4b71Sopenharmony_ciThis API can be called only after [prepare()](#prepare9-3) is called.
4071e41f4b71Sopenharmony_ci
4072e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
4073e41f4b71Sopenharmony_ci
4074e41f4b71Sopenharmony_ci**Return value**
4075e41f4b71Sopenharmony_ci
4076e41f4b71Sopenharmony_ci| Type            | Description                            |
4077e41f4b71Sopenharmony_ci| ---------------- | -------------------------------- |
4078e41f4b71Sopenharmony_ci| Promise\<[AVRecorderConfig](#avrecorderconfig9)> | Promise used to return the real-time configuration.|
4079e41f4b71Sopenharmony_ci
4080e41f4b71Sopenharmony_ci**Error codes**
4081e41f4b71Sopenharmony_ci
4082e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
4083e41f4b71Sopenharmony_ci
4084e41f4b71Sopenharmony_ci| ID| Error Message                                 |
4085e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
4086e41f4b71Sopenharmony_ci| 5400102  | Operate not permit. Return by promise. |
4087e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by promise.             |
4088e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise.          |
4089e41f4b71Sopenharmony_ci
4090e41f4b71Sopenharmony_ci**Example**
4091e41f4b71Sopenharmony_ci
4092e41f4b71Sopenharmony_ci```ts
4093e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4094e41f4b71Sopenharmony_ci
4095e41f4b71Sopenharmony_cilet avConfig: media.AVRecorderConfig;
4096e41f4b71Sopenharmony_ci
4097e41f4b71Sopenharmony_ciavRecorder.getAVRecorderConfig().then((config: media.AVRecorderConfig) => {
4098e41f4b71Sopenharmony_ci  console.info('Succeeded in getting AVRecorderConfig');
4099e41f4b71Sopenharmony_ci  avConfig = config;
4100e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
4101e41f4b71Sopenharmony_ci  console.error('Failed to get AVRecorderConfig and catch error is ' + err.message);
4102e41f4b71Sopenharmony_ci});
4103e41f4b71Sopenharmony_ci```
4104e41f4b71Sopenharmony_ci
4105e41f4b71Sopenharmony_ci### on('stateChange')<sup>9+</sup>
4106e41f4b71Sopenharmony_ci
4107e41f4b71Sopenharmony_cion(type: 'stateChange', callback: OnAVRecorderStateChangeHandler): void
4108e41f4b71Sopenharmony_ci
4109e41f4b71Sopenharmony_ciSubscribes 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 prevails.
4110e41f4b71Sopenharmony_ci
4111e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4112e41f4b71Sopenharmony_ci
4113e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
4114e41f4b71Sopenharmony_ci
4115e41f4b71Sopenharmony_ci**Parameters**
4116e41f4b71Sopenharmony_ci
4117e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
4118e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
4119e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'stateChange'** in this case. This event can be triggered by both user operations and the system.|
4120e41f4b71Sopenharmony_ci| callback | [OnAVRecorderStateChangeHandler](#onavrecorderstatechangehandler12) | Yes  | Callback invoked when the event is triggered.|
4121e41f4b71Sopenharmony_ci
4122e41f4b71Sopenharmony_ci**Error codes**
4123e41f4b71Sopenharmony_ci
4124e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
4125e41f4b71Sopenharmony_ci
4126e41f4b71Sopenharmony_ci| ID| Error Message                         |
4127e41f4b71Sopenharmony_ci| -------- | --------------------------------- |
4128e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by callback.     |
4129e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by callback. |
4130e41f4b71Sopenharmony_ci
4131e41f4b71Sopenharmony_ci**Example**
4132e41f4b71Sopenharmony_ci
4133e41f4b71Sopenharmony_ci```ts
4134e41f4b71Sopenharmony_ciavRecorder.on('stateChange', async (state: media.AVRecorderState, reason: media.StateChangeReason) => {
4135e41f4b71Sopenharmony_ci  console.info('case state has changed, new state is :' + state + ',and new reason is : ' + reason);
4136e41f4b71Sopenharmony_ci});
4137e41f4b71Sopenharmony_ci```
4138e41f4b71Sopenharmony_ci
4139e41f4b71Sopenharmony_ci### off('stateChange')<sup>9+</sup>
4140e41f4b71Sopenharmony_ci
4141e41f4b71Sopenharmony_cioff(type: 'stateChange', callback?: OnAVRecorderStateChangeHandler): void
4142e41f4b71Sopenharmony_ci
4143e41f4b71Sopenharmony_ciUnsubscribes from AVRecorder state changes.
4144e41f4b71Sopenharmony_ci
4145e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4146e41f4b71Sopenharmony_ci
4147e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
4148e41f4b71Sopenharmony_ci
4149e41f4b71Sopenharmony_ci**Parameters**
4150e41f4b71Sopenharmony_ci
4151e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
4152e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
4153e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'stateChange'** in this case. This event can be triggered by both user operations and the system.|
4154e41f4b71Sopenharmony_ci| callback | [OnAVRecorderStateChangeHandler](#onavrecorderstatechangehandler12) | No  | Callback invoked when the event is triggered.<br>This parameter is supported since API version 12.|
4155e41f4b71Sopenharmony_ci
4156e41f4b71Sopenharmony_ci**Example**
4157e41f4b71Sopenharmony_ci
4158e41f4b71Sopenharmony_ci```ts
4159e41f4b71Sopenharmony_ciavRecorder.off('stateChange');
4160e41f4b71Sopenharmony_ci```
4161e41f4b71Sopenharmony_ci
4162e41f4b71Sopenharmony_ci### on('error')<sup>9+</sup>
4163e41f4b71Sopenharmony_ci
4164e41f4b71Sopenharmony_cion(type: 'error', callback: ErrorCallback): void
4165e41f4b71Sopenharmony_ci
4166e41f4b71Sopenharmony_ciSubscribes to AVRecorder errors. This event is used only for error prompt and does not require the user to stop recording control. If the [AVRecorderState](#avrecorderstate9) is also switched to error, call [reset()](#reset9-2) or [release()][release()](#release9-2) to exit the recording.
4167e41f4b71Sopenharmony_ci
4168e41f4b71Sopenharmony_ciAn application can subscribe to only one AVRecorder error event. When the application initiates multiple subscriptions to this event, the last subscription prevails.
4169e41f4b71Sopenharmony_ci
4170e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4171e41f4b71Sopenharmony_ci
4172e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
4173e41f4b71Sopenharmony_ci
4174e41f4b71Sopenharmony_ci**Parameters**
4175e41f4b71Sopenharmony_ci
4176e41f4b71Sopenharmony_ci| Name  | Type         | Mandatory| Description                                                        |
4177e41f4b71Sopenharmony_ci| -------- | ------------- | ---- | ------------------------------------------------------------ |
4178e41f4b71Sopenharmony_ci| type     | string        | Yes  | Event type, which is **'error'** in this case.<br>This event is triggered when an error occurs during recording.|
4179e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes  | Callback invoked when the event is triggered.                                      |
4180e41f4b71Sopenharmony_ci
4181e41f4b71Sopenharmony_ci**Error codes**
4182e41f4b71Sopenharmony_ci
4183e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
4184e41f4b71Sopenharmony_ci
4185e41f4b71Sopenharmony_ci| ID| Error Message                                  |
4186e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
4187e41f4b71Sopenharmony_ci| 201      | Permission denied.     |
4188e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. |
4189e41f4b71Sopenharmony_ci| 801      | Capability not supported. |
4190e41f4b71Sopenharmony_ci| 5400101  | No memory.             |
4191e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. |
4192e41f4b71Sopenharmony_ci| 5400103  | I/O error.             |
4193e41f4b71Sopenharmony_ci| 5400104  | Time out.              |
4194e41f4b71Sopenharmony_ci| 5400105  | Service died.          |
4195e41f4b71Sopenharmony_ci| 5400106  | Unsupport format.      |
4196e41f4b71Sopenharmony_ci| 5400107  | Audio interrupted.     |
4197e41f4b71Sopenharmony_ci
4198e41f4b71Sopenharmony_ci**Example**
4199e41f4b71Sopenharmony_ci
4200e41f4b71Sopenharmony_ci```ts
4201e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4202e41f4b71Sopenharmony_ci
4203e41f4b71Sopenharmony_ciavRecorder.on('error', (err: BusinessError) => {
4204e41f4b71Sopenharmony_ci  console.info('case avRecorder.on(error) called, errMessage is ' + err.message);
4205e41f4b71Sopenharmony_ci});
4206e41f4b71Sopenharmony_ci```
4207e41f4b71Sopenharmony_ci
4208e41f4b71Sopenharmony_ci### off('error')<sup>9+</sup>
4209e41f4b71Sopenharmony_ci
4210e41f4b71Sopenharmony_cioff(type: 'error', callback?: ErrorCallback): void
4211e41f4b71Sopenharmony_ci
4212e41f4b71Sopenharmony_ciUnsubscribes from AVRecorder errors. After the unsubscription, your application can no longer receive AVRecorder errors.
4213e41f4b71Sopenharmony_ci
4214e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4215e41f4b71Sopenharmony_ci
4216e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
4217e41f4b71Sopenharmony_ci
4218e41f4b71Sopenharmony_ci**Parameters**
4219e41f4b71Sopenharmony_ci
4220e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
4221e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
4222e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'error'** in this case.<br>This event is triggered when an error occurs during recording.|
4223e41f4b71Sopenharmony_ci| 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.                  |
4224e41f4b71Sopenharmony_ci
4225e41f4b71Sopenharmony_ci**Example**
4226e41f4b71Sopenharmony_ci
4227e41f4b71Sopenharmony_ci```ts
4228e41f4b71Sopenharmony_ciavRecorder.off('error');
4229e41f4b71Sopenharmony_ci```
4230e41f4b71Sopenharmony_ci
4231e41f4b71Sopenharmony_ci### on('audioCapturerChange')<sup>11+</sup>
4232e41f4b71Sopenharmony_ci
4233e41f4b71Sopenharmony_cion(type: 'audioCapturerChange', callback: Callback<audio.AudioCapturerChangeInfo>): void
4234e41f4b71Sopenharmony_ci
4235e41f4b71Sopenharmony_ciSubscribes to audio capturer configuration changes. Any configuration change triggers the callback that returns the entire configuration information.
4236e41f4b71Sopenharmony_ci
4237e41f4b71Sopenharmony_ciWhen the application initiates multiple subscriptions to this event, the last subscription prevails.
4238e41f4b71Sopenharmony_ci
4239e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
4240e41f4b71Sopenharmony_ci
4241e41f4b71Sopenharmony_ci**Parameters**
4242e41f4b71Sopenharmony_ci
4243e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
4244e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
4245e41f4b71Sopenharmony_ci| type     | string   | Yes  |Event type, which is **'audioCapturerChange'** in this case.|
4246e41f4b71Sopenharmony_ci| callback | Callback<[audio.AudioCapturerChangeInfo](../apis-audio-kit/js-apis-audio.md#audiocapturerchangeinfo9)> | Yes| Callback used to return the entire configuration information about the audio capturer.|
4247e41f4b71Sopenharmony_ci
4248e41f4b71Sopenharmony_ci**Error codes**
4249e41f4b71Sopenharmony_ci
4250e41f4b71Sopenharmony_ci| ID| Error Message                                  |
4251e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
4252e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
4253e41f4b71Sopenharmony_ci
4254e41f4b71Sopenharmony_ci**Example**
4255e41f4b71Sopenharmony_ci
4256e41f4b71Sopenharmony_ci```ts
4257e41f4b71Sopenharmony_cilet capturerChangeInfo: audio.AudioCapturerChangeInfo;
4258e41f4b71Sopenharmony_ci
4259e41f4b71Sopenharmony_ciavRecorder.on('audioCapturerChange',  (audioCapturerChangeInfo: audio.AudioCapturerChangeInfo) => {
4260e41f4b71Sopenharmony_ci  console.info('audioCapturerChange called');
4261e41f4b71Sopenharmony_ci  capturerChangeInfo = audioCapturerChangeInfo;
4262e41f4b71Sopenharmony_ci});
4263e41f4b71Sopenharmony_ci```
4264e41f4b71Sopenharmony_ci
4265e41f4b71Sopenharmony_ci### off('audioCapturerChange')<sup>11+</sup>
4266e41f4b71Sopenharmony_ci
4267e41f4b71Sopenharmony_cioff(type: 'audioCapturerChange', callback?: Callback<audio.AudioCapturerChangeInfo>): void
4268e41f4b71Sopenharmony_ci
4269e41f4b71Sopenharmony_ciSubscribes to audio capturer configuration changes.
4270e41f4b71Sopenharmony_ci
4271e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
4272e41f4b71Sopenharmony_ci
4273e41f4b71Sopenharmony_ci**Parameters**
4274e41f4b71Sopenharmony_ci
4275e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
4276e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
4277e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'audioCapturerChange'** in this case.|
4278e41f4b71Sopenharmony_ci| callback | Callback<[audio.AudioCapturerChangeInfo](../apis-audio-kit/js-apis-audio.md#audiocapturerchangeinfo9)> | No| Callback used to return the entire configuration information about the audio capturer.<br>This parameter is supported since API version 12.|
4279e41f4b71Sopenharmony_ci
4280e41f4b71Sopenharmony_ci**Example**
4281e41f4b71Sopenharmony_ci
4282e41f4b71Sopenharmony_ci```ts
4283e41f4b71Sopenharmony_ciavRecorder.off('audioCapturerChange');
4284e41f4b71Sopenharmony_ci```
4285e41f4b71Sopenharmony_ci
4286e41f4b71Sopenharmony_ci### on('photoAssetAvailable')<sup>12+</sup>
4287e41f4b71Sopenharmony_ci
4288e41f4b71Sopenharmony_cion(type: 'photoAssetAvailable', callback: Callback\<photoAccessHelper.PhotoAsset>): void
4289e41f4b71Sopenharmony_ci
4290e41f4b71Sopenharmony_ciSubscribes to media asset callback events. When [FileGenerationMode](#filegenerationmode12) is used during media file creation, the [PhotoAsset](../apis-media-library-kit/js-apis-photoAccessHelper.md#photoasset) object is called back to the application after the [stop](#stop9-2) operation is complete.
4291e41f4b71Sopenharmony_ci
4292e41f4b71Sopenharmony_ciWhen the application initiates multiple subscriptions to this event, the last subscription prevails.
4293e41f4b71Sopenharmony_ci
4294e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
4295e41f4b71Sopenharmony_ci
4296e41f4b71Sopenharmony_ci**Parameters**
4297e41f4b71Sopenharmony_ci
4298e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
4299e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
4300e41f4b71Sopenharmony_ci| type     | string   | Yes  |Event type, which is **'photoAssetAvailable'** in this case. The event is triggered when a photo asset is available.|
4301e41f4b71Sopenharmony_ci| callback | Callback<[photoAccessHelper.PhotoAsset](../apis-media-library-kit/js-apis-photoAccessHelper.md#photoasset)> | Yes| Callback used to return the **PhotoAsset** object corresponding to the resource file created by the system.|
4302e41f4b71Sopenharmony_ci
4303e41f4b71Sopenharmony_ci**Error codes**
4304e41f4b71Sopenharmony_ci
4305e41f4b71Sopenharmony_ci| ID| Error Message                                  |
4306e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
4307e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by callback.             |
4308e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by callback.          |
4309e41f4b71Sopenharmony_ci
4310e41f4b71Sopenharmony_ci**Example**
4311e41f4b71Sopenharmony_ci
4312e41f4b71Sopenharmony_ci```ts
4313e41f4b71Sopenharmony_ciimport { photoAccessHelper } from '@kit.MediaLibraryKit';
4314e41f4b71Sopenharmony_cilet photoAsset: photoAccessHelper.PhotoAsset;
4315e41f4b71Sopenharmony_ci
4316e41f4b71Sopenharmony_ci// Example: Process the photoAsset callback and save the video.
4317e41f4b71Sopenharmony_ciasync saveVideo(asset: photoAccessHelper.PhotoAsset) {
4318e41f4b71Sopenharmony_ci  console.info("saveVideo called");
4319e41f4b71Sopenharmony_ci  try {
4320e41f4b71Sopenharmony_ci    let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(getContext(this));
4321e41f4b71Sopenharmony_ci    let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset);
4322e41f4b71Sopenharmony_ci    assetChangeRequest.saveCameraPhoto();
4323e41f4b71Sopenharmony_ci    await phAccessHelper.applyChanges(assetChangeRequest);
4324e41f4b71Sopenharmony_ci    console.info('apply saveVideo successfully');
4325e41f4b71Sopenharmony_ci  } catch (err) {
4326e41f4b71Sopenharmony_ci    console.error(`apply saveVideo failed with error: ${err.code}, ${err.message}`);
4327e41f4b71Sopenharmony_ci  }
4328e41f4b71Sopenharmony_ci}
4329e41f4b71Sopenharmony_ci// Subscribe to the photoAsset event.
4330e41f4b71Sopenharmony_ciavRecorder.on('photoAssetAvailable',  (asset: photoAccessHelper.PhotoAsset) => {
4331e41f4b71Sopenharmony_ci  console.info('photoAssetAvailable called');
4332e41f4b71Sopenharmony_ci  if (asset != undefined) {
4333e41f4b71Sopenharmony_ci    photoAsset = asset;
4334e41f4b71Sopenharmony_ci    // Process the photoAsset callback.
4335e41f4b71Sopenharmony_ci    // Example: this.saveVideo (asset);
4336e41f4b71Sopenharmony_ci  } else {
4337e41f4b71Sopenharmony_ci    console.error('photoAsset is undefined');
4338e41f4b71Sopenharmony_ci  }
4339e41f4b71Sopenharmony_ci});
4340e41f4b71Sopenharmony_ci```
4341e41f4b71Sopenharmony_ci
4342e41f4b71Sopenharmony_ci### off('photoAssetAvailable')<sup>12+</sup>
4343e41f4b71Sopenharmony_ci
4344e41f4b71Sopenharmony_cioff(type: 'photoAssetAvailable', callback?: Callback<photoAccessHelper.PhotoAsset>): void
4345e41f4b71Sopenharmony_ci
4346e41f4b71Sopenharmony_ciUnsubscribes from media asset callback events.
4347e41f4b71Sopenharmony_ci
4348e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
4349e41f4b71Sopenharmony_ci
4350e41f4b71Sopenharmony_ci**Parameters**
4351e41f4b71Sopenharmony_ci
4352e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
4353e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
4354e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'photoAssetAvailable'** in this case.|
4355e41f4b71Sopenharmony_ci
4356e41f4b71Sopenharmony_ci**Example**
4357e41f4b71Sopenharmony_ci
4358e41f4b71Sopenharmony_ci```ts
4359e41f4b71Sopenharmony_ciavRecorder.off('photoAssetAvailable');
4360e41f4b71Sopenharmony_ci```
4361e41f4b71Sopenharmony_ci
4362e41f4b71Sopenharmony_ci## AVRecorderState<sup>9+</sup>
4363e41f4b71Sopenharmony_ci
4364e41f4b71Sopenharmony_citype AVRecorderState = 'idle' | 'prepared' | 'started' | 'paused' | 'stopped' | 'released' | 'error'
4365e41f4b71Sopenharmony_ci
4366e41f4b71Sopenharmony_ciEnumerates the AVRecorder states. You can obtain the state through the **state** attribute.
4367e41f4b71Sopenharmony_ci
4368e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4369e41f4b71Sopenharmony_ci
4370e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
4371e41f4b71Sopenharmony_ci
4372e41f4b71Sopenharmony_ci| Type    | Description                                                        |
4373e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
4374e41f4b71Sopenharmony_ci| 'idle'     | The AVRecorder enters this state after it is just created or the [AVRecorder.reset()](#reset9-2) API is called when the AVRecorder is in any state except released. In this state, you can call [AVRecorder.prepare()](#prepare9-2) to set recording parameters.  |
4375e41f4b71Sopenharmony_ci| 'prepared' | The AVRecorder enters this state when the parameters are set. In this state, you can call [AVRecorder.start()](#start9) to start recording.|
4376e41f4b71Sopenharmony_ci| 'started'  | The AVRecorder enters this state when the recording starts. In this state, you can call [AVRecorder.pause()](#pause9-2) to pause recording or call [AVRecorder.stop()](#stop9-2) to stop recording.|
4377e41f4b71Sopenharmony_ci| 'paused'   | The AVRecorder enters this state when the recording is paused. In this state, you can call [AVRecorder.resume()](#resume9) to continue recording or call [AVRecorder.stop()](#stop9-2) to stop recording.|
4378e41f4b71Sopenharmony_ci| 'stopped'  | The AVRecorder enters this state when the recording stops. In this state, you can call [AVRecorder.prepare()](#prepare9-2) to set recording parameters so that the AVRecorder enters the prepared state again.|
4379e41f4b71Sopenharmony_ci| 'released' | The AVRecorder enters this state when the recording resources are released. In this state, no operation can be performed. In any other state, you can call [AVRecorder.release()](#release9-2) to enter the released state.|
4380e41f4b71Sopenharmony_ci| 'error'    | The AVRecorder enters this state when an irreversible error occurs in the **AVRecorder** instance. In this state, the [AVRecorder.on('error') event](#onerror9-1) is reported, with the detailed error cause. In the error state, you must call [AVRecorder.reset()](#reset9-2) to reset the **AVRecorder** instance or call [AVRecorder.release()](#release9-2) to release the resources.|
4381e41f4b71Sopenharmony_ci
4382e41f4b71Sopenharmony_ci## OnAVRecorderStateChangeHandler<sup>12+</sup>
4383e41f4b71Sopenharmony_ci
4384e41f4b71Sopenharmony_citype OnAVRecorderStateChangeHandler = (state: AVRecorderState, reason: StateChangeReason) => void
4385e41f4b71Sopenharmony_ci
4386e41f4b71Sopenharmony_ciDescribes the callback invoked for the AVRecorder state change event. 
4387e41f4b71Sopenharmony_ci
4388e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4389e41f4b71Sopenharmony_ci
4390e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVPlayer
4391e41f4b71Sopenharmony_ci
4392e41f4b71Sopenharmony_ci| Name  | Type  | Mandatory| Description                                                        |
4393e41f4b71Sopenharmony_ci| ------ | ------ | ------ | ------------------------------------------------------------ |
4394e41f4b71Sopenharmony_ci| state  | [AVRecorderState](#avrecorderstate9) | Mandatory| AVRecorder state.    |
4395e41f4b71Sopenharmony_ci| reason | [StateChangeReason](#statechangereason9) | Mandatory| Reason for the state change.|
4396e41f4b71Sopenharmony_ci
4397e41f4b71Sopenharmony_ci## AVRecorderConfig<sup>9+</sup>
4398e41f4b71Sopenharmony_ci
4399e41f4b71Sopenharmony_ciDescribes the audio and video recording parameters.
4400e41f4b71Sopenharmony_ci
4401e41f4b71Sopenharmony_ciThe **audioSourceType** and **videoSourceType** parameters are used to distinguish audio-only recording, video-only recording, and audio and video recording. For audio-only recording, set only **audioSourceType**. For video-only recording, set only **videoSourceType**. For audio and video recording, set both **audioSourceType** and **videoSourceType**.
4402e41f4b71Sopenharmony_ci
4403e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
4404e41f4b71Sopenharmony_ci
4405e41f4b71Sopenharmony_ci| Name           | Type                                    | Mandatory| Description                                                        |
4406e41f4b71Sopenharmony_ci| --------------- | ---------------------------------------- | ---- | ------------------------------------------------------------ |
4407e41f4b71Sopenharmony_ci| audioSourceType | [AudioSourceType](#audiosourcetype9)     | No  | Type of the audio source to record. This parameter is mandatory for audio recording.<br> **Atomic service API**: This API can be used in atomic services since API version 12.|
4408e41f4b71Sopenharmony_ci| videoSourceType | [VideoSourceType](#videosourcetype9)     | No  | Type of the video source to record. This parameter is mandatory for video recording.                  |
4409e41f4b71Sopenharmony_ci| profile         | [AVRecorderProfile](#avrecorderprofile9) | Yes  | Recording profile. This parameter is mandatory.<br> **Atomic service API**: This API can be used in atomic services since API version 12.|
4410e41f4b71Sopenharmony_ci| url             | string                                   | Yes  | Recording output URL: fd://xx (fd number).<br>![img](figures/en-us_image_url.png)<br>This parameter is mandatory.<br> **Atomic service API**: This API can be used in atomic services since API version 12.|
4411e41f4b71Sopenharmony_ci|fileGenerationMode<sup>12+</sup> | [FileGenerationMode](#filegenerationmode12)  | No  |  Mode for creating the file, which is used together with [on('photoAssetAvailable')](#onphotoassetavailable12).|
4412e41f4b71Sopenharmony_ci| rotation<sup>(deprecated)</sup>        | number                                   | No  | Rotation angle of the recorded video. The value can be 0 (default), 90, 180, or 270 for MP4 videos.<br>This API is supported since API version 6 and deprecated since API version 12. You are advised to use **[AVMetadata](#avmetadata11).videoOrientation** instead. If both parameters are set, **[AVMetadata](#avmetadata11).videoOrientation** is used.    |
4413e41f4b71Sopenharmony_ci| location<sup>(deprecated)</sup>        | [Location](#location)                    | No  | Geographical location of the recorded video. By default, the geographical location information is not recorded.<br>This API is supported since API version 6 and deprecated since API version 12. You are advised to use **[AVMetadata](#avmetadata11).location** instead. If both parameters are set, **[AVMetadata](#avmetadata11).location** is used.|
4414e41f4b71Sopenharmony_ci| metadata<sup>12+</sup>        | [AVMetadata](#avmetadata11)              | No  | Metadata. For details, see [AVMetadata](#avmetadata11).                 |
4415e41f4b71Sopenharmony_ci
4416e41f4b71Sopenharmony_ci## AVRecorderProfile<sup>9+</sup>
4417e41f4b71Sopenharmony_ci
4418e41f4b71Sopenharmony_ciDescribes the audio and video recording profile.
4419e41f4b71Sopenharmony_ci
4420e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
4421e41f4b71Sopenharmony_ci
4422e41f4b71Sopenharmony_ci| Name            | Type                                        | Mandatory| Description                                                        |
4423e41f4b71Sopenharmony_ci| ---------------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
4424e41f4b71Sopenharmony_ci| audioBitrate     | number                                       | No  | Audio encoding bit rate. This parameter is mandatory for audio recording.<br>Supported bit rate ranges:<br>- Range [32000 - 500000] for the AAC encoding format.<br>- Range [64000 - 64000] for the G.711 μ-law encoding format.<br>- Range [8000, 16000, 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000] for the MP3 encoding format.<br>When the MP3 encoding format is used, the mapping between the sampling rate and bit rate is as follows:<br>- When the sampling rate is lower than 16 kHz, the bit rate range is [8 kbit/s - 64 kbit/s].<br>- When the sampling rate ranges from 16 kHz to 32 kHz, the bit rate range is [8 kbit/s - 160 kbit/s].<br>- When the sampling rate is greater than 32 kHz, the bit rate range is [32 kbit/s - 320 kbit/s].<br> **Atomic service API**: This API can be used in atomic services since API version 12.|
4425e41f4b71Sopenharmony_ci| audioChannels    | number                                       | No  | Number of audio channels. This parameter is mandatory for audio recording.<br>- Range [1 - 8] for the AAC encoding format.<br>- Range [1 - 1] for the G.711 μ-law encoding format.<br>- Range [1 - 2] for the MP3 encoding format.<br> **Atomic service API**: This API can be used in atomic services since API version 12.      |
4426e41f4b71Sopenharmony_ci| audioCodec       | [CodecMimeType](#codecmimetype8)             | No  | Audio encoding format. This parameter is mandatory for audio recording. Currently, **AUDIO_AAC**, **AUDIO_MP3**, and **AUDIO_G711MU** are supported.<br> **Atomic service API**: This API can be used in atomic services since API version 12.    |
4427e41f4b71Sopenharmony_ci| audioSampleRate  | number                                       | No  | Audio sampling rate. This parameter is mandatory for audio recording.<br>Supported sampling rate ranges:<br>- Range [8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 64000, 88200, 96000] for the AAC encoding format.<br>- Range [8000 - 8000] for the G.711 μ-law encoding format.<br>- Range [8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000] for the MP3 encoding format.<br>Variable bit rate. The bit rate is for reference only.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
4428e41f4b71Sopenharmony_ci| fileFormat       | [ContainerFormatType](#containerformattype8) | Yes  | Container format of a file. This parameter is mandatory. Currently, the MP4, M4A, MP3, and WAV container formats are supported. The AUDIO_MP3 encoding format cannot be used in the MP4 container format.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
4429e41f4b71Sopenharmony_ci| videoBitrate     | number                                       | No  | Video encoding bit rate. This parameter is mandatory for video recording. The value range is [10000 - 100000000]. |
4430e41f4b71Sopenharmony_ci| videoCodec       | [CodecMimeType](#codecmimetype8)             | No  | Video encoding format. This parameter is mandatory for video recording. Currently, VIDEO_AVC is supported.|
4431e41f4b71Sopenharmony_ci| videoFrameWidth  | number                                       | No  | Width of a video frame. This parameter is mandatory for video recording. The value range is [176 - 4096].        |
4432e41f4b71Sopenharmony_ci| videoFrameHeight | number                                       | No  | Height of a video frame. This parameter is mandatory for video recording. The value range is [144 - 4096].        |
4433e41f4b71Sopenharmony_ci| videoFrameRate   | number                                       | No  | Video frame rate. This parameter is mandatory for video recording. The value range is [1 - 60].            |
4434e41f4b71Sopenharmony_ci| isHdr<sup>11+</sup>            | boolean                        | No  | HDR encoding. This parameter is optional for video recording. The default value is **false**, and there is no requirement on the encoding format. When **isHdr** is set to **true**, the encoding format must be **video/hevc**.|
4435e41f4b71Sopenharmony_ci| enableTemporalScale<sup>12+</sup>            | boolean                        | No  | Whether temporal layered encoding is supported. This parameter is optional for video recording. The default value is **false**. If this parameter is set to **true**, some frames in the video output streams can be skipped without being encoded.|
4436e41f4b71Sopenharmony_ci
4437e41f4b71Sopenharmony_ci## AudioSourceType<sup>9+</sup>
4438e41f4b71Sopenharmony_ci
4439e41f4b71Sopenharmony_ciEnumerates the audio source types for video recording.
4440e41f4b71Sopenharmony_ci
4441e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
4442e41f4b71Sopenharmony_ci
4443e41f4b71Sopenharmony_ci| Name                     | Value  | Description                  |
4444e41f4b71Sopenharmony_ci| ------------------------- | ---- | ---------------------- |
4445e41f4b71Sopenharmony_ci| AUDIO_SOURCE_TYPE_DEFAULT | 0    | Default audio input source.|
4446e41f4b71Sopenharmony_ci| AUDIO_SOURCE_TYPE_MIC     | 1    | Microphone audio input source.<br> **Atomic service API**: This API can be used in atomic services since API version 12.|
4447e41f4b71Sopenharmony_ci| AUDIO_SOURCE_TYPE_VOICE_RECOGNITION<sup>12+</sup> | 2    | Audio source in speech recognition scenarios.|
4448e41f4b71Sopenharmony_ci| AUDIO_SOURCE_TYPE_VOICE_COMMUNICATION<sup>12+</sup>     | 7    | Voice communication source.|
4449e41f4b71Sopenharmony_ci| AUDIO_SOURCE_TYPE_VOICE_MESSAGE<sup>12+</sup> | 10    | Voice message source.|
4450e41f4b71Sopenharmony_ci| AUDIO_SOURCE_TYPE_CAMCORDER<sup>12+</sup>     | 13    | Audio source in camera recording scenarios.|
4451e41f4b71Sopenharmony_ci
4452e41f4b71Sopenharmony_ci## VideoSourceType<sup>9+</sup>
4453e41f4b71Sopenharmony_ci
4454e41f4b71Sopenharmony_ciEnumerates the video source types for video recording.
4455e41f4b71Sopenharmony_ci
4456e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
4457e41f4b71Sopenharmony_ci
4458e41f4b71Sopenharmony_ci| Name                         | Value  | Description                           |
4459e41f4b71Sopenharmony_ci| ----------------------------- | ---- | ------------------------------- |
4460e41f4b71Sopenharmony_ci| VIDEO_SOURCE_TYPE_SURFACE_YUV | 0    | The input surface carries raw data.|
4461e41f4b71Sopenharmony_ci| VIDEO_SOURCE_TYPE_SURFACE_ES  | 1    | The input surface carries ES data. |
4462e41f4b71Sopenharmony_ci
4463e41f4b71Sopenharmony_ci## ContainerFormatType<sup>8+</sup>
4464e41f4b71Sopenharmony_ci
4465e41f4b71Sopenharmony_ciEnumerates the container format types (CFTs).
4466e41f4b71Sopenharmony_ci
4467e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
4468e41f4b71Sopenharmony_ci
4469e41f4b71Sopenharmony_ci| Name       | Value   | Description                 |
4470e41f4b71Sopenharmony_ci| ----------- | ----- | --------------------- |
4471e41f4b71Sopenharmony_ci| CFT_MPEG_4  | 'mp4' | Video container format MP4.|
4472e41f4b71Sopenharmony_ci| CFT_MPEG_4A | 'm4a' | Audio container format M4A.<br> **Atomic service API**: This API can be used in atomic services since API version 12.|
4473e41f4b71Sopenharmony_ci| CFT_MP3<sup>12+</sup>  | 'mp3' | Audio container format MP3.|
4474e41f4b71Sopenharmony_ci| CFT_WAV<sup>12+</sup>  | 'wav' | Audio container format WAV.|
4475e41f4b71Sopenharmony_ci
4476e41f4b71Sopenharmony_ci## Location
4477e41f4b71Sopenharmony_ci
4478e41f4b71Sopenharmony_ciDescribes the geographical location of the recorded video.
4479e41f4b71Sopenharmony_ci
4480e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
4481e41f4b71Sopenharmony_ci
4482e41f4b71Sopenharmony_ci| Name     | Type  | Mandatory| Description            |
4483e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ---------------- |
4484e41f4b71Sopenharmony_ci| latitude  | number | Yes  | Latitude of the geographical location.|
4485e41f4b71Sopenharmony_ci| longitude | number | Yes  | Longitude of the geographical location.|
4486e41f4b71Sopenharmony_ci
4487e41f4b71Sopenharmony_ci## EncoderInfo<sup>11+</sup>
4488e41f4b71Sopenharmony_ci
4489e41f4b71Sopenharmony_ciDescribes the information about an encoder.
4490e41f4b71Sopenharmony_ci
4491e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
4492e41f4b71Sopenharmony_ci
4493e41f4b71Sopenharmony_ci| Name      | Type                            | Readable| Writable| Description                                                        |
4494e41f4b71Sopenharmony_ci| ---------- | -------------------------------- | ---- | ---- | ------------------------------------------------------------ |
4495e41f4b71Sopenharmony_ci| mimeType   | [CodecMimeType](#codecmimetype8) | Yes  | No  | MIME type of the encoder.                                          |
4496e41f4b71Sopenharmony_ci| type       | string                           | Yes  | No  | Encoder type. The value **audio** means an audio encoder, and **video** means a video encoder.        |
4497e41f4b71Sopenharmony_ci| bitRate    | [Range](#range11)                | Yes  | No  | Bit rate range of the encoder, with the minimum and maximum bit rates specified.                          |
4498e41f4b71Sopenharmony_ci| frameRate  | [Range](#range11)                | Yes  | No  | Video frame rate range, with the minimum and maximum frame rates specified. This parameter is available only for video encoders.          |
4499e41f4b71Sopenharmony_ci| width      | [Range](#range11)                | Yes  | No  | Video frame width range, with the minimum and maximum widths specified. This parameter is available only for video encoders.      |
4500e41f4b71Sopenharmony_ci| height     | [Range](#range11)                | Yes  | No  | Video frame height range, with the minimum and maximum heights specified. This parameter is available only for video encoders.      |
4501e41f4b71Sopenharmony_ci| channels   | [Range](#range11)                | Yes  | No  | Number of audio channels for the audio capturer, with the minimum and maximum numbers of audio channels specified. This parameter is available only for audio encoders.  |
4502e41f4b71Sopenharmony_ci| sampleRate | Array\<number>                    | Yes  | No  | Audio sampling rate, including all available audio sampling rates. This parameter is available only for audio encoders.|
4503e41f4b71Sopenharmony_ci
4504e41f4b71Sopenharmony_ci## Range<sup>11+</sup>
4505e41f4b71Sopenharmony_ci
4506e41f4b71Sopenharmony_ciDescribes a range.
4507e41f4b71Sopenharmony_ci
4508e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
4509e41f4b71Sopenharmony_ci
4510e41f4b71Sopenharmony_ci| Name| Type  | Readable| Writable| Description        |
4511e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ---- | ------------ |
4512e41f4b71Sopenharmony_ci| min  | number | Yes  | No  | Minimum value.|
4513e41f4b71Sopenharmony_ci| max  | number | Yes  | No  | Maximum value.|
4514e41f4b71Sopenharmony_ci
4515e41f4b71Sopenharmony_ci## FileGenerationMode<sup>12+</sup>
4516e41f4b71Sopenharmony_ci
4517e41f4b71Sopenharmony_ciEnumerates the modes for creating media files.
4518e41f4b71Sopenharmony_ci
4519e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVRecorder
4520e41f4b71Sopenharmony_ci
4521e41f4b71Sopenharmony_ci| Name                         | Value  | Description                           |
4522e41f4b71Sopenharmony_ci| ----------------------------- | ---- | ------------------------------- |
4523e41f4b71Sopenharmony_ci| APP_CREATE  | 0    | The application creates a media file in the sandbox.|
4524e41f4b71Sopenharmony_ci| AUTO_CREATE_CAMERA_SCENE  | 1    | The system creates a media file. Currently, this mode takes effect only in camera recording scenarios. The URL set by the application is ignored.|
4525e41f4b71Sopenharmony_ci
4526e41f4b71Sopenharmony_ci## AVTranscoder<sup>12+</sup>
4527e41f4b71Sopenharmony_ci
4528e41f4b71Sopenharmony_ciA transcoding management class that provides APIs to transcode videos. Before calling any API in **AVTranscoder**, you must use **createAVTranscoder()** to create an **AVTranscoder** instance.
4529e41f4b71Sopenharmony_ci
4530e41f4b71Sopenharmony_ciFor details about the AVTranscoder demo, see [Using AVTranscoder for Transcoding](../../media/media/using-avtranscoder-for-transcodering.md).
4531e41f4b71Sopenharmony_ci
4532e41f4b71Sopenharmony_ci### Attributes
4533e41f4b71Sopenharmony_ci
4534e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVTranscoder
4535e41f4b71Sopenharmony_ci
4536e41f4b71Sopenharmony_ci| Name   | Type                                | Read-Only| Optional| Description              |
4537e41f4b71Sopenharmony_ci| ------- | ------------------------------------ | ---- | ---- | ------------------ |
4538e41f4b71Sopenharmony_ci| fdSrc<sup>12+</sup>                                  | [AVFileDescriptor](#avfiledescriptor9)                       |  No | No  | Source media file descriptor, which specifies the data source.<br> **Example:**<br>There is a media file that stores continuous assets, the address offset is 0, and the byte length is 100. Its file descriptor is **AVFileDescriptor {fd = resourceHandle; offset = 0; length = 100; }**.<br>**NOTE**<br> - After the resource handle (FD) is transferred to an **AVTranscoder** instance, do not use the resource handle to perform other read and write operations, including but not limited to transferring this handle to other **AVPlayer**, **AVMetadataExtractor**, **AVImageGenerator**, or **AVTranscoder** instance. Competition occurs when multiple AVTranscoders use the same resource handle to read and write files at the same time, resulting in errors in obtaining data.|
4539e41f4b71Sopenharmony_ci| fdDst<sup>12+</sup>                               | number                 |  No | No  | Destination media file descriptor, which specifies the data source. After creating an **AVTranscoder** instance, you must set both **fdSrc** and **fdDst**.<br>**NOTE**<br> - After the resource handle (FD) is transferred to an **AVTranscoder** instance, do not use the resource handle to perform other read and write operations, including but not limited to transferring this handle to other **AVPlayer**, **AVMetadataExtractor**, **AVImageGenerator**, or **AVTranscoder** instance. Competition occurs when multiple AVTranscoders use the same resource handle to read and write files at the same time, resulting in errors in obtaining data.|
4540e41f4b71Sopenharmony_ci
4541e41f4b71Sopenharmony_ci### prepare<sup>12+</sup>
4542e41f4b71Sopenharmony_ci
4543e41f4b71Sopenharmony_ciprepare(config: AVTranscoderConfig): Promise\<void>
4544e41f4b71Sopenharmony_ci
4545e41f4b71Sopenharmony_ciSets video transcoding parameters. This API uses a promise to return the result.
4546e41f4b71Sopenharmony_ci
4547e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVTranscoder
4548e41f4b71Sopenharmony_ci
4549e41f4b71Sopenharmony_ci**Parameters**
4550e41f4b71Sopenharmony_ci
4551e41f4b71Sopenharmony_ci| Name| Type                                  | Mandatory| Description                      |
4552e41f4b71Sopenharmony_ci| ------ | -------------------------------------- | ---- | -------------------------- |
4553e41f4b71Sopenharmony_ci| config | [AVTranscoderConfig](#avtranscoderconfig12) | Yes  | Video transcoding parameters to set.|
4554e41f4b71Sopenharmony_ci
4555e41f4b71Sopenharmony_ci**Return value**
4556e41f4b71Sopenharmony_ci
4557e41f4b71Sopenharmony_ci| Type          | Description                                      |
4558e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------ |
4559e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
4560e41f4b71Sopenharmony_ci
4561e41f4b71Sopenharmony_ci**Error codes**
4562e41f4b71Sopenharmony_ci
4563e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
4564e41f4b71Sopenharmony_ci
4565e41f4b71Sopenharmony_ci| ID| Error Message                              |
4566e41f4b71Sopenharmony_ci| -------- | -------------------------------------- |
4567e41f4b71Sopenharmony_ci| 401  | The parameter check failed. Return by promise. |
4568e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
4569e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise.       |
4570e41f4b71Sopenharmony_ci| 5400106  | Unsupported format. Returned by promise.  |
4571e41f4b71Sopenharmony_ci
4572e41f4b71Sopenharmony_ci**Example**
4573e41f4b71Sopenharmony_ci
4574e41f4b71Sopenharmony_ci```ts
4575e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4576e41f4b71Sopenharmony_ci
4577e41f4b71Sopenharmony_ci// Configure the parameters based on those supported by the hardware device.
4578e41f4b71Sopenharmony_cilet avTranscoderConfig: media.AVTranscoderConfig = {
4579e41f4b71Sopenharmony_ci  audioBitrate : 200000,
4580e41f4b71Sopenharmony_ci  audioCodec : media.CodecMimeType.AUDIO_AAC,
4581e41f4b71Sopenharmony_ci  fileFormat : media.ContainerFormatType.CFT_MPEG_4,
4582e41f4b71Sopenharmony_ci  videoBitrate : 3000000,
4583e41f4b71Sopenharmony_ci  videoCodec : media.CodecMimeType.VIDEO_AVC,
4584e41f4b71Sopenharmony_ci  videoFrameWidth : 1280,
4585e41f4b71Sopenharmony_ci  videoFrameHeight : 720,
4586e41f4b71Sopenharmony_ci}
4587e41f4b71Sopenharmony_ci
4588e41f4b71Sopenharmony_ciavTranscoder.prepare(avTranscoderConfig).then(() => {
4589e41f4b71Sopenharmony_ci  console.info('prepare success');
4590e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
4591e41f4b71Sopenharmony_ci  console.error('prepare failed and catch error is ' + err.message);
4592e41f4b71Sopenharmony_ci});
4593e41f4b71Sopenharmony_ci```
4594e41f4b71Sopenharmony_ci
4595e41f4b71Sopenharmony_ci### start<sup>12+</sup>
4596e41f4b71Sopenharmony_ci
4597e41f4b71Sopenharmony_cistart(): Promise\<void>
4598e41f4b71Sopenharmony_ci
4599e41f4b71Sopenharmony_ciStarts transcoding. This API uses a promise to return the result.
4600e41f4b71Sopenharmony_ci
4601e41f4b71Sopenharmony_ciThis API can be called only after the [prepare()](#prepare12) API is called.
4602e41f4b71Sopenharmony_ci
4603e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVTranscoder
4604e41f4b71Sopenharmony_ci
4605e41f4b71Sopenharmony_ci**Return value**
4606e41f4b71Sopenharmony_ci
4607e41f4b71Sopenharmony_ci| Type          | Description                                 |
4608e41f4b71Sopenharmony_ci| -------------- | ------------------------------------- |
4609e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
4610e41f4b71Sopenharmony_ci
4611e41f4b71Sopenharmony_ci**Error codes**
4612e41f4b71Sopenharmony_ci
4613e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
4614e41f4b71Sopenharmony_ci
4615e41f4b71Sopenharmony_ci| ID| Error Message                              |
4616e41f4b71Sopenharmony_ci| -------- | -------------------------------------- |
4617e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
4618e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by promise.           |
4619e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise.       |
4620e41f4b71Sopenharmony_ci
4621e41f4b71Sopenharmony_ci**Example**
4622e41f4b71Sopenharmony_ci
4623e41f4b71Sopenharmony_ci```ts
4624e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4625e41f4b71Sopenharmony_ci
4626e41f4b71Sopenharmony_ciavTranscoder.start().then(() => {
4627e41f4b71Sopenharmony_ci  console.info('start AVTranscoder success');
4628e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
4629e41f4b71Sopenharmony_ci  console.error('start AVTranscoder failed and catch error is ' + err.message);
4630e41f4b71Sopenharmony_ci});
4631e41f4b71Sopenharmony_ci```
4632e41f4b71Sopenharmony_ci
4633e41f4b71Sopenharmony_ci### pause<sup>12+</sup>
4634e41f4b71Sopenharmony_ci
4635e41f4b71Sopenharmony_cipause(): Promise\<void>
4636e41f4b71Sopenharmony_ci
4637e41f4b71Sopenharmony_ciPauses transcoding. This API uses a promise to return the result.
4638e41f4b71Sopenharmony_ci
4639e41f4b71Sopenharmony_ciThis API can be called only after the [start()](#start12) API is called. You can call [resume()](#resume12) to resume transcoding.
4640e41f4b71Sopenharmony_ci
4641e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVTranscoder
4642e41f4b71Sopenharmony_ci
4643e41f4b71Sopenharmony_ci**Return value**
4644e41f4b71Sopenharmony_ci
4645e41f4b71Sopenharmony_ci| Type          | Description                                 |
4646e41f4b71Sopenharmony_ci| -------------- | ------------------------------------- |
4647e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
4648e41f4b71Sopenharmony_ci
4649e41f4b71Sopenharmony_ci**Error codes**
4650e41f4b71Sopenharmony_ci
4651e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
4652e41f4b71Sopenharmony_ci
4653e41f4b71Sopenharmony_ci| ID| Error Message                              |
4654e41f4b71Sopenharmony_ci| -------- | -------------------------------------- |
4655e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
4656e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by promise.           |
4657e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise.       |
4658e41f4b71Sopenharmony_ci
4659e41f4b71Sopenharmony_ci**Example**
4660e41f4b71Sopenharmony_ci
4661e41f4b71Sopenharmony_ci```ts
4662e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4663e41f4b71Sopenharmony_ci
4664e41f4b71Sopenharmony_ciavTranscoder.pause().then(() => {
4665e41f4b71Sopenharmony_ci  console.info('pause AVTranscoder success');
4666e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
4667e41f4b71Sopenharmony_ci  console.error('pause AVTranscoder failed and catch error is ' + err.message);
4668e41f4b71Sopenharmony_ci});
4669e41f4b71Sopenharmony_ci```
4670e41f4b71Sopenharmony_ci
4671e41f4b71Sopenharmony_ci### resume<sup>12+</sup>
4672e41f4b71Sopenharmony_ci
4673e41f4b71Sopenharmony_ciresume(): Promise\<void>
4674e41f4b71Sopenharmony_ci
4675e41f4b71Sopenharmony_ciResumes transcoding. This API uses a promise to return the result.
4676e41f4b71Sopenharmony_ci
4677e41f4b71Sopenharmony_ciThis API can be called only after the [pause()](#pause12) API is called.
4678e41f4b71Sopenharmony_ci
4679e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVTranscoder
4680e41f4b71Sopenharmony_ci
4681e41f4b71Sopenharmony_ci**Return value**
4682e41f4b71Sopenharmony_ci
4683e41f4b71Sopenharmony_ci| Type          | Description                                 |
4684e41f4b71Sopenharmony_ci| -------------- | ------------------------------------- |
4685e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
4686e41f4b71Sopenharmony_ci
4687e41f4b71Sopenharmony_ci**Error codes**
4688e41f4b71Sopenharmony_ci
4689e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
4690e41f4b71Sopenharmony_ci
4691e41f4b71Sopenharmony_ci| ID| Error Message                              |
4692e41f4b71Sopenharmony_ci| -------- | -------------------------------------- |
4693e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
4694e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by promise.           |
4695e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise.       |
4696e41f4b71Sopenharmony_ci
4697e41f4b71Sopenharmony_ci**Example**
4698e41f4b71Sopenharmony_ci
4699e41f4b71Sopenharmony_ci```ts
4700e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4701e41f4b71Sopenharmony_ci
4702e41f4b71Sopenharmony_ciavTranscoder.resume().then(() => {
4703e41f4b71Sopenharmony_ci  console.info('resume AVTranscoder success');
4704e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
4705e41f4b71Sopenharmony_ci  console.error('resume AVTranscoder failed and catch error is ' + err.message);
4706e41f4b71Sopenharmony_ci});
4707e41f4b71Sopenharmony_ci```
4708e41f4b71Sopenharmony_ci
4709e41f4b71Sopenharmony_ci### cancel<sup>12+</sup>
4710e41f4b71Sopenharmony_ci
4711e41f4b71Sopenharmony_cicancel(): Promise\<void>
4712e41f4b71Sopenharmony_ci
4713e41f4b71Sopenharmony_ciCancels transcoding. This API uses a promise to return the result.
4714e41f4b71Sopenharmony_ci
4715e41f4b71Sopenharmony_ciThis API can be called only after the [prepare()](#prepare12), [start()](#start12), [pause()](#pause12), or [resume()](#resume12) API is called.
4716e41f4b71Sopenharmony_ci
4717e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVTranscoder
4718e41f4b71Sopenharmony_ci
4719e41f4b71Sopenharmony_ci**Return value**
4720e41f4b71Sopenharmony_ci
4721e41f4b71Sopenharmony_ci| Type          | Description                                 |
4722e41f4b71Sopenharmony_ci| -------------- | ------------------------------------- |
4723e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
4724e41f4b71Sopenharmony_ci
4725e41f4b71Sopenharmony_ci**Error codes**
4726e41f4b71Sopenharmony_ci
4727e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
4728e41f4b71Sopenharmony_ci
4729e41f4b71Sopenharmony_ci| ID| Error Message                              |
4730e41f4b71Sopenharmony_ci| -------- | -------------------------------------- |
4731e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
4732e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by promise.           |
4733e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise.       |
4734e41f4b71Sopenharmony_ci
4735e41f4b71Sopenharmony_ci**Example**
4736e41f4b71Sopenharmony_ci
4737e41f4b71Sopenharmony_ci```ts
4738e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4739e41f4b71Sopenharmony_ci
4740e41f4b71Sopenharmony_ciavTranscoder.cancel().then(() => {
4741e41f4b71Sopenharmony_ci  console.info('cancel AVTranscoder success');
4742e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
4743e41f4b71Sopenharmony_ci  console.error('cancel AVTranscoder failed and catch error is ' + err.message);
4744e41f4b71Sopenharmony_ci});
4745e41f4b71Sopenharmony_ci```
4746e41f4b71Sopenharmony_ci
4747e41f4b71Sopenharmony_ci### release<sup>12+</sup>
4748e41f4b71Sopenharmony_ci
4749e41f4b71Sopenharmony_cirelease(): Promise\<void>
4750e41f4b71Sopenharmony_ci
4751e41f4b71Sopenharmony_ciReleases the video transcoding resources. This API uses a promise to return the result.
4752e41f4b71Sopenharmony_ci
4753e41f4b71Sopenharmony_ciAfter the resources are released, you can no longer perform any operation on the **AVTranscoder** instance.
4754e41f4b71Sopenharmony_ci
4755e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVTranscoder
4756e41f4b71Sopenharmony_ci
4757e41f4b71Sopenharmony_ci**Return value**
4758e41f4b71Sopenharmony_ci
4759e41f4b71Sopenharmony_ci| Type          | Description                                       |
4760e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------- |
4761e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
4762e41f4b71Sopenharmony_ci
4763e41f4b71Sopenharmony_ci**Error codes**
4764e41f4b71Sopenharmony_ci
4765e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
4766e41f4b71Sopenharmony_ci
4767e41f4b71Sopenharmony_ci| ID| Error Message                         |
4768e41f4b71Sopenharmony_ci| -------- | --------------------------------- |
4769e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by promise. |
4770e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise. |
4771e41f4b71Sopenharmony_ci
4772e41f4b71Sopenharmony_ci**Example**
4773e41f4b71Sopenharmony_ci
4774e41f4b71Sopenharmony_ci```ts
4775e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4776e41f4b71Sopenharmony_ci
4777e41f4b71Sopenharmony_ciavTranscoder.release().then(() => {
4778e41f4b71Sopenharmony_ci  console.info('release AVTranscoder success');
4779e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
4780e41f4b71Sopenharmony_ci  console.error('release AVTranscoder failed and catch error is ' + err.message);
4781e41f4b71Sopenharmony_ci});
4782e41f4b71Sopenharmony_ci```
4783e41f4b71Sopenharmony_ci
4784e41f4b71Sopenharmony_ci### on('progressUpdate')<sup>12+</sup>
4785e41f4b71Sopenharmony_ci
4786e41f4b71Sopenharmony_cion(type: 'progressUpdate', callback: Callback\<number>): void
4787e41f4b71Sopenharmony_ci
4788e41f4b71Sopenharmony_ciSubscribes to transcoding progress updates. An application can subscribe to only one transcoding progress update event. When the application initiates multiple subscriptions to this event, the last subscription prevails.
4789e41f4b71Sopenharmony_ci
4790e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVTranscoder
4791e41f4b71Sopenharmony_ci
4792e41f4b71Sopenharmony_ci**Parameters**
4793e41f4b71Sopenharmony_ci
4794e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
4795e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
4796e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'progressUpdate'** in this case. This event is triggered by the system during transcoding.|
4797e41f4b71Sopenharmony_ci| callback | [Callback](../apis-basic-services-kit/js-apis-base.md#callback) | Yes  | Callback invoked when the event is triggered. **progress** is a number that indicates the current transcoding progress.|
4798e41f4b71Sopenharmony_ci
4799e41f4b71Sopenharmony_ci**Example**
4800e41f4b71Sopenharmony_ci
4801e41f4b71Sopenharmony_ci```ts
4802e41f4b71Sopenharmony_ciavTranscoder.on('progressUpdate', (progress: number) => {
4803e41f4b71Sopenharmony_ci  console.info('avTranscoder progressUpdate = ' + progress);
4804e41f4b71Sopenharmony_ci});
4805e41f4b71Sopenharmony_ci```
4806e41f4b71Sopenharmony_ci
4807e41f4b71Sopenharmony_ci### off('progressUpdate')<sup>12+</sup>
4808e41f4b71Sopenharmony_ci
4809e41f4b71Sopenharmony_cioff(type:'progressUpdate', callback?: Callback\<number>): void
4810e41f4b71Sopenharmony_ci
4811e41f4b71Sopenharmony_ciUnsubscribes from transcoding progress updates.
4812e41f4b71Sopenharmony_ci
4813e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVTranscoder
4814e41f4b71Sopenharmony_ci
4815e41f4b71Sopenharmony_ci**Parameters**
4816e41f4b71Sopenharmony_ci
4817e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
4818e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
4819e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'progressUpdate'** in this case. This event can be triggered by both user operations and the system.|
4820e41f4b71Sopenharmony_ci| callback | [Callback](../apis-basic-services-kit/js-apis-base.md#callback) | No  | Called that has been registered to listen for progress updates. You are advised to use the default value because only the last registered callback is retained in the current callback mechanism.|
4821e41f4b71Sopenharmony_ci
4822e41f4b71Sopenharmony_ci**Example**
4823e41f4b71Sopenharmony_ci
4824e41f4b71Sopenharmony_ci```ts
4825e41f4b71Sopenharmony_ciavTranscoder.off('progressUpdate');
4826e41f4b71Sopenharmony_ci```
4827e41f4b71Sopenharmony_ci
4828e41f4b71Sopenharmony_ci### on('error')<sup>12+</sup>
4829e41f4b71Sopenharmony_ci
4830e41f4b71Sopenharmony_cion(type: 'error', callback: ErrorCallback): void
4831e41f4b71Sopenharmony_ci
4832e41f4b71Sopenharmony_ciSubscribes to AVTranscoder errors. If this event is reported, call [release()](#release12) to exit the transcoding.
4833e41f4b71Sopenharmony_ci
4834e41f4b71Sopenharmony_ciAn application can subscribe to only one AVTranscoder error event. When the application initiates multiple subscriptions to this event, the last subscription prevails.
4835e41f4b71Sopenharmony_ci
4836e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVTranscoder
4837e41f4b71Sopenharmony_ci
4838e41f4b71Sopenharmony_ci**Parameters**
4839e41f4b71Sopenharmony_ci
4840e41f4b71Sopenharmony_ci| Name  | Type         | Mandatory| Description                                                        |
4841e41f4b71Sopenharmony_ci| -------- | ------------- | ---- | ------------------------------------------------------------ |
4842e41f4b71Sopenharmony_ci| type     | string        | Yes  | Event type, which is **'error'** in this case.<br>This event is triggered when an error occurs during recording.|
4843e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes  | Callback invoked when the event is triggered.                                      |
4844e41f4b71Sopenharmony_ci
4845e41f4b71Sopenharmony_ci**Error codes**
4846e41f4b71Sopenharmony_ci
4847e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
4848e41f4b71Sopenharmony_ci
4849e41f4b71Sopenharmony_ci| ID| Error Message                                  |
4850e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
4851e41f4b71Sopenharmony_ci| 401      | The parameter check failed. |
4852e41f4b71Sopenharmony_ci| 801      | Capability not supported. |
4853e41f4b71Sopenharmony_ci| 5400101  | No memory.            |
4854e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. |
4855e41f4b71Sopenharmony_ci| 5400103  | I/O error.              |
4856e41f4b71Sopenharmony_ci| 5400104  | Time out.            |
4857e41f4b71Sopenharmony_ci| 5400105  | Service died.           |
4858e41f4b71Sopenharmony_ci| 5400106  | Unsupport format.      |
4859e41f4b71Sopenharmony_ci
4860e41f4b71Sopenharmony_ci**Example**
4861e41f4b71Sopenharmony_ci
4862e41f4b71Sopenharmony_ci```ts
4863e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4864e41f4b71Sopenharmony_ci
4865e41f4b71Sopenharmony_ciavTranscoder.on('error', (err: BusinessError) => {
4866e41f4b71Sopenharmony_ci  console.info('case avTranscoder.on(error) called, errMessage is ' + err.message);
4867e41f4b71Sopenharmony_ci});
4868e41f4b71Sopenharmony_ci```
4869e41f4b71Sopenharmony_ci
4870e41f4b71Sopenharmony_ci### off('error')<sup>12+</sup>
4871e41f4b71Sopenharmony_ci
4872e41f4b71Sopenharmony_cioff(type:'error', callback?: ErrorCallback): void
4873e41f4b71Sopenharmony_ci
4874e41f4b71Sopenharmony_ciUnsubscribes from AVTranscoder errors. After the unsubscription, your application can no longer receive AVTranscoder errors.
4875e41f4b71Sopenharmony_ci
4876e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVTranscoder
4877e41f4b71Sopenharmony_ci
4878e41f4b71Sopenharmony_ci**Parameters**
4879e41f4b71Sopenharmony_ci
4880e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
4881e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
4882e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'error'** in this case.<br>This event is triggered when an error occurs during transcoding.|
4883e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | No  | Callback that has been registered to listen for AVTranscoder errors.|
4884e41f4b71Sopenharmony_ci
4885e41f4b71Sopenharmony_ci**Example**
4886e41f4b71Sopenharmony_ci
4887e41f4b71Sopenharmony_ci```ts
4888e41f4b71Sopenharmony_ciavTranscoder.off('error');
4889e41f4b71Sopenharmony_ci```
4890e41f4b71Sopenharmony_ci
4891e41f4b71Sopenharmony_ci### on('complete')<sup>12+</sup>
4892e41f4b71Sopenharmony_ci
4893e41f4b71Sopenharmony_cion(type: 'complete', callback: Callback\<void>): void
4894e41f4b71Sopenharmony_ci
4895e41f4b71Sopenharmony_ciSubscribes to the event indicating that transcoding is complete. An application can subscribe to only one transcoding completion event. When the application initiates multiple subscriptions to this event, the last subscription prevails.
4896e41f4b71Sopenharmony_ci
4897e41f4b71Sopenharmony_ciWhen this event is reported, the current transcoding operation is complete. You can call [release()](#release12) to exit the transcoding.
4898e41f4b71Sopenharmony_ci
4899e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVTranscoder
4900e41f4b71Sopenharmony_ci
4901e41f4b71Sopenharmony_ci**Parameters**
4902e41f4b71Sopenharmony_ci
4903e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
4904e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
4905e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'complete'** in this case. This event is triggered by the system during transcoding.|
4906e41f4b71Sopenharmony_ci| callback | [Callback](../apis-basic-services-kit/js-apis-base.md#callback) | Yes  | Callback that has been registered to listen for transcoding completion events.|
4907e41f4b71Sopenharmony_ci
4908e41f4b71Sopenharmony_ci**Example**
4909e41f4b71Sopenharmony_ci
4910e41f4b71Sopenharmony_ci```ts
4911e41f4b71Sopenharmony_ciavTranscoder.on('complete', () => {
4912e41f4b71Sopenharmony_ci  console.info('avTranscoder complete');
4913e41f4b71Sopenharmony_ci});
4914e41f4b71Sopenharmony_ci```
4915e41f4b71Sopenharmony_ci
4916e41f4b71Sopenharmony_ci### off('complete')<sup>12+</sup>
4917e41f4b71Sopenharmony_ci
4918e41f4b71Sopenharmony_cioff(type:'complete', callback?: Callback\<void>): void
4919e41f4b71Sopenharmony_ci
4920e41f4b71Sopenharmony_ciUnsubscribes from the event indicating that transcoding is complete.
4921e41f4b71Sopenharmony_ci
4922e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVTranscoder
4923e41f4b71Sopenharmony_ci
4924e41f4b71Sopenharmony_ci**Parameters**
4925e41f4b71Sopenharmony_ci
4926e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
4927e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
4928e41f4b71Sopenharmony_ci| type   | string | Yes  | Event type, which is **'complete'** in this case. This event can be triggered by both user operations and the system.|
4929e41f4b71Sopenharmony_ci| callback | [Callback](../apis-basic-services-kit/js-apis-base.md#callback) | No  | Callback invoked when the event is triggered.|
4930e41f4b71Sopenharmony_ci
4931e41f4b71Sopenharmony_ci**Example**
4932e41f4b71Sopenharmony_ci
4933e41f4b71Sopenharmony_ci```ts
4934e41f4b71Sopenharmony_ciavTranscoder.off('complete');
4935e41f4b71Sopenharmony_ci```
4936e41f4b71Sopenharmony_ci
4937e41f4b71Sopenharmony_ci## AVTranscoderConfig<sup>12+</sup>
4938e41f4b71Sopenharmony_ci
4939e41f4b71Sopenharmony_ciDescribes the video transcoding parameters.
4940e41f4b71Sopenharmony_ci
4941e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVTranscoder
4942e41f4b71Sopenharmony_ci
4943e41f4b71Sopenharmony_ci| Name           | Type                                   | Read-Only| Optional| Description                                                        |
4944e41f4b71Sopenharmony_ci| --------------- | ---------------------------------------- |---- | ---- | ------------------------------------------------------------ |
4945e41f4b71Sopenharmony_ci| audioBitrate | number     | No| Yes| Bit rate of the output audio, in bit/s. The default value is 48 kbit/s.|
4946e41f4b71Sopenharmony_ci| audioCodec | [CodecMimeType](#codecmimetype8)     | No| Yes | Encoding format of the output audio. Currently, only AAC is supported.                  |
4947e41f4b71Sopenharmony_ci| fileFormat         | [ContainerFormatType](#containerformattype8) | No| No  | Container format of the output video file. Currently, only MP4 is supported.|
4948e41f4b71Sopenharmony_ci| videoBitrate         | number | No|  Yes | Bit rate of the output video, in bit/s. The default bit rate depends on the resolution of the output video. The default bit rate is 1 Mbit/s for the resolution in the range [240p, 480P], 2 Mbit/s for the range (480P,720P], 4 Mbit/s for the range (720P,1080P], and 8 Mbit/s for 1080p or higher.|
4949e41f4b71Sopenharmony_ci| videoCodec        | [CodecMimeType](#codecmimetype8) | No| Yes  | Encoding format of the output video. Currently, only AVC and HEVC are supported.|
4950e41f4b71Sopenharmony_ci| videoFrameWidth        | number | No|  Yes  | Width of the output video frame, in px. If this parameter is unspecified, the width of the source video frame is used.|
4951e41f4b71Sopenharmony_ci| videoFrameHeight        | number | No|  Yes  | Height of the output video frame, in px. If this parameter is unspecified, the height of the source video frame is used.|
4952e41f4b71Sopenharmony_ci
4953e41f4b71Sopenharmony_ci
4954e41f4b71Sopenharmony_ci
4955e41f4b71Sopenharmony_ci## AVMetadataExtractor<sup>11+</sup>
4956e41f4b71Sopenharmony_ci
4957e41f4b71Sopenharmony_ciProvides APIs to obtain metadata from media resources. Before calling any API of **AVMetadataExtractor**, you must use [createAVMetadataExtractor()](#mediacreateavmetadataextractor11) to create an **AVMetadataExtractor** instance.
4958e41f4b71Sopenharmony_ci
4959e41f4b71Sopenharmony_ciFor details about the demo for obtaining audio or video metadata, see [Obtaining Audio/Video Metadata](../../media/media/avmetadataextractor.md).
4960e41f4b71Sopenharmony_ci
4961e41f4b71Sopenharmony_ci### Attributes
4962e41f4b71Sopenharmony_ci
4963e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor
4964e41f4b71Sopenharmony_ci
4965e41f4b71Sopenharmony_ci| Name                                               | Type                                                        | Readable| Writable| Description                                                        |
4966e41f4b71Sopenharmony_ci| --------------------------------------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
4967e41f4b71Sopenharmony_ci| fdSrc<sup>11+</sup>                                  | [AVFileDescriptor](#avfiledescriptor9)                       | Yes  | Yes  | Media file descriptor, which specifies the data source. Before obtaining metadata, you must set the data source through either **fdSrc** or **dataSrc**.<br> **Example:**<br>There is a media file that stores continuous assets, the address offset is 0, and the byte length is 100. Its file descriptor is **AVFileDescriptor {fd = resourceHandle; offset = 0; length = 100; }**.<br>**NOTE**<br> - After the resource handle (FD) is transferred to an **AVMetadataExtractor** instance, do not use the resource handle to perform other read and write operations, including but not limited to transferring this handle to other **AVPlayer**, **AVMetadataExtractor**, **AVImageGenerator**, or **AVTranscoder** instance. Competition occurs when multiple AVMetadataExtractor use the same resource handle to read and write files at the same time, resulting in errors in obtaining data.|
4968e41f4b71Sopenharmony_ci| dataSrc<sup>11+</sup>                               | [AVDataSrcDescriptor](#avdatasrcdescriptor10)                | Yes  | Yes  | Streaming media resource descriptor, which specifies the data source. Before obtaining metadata, you must set the data source through either **fdSrc** or **dataSrc**.<br> When an application obtains a media file from the remote, you can set **dataSrc** to obtain the metadata before the application finishes the downloading.|
4969e41f4b71Sopenharmony_ci
4970e41f4b71Sopenharmony_ci### fetchMetadata<sup>11+</sup>
4971e41f4b71Sopenharmony_ci
4972e41f4b71Sopenharmony_cifetchMetadata(callback: AsyncCallback\<AVMetadata>): void
4973e41f4b71Sopenharmony_ci
4974e41f4b71Sopenharmony_ciObtains media metadata. This API uses an asynchronous callback to return the result.
4975e41f4b71Sopenharmony_ci
4976e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor
4977e41f4b71Sopenharmony_ci
4978e41f4b71Sopenharmony_ci**Parameters**
4979e41f4b71Sopenharmony_ci
4980e41f4b71Sopenharmony_ci| Name  | Type                                        | Mandatory| Description                               |
4981e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | ----------------------------------- |
4982e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[AVMetadata](#avmetadata11)>       | Yes  | Callback used to return the result, which is an **AVMetadata** instance.|
4983e41f4b71Sopenharmony_ci
4984e41f4b71Sopenharmony_ci**Error codes**
4985e41f4b71Sopenharmony_ci
4986e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
4987e41f4b71Sopenharmony_ci
4988e41f4b71Sopenharmony_ci| ID| Error Message                                  |
4989e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
4990e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Returned by callback. |
4991e41f4b71Sopenharmony_ci| 5400106  | Unsupported format. Returned by callback.  |
4992e41f4b71Sopenharmony_ci
4993e41f4b71Sopenharmony_ci**Example**
4994e41f4b71Sopenharmony_ci
4995e41f4b71Sopenharmony_ci```ts
4996e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4997e41f4b71Sopenharmony_ci
4998e41f4b71Sopenharmony_ciavMetadataExtractor.fetchMetadata((error: BusinessError, metadata: media.AVMetadata) => {
4999e41f4b71Sopenharmony_ci  if (error) {
5000e41f4b71Sopenharmony_ci    console.error(`Failed to fetch Metadata, err = ${JSON.stringify(error)}`);
5001e41f4b71Sopenharmony_ci    return;
5002e41f4b71Sopenharmony_ci  }
5003e41f4b71Sopenharmony_ci  console.info(`Succeeded in fetching Metadata, genre: ${metadata.genre}`);
5004e41f4b71Sopenharmony_ci});
5005e41f4b71Sopenharmony_ci```
5006e41f4b71Sopenharmony_ci
5007e41f4b71Sopenharmony_ci### fetchMetadata<sup>11+</sup>
5008e41f4b71Sopenharmony_ci
5009e41f4b71Sopenharmony_cifetchMetadata(): Promise\<AVMetadata>
5010e41f4b71Sopenharmony_ci
5011e41f4b71Sopenharmony_ciObtains media metadata. This API uses a promise to return the result.
5012e41f4b71Sopenharmony_ci
5013e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor
5014e41f4b71Sopenharmony_ci
5015e41f4b71Sopenharmony_ci**Return value**
5016e41f4b71Sopenharmony_ci
5017e41f4b71Sopenharmony_ci| Type          | Description                                    |
5018e41f4b71Sopenharmony_ci| -------------- | ---------------------------------------- |
5019e41f4b71Sopenharmony_ci| Promise\<[AVMetadata](#avmetadata11)>  | Promise used to return the result, which is an **AVMetadata** instance.|
5020e41f4b71Sopenharmony_ci
5021e41f4b71Sopenharmony_ci**Error codes**
5022e41f4b71Sopenharmony_ci
5023e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
5024e41f4b71Sopenharmony_ci
5025e41f4b71Sopenharmony_ci| ID| Error Message                                 |
5026e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
5027e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Returned by promise. |
5028e41f4b71Sopenharmony_ci| 5400106  | Unsupported format. Returned by promise.  |
5029e41f4b71Sopenharmony_ci
5030e41f4b71Sopenharmony_ci**Example**
5031e41f4b71Sopenharmony_ci
5032e41f4b71Sopenharmony_ci```ts
5033e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5034e41f4b71Sopenharmony_ci
5035e41f4b71Sopenharmony_ciavMetadataExtractor.fetchMetadata().then((metadata: media.AVMetadata) => {
5036e41f4b71Sopenharmony_ci  console.info(`Succeeded in fetching Metadata, genre: ${metadata.genre}`)
5037e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
5038e41f4b71Sopenharmony_ci  console.error(`Failed to fetch Metadata, error message:${error.message}`);
5039e41f4b71Sopenharmony_ci});
5040e41f4b71Sopenharmony_ci```
5041e41f4b71Sopenharmony_ci
5042e41f4b71Sopenharmony_ci### fetchAlbumCover<sup>11+</sup>
5043e41f4b71Sopenharmony_ci
5044e41f4b71Sopenharmony_cifetchAlbumCover(callback: AsyncCallback\<image.PixelMap>): void
5045e41f4b71Sopenharmony_ci
5046e41f4b71Sopenharmony_ciObtains the cover of the audio album. This API uses an asynchronous callback to return the result.
5047e41f4b71Sopenharmony_ci
5048e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor
5049e41f4b71Sopenharmony_ci
5050e41f4b71Sopenharmony_ci**Parameters**
5051e41f4b71Sopenharmony_ci
5052e41f4b71Sopenharmony_ci| Name  | Type                                        | Mandatory| Description                               |
5053e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | ----------------------------------- |
5054e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)>    | Yes  | Callback used to return the album cover.|
5055e41f4b71Sopenharmony_ci
5056e41f4b71Sopenharmony_ci**Error codes**
5057e41f4b71Sopenharmony_ci
5058e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
5059e41f4b71Sopenharmony_ci
5060e41f4b71Sopenharmony_ci| ID| Error Message                                  |
5061e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
5062e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Return by callback. |
5063e41f4b71Sopenharmony_ci| 5400106  | Unsupported format. Returned by callback.  |
5064e41f4b71Sopenharmony_ci
5065e41f4b71Sopenharmony_ci**Example**
5066e41f4b71Sopenharmony_ci
5067e41f4b71Sopenharmony_ci```ts
5068e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5069e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
5070e41f4b71Sopenharmony_ci
5071e41f4b71Sopenharmony_cilet pixel_map : image.PixelMap | undefined = undefined;
5072e41f4b71Sopenharmony_ci
5073e41f4b71Sopenharmony_ciavMetadataExtractor.fetchAlbumCover((error: BusinessError, pixelMap: image.PixelMap) => {
5074e41f4b71Sopenharmony_ci  if (error) {
5075e41f4b71Sopenharmony_ci    console.error(`Failed to fetch AlbumCover, error = ${JSON.stringify(error)}`);
5076e41f4b71Sopenharmony_ci    return;
5077e41f4b71Sopenharmony_ci  }
5078e41f4b71Sopenharmony_ci  pixel_map = pixelMap;
5079e41f4b71Sopenharmony_ci});
5080e41f4b71Sopenharmony_ci```
5081e41f4b71Sopenharmony_ci
5082e41f4b71Sopenharmony_ci### fetchAlbumCover<sup>11+</sup>
5083e41f4b71Sopenharmony_ci
5084e41f4b71Sopenharmony_cifetchAlbumCover(): Promise\<image.PixelMap>
5085e41f4b71Sopenharmony_ci
5086e41f4b71Sopenharmony_ciObtains the cover of the audio album. This API uses a promise to return the result.
5087e41f4b71Sopenharmony_ci
5088e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor
5089e41f4b71Sopenharmony_ci
5090e41f4b71Sopenharmony_ci**Return value**
5091e41f4b71Sopenharmony_ci
5092e41f4b71Sopenharmony_ci| Type          | Description                                    |
5093e41f4b71Sopenharmony_ci| -------------- | ---------------------------------------- |
5094e41f4b71Sopenharmony_ci| Promise\<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> |  Promise used to return the album cover.|
5095e41f4b71Sopenharmony_ci
5096e41f4b71Sopenharmony_ci**Error codes**
5097e41f4b71Sopenharmony_ci
5098e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
5099e41f4b71Sopenharmony_ci
5100e41f4b71Sopenharmony_ci| ID| Error Message                                 |
5101e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
5102e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Returned by promise. |
5103e41f4b71Sopenharmony_ci| 5400106  | Unsupported format. Returned by promise.  |
5104e41f4b71Sopenharmony_ci
5105e41f4b71Sopenharmony_ci**Example**
5106e41f4b71Sopenharmony_ci
5107e41f4b71Sopenharmony_ci```ts
5108e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5109e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
5110e41f4b71Sopenharmony_ci
5111e41f4b71Sopenharmony_cilet pixel_map : image.PixelMap | undefined = undefined;
5112e41f4b71Sopenharmony_ci
5113e41f4b71Sopenharmony_ciavMetadataExtractor.fetchAlbumCover().then((pixelMap: image.PixelMap) => {
5114e41f4b71Sopenharmony_ci  pixel_map = pixelMap;
5115e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
5116e41f4b71Sopenharmony_ci  console.error(`Failed to fetch AlbumCover, error message:${error.message}`);
5117e41f4b71Sopenharmony_ci});
5118e41f4b71Sopenharmony_ci```
5119e41f4b71Sopenharmony_ci
5120e41f4b71Sopenharmony_ci### release<sup>11+</sup>
5121e41f4b71Sopenharmony_ci
5122e41f4b71Sopenharmony_cirelease(callback: AsyncCallback\<void>): void
5123e41f4b71Sopenharmony_ci
5124e41f4b71Sopenharmony_ciReleases this **AVMetadataExtractor** instance. This API uses an asynchronous callback to return the result.
5125e41f4b71Sopenharmony_ci
5126e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor
5127e41f4b71Sopenharmony_ci
5128e41f4b71Sopenharmony_ci**Parameters**
5129e41f4b71Sopenharmony_ci
5130e41f4b71Sopenharmony_ci| Name  | Type                                        | Mandatory| Description                               |
5131e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | ----------------------------------- |
5132e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>                   | Yes  |Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
5133e41f4b71Sopenharmony_ci
5134e41f4b71Sopenharmony_ci**Error codes**
5135e41f4b71Sopenharmony_ci
5136e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
5137e41f4b71Sopenharmony_ci
5138e41f4b71Sopenharmony_ci| ID| Error Message                                  |
5139e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
5140e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Returned by callback. |
5141e41f4b71Sopenharmony_ci
5142e41f4b71Sopenharmony_ci**Example**
5143e41f4b71Sopenharmony_ci
5144e41f4b71Sopenharmony_ci```ts
5145e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5146e41f4b71Sopenharmony_ci
5147e41f4b71Sopenharmony_ciavMetadataExtractor.release((error: BusinessError) => {
5148e41f4b71Sopenharmony_ci  if (error) {
5149e41f4b71Sopenharmony_ci    console.error(`Failed to release, err = ${JSON.stringify(error)}`);
5150e41f4b71Sopenharmony_ci    return;
5151e41f4b71Sopenharmony_ci  }
5152e41f4b71Sopenharmony_ci  console.info(`Succeeded in releasing.`);
5153e41f4b71Sopenharmony_ci});
5154e41f4b71Sopenharmony_ci```
5155e41f4b71Sopenharmony_ci
5156e41f4b71Sopenharmony_ci### release<sup>11+</sup>
5157e41f4b71Sopenharmony_ci
5158e41f4b71Sopenharmony_cirelease(): Promise\<void>
5159e41f4b71Sopenharmony_ci
5160e41f4b71Sopenharmony_ciReleases this **AVMetadataExtractor** instance. This API uses a promise to return the result.
5161e41f4b71Sopenharmony_ci
5162e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor
5163e41f4b71Sopenharmony_ci
5164e41f4b71Sopenharmony_ci**Return value**
5165e41f4b71Sopenharmony_ci
5166e41f4b71Sopenharmony_ci| Type          | Description                                    |
5167e41f4b71Sopenharmony_ci| -------------- | ---------------------------------------- |
5168e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
5169e41f4b71Sopenharmony_ci
5170e41f4b71Sopenharmony_ci**Error codes**
5171e41f4b71Sopenharmony_ci
5172e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
5173e41f4b71Sopenharmony_ci
5174e41f4b71Sopenharmony_ci| ID| Error Message                                 |
5175e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
5176e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Returned by promise. |
5177e41f4b71Sopenharmony_ci
5178e41f4b71Sopenharmony_ci**Example**
5179e41f4b71Sopenharmony_ci
5180e41f4b71Sopenharmony_ci```ts
5181e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5182e41f4b71Sopenharmony_ci
5183e41f4b71Sopenharmony_ciavMetadataExtractor.release().then(() => {
5184e41f4b71Sopenharmony_ci  console.info(`Succeeded in releasing.`);
5185e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
5186e41f4b71Sopenharmony_ci  console.error(`Failed to release, error message:${error.message}`);
5187e41f4b71Sopenharmony_ci});
5188e41f4b71Sopenharmony_ci```
5189e41f4b71Sopenharmony_ci
5190e41f4b71Sopenharmony_ci## AVMetadata<sup>11+</sup>
5191e41f4b71Sopenharmony_ci
5192e41f4b71Sopenharmony_ciDefines the audio and video metadata. Parameters that are not declared as read-only in [AVRecorderConfig](#avrecorderconfig9) can be used as input parameters for recording of [AVRecorder](#avrecorder9).
5193e41f4b71Sopenharmony_ci
5194e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor
5195e41f4b71Sopenharmony_ci
5196e41f4b71Sopenharmony_ci| Name  | Type  | Mandatory| Description                                                        |
5197e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
5198e41f4b71Sopenharmony_ci| album     | string | No  | Title of the album. This parameter is read-only in the current version.    |
5199e41f4b71Sopenharmony_ci| albumArtist | string | No  | Artist of the album. This parameter is read-only in the current version.|
5200e41f4b71Sopenharmony_ci| artist | string | No  | Artist of the media asset. This parameter is read-only in the current version.|
5201e41f4b71Sopenharmony_ci| author | string | No  | Author of the media asset. This parameter is read-only in the current version.|
5202e41f4b71Sopenharmony_ci| dateTime | string | No  | Time when the media asset is created. This parameter is read-only in the current version.|
5203e41f4b71Sopenharmony_ci| dateTimeFormat | string | No  | Time when the media asset is created. The value is in the YYYY-MM-DD HH:mm:ss format. This parameter is read-only in the current version.|
5204e41f4b71Sopenharmony_ci| composer | string | No  | Composer of the media asset. This parameter is read-only in the current version.|
5205e41f4b71Sopenharmony_ci| duration | string | No  | Duration of the media asset. This parameter is read-only in the current version.|
5206e41f4b71Sopenharmony_ci| genre | string | No  | Type or genre of the media asset.|
5207e41f4b71Sopenharmony_ci| hasAudio | string | No  | Whether the media asset contains audio. This parameter is read-only in the current version.|
5208e41f4b71Sopenharmony_ci| hasVideo | string | No  | Whether the media asset contains a video. This parameter is read-only in the current version.|
5209e41f4b71Sopenharmony_ci| mimeType | string | No  | MIME type of the media asset. This parameter is read-only in the current version.|
5210e41f4b71Sopenharmony_ci| trackCount | string | No  | Number of tracks of the media asset. This parameter is read-only in the current version.|
5211e41f4b71Sopenharmony_ci| sampleRate | string | No  | Audio sampling rate, in Hz. This parameter is read-only in the current version.|
5212e41f4b71Sopenharmony_ci| title | string | No  | Title of the media asset. This parameter is read-only in the current version. This parameter is read-only in the current version.|
5213e41f4b71Sopenharmony_ci| videoHeight | string | No  | Video height, in px. This parameter is read-only in the current version.|
5214e41f4b71Sopenharmony_ci| videoWidth | string | No  | Video width, in px. This parameter is read-only in the current version.|
5215e41f4b71Sopenharmony_ci| videoOrientation | string | No  | Video rotation direction, in degrees.|
5216e41f4b71Sopenharmony_ci| hdrType<sup>12+</sup> | [HdrType](#hdrtype12) | No  | HDR type of the media asset. This parameter is read-only in the current version.|
5217e41f4b71Sopenharmony_ci| location<sup>12+</sup> | [Location](#location) | No| Geographical location of the media asset.|
5218e41f4b71Sopenharmony_ci| customInfo<sup>12+</sup> | Record<string, string> | No| Custom key-value mappings obtained from **moov.meta.list**.|
5219e41f4b71Sopenharmony_ci
5220e41f4b71Sopenharmony_ci## HdrType<sup>12+</sup>
5221e41f4b71Sopenharmony_ci
5222e41f4b71Sopenharmony_ciEnumerates the HDR types.
5223e41f4b71Sopenharmony_ci
5224e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
5225e41f4b71Sopenharmony_ci
5226e41f4b71Sopenharmony_ci| Name                     | Value  | Description                  |
5227e41f4b71Sopenharmony_ci| ------------------------- | ---- | ---------------------- |
5228e41f4b71Sopenharmony_ci| AV_HDR_TYPE_NONE          | 0    | No HDR.|
5229e41f4b71Sopenharmony_ci| AV_HDR_TYPE_VIVID         | 1    | HDR VIVID.|
5230e41f4b71Sopenharmony_ci
5231e41f4b71Sopenharmony_ci## media.createAudioPlayer<sup>(deprecated)</sup>
5232e41f4b71Sopenharmony_ci
5233e41f4b71Sopenharmony_cicreateAudioPlayer(): AudioPlayer
5234e41f4b71Sopenharmony_ci
5235e41f4b71Sopenharmony_ciCreates an **AudioPlayer** instance in synchronous mode.
5236e41f4b71Sopenharmony_ci
5237e41f4b71Sopenharmony_ci> **NOTE**
5238e41f4b71Sopenharmony_ci>
5239e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [createAVPlayer](#mediacreateavplayer9) instead.
5240e41f4b71Sopenharmony_ci
5241e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
5242e41f4b71Sopenharmony_ci
5243e41f4b71Sopenharmony_ci**Return value**
5244e41f4b71Sopenharmony_ci
5245e41f4b71Sopenharmony_ci| Type                       | Description                                                        |
5246e41f4b71Sopenharmony_ci| --------------------------- | ------------------------------------------------------------ |
5247e41f4b71Sopenharmony_ci| [AudioPlayer](#audioplayerdeprecated) | If the operation is successful, an **AudioPlayer** instance is returned; otherwise, **null** is returned. After the instance is created, you can start, pause, or stop audio playback.|
5248e41f4b71Sopenharmony_ci
5249e41f4b71Sopenharmony_ci**Example**
5250e41f4b71Sopenharmony_ci
5251e41f4b71Sopenharmony_ci```ts
5252e41f4b71Sopenharmony_cilet audioPlayer: media.AudioPlayer = media.createAudioPlayer();
5253e41f4b71Sopenharmony_ci```
5254e41f4b71Sopenharmony_ci
5255e41f4b71Sopenharmony_ci## media.createVideoPlayer<sup>(deprecated)</sup>
5256e41f4b71Sopenharmony_ci
5257e41f4b71Sopenharmony_cicreateVideoPlayer(callback: AsyncCallback\<VideoPlayer>): void
5258e41f4b71Sopenharmony_ci
5259e41f4b71Sopenharmony_ciCreates a **VideoPlayer** instance. This API uses an asynchronous callback to return the result.
5260e41f4b71Sopenharmony_ci
5261e41f4b71Sopenharmony_ci> **NOTE**
5262e41f4b71Sopenharmony_ci>
5263e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [createAVPlayer](#mediacreateavplayer9) instead.
5264e41f4b71Sopenharmony_ci
5265e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
5266e41f4b71Sopenharmony_ci
5267e41f4b71Sopenharmony_ci**Parameters**
5268e41f4b71Sopenharmony_ci
5269e41f4b71Sopenharmony_ci| Name  | Type                                      | Mandatory| Description                                                        |
5270e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ |
5271e41f4b71Sopenharmony_ci| callback | AsyncCallback<[VideoPlayer](#videoplayerdeprecated)> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the **VideoPlayer** instance created; otherwise, **err** is an error object.|
5272e41f4b71Sopenharmony_ci
5273e41f4b71Sopenharmony_ci**Example**
5274e41f4b71Sopenharmony_ci
5275e41f4b71Sopenharmony_ci```ts
5276e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5277e41f4b71Sopenharmony_ci
5278e41f4b71Sopenharmony_cilet videoPlayer: media.VideoPlayer;
5279e41f4b71Sopenharmony_cimedia.createVideoPlayer((error: BusinessError, video: media.VideoPlayer) => {
5280e41f4b71Sopenharmony_ci  if (video != null) {
5281e41f4b71Sopenharmony_ci    videoPlayer = video;
5282e41f4b71Sopenharmony_ci    console.info('Succeeded in creating VideoPlayer');
5283e41f4b71Sopenharmony_ci  } else {
5284e41f4b71Sopenharmony_ci    console.error(`Failed to create VideoPlayer, error:${error}`);
5285e41f4b71Sopenharmony_ci  }
5286e41f4b71Sopenharmony_ci});
5287e41f4b71Sopenharmony_ci```
5288e41f4b71Sopenharmony_ci
5289e41f4b71Sopenharmony_ci## media.createVideoPlayer<sup>(deprecated)</sup>
5290e41f4b71Sopenharmony_ci
5291e41f4b71Sopenharmony_cicreateVideoPlayer(): Promise\<VideoPlayer>
5292e41f4b71Sopenharmony_ci
5293e41f4b71Sopenharmony_ciCreates a **VideoPlayer** instance. This API uses a promise to return the result.
5294e41f4b71Sopenharmony_ci
5295e41f4b71Sopenharmony_ci> **NOTE**
5296e41f4b71Sopenharmony_ci>
5297e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [createAVPlayer](#mediacreateavplayer9-1) instead.
5298e41f4b71Sopenharmony_ci
5299e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
5300e41f4b71Sopenharmony_ci
5301e41f4b71Sopenharmony_ci**Return value**
5302e41f4b71Sopenharmony_ci
5303e41f4b71Sopenharmony_ci| Type                                | Description                                                        |
5304e41f4b71Sopenharmony_ci| ------------------------------------ | ------------------------------------------------------------ |
5305e41f4b71Sopenharmony_ci| Promise<[VideoPlayer](#videoplayerdeprecated)> | Promise used to return the result. If the operation is successful, a **VideoPlayer** instance is returned; otherwise, **null** is returned. The instance can be used to manage and play video.|
5306e41f4b71Sopenharmony_ci
5307e41f4b71Sopenharmony_ci**Example**
5308e41f4b71Sopenharmony_ci
5309e41f4b71Sopenharmony_ci```ts
5310e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5311e41f4b71Sopenharmony_ci
5312e41f4b71Sopenharmony_cilet videoPlayer: media.VideoPlayer;
5313e41f4b71Sopenharmony_cimedia.createVideoPlayer().then((video: media.VideoPlayer) => {
5314e41f4b71Sopenharmony_ci  if (video != null) {
5315e41f4b71Sopenharmony_ci    videoPlayer = video;
5316e41f4b71Sopenharmony_ci    console.info('Succeeded in creating VideoPlayer');
5317e41f4b71Sopenharmony_ci  } else {
5318e41f4b71Sopenharmony_ci    console.error('Failed to create VideoPlayer');
5319e41f4b71Sopenharmony_ci  }
5320e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
5321e41f4b71Sopenharmony_ci  console.error(`Failed to create VideoPlayer, error:${error}`);
5322e41f4b71Sopenharmony_ci});
5323e41f4b71Sopenharmony_ci```
5324e41f4b71Sopenharmony_ci
5325e41f4b71Sopenharmony_ci## media.createAudioRecorder<sup>(deprecated)</sup>
5326e41f4b71Sopenharmony_ci
5327e41f4b71Sopenharmony_cicreateAudioRecorder(): AudioRecorder
5328e41f4b71Sopenharmony_ci
5329e41f4b71Sopenharmony_ciCreates an **AudioRecorder** instance to control audio recording.
5330e41f4b71Sopenharmony_ciOnly one **AudioRecorder** instance can be created per device.
5331e41f4b71Sopenharmony_ci
5332e41f4b71Sopenharmony_ci> **NOTE**
5333e41f4b71Sopenharmony_ci>
5334e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [createAVRecorder](#mediacreateavrecorder9) instead.
5335e41f4b71Sopenharmony_ci
5336e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioRecorder
5337e41f4b71Sopenharmony_ci
5338e41f4b71Sopenharmony_ci**Return value**
5339e41f4b71Sopenharmony_ci
5340e41f4b71Sopenharmony_ci| Type                           | Description                                                        |
5341e41f4b71Sopenharmony_ci| ------------------------------- | ------------------------------------------------------------ |
5342e41f4b71Sopenharmony_ci| [AudioRecorder](#audiorecorderdeprecated) | If the operation is successful, an **AudioRecorder** instance is returned; otherwise, **null** is returned. The instance can be used to record audio.|
5343e41f4b71Sopenharmony_ci
5344e41f4b71Sopenharmony_ci**Example**
5345e41f4b71Sopenharmony_ci
5346e41f4b71Sopenharmony_ci```ts
5347e41f4b71Sopenharmony_cilet audioRecorder: media.AudioRecorder = media.createAudioRecorder();
5348e41f4b71Sopenharmony_ci```
5349e41f4b71Sopenharmony_ci
5350e41f4b71Sopenharmony_ci## MediaErrorCode<sup>(deprecated)</sup>
5351e41f4b71Sopenharmony_ci
5352e41f4b71Sopenharmony_ciEnumerates the media error codes.
5353e41f4b71Sopenharmony_ci
5354e41f4b71Sopenharmony_ci> **NOTE**
5355e41f4b71Sopenharmony_ci>
5356e41f4b71Sopenharmony_ci> This enum is supported since API version 8 and deprecated since API version 11. You are advised to use [Media Error Codes](#averrorcode9) instead.
5357e41f4b71Sopenharmony_ci
5358e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
5359e41f4b71Sopenharmony_ci
5360e41f4b71Sopenharmony_ci| Name                      | Value  | Description                                  |
5361e41f4b71Sopenharmony_ci| -------------------------- | ---- | -------------------------------------- |
5362e41f4b71Sopenharmony_ci| MSERR_OK                   | 0    | The operation is successful.                        |
5363e41f4b71Sopenharmony_ci| MSERR_NO_MEMORY            | 1    | Failed to allocate memory. The system may have no available memory.|
5364e41f4b71Sopenharmony_ci| MSERR_OPERATION_NOT_PERMIT | 2    | No permission to perform the operation.                |
5365e41f4b71Sopenharmony_ci| MSERR_INVALID_VAL          | 3    | Invalid input parameter.                    |
5366e41f4b71Sopenharmony_ci| MSERR_IO                   | 4    | An I/O error occurs.                      |
5367e41f4b71Sopenharmony_ci| MSERR_TIMEOUT              | 5    | The operation times out.                        |
5368e41f4b71Sopenharmony_ci| MSERR_UNKNOWN              | 6    | An unknown error occurs.                        |
5369e41f4b71Sopenharmony_ci| MSERR_SERVICE_DIED         | 7    | Invalid server.                      |
5370e41f4b71Sopenharmony_ci| MSERR_INVALID_STATE        | 8    | The operation is not allowed in the current state.  |
5371e41f4b71Sopenharmony_ci| MSERR_UNSUPPORTED          | 9    | The operation is not supported in the current version.      |
5372e41f4b71Sopenharmony_ci
5373e41f4b71Sopenharmony_ci## AudioPlayer<sup>(deprecated)</sup>
5374e41f4b71Sopenharmony_ci
5375e41f4b71Sopenharmony_ci> **NOTE**
5376e41f4b71Sopenharmony_ci>
5377e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVPlayer](#avplayer9) instead.
5378e41f4b71Sopenharmony_ci
5379e41f4b71Sopenharmony_ciProvides APIs to manage and play audio. Before calling any API in **AudioPlayer**, you must use [createAudioPlayer()](#mediacreateaudioplayerdeprecated) to create an **AudioPlayer** instance.
5380e41f4b71Sopenharmony_ci
5381e41f4b71Sopenharmony_ci### Attributes<sup>(deprecated)</sup>
5382e41f4b71Sopenharmony_ci
5383e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
5384e41f4b71Sopenharmony_ci
5385e41f4b71Sopenharmony_ci| Name                           | Type                                                  | Read-Only| Optional| Description                                                        |
5386e41f4b71Sopenharmony_ci| ------------------------------- | ------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
5387e41f4b71Sopenharmony_ci| src                             | string                                                 | No  | No  | Audio file URI. The mainstream audio formats (M4A, AAC, MP3, OGG, WAV, and AMR) are supported.<br>**Example of supported URLs**:<br>1. FD: fd://xx<br>![](figures/en-us_image_url.png)<br>2. HTTP: http\://xx<br>3. HTTPS: https\://xx<br>4. HLS: http\://xx or https\://xx<br>**Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.INTERNET|
5388e41f4b71Sopenharmony_ci| fdSrc<sup>9+</sup>              | [AVFileDescriptor](#avfiledescriptor9)                 | No  | No  | Description of the audio file. This attribute is required when audio assets of an application are continuously stored in a file.<br>**Example:**<br>Assume that a music file that stores continuous music assets consists of the following:<br>Music 1 (address offset: 0, byte length: 100)<br>Music 2 (address offset: 101; byte length: 50)<br>Music 3 (address offset: 151, byte length: 150)<br>1. To play music 1: AVFileDescriptor {fd = resource handle; offset = 0; length = 100; }<br>2. To play music 2: AVFileDescriptor {fd = resource handle; offset = 101; length = 50; }<br>3. To play music 3: AVFileDescriptor {fd = resource handle; offset = 151; length = 150; }<br>To play an independent music file, use **src=fd://xx**.<br>|
5389e41f4b71Sopenharmony_ci| loop                            | boolean                                                | No  | No | Whether to loop audio playback. The value **true** means to loop audio playback, and **false** means the opposite.                |
5390e41f4b71Sopenharmony_ci| audioInterruptMode<sup>9+</sup> | [audio.InterruptMode](../apis-audio-kit/js-apis-audio.md#interruptmode9) | Yes  | Yes  | Audio interruption mode.                                              |
5391e41f4b71Sopenharmony_ci| currentTime                     | number                                                 | Yes  | No  | Current audio playback position, in ms.                      |
5392e41f4b71Sopenharmony_ci| duration                        | number                                                 | Yes  | No  | Audio duration, in ms.                                |
5393e41f4b71Sopenharmony_ci| state                           | [AudioState](#audiostatedeprecated)                              | Yes  | No  | Audio playback state. This state cannot be used as the condition for triggering the call of **play()**, **pause()**, or **stop()**.|
5394e41f4b71Sopenharmony_ci
5395e41f4b71Sopenharmony_ci### play<sup>(deprecated)</sup>
5396e41f4b71Sopenharmony_ci
5397e41f4b71Sopenharmony_ciplay(): void
5398e41f4b71Sopenharmony_ci
5399e41f4b71Sopenharmony_ciStarts to play an audio asset. This API can be called only after the **'dataLoad'** event is triggered.
5400e41f4b71Sopenharmony_ci
5401e41f4b71Sopenharmony_ci> **NOTE**
5402e41f4b71Sopenharmony_ci>
5403e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVPlayer.play](#play9) instead.
5404e41f4b71Sopenharmony_ci
5405e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
5406e41f4b71Sopenharmony_ci
5407e41f4b71Sopenharmony_ci**Example**
5408e41f4b71Sopenharmony_ci
5409e41f4b71Sopenharmony_ci```ts
5410e41f4b71Sopenharmony_ciaudioPlayer.on('play', () => {    // Set the 'play' event callback.
5411e41f4b71Sopenharmony_ci  console.info('audio play called');
5412e41f4b71Sopenharmony_ci});
5413e41f4b71Sopenharmony_ciaudioPlayer.play();
5414e41f4b71Sopenharmony_ci```
5415e41f4b71Sopenharmony_ci
5416e41f4b71Sopenharmony_ci### pause<sup>(deprecated)</sup>
5417e41f4b71Sopenharmony_ci
5418e41f4b71Sopenharmony_cipause(): void
5419e41f4b71Sopenharmony_ci
5420e41f4b71Sopenharmony_ciPauses audio playback.
5421e41f4b71Sopenharmony_ci
5422e41f4b71Sopenharmony_ci> **NOTE**
5423e41f4b71Sopenharmony_ci>
5424e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVPlayer.pause](#pause9) instead.
5425e41f4b71Sopenharmony_ci
5426e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
5427e41f4b71Sopenharmony_ci
5428e41f4b71Sopenharmony_ci**Example**
5429e41f4b71Sopenharmony_ci
5430e41f4b71Sopenharmony_ci```ts
5431e41f4b71Sopenharmony_ciaudioPlayer.on('pause', () => {    // Set the 'pause' event callback.
5432e41f4b71Sopenharmony_ci  console.info('audio pause called');
5433e41f4b71Sopenharmony_ci});
5434e41f4b71Sopenharmony_ciaudioPlayer.pause();
5435e41f4b71Sopenharmony_ci```
5436e41f4b71Sopenharmony_ci
5437e41f4b71Sopenharmony_ci### stop<sup>(deprecated)</sup>
5438e41f4b71Sopenharmony_ci
5439e41f4b71Sopenharmony_cistop(): void
5440e41f4b71Sopenharmony_ci
5441e41f4b71Sopenharmony_ciStops audio playback.
5442e41f4b71Sopenharmony_ci
5443e41f4b71Sopenharmony_ci> **NOTE**
5444e41f4b71Sopenharmony_ci>
5445e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVPlayer.stop](#stop9) instead.
5446e41f4b71Sopenharmony_ci
5447e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
5448e41f4b71Sopenharmony_ci
5449e41f4b71Sopenharmony_ci**Example**
5450e41f4b71Sopenharmony_ci
5451e41f4b71Sopenharmony_ci```ts
5452e41f4b71Sopenharmony_ciaudioPlayer.on('stop', () => {    // Set the 'stop' event callback.
5453e41f4b71Sopenharmony_ci  console.info('audio stop called');
5454e41f4b71Sopenharmony_ci});
5455e41f4b71Sopenharmony_ciaudioPlayer.stop();
5456e41f4b71Sopenharmony_ci```
5457e41f4b71Sopenharmony_ci
5458e41f4b71Sopenharmony_ci### reset<sup>(deprecated)</sup>
5459e41f4b71Sopenharmony_ci
5460e41f4b71Sopenharmony_cireset(): void
5461e41f4b71Sopenharmony_ci
5462e41f4b71Sopenharmony_ciResets the audio asset to be played.
5463e41f4b71Sopenharmony_ci
5464e41f4b71Sopenharmony_ci> **NOTE**
5465e41f4b71Sopenharmony_ci>
5466e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [AVPlayer.reset](#reset9) instead.
5467e41f4b71Sopenharmony_ci
5468e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
5469e41f4b71Sopenharmony_ci
5470e41f4b71Sopenharmony_ci**Example**
5471e41f4b71Sopenharmony_ci
5472e41f4b71Sopenharmony_ci```ts
5473e41f4b71Sopenharmony_ciaudioPlayer.on('reset', () => {    // Set the 'reset' event callback.
5474e41f4b71Sopenharmony_ci  console.info('audio reset called');
5475e41f4b71Sopenharmony_ci});
5476e41f4b71Sopenharmony_ciaudioPlayer.reset();
5477e41f4b71Sopenharmony_ci```
5478e41f4b71Sopenharmony_ci
5479e41f4b71Sopenharmony_ci### seek<sup>(deprecated)</sup>
5480e41f4b71Sopenharmony_ci
5481e41f4b71Sopenharmony_ciseek(timeMs: number): void
5482e41f4b71Sopenharmony_ci
5483e41f4b71Sopenharmony_ciSeeks to the specified playback position.
5484e41f4b71Sopenharmony_ci
5485e41f4b71Sopenharmony_ci> **NOTE**
5486e41f4b71Sopenharmony_ci>
5487e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVPlayer.seek](#seek9) instead.
5488e41f4b71Sopenharmony_ci
5489e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
5490e41f4b71Sopenharmony_ci
5491e41f4b71Sopenharmony_ci**Parameters**
5492e41f4b71Sopenharmony_ci
5493e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                       |
5494e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------------------------------------------- |
5495e41f4b71Sopenharmony_ci| timeMs | number | Yes  | Position to seek to, in ms. The value range is [0, duration].|
5496e41f4b71Sopenharmony_ci
5497e41f4b71Sopenharmony_ci**Example**
5498e41f4b71Sopenharmony_ci
5499e41f4b71Sopenharmony_ci```ts
5500e41f4b71Sopenharmony_ciaudioPlayer.on('timeUpdate', (seekDoneTime: number) => {    // Set the 'timeUpdate' event callback.
5501e41f4b71Sopenharmony_ci  if (seekDoneTime == null) {
5502e41f4b71Sopenharmony_ci    console.error('Failed to seek');
5503e41f4b71Sopenharmony_ci    return;
5504e41f4b71Sopenharmony_ci  }
5505e41f4b71Sopenharmony_ci  console.info('Succeeded in seek. seekDoneTime: ' + seekDoneTime);
5506e41f4b71Sopenharmony_ci});
5507e41f4b71Sopenharmony_ciaudioPlayer.seek(30000); // Seek to 30000 ms.
5508e41f4b71Sopenharmony_ci```
5509e41f4b71Sopenharmony_ci
5510e41f4b71Sopenharmony_ci### setVolume<sup>(deprecated)</sup>
5511e41f4b71Sopenharmony_ci
5512e41f4b71Sopenharmony_cisetVolume(vol: number): void
5513e41f4b71Sopenharmony_ci
5514e41f4b71Sopenharmony_ciSets the volume.
5515e41f4b71Sopenharmony_ci
5516e41f4b71Sopenharmony_ci> **NOTE**
5517e41f4b71Sopenharmony_ci>
5518e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVPlayer.setVolume](#setvolume9) instead.
5519e41f4b71Sopenharmony_ci
5520e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
5521e41f4b71Sopenharmony_ci
5522e41f4b71Sopenharmony_ci**Parameters**
5523e41f4b71Sopenharmony_ci
5524e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
5525e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
5526e41f4b71Sopenharmony_ci| vol    | number | Yes  | Relative volume. The value ranges from 0.00 to 1.00. The value **1.00** indicates the maximum volume (100%).|
5527e41f4b71Sopenharmony_ci
5528e41f4b71Sopenharmony_ci**Example**
5529e41f4b71Sopenharmony_ci
5530e41f4b71Sopenharmony_ci```ts
5531e41f4b71Sopenharmony_ciaudioPlayer.on('volumeChange', () => {    // Set the 'volumeChange' event callback.
5532e41f4b71Sopenharmony_ci  console.info('audio volumeChange called');
5533e41f4b71Sopenharmony_ci});
5534e41f4b71Sopenharmony_ciaudioPlayer.setVolume(1);    // Set the volume to 100%.
5535e41f4b71Sopenharmony_ci```
5536e41f4b71Sopenharmony_ci
5537e41f4b71Sopenharmony_ci### release<sup>(deprecated)</sup>
5538e41f4b71Sopenharmony_ci
5539e41f4b71Sopenharmony_cirelease(): void
5540e41f4b71Sopenharmony_ci
5541e41f4b71Sopenharmony_ciReleases the audio playback resources.
5542e41f4b71Sopenharmony_ci
5543e41f4b71Sopenharmony_ci> **NOTE**
5544e41f4b71Sopenharmony_ci>
5545e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVPlayer.release](#release9) instead.
5546e41f4b71Sopenharmony_ci
5547e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
5548e41f4b71Sopenharmony_ci
5549e41f4b71Sopenharmony_ci**Example**
5550e41f4b71Sopenharmony_ci
5551e41f4b71Sopenharmony_ci```ts
5552e41f4b71Sopenharmony_ciaudioPlayer.release();
5553e41f4b71Sopenharmony_ciaudioPlayer = undefined;
5554e41f4b71Sopenharmony_ci```
5555e41f4b71Sopenharmony_ci
5556e41f4b71Sopenharmony_ci### getTrackDescription<sup>(deprecated)</sup>
5557e41f4b71Sopenharmony_ci
5558e41f4b71Sopenharmony_cigetTrackDescription(callback: AsyncCallback\<Array\<MediaDescription>>): void
5559e41f4b71Sopenharmony_ci
5560e41f4b71Sopenharmony_ciObtains the audio track information. It can be called only after the **'dataLoad'** event is triggered. This API uses an asynchronous callback to return the result.
5561e41f4b71Sopenharmony_ci
5562e41f4b71Sopenharmony_ci> **NOTE**
5563e41f4b71Sopenharmony_ci>
5564e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.getTrackDescription](#gettrackdescription9) instead.
5565e41f4b71Sopenharmony_ci
5566e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
5567e41f4b71Sopenharmony_ci
5568e41f4b71Sopenharmony_ci**Parameters**
5569e41f4b71Sopenharmony_ci
5570e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory| Description                                      |
5571e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------ |
5572e41f4b71Sopenharmony_ci| callback | AsyncCallback\<Array\<[MediaDescription](#mediadescription8)>> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the MediaDescription array obtained; otherwise, **err** is an error object.|
5573e41f4b71Sopenharmony_ci
5574e41f4b71Sopenharmony_ci**Example**
5575e41f4b71Sopenharmony_ci
5576e41f4b71Sopenharmony_ci```ts
5577e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5578e41f4b71Sopenharmony_ci
5579e41f4b71Sopenharmony_ciaudioPlayer.getTrackDescription((error: BusinessError, arrList: Array<media.MediaDescription>) => {
5580e41f4b71Sopenharmony_ci  if (arrList != null) {
5581e41f4b71Sopenharmony_ci    console.info('Succeeded in getting TrackDescription');
5582e41f4b71Sopenharmony_ci  } else {
5583e41f4b71Sopenharmony_ci    console.error(`Failed to get TrackDescription, error:${error}`);
5584e41f4b71Sopenharmony_ci  }
5585e41f4b71Sopenharmony_ci});
5586e41f4b71Sopenharmony_ci```
5587e41f4b71Sopenharmony_ci
5588e41f4b71Sopenharmony_ci### getTrackDescription<sup>(deprecated)</sup>
5589e41f4b71Sopenharmony_ci
5590e41f4b71Sopenharmony_cigetTrackDescription(): Promise\<Array\<MediaDescription>>
5591e41f4b71Sopenharmony_ci
5592e41f4b71Sopenharmony_ciObtains the audio track information. It can be called only after the **'dataLoad'** event is triggered. This API uses a promise to return the result.
5593e41f4b71Sopenharmony_ci
5594e41f4b71Sopenharmony_ci> **NOTE**
5595e41f4b71Sopenharmony_ci>
5596e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.getTrackDescription](#gettrackdescription9-1) instead.
5597e41f4b71Sopenharmony_ci
5598e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
5599e41f4b71Sopenharmony_ci
5600e41f4b71Sopenharmony_ci**Return value**
5601e41f4b71Sopenharmony_ci
5602e41f4b71Sopenharmony_ci| Type                                                  | Description                                           |
5603e41f4b71Sopenharmony_ci| ------------------------------------------------------ | ----------------------------------------------- |
5604e41f4b71Sopenharmony_ci| Promise<Array<[MediaDescription](#mediadescription8)>> | Promise used to return a **MediaDescription** array, which records the audio track information.|
5605e41f4b71Sopenharmony_ci
5606e41f4b71Sopenharmony_ci**Example**
5607e41f4b71Sopenharmony_ci
5608e41f4b71Sopenharmony_ci```ts
5609e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5610e41f4b71Sopenharmony_ci
5611e41f4b71Sopenharmony_ciaudioPlayer.getTrackDescription().then((arrList: Array<media.MediaDescription>) => {
5612e41f4b71Sopenharmony_ci  console.info('Succeeded in getting TrackDescription');
5613e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
5614e41f4b71Sopenharmony_ci  console.error(`Failed to get TrackDescription, error:${error}`);
5615e41f4b71Sopenharmony_ci});
5616e41f4b71Sopenharmony_ci```
5617e41f4b71Sopenharmony_ci
5618e41f4b71Sopenharmony_ci### on('bufferingUpdate')<sup>(deprecated)</sup>
5619e41f4b71Sopenharmony_ci
5620e41f4b71Sopenharmony_cion(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: number) => void): void
5621e41f4b71Sopenharmony_ci
5622e41f4b71Sopenharmony_ciSubscribes to the audio buffering update event. This API works only under online playback.
5623e41f4b71Sopenharmony_ci
5624e41f4b71Sopenharmony_ci> **NOTE**
5625e41f4b71Sopenharmony_ci>
5626e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.on('bufferingUpdate')](#onbufferingupdate9) instead.
5627e41f4b71Sopenharmony_ci
5628e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
5629e41f4b71Sopenharmony_ci
5630e41f4b71Sopenharmony_ci**Parameters**
5631e41f4b71Sopenharmony_ci
5632e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
5633e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
5634e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'bufferingUpdate'** in this case.       |
5635e41f4b71Sopenharmony_ci| callback | function | Yes  | Callback invoked when the event is triggered.<br>The value of [BufferingInfoType](#bufferinginfotype8) is fixed at **0**.|
5636e41f4b71Sopenharmony_ci
5637e41f4b71Sopenharmony_ci**Example**
5638e41f4b71Sopenharmony_ci
5639e41f4b71Sopenharmony_ci```ts
5640e41f4b71Sopenharmony_ciaudioPlayer.on('bufferingUpdate', (infoType: media.BufferingInfoType, value: number) => {
5641e41f4b71Sopenharmony_ci  console.info('audio bufferingInfo type: ' + infoType);
5642e41f4b71Sopenharmony_ci  console.info('audio bufferingInfo value: ' + value);
5643e41f4b71Sopenharmony_ci});
5644e41f4b71Sopenharmony_ci```
5645e41f4b71Sopenharmony_ci
5646e41f4b71Sopenharmony_ci### on('play' | 'pause' | 'stop' | 'reset' | 'dataLoad' | 'finish' | 'volumeChange')<sup>(deprecated)</sup>
5647e41f4b71Sopenharmony_ci
5648e41f4b71Sopenharmony_cion(type: 'play' | 'pause' | 'stop' | 'reset' | 'dataLoad' | 'finish' | 'volumeChange', callback: () => void): void
5649e41f4b71Sopenharmony_ci
5650e41f4b71Sopenharmony_ciSubscribes to the audio playback events.
5651e41f4b71Sopenharmony_ci
5652e41f4b71Sopenharmony_ci> **NOTE**
5653e41f4b71Sopenharmony_ci>
5654e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVPlayer.on('stateChange')](#onstatechange9) instead.
5655e41f4b71Sopenharmony_ci
5656e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
5657e41f4b71Sopenharmony_ci
5658e41f4b71Sopenharmony_ci**Parameters**
5659e41f4b71Sopenharmony_ci
5660e41f4b71Sopenharmony_ci| Name  | Type      | Mandatory| Description                                                        |
5661e41f4b71Sopenharmony_ci| -------- | ---------- | ---- | ------------------------------------------------------------ |
5662e41f4b71Sopenharmony_ci| type     | string     | Yes  | Event type. The following events are supported:<br>- 'play': triggered when the [play()](#playdeprecated) API is called and audio playback starts.<br>- 'pause': triggered when the [pause()](#pausedeprecated) API is called and audio playback is paused.<br>- 'stop': triggered when the [stop()](#stopdeprecated) API is called and audio playback stops.<br>- 'reset': triggered when the [reset()](#resetdeprecated) API is called and audio playback is reset.<br>- 'dataLoad': triggered when the audio data is loaded, that is, when the **src** attribute is configured.<br>- 'finish': triggered when the audio playback is finished.<br>- 'volumeChange': triggered when the [setVolume()](#setvolumedeprecated) API is called and the playback volume is changed.|
5663e41f4b71Sopenharmony_ci| callback | () => void | Yes  | Callback invoked when the event is triggered.                                          |
5664e41f4b71Sopenharmony_ci
5665e41f4b71Sopenharmony_ci**Example**
5666e41f4b71Sopenharmony_ci
5667e41f4b71Sopenharmony_ci```ts
5668e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
5669e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5670e41f4b71Sopenharmony_ci
5671e41f4b71Sopenharmony_cilet audioPlayer: media.AudioPlayer = media.createAudioPlayer();  // Create an AudioPlayer instance.
5672e41f4b71Sopenharmony_ciaudioPlayer.on('dataLoad', () => {            // Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
5673e41f4b71Sopenharmony_ci  console.info('audio set source called');
5674e41f4b71Sopenharmony_ci  audioPlayer.play();                       // Start the playback and trigger the 'play' event callback.
5675e41f4b71Sopenharmony_ci});
5676e41f4b71Sopenharmony_ciaudioPlayer.on('play', () => {                // Set the 'play' event callback.
5677e41f4b71Sopenharmony_ci  console.info('audio play called');
5678e41f4b71Sopenharmony_ci  audioPlayer.seek(30000);                  // Call the seek() API and trigger the 'timeUpdate' event callback.
5679e41f4b71Sopenharmony_ci});
5680e41f4b71Sopenharmony_ciaudioPlayer.on('pause', () => {               // Set the 'pause' event callback.
5681e41f4b71Sopenharmony_ci  console.info('audio pause called');
5682e41f4b71Sopenharmony_ci  audioPlayer.stop();                       // Stop the playback and trigger the 'stop' event callback.
5683e41f4b71Sopenharmony_ci});
5684e41f4b71Sopenharmony_ciaudioPlayer.on('reset', () => {               // Set the 'reset' event callback.
5685e41f4b71Sopenharmony_ci  console.info('audio reset called');
5686e41f4b71Sopenharmony_ci  audioPlayer.release();                    // Release the AudioPlayer instance.
5687e41f4b71Sopenharmony_ci  audioPlayer = undefined;
5688e41f4b71Sopenharmony_ci});
5689e41f4b71Sopenharmony_ciaudioPlayer.on('timeUpdate', (seekDoneTime: number) => {  // Set the 'timeUpdate' event callback.
5690e41f4b71Sopenharmony_ci  if (seekDoneTime == null) {
5691e41f4b71Sopenharmony_ci    console.error('Failed to seek');
5692e41f4b71Sopenharmony_ci    return;
5693e41f4b71Sopenharmony_ci  }
5694e41f4b71Sopenharmony_ci  console.info('Succeeded in seek, and seek time is ' + seekDoneTime);
5695e41f4b71Sopenharmony_ci  audioPlayer.setVolume(0.5);                // Set the volume to 50% and trigger the 'volumeChange' event callback.
5696e41f4b71Sopenharmony_ci});
5697e41f4b71Sopenharmony_ciaudioPlayer.on('volumeChange', () => {         // Set the 'volumeChange' event callback.
5698e41f4b71Sopenharmony_ci  console.info('audio volumeChange called');
5699e41f4b71Sopenharmony_ci  audioPlayer.pause();                       // Pause the playback and trigger the 'pause' event callback.
5700e41f4b71Sopenharmony_ci});
5701e41f4b71Sopenharmony_ciaudioPlayer.on('finish', () => {               // Set the 'finish' event callback.
5702e41f4b71Sopenharmony_ci  console.info('audio play finish');
5703e41f4b71Sopenharmony_ci  audioPlayer.stop();                        // Stop the playback and trigger the 'stop' event callback.
5704e41f4b71Sopenharmony_ci});
5705e41f4b71Sopenharmony_ciaudioPlayer.on('error', (error: BusinessError) => {  // Set the 'error' event callback.
5706e41f4b71Sopenharmony_ci  console.error(`audio error called, error: ${error}`);
5707e41f4b71Sopenharmony_ci});
5708e41f4b71Sopenharmony_ci
5709e41f4b71Sopenharmony_ci// Set the FD (local playback) of the audio file selected by the user.
5710e41f4b71Sopenharmony_cilet fdPath = 'fd://';
5711e41f4b71Sopenharmony_ci// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/accounts/account_0/appdata" command.
5712e41f4b71Sopenharmony_cilet path = '/data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
5713e41f4b71Sopenharmony_cifs.open(path).then((file) => {
5714e41f4b71Sopenharmony_ci  fdPath = fdPath + '' + file.fd;
5715e41f4b71Sopenharmony_ci  console.info('Succeeded in opening fd, fd is' + fdPath);
5716e41f4b71Sopenharmony_ci  audioPlayer.src = fdPath;  // Set the src attribute and trigger the 'dataLoad' event callback.
5717e41f4b71Sopenharmony_ci}, (err: BusinessError) => {
5718e41f4b71Sopenharmony_ci  console.error('Failed to open fd, err is' + err);
5719e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
5720e41f4b71Sopenharmony_ci  console.error('Failed to open fd, err is' + err);
5721e41f4b71Sopenharmony_ci});
5722e41f4b71Sopenharmony_ci```
5723e41f4b71Sopenharmony_ci
5724e41f4b71Sopenharmony_ci### on('timeUpdate')<sup>(deprecated)</sup>
5725e41f4b71Sopenharmony_ci
5726e41f4b71Sopenharmony_cion(type: 'timeUpdate', callback: Callback\<number>): void
5727e41f4b71Sopenharmony_ci
5728e41f4b71Sopenharmony_ciSubscribes to the **'timeUpdate'** event. This event is reported every second when the audio playback is in progress.
5729e41f4b71Sopenharmony_ci
5730e41f4b71Sopenharmony_ci> **NOTE**
5731e41f4b71Sopenharmony_ci>
5732e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVPlayer.on('timeUpdate')](#ontimeupdate9) instead.
5733e41f4b71Sopenharmony_ci
5734e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
5735e41f4b71Sopenharmony_ci
5736e41f4b71Sopenharmony_ci**Parameters**
5737e41f4b71Sopenharmony_ci
5738e41f4b71Sopenharmony_ci| Name  | Type             | Mandatory| Description                                                        |
5739e41f4b71Sopenharmony_ci| -------- | ----------------- | ---- | ------------------------------------------------------------ |
5740e41f4b71Sopenharmony_ci| type     | string            | Yes  | Event type, which is **'timeUpdate'** in this case.<br>The **'timeUpdate'** event is triggered when the audio playback starts after an audio playback timestamp update.|
5741e41f4b71Sopenharmony_ci| callback | Callback\<number> | Yes  | Callback invoked when the event is triggered. The input parameter is the updated timestamp.            |
5742e41f4b71Sopenharmony_ci
5743e41f4b71Sopenharmony_ci**Example**
5744e41f4b71Sopenharmony_ci
5745e41f4b71Sopenharmony_ci```ts
5746e41f4b71Sopenharmony_ciaudioPlayer.on('timeUpdate', (newTime: number) => {    // Set the 'timeUpdate' event callback.
5747e41f4b71Sopenharmony_ci  if (newTime == null) {
5748e41f4b71Sopenharmony_ci    console.error('Failed to do timeUpadate');
5749e41f4b71Sopenharmony_ci    return;
5750e41f4b71Sopenharmony_ci  }
5751e41f4b71Sopenharmony_ci  console.info('Succeeded in doing timeUpadate. seekDoneTime: ' + newTime);
5752e41f4b71Sopenharmony_ci});
5753e41f4b71Sopenharmony_ciaudioPlayer.play();    // The 'timeUpdate' event is triggered when the playback starts.
5754e41f4b71Sopenharmony_ci```
5755e41f4b71Sopenharmony_ci
5756e41f4b71Sopenharmony_ci### on('audioInterrupt')<sup>(deprecated)</sup>
5757e41f4b71Sopenharmony_ci
5758e41f4b71Sopenharmony_cion(type: 'audioInterrupt', callback: (info: audio.InterruptEvent) => void): void
5759e41f4b71Sopenharmony_ci
5760e41f4b71Sopenharmony_ciSubscribes to the audio interruption event. For details, see [audio.InterruptEvent](../apis-audio-kit/js-apis-audio.md#interruptevent9).
5761e41f4b71Sopenharmony_ci
5762e41f4b71Sopenharmony_ci> **NOTE**
5763e41f4b71Sopenharmony_ci>
5764e41f4b71Sopenharmony_ci> This API is supported in API version 9 and deprecated since API version 9. You are advised to use [AVPlayer.on('audioInterrupt')](#onaudiointerrupt9) instead.
5765e41f4b71Sopenharmony_ci
5766e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
5767e41f4b71Sopenharmony_ci
5768e41f4b71Sopenharmony_ci**Parameters**
5769e41f4b71Sopenharmony_ci
5770e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory| Description                                                    |
5771e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- |
5772e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type, which is **'audioInterrupt'** in this case.|
5773e41f4b71Sopenharmony_ci| callback | function  | Yes  | Callback invoked when the event is triggered.                              |
5774e41f4b71Sopenharmony_ci
5775e41f4b71Sopenharmony_ci**Example**
5776e41f4b71Sopenharmony_ci
5777e41f4b71Sopenharmony_ci```ts
5778e41f4b71Sopenharmony_ciimport { audio } from '@kit.AudioKit';
5779e41f4b71Sopenharmony_ci
5780e41f4b71Sopenharmony_ciaudioPlayer.on('audioInterrupt', (info: audio.InterruptEvent) => {
5781e41f4b71Sopenharmony_ci  console.info('audioInterrupt called,and InterruptEvent info is:' + info)
5782e41f4b71Sopenharmony_ci})
5783e41f4b71Sopenharmony_ci```
5784e41f4b71Sopenharmony_ci
5785e41f4b71Sopenharmony_ci### on('error')<sup>(deprecated)</sup>
5786e41f4b71Sopenharmony_ci
5787e41f4b71Sopenharmony_cion(type: 'error', callback: ErrorCallback): void
5788e41f4b71Sopenharmony_ci
5789e41f4b71Sopenharmony_ciSubscribes to audio playback error events. After an error event is reported, you must handle the event and exit the playback.
5790e41f4b71Sopenharmony_ci
5791e41f4b71Sopenharmony_ci> **NOTE**
5792e41f4b71Sopenharmony_ci>
5793e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVPlayer.on('error')](#onerror9) instead.
5794e41f4b71Sopenharmony_ci
5795e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
5796e41f4b71Sopenharmony_ci
5797e41f4b71Sopenharmony_ci**Parameters**
5798e41f4b71Sopenharmony_ci
5799e41f4b71Sopenharmony_ci| Name  | Type         | Mandatory| Description                                                        |
5800e41f4b71Sopenharmony_ci| -------- | ------------- | ---- | ------------------------------------------------------------ |
5801e41f4b71Sopenharmony_ci| type     | string        | Yes  | Event type, which is **'error'** in this case.<br>This event is triggered when an error occurs during audio playback.|
5802e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes  | Callback invoked when the event is triggered.                                      |
5803e41f4b71Sopenharmony_ci
5804e41f4b71Sopenharmony_ci**Example**
5805e41f4b71Sopenharmony_ci
5806e41f4b71Sopenharmony_ci```ts
5807e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5808e41f4b71Sopenharmony_ci
5809e41f4b71Sopenharmony_ciaudioPlayer.on('error', (error: BusinessError) => {  // Set the 'error' event callback.
5810e41f4b71Sopenharmony_ci  console.error(`audio error called, error: ${error}`);
5811e41f4b71Sopenharmony_ci});
5812e41f4b71Sopenharmony_ciaudioPlayer.setVolume(3); // Set volume to an invalid value to trigger the 'error' event.
5813e41f4b71Sopenharmony_ci```
5814e41f4b71Sopenharmony_ci
5815e41f4b71Sopenharmony_ci## AudioState<sup>(deprecated)</sup>
5816e41f4b71Sopenharmony_ci
5817e41f4b71Sopenharmony_citype AudioState = 'idle' | 'playing' | 'paused' | 'stopped' | 'error'
5818e41f4b71Sopenharmony_ci
5819e41f4b71Sopenharmony_ciEnumerates the audio playback states. You can obtain the state through the **state** attribute.
5820e41f4b71Sopenharmony_ci
5821e41f4b71Sopenharmony_ci> **NOTE**
5822e41f4b71Sopenharmony_ci>
5823e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVPlayerState](#avplayerstate9) instead.
5824e41f4b71Sopenharmony_ci
5825e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
5826e41f4b71Sopenharmony_ci
5827e41f4b71Sopenharmony_ci| Type   | Description                                          |
5828e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------- |
5829e41f4b71Sopenharmony_ci| 'idle'    | No audio playback is in progress. The audio player is in this state after the **'dataload'** or **'reset'** event is triggered.|
5830e41f4b71Sopenharmony_ci| 'playing' | Audio playback is in progress. The audio player is in this state after the **'play'** event is triggered.          |
5831e41f4b71Sopenharmony_ci| 'paused'  | Audio playback is paused. The audio player is in this state after the **'pause'** event is triggered.         |
5832e41f4b71Sopenharmony_ci| 'stopped' | Audio playback is stopped. The audio player is in this state after the **'stop'** event is triggered.     |
5833e41f4b71Sopenharmony_ci| 'error'   | Audio playback is in the error state.                                    |
5834e41f4b71Sopenharmony_ci
5835e41f4b71Sopenharmony_ci## VideoPlayer<sup>(deprecated)</sup>
5836e41f4b71Sopenharmony_ci
5837e41f4b71Sopenharmony_ci> **NOTE**
5838e41f4b71Sopenharmony_ci>
5839e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer](#avplayer9) instead.
5840e41f4b71Sopenharmony_ci
5841e41f4b71Sopenharmony_ciProvides APIs to manage and play video. Before calling any API of **VideoPlayer**, you must use [createVideoPlayer()](#mediacreatevideoplayerdeprecated) to create a **VideoPlayer** instance.
5842e41f4b71Sopenharmony_ci
5843e41f4b71Sopenharmony_ci### Attributes
5844e41f4b71Sopenharmony_ci
5845e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
5846e41f4b71Sopenharmony_ci
5847e41f4b71Sopenharmony_ci| Name                           | Type                                                  | Read-Only| Optional| Description                                                        |
5848e41f4b71Sopenharmony_ci| ------------------------------- | ------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
5849e41f4b71Sopenharmony_ci| url<sup>8+</sup>                | string                                                 | No  | No  | Video URL. The video formats MP4, MPEG-TS, and MKV are supported.<br>**Example of supported URLs**:<br>1. FD: fd://xx<br>![](figures/en-us_image_url.png)<br>2. HTTP: http\://xx<br>3. HTTPS: https\://xx<br>4. HLS: http\://xx or https\://xx<br>5. File type: file\://xx<br>**NOTE**<br>WebM is no longer supported since API version 11.|
5850e41f4b71Sopenharmony_ci| fdSrc<sup>9+</sup>              | [AVFileDescriptor](#avfiledescriptor9)                 | No  | No  | Description of a video file. This attribute is required when video assets of an application are continuously stored in a file.<br>**Example:**<br>Assume that a music file that stores continuous music assets consists of the following:<br>Video 1 (address offset: 0, byte length: 100)<br>Video 2 (address offset: 101; byte length: 50)<br>Video 3 (address offset: 151, byte length: 150)<br>1. To play video 1: AVFileDescriptor {fd = resource handle; offset = 0; length = 100; }<br>2. To play video 2: AVFileDescriptor {fd = resource handle; offset = 101; length = 50; }<br>3. To play video 3: AVFileDescriptor {fd = resource handle; offset = 151; length = 150; }<br>To play an independent video file, use **src=fd://xx**.<br>|
5851e41f4b71Sopenharmony_ci| loop<sup>8+</sup>               | boolean                                                | No  | No  | Whether to loop video playback. The value **true** means to loop video playback, and **false** means the opposite.                |
5852e41f4b71Sopenharmony_ci| videoScaleType<sup>9+</sup>     | [VideoScaleType](#videoscaletype9)                     | No  | Yes  | Video scale type. The default value is **VIDEO_SCALE_TYPE_FIT**.                                              |
5853e41f4b71Sopenharmony_ci| audioInterruptMode<sup>9+</sup> | [audio.InterruptMode](../apis-audio-kit/js-apis-audio.md#interruptmode9) | No  | Yes  | Audio interruption mode.                                              |
5854e41f4b71Sopenharmony_ci| currentTime<sup>8+</sup>        | number                                                 | Yes  | No  | Current video playback position, in ms.                      |
5855e41f4b71Sopenharmony_ci| duration<sup>8+</sup>           | number                                                 | Yes  | No  | Video duration, in ms. The value **-1** indicates the live mode.            |
5856e41f4b71Sopenharmony_ci| state<sup>8+</sup>              | [VideoPlayState](#videoplaystatedeprecated)                    | Yes  | No  | Video playback state.                                            |
5857e41f4b71Sopenharmony_ci| width<sup>8+</sup>              | number                                                 | Yes  | No  | Video width, in px.                                  |
5858e41f4b71Sopenharmony_ci| height<sup>8+</sup>             | number                                                 | Yes  | No  | Video height, in px.                                  |
5859e41f4b71Sopenharmony_ci
5860e41f4b71Sopenharmony_ci### setDisplaySurface<sup>(deprecated)</sup>
5861e41f4b71Sopenharmony_ci
5862e41f4b71Sopenharmony_cisetDisplaySurface(surfaceId: string, callback: AsyncCallback\<void>): void
5863e41f4b71Sopenharmony_ci
5864e41f4b71Sopenharmony_ciSets a surface ID. This API uses an asynchronous callback to return the result.
5865e41f4b71Sopenharmony_ci
5866e41f4b71Sopenharmony_ci*Note: **SetDisplaySurface** must be called between the URL setting and the calling of **prepare**. A surface must be set for video streams without audio. Otherwise, the calling of **prepare** fails.
5867e41f4b71Sopenharmony_ci
5868e41f4b71Sopenharmony_ci> **NOTE**
5869e41f4b71Sopenharmony_ci>
5870e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.surfaceId](#attributes) instead.
5871e41f4b71Sopenharmony_ci
5872e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
5873e41f4b71Sopenharmony_ci
5874e41f4b71Sopenharmony_ci**Parameters**
5875e41f4b71Sopenharmony_ci
5876e41f4b71Sopenharmony_ci| Name   | Type                | Mandatory| Description                     |
5877e41f4b71Sopenharmony_ci| --------- | -------------------- | ---- | ------------------------- |
5878e41f4b71Sopenharmony_ci| surfaceId | string               | Yes  | Surface ID to set.                |
5879e41f4b71Sopenharmony_ci| callback  | AsyncCallback\<void> | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
5880e41f4b71Sopenharmony_ci
5881e41f4b71Sopenharmony_ci**Example**
5882e41f4b71Sopenharmony_ci
5883e41f4b71Sopenharmony_ci```ts
5884e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5885e41f4b71Sopenharmony_ci
5886e41f4b71Sopenharmony_cilet surfaceId: string = '';
5887e41f4b71Sopenharmony_civideoPlayer.setDisplaySurface(surfaceId, (err: BusinessError) => {
5888e41f4b71Sopenharmony_ci  if (err) {
5889e41f4b71Sopenharmony_ci    console.error('Failed to set DisplaySurface!');
5890e41f4b71Sopenharmony_ci  } else {
5891e41f4b71Sopenharmony_ci    console.info('Succeeded in setting DisplaySurface!');
5892e41f4b71Sopenharmony_ci  }
5893e41f4b71Sopenharmony_ci});
5894e41f4b71Sopenharmony_ci```
5895e41f4b71Sopenharmony_ci
5896e41f4b71Sopenharmony_ci### setDisplaySurface<sup>(deprecated)</sup>
5897e41f4b71Sopenharmony_ci
5898e41f4b71Sopenharmony_cisetDisplaySurface(surfaceId: string): Promise\<void>
5899e41f4b71Sopenharmony_ci
5900e41f4b71Sopenharmony_ciSets a surface ID. This API uses a promise to return the result.
5901e41f4b71Sopenharmony_ci
5902e41f4b71Sopenharmony_ci*Note: **SetDisplaySurface** must be called between the URL setting and the calling of **prepare**. A surface must be set for video streams without audio. Otherwise, the calling of **prepare** fails.
5903e41f4b71Sopenharmony_ci
5904e41f4b71Sopenharmony_ci> **NOTE**
5905e41f4b71Sopenharmony_ci>
5906e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.surfaceId](#attributes) instead.
5907e41f4b71Sopenharmony_ci
5908e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
5909e41f4b71Sopenharmony_ci
5910e41f4b71Sopenharmony_ci**Parameters**
5911e41f4b71Sopenharmony_ci
5912e41f4b71Sopenharmony_ci| Name   | Type  | Mandatory| Description     |
5913e41f4b71Sopenharmony_ci| --------- | ------ | ---- | --------- |
5914e41f4b71Sopenharmony_ci| surfaceId | string | Yes  | Surface ID to set.|
5915e41f4b71Sopenharmony_ci
5916e41f4b71Sopenharmony_ci**Return value**
5917e41f4b71Sopenharmony_ci
5918e41f4b71Sopenharmony_ci| Type          | Description                          |
5919e41f4b71Sopenharmony_ci| -------------- | ------------------------------ |
5920e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
5921e41f4b71Sopenharmony_ci
5922e41f4b71Sopenharmony_ci**Example**
5923e41f4b71Sopenharmony_ci
5924e41f4b71Sopenharmony_ci```ts
5925e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5926e41f4b71Sopenharmony_ci
5927e41f4b71Sopenharmony_cilet surfaceId: string = '';
5928e41f4b71Sopenharmony_civideoPlayer.setDisplaySurface(surfaceId).then(() => {
5929e41f4b71Sopenharmony_ci  console.info('Succeeded in setting DisplaySurface');
5930e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
5931e41f4b71Sopenharmony_ci  console.error(`video catchCallback, error:${error}`);
5932e41f4b71Sopenharmony_ci});
5933e41f4b71Sopenharmony_ci```
5934e41f4b71Sopenharmony_ci
5935e41f4b71Sopenharmony_ci### prepare<sup>(deprecated)</sup>
5936e41f4b71Sopenharmony_ci
5937e41f4b71Sopenharmony_ciprepare(callback: AsyncCallback\<void>): void
5938e41f4b71Sopenharmony_ci
5939e41f4b71Sopenharmony_ciPrepares for video playback. This API uses an asynchronous callback to return the result.
5940e41f4b71Sopenharmony_ci
5941e41f4b71Sopenharmony_ci> **NOTE**
5942e41f4b71Sopenharmony_ci>
5943e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.prepare](#prepare9) instead.
5944e41f4b71Sopenharmony_ci
5945e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
5946e41f4b71Sopenharmony_ci
5947e41f4b71Sopenharmony_ci**Parameters**
5948e41f4b71Sopenharmony_ci
5949e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                    |
5950e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------ |
5951e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
5952e41f4b71Sopenharmony_ci
5953e41f4b71Sopenharmony_ci**Example**
5954e41f4b71Sopenharmony_ci
5955e41f4b71Sopenharmony_ci```ts
5956e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5957e41f4b71Sopenharmony_ci
5958e41f4b71Sopenharmony_civideoPlayer.prepare((err: BusinessError) => {
5959e41f4b71Sopenharmony_ci  if (err) {
5960e41f4b71Sopenharmony_ci    console.error('Failed to prepare!');
5961e41f4b71Sopenharmony_ci  } else {
5962e41f4b71Sopenharmony_ci    console.info('Succeeded in preparing!');
5963e41f4b71Sopenharmony_ci  }
5964e41f4b71Sopenharmony_ci});
5965e41f4b71Sopenharmony_ci```
5966e41f4b71Sopenharmony_ci
5967e41f4b71Sopenharmony_ci### prepare<sup>(deprecated)</sup>
5968e41f4b71Sopenharmony_ci
5969e41f4b71Sopenharmony_ciprepare(): Promise\<void>
5970e41f4b71Sopenharmony_ci
5971e41f4b71Sopenharmony_ciPrepares for video playback. This API uses a promise to return the result.
5972e41f4b71Sopenharmony_ci
5973e41f4b71Sopenharmony_ci> **NOTE**
5974e41f4b71Sopenharmony_ci>
5975e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.prepare](#prepare9-1) instead.
5976e41f4b71Sopenharmony_ci
5977e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
5978e41f4b71Sopenharmony_ci
5979e41f4b71Sopenharmony_ci**Return value**
5980e41f4b71Sopenharmony_ci
5981e41f4b71Sopenharmony_ci| Type          | Description                         |
5982e41f4b71Sopenharmony_ci| -------------- | ----------------------------- |
5983e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
5984e41f4b71Sopenharmony_ci
5985e41f4b71Sopenharmony_ci**Example**
5986e41f4b71Sopenharmony_ci
5987e41f4b71Sopenharmony_ci```ts
5988e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5989e41f4b71Sopenharmony_ci
5990e41f4b71Sopenharmony_civideoPlayer.prepare().then(() => {
5991e41f4b71Sopenharmony_ci  console.info('Succeeded in preparing');
5992e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
5993e41f4b71Sopenharmony_ci  console.error(`video catchCallback, error:${error}`);
5994e41f4b71Sopenharmony_ci});
5995e41f4b71Sopenharmony_ci```
5996e41f4b71Sopenharmony_ci
5997e41f4b71Sopenharmony_ci### play<sup>(deprecated)</sup>
5998e41f4b71Sopenharmony_ci
5999e41f4b71Sopenharmony_ciplay(callback: AsyncCallback\<void>): void
6000e41f4b71Sopenharmony_ci
6001e41f4b71Sopenharmony_ciStarts video playback. This API uses an asynchronous callback to return the result.
6002e41f4b71Sopenharmony_ci
6003e41f4b71Sopenharmony_ci> **NOTE**
6004e41f4b71Sopenharmony_ci>
6005e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.play](#play9) instead.
6006e41f4b71Sopenharmony_ci
6007e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6008e41f4b71Sopenharmony_ci
6009e41f4b71Sopenharmony_ci**Parameters**
6010e41f4b71Sopenharmony_ci
6011e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                    |
6012e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------ |
6013e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
6014e41f4b71Sopenharmony_ci
6015e41f4b71Sopenharmony_ci**Example**
6016e41f4b71Sopenharmony_ci
6017e41f4b71Sopenharmony_ci```ts
6018e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6019e41f4b71Sopenharmony_ci
6020e41f4b71Sopenharmony_civideoPlayer.play((err: BusinessError) => {
6021e41f4b71Sopenharmony_ci  if (err) {
6022e41f4b71Sopenharmony_ci    console.error('Failed to play!');
6023e41f4b71Sopenharmony_ci  } else {
6024e41f4b71Sopenharmony_ci    console.info('Succeeded in playing!');
6025e41f4b71Sopenharmony_ci  }
6026e41f4b71Sopenharmony_ci});
6027e41f4b71Sopenharmony_ci```
6028e41f4b71Sopenharmony_ci
6029e41f4b71Sopenharmony_ci### play<sup>(deprecated)</sup>
6030e41f4b71Sopenharmony_ci
6031e41f4b71Sopenharmony_ciplay(): Promise\<void>
6032e41f4b71Sopenharmony_ci
6033e41f4b71Sopenharmony_ciStarts video playback. This API uses a promise to return the result.
6034e41f4b71Sopenharmony_ci
6035e41f4b71Sopenharmony_ci> **NOTE**
6036e41f4b71Sopenharmony_ci>
6037e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.play](#play9-1) instead.
6038e41f4b71Sopenharmony_ci
6039e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6040e41f4b71Sopenharmony_ci
6041e41f4b71Sopenharmony_ci**Return value**
6042e41f4b71Sopenharmony_ci
6043e41f4b71Sopenharmony_ci| Type          | Description                         |
6044e41f4b71Sopenharmony_ci| -------------- | ----------------------------- |
6045e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
6046e41f4b71Sopenharmony_ci
6047e41f4b71Sopenharmony_ci**Example**
6048e41f4b71Sopenharmony_ci
6049e41f4b71Sopenharmony_ci```ts
6050e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6051e41f4b71Sopenharmony_ci
6052e41f4b71Sopenharmony_civideoPlayer.play().then(() => {
6053e41f4b71Sopenharmony_ci  console.info('Succeeded in playing');
6054e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
6055e41f4b71Sopenharmony_ci  console.error(`video catchCallback, error:${error}`);
6056e41f4b71Sopenharmony_ci});
6057e41f4b71Sopenharmony_ci```
6058e41f4b71Sopenharmony_ci
6059e41f4b71Sopenharmony_ci### pause<sup>(deprecated)</sup>
6060e41f4b71Sopenharmony_ci
6061e41f4b71Sopenharmony_cipause(callback: AsyncCallback\<void>): void
6062e41f4b71Sopenharmony_ci
6063e41f4b71Sopenharmony_ciPauses video playback. This API uses an asynchronous callback to return the result.
6064e41f4b71Sopenharmony_ci
6065e41f4b71Sopenharmony_ci> **NOTE**
6066e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.pause](#pause9) instead.
6067e41f4b71Sopenharmony_ci
6068e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6069e41f4b71Sopenharmony_ci
6070e41f4b71Sopenharmony_ci**Parameters**
6071e41f4b71Sopenharmony_ci
6072e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                    |
6073e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------ |
6074e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
6075e41f4b71Sopenharmony_ci
6076e41f4b71Sopenharmony_ci**Example**
6077e41f4b71Sopenharmony_ci
6078e41f4b71Sopenharmony_ci```ts
6079e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6080e41f4b71Sopenharmony_ci
6081e41f4b71Sopenharmony_civideoPlayer.pause((err: BusinessError) => {
6082e41f4b71Sopenharmony_ci  if (err) {
6083e41f4b71Sopenharmony_ci    console.error('Failed to pause!');
6084e41f4b71Sopenharmony_ci  } else {
6085e41f4b71Sopenharmony_ci    console.info('Succeeded in pausing!');
6086e41f4b71Sopenharmony_ci  }
6087e41f4b71Sopenharmony_ci});
6088e41f4b71Sopenharmony_ci```
6089e41f4b71Sopenharmony_ci
6090e41f4b71Sopenharmony_ci### pause<sup>(deprecated)</sup>
6091e41f4b71Sopenharmony_ci
6092e41f4b71Sopenharmony_cipause(): Promise\<void>
6093e41f4b71Sopenharmony_ci
6094e41f4b71Sopenharmony_ciPauses video playback. This API uses a promise to return the result.
6095e41f4b71Sopenharmony_ci
6096e41f4b71Sopenharmony_ci> **NOTE**
6097e41f4b71Sopenharmony_ci>
6098e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.pause](#pause9-1) instead.
6099e41f4b71Sopenharmony_ci
6100e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6101e41f4b71Sopenharmony_ci
6102e41f4b71Sopenharmony_ci**Return value**
6103e41f4b71Sopenharmony_ci
6104e41f4b71Sopenharmony_ci| Type          | Description                         |
6105e41f4b71Sopenharmony_ci| -------------- | ----------------------------- |
6106e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
6107e41f4b71Sopenharmony_ci
6108e41f4b71Sopenharmony_ci**Example**
6109e41f4b71Sopenharmony_ci
6110e41f4b71Sopenharmony_ci```ts
6111e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6112e41f4b71Sopenharmony_ci
6113e41f4b71Sopenharmony_civideoPlayer.pause().then(() => {
6114e41f4b71Sopenharmony_ci  console.info('Succeeded in pausing');
6115e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
6116e41f4b71Sopenharmony_ci  console.error(`video catchCallback, error:${error}`);
6117e41f4b71Sopenharmony_ci});
6118e41f4b71Sopenharmony_ci```
6119e41f4b71Sopenharmony_ci
6120e41f4b71Sopenharmony_ci### stop<sup>(deprecated)</sup>
6121e41f4b71Sopenharmony_ci
6122e41f4b71Sopenharmony_cistop(callback: AsyncCallback\<void>): void
6123e41f4b71Sopenharmony_ci
6124e41f4b71Sopenharmony_ciStops video playback. This API uses an asynchronous callback to return the result.
6125e41f4b71Sopenharmony_ci
6126e41f4b71Sopenharmony_ci> **NOTE**
6127e41f4b71Sopenharmony_ci>
6128e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.stop](#stop9) instead.
6129e41f4b71Sopenharmony_ci
6130e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6131e41f4b71Sopenharmony_ci
6132e41f4b71Sopenharmony_ci**Parameters**
6133e41f4b71Sopenharmony_ci
6134e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                    |
6135e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------ |
6136e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
6137e41f4b71Sopenharmony_ci
6138e41f4b71Sopenharmony_ci**Example**
6139e41f4b71Sopenharmony_ci
6140e41f4b71Sopenharmony_ci```ts
6141e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6142e41f4b71Sopenharmony_ci
6143e41f4b71Sopenharmony_civideoPlayer.stop((err: BusinessError) => {
6144e41f4b71Sopenharmony_ci  if (err) {
6145e41f4b71Sopenharmony_ci    console.error('Failed to stop!');
6146e41f4b71Sopenharmony_ci  } else {
6147e41f4b71Sopenharmony_ci    console.info('Succeeded in stopping!');
6148e41f4b71Sopenharmony_ci  }
6149e41f4b71Sopenharmony_ci});
6150e41f4b71Sopenharmony_ci```
6151e41f4b71Sopenharmony_ci
6152e41f4b71Sopenharmony_ci### stop<sup>(deprecated)</sup>
6153e41f4b71Sopenharmony_ci
6154e41f4b71Sopenharmony_cistop(): Promise\<void>
6155e41f4b71Sopenharmony_ci
6156e41f4b71Sopenharmony_ciStops video playback. This API uses a promise to return the result.
6157e41f4b71Sopenharmony_ci
6158e41f4b71Sopenharmony_ci> **NOTE**
6159e41f4b71Sopenharmony_ci>
6160e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.stop](#stop9-1) instead.
6161e41f4b71Sopenharmony_ci
6162e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6163e41f4b71Sopenharmony_ci
6164e41f4b71Sopenharmony_ci**Return value**
6165e41f4b71Sopenharmony_ci
6166e41f4b71Sopenharmony_ci| Type          | Description                         |
6167e41f4b71Sopenharmony_ci| -------------- | ----------------------------- |
6168e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
6169e41f4b71Sopenharmony_ci
6170e41f4b71Sopenharmony_ci**Example**
6171e41f4b71Sopenharmony_ci
6172e41f4b71Sopenharmony_ci```ts
6173e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6174e41f4b71Sopenharmony_ci
6175e41f4b71Sopenharmony_civideoPlayer.stop().then(() => {
6176e41f4b71Sopenharmony_ci  console.info('Succeeded in stopping');
6177e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
6178e41f4b71Sopenharmony_ci  console.error(`video catchCallback, error:${error}`);
6179e41f4b71Sopenharmony_ci});
6180e41f4b71Sopenharmony_ci```
6181e41f4b71Sopenharmony_ci
6182e41f4b71Sopenharmony_ci### reset<sup>(deprecated)</sup>
6183e41f4b71Sopenharmony_ci
6184e41f4b71Sopenharmony_cireset(callback: AsyncCallback\<void>): void
6185e41f4b71Sopenharmony_ci
6186e41f4b71Sopenharmony_ciResets video playback. This API uses an asynchronous callback to return the result.
6187e41f4b71Sopenharmony_ci
6188e41f4b71Sopenharmony_ci> **NOTE**
6189e41f4b71Sopenharmony_ci>
6190e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.reset](#reset9) instead.
6191e41f4b71Sopenharmony_ci
6192e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6193e41f4b71Sopenharmony_ci
6194e41f4b71Sopenharmony_ci**Parameters**
6195e41f4b71Sopenharmony_ci
6196e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                    |
6197e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------ |
6198e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
6199e41f4b71Sopenharmony_ci
6200e41f4b71Sopenharmony_ci**Example**
6201e41f4b71Sopenharmony_ci
6202e41f4b71Sopenharmony_ci```ts
6203e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6204e41f4b71Sopenharmony_ci
6205e41f4b71Sopenharmony_civideoPlayer.reset((err: BusinessError) => {
6206e41f4b71Sopenharmony_ci  if (err) {
6207e41f4b71Sopenharmony_ci    console.error('Failed to reset!');
6208e41f4b71Sopenharmony_ci  } else {
6209e41f4b71Sopenharmony_ci    console.info('Succeeded in resetting!');
6210e41f4b71Sopenharmony_ci  }
6211e41f4b71Sopenharmony_ci});
6212e41f4b71Sopenharmony_ci```
6213e41f4b71Sopenharmony_ci
6214e41f4b71Sopenharmony_ci### reset<sup>(deprecated)</sup>
6215e41f4b71Sopenharmony_ci
6216e41f4b71Sopenharmony_cireset(): Promise\<void>
6217e41f4b71Sopenharmony_ci
6218e41f4b71Sopenharmony_ciResets video playback. This API uses a promise to return the result.
6219e41f4b71Sopenharmony_ci
6220e41f4b71Sopenharmony_ci> **NOTE**
6221e41f4b71Sopenharmony_ci>
6222e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.reset](#reset9-1) instead.
6223e41f4b71Sopenharmony_ci
6224e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6225e41f4b71Sopenharmony_ci
6226e41f4b71Sopenharmony_ci**Return value**
6227e41f4b71Sopenharmony_ci
6228e41f4b71Sopenharmony_ci| Type          | Description                         |
6229e41f4b71Sopenharmony_ci| -------------- | ----------------------------- |
6230e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
6231e41f4b71Sopenharmony_ci
6232e41f4b71Sopenharmony_ci**Example**
6233e41f4b71Sopenharmony_ci
6234e41f4b71Sopenharmony_ci```ts
6235e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6236e41f4b71Sopenharmony_ci
6237e41f4b71Sopenharmony_civideoPlayer.reset().then(() => {
6238e41f4b71Sopenharmony_ci  console.info('Succeeded in resetting');
6239e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
6240e41f4b71Sopenharmony_ci  console.error(`video catchCallback, error:${error}`);
6241e41f4b71Sopenharmony_ci});
6242e41f4b71Sopenharmony_ci```
6243e41f4b71Sopenharmony_ci
6244e41f4b71Sopenharmony_ci### seek<sup>(deprecated)</sup>
6245e41f4b71Sopenharmony_ci
6246e41f4b71Sopenharmony_ciseek(timeMs: number, callback: AsyncCallback\<number>): void
6247e41f4b71Sopenharmony_ci
6248e41f4b71Sopenharmony_ciSeeks to the specified playback position. The previous key frame at the specified position is played. This API uses an asynchronous callback to return the result.
6249e41f4b71Sopenharmony_ci
6250e41f4b71Sopenharmony_ci> **NOTE**
6251e41f4b71Sopenharmony_ci>
6252e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.seek](#seek9) instead.
6253e41f4b71Sopenharmony_ci
6254e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6255e41f4b71Sopenharmony_ci
6256e41f4b71Sopenharmony_ci**Parameters**
6257e41f4b71Sopenharmony_ci
6258e41f4b71Sopenharmony_ci| Name  | Type                  | Mandatory| Description                                                        |
6259e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
6260e41f4b71Sopenharmony_ci| timeMs   | number                 | Yes  | Position to seek to, in ms. The value range is [0, duration].|
6261e41f4b71Sopenharmony_ci| callback | AsyncCallback\<number> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the new playback position; otherwise, **err** is an error object.                              |
6262e41f4b71Sopenharmony_ci
6263e41f4b71Sopenharmony_ci**Example**
6264e41f4b71Sopenharmony_ci
6265e41f4b71Sopenharmony_ci```ts
6266e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6267e41f4b71Sopenharmony_ci
6268e41f4b71Sopenharmony_cilet videoPlayer: media.VideoPlayer;
6269e41f4b71Sopenharmony_cimedia.createVideoPlayer((error: BusinessError, video: media.VideoPlayer) => {
6270e41f4b71Sopenharmony_ci  if (video != null) {
6271e41f4b71Sopenharmony_ci    videoPlayer = video;
6272e41f4b71Sopenharmony_ci    console.info('Succeeded in creating VideoPlayer');
6273e41f4b71Sopenharmony_ci  } else {
6274e41f4b71Sopenharmony_ci    console.error(`Failed to create VideoPlayer, error:${error}`);
6275e41f4b71Sopenharmony_ci  }
6276e41f4b71Sopenharmony_ci});
6277e41f4b71Sopenharmony_ci
6278e41f4b71Sopenharmony_cilet seekTime: number = 5000;
6279e41f4b71Sopenharmony_civideoPlayer.seek(seekTime, (err: BusinessError, result: number) => {
6280e41f4b71Sopenharmony_ci  if (err) {
6281e41f4b71Sopenharmony_ci    console.error('Failed to do seek!');
6282e41f4b71Sopenharmony_ci  } else {
6283e41f4b71Sopenharmony_ci    console.info('Succeeded in doing seek!');
6284e41f4b71Sopenharmony_ci  }
6285e41f4b71Sopenharmony_ci});
6286e41f4b71Sopenharmony_ci```
6287e41f4b71Sopenharmony_ci
6288e41f4b71Sopenharmony_ci### seek<sup>(deprecated)</sup>
6289e41f4b71Sopenharmony_ci
6290e41f4b71Sopenharmony_ciseek(timeMs: number, mode:SeekMode, callback: AsyncCallback\<number>): void
6291e41f4b71Sopenharmony_ci
6292e41f4b71Sopenharmony_ciSeeks to the specified playback position. This API uses an asynchronous callback to return the result.
6293e41f4b71Sopenharmony_ci
6294e41f4b71Sopenharmony_ci> **NOTE**
6295e41f4b71Sopenharmony_ci>
6296e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.seek](#seek9) instead.
6297e41f4b71Sopenharmony_ci
6298e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6299e41f4b71Sopenharmony_ci
6300e41f4b71Sopenharmony_ci**Parameters**
6301e41f4b71Sopenharmony_ci
6302e41f4b71Sopenharmony_ci| Name  | Type                  | Mandatory| Description                                                        |
6303e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
6304e41f4b71Sopenharmony_ci| timeMs   | number                 | Yes  | Position to seek to, in ms. The value range is [0, duration].|
6305e41f4b71Sopenharmony_ci| mode     | [SeekMode](#seekmode8) | Yes  | Seek mode.                                                  |
6306e41f4b71Sopenharmony_ci| callback | AsyncCallback\<number> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the new playback position; otherwise, **err** is an error object.                              |
6307e41f4b71Sopenharmony_ci
6308e41f4b71Sopenharmony_ci**Example**
6309e41f4b71Sopenharmony_ci
6310e41f4b71Sopenharmony_ci```ts
6311e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6312e41f4b71Sopenharmony_ci
6313e41f4b71Sopenharmony_cilet videoPlayer: media.VideoPlayer | null = null;
6314e41f4b71Sopenharmony_cimedia.createVideoPlayer((error: BusinessError, video: media.VideoPlayer) => {
6315e41f4b71Sopenharmony_ci  if (video != null) {
6316e41f4b71Sopenharmony_ci    videoPlayer = video;
6317e41f4b71Sopenharmony_ci    console.info('Succeeded in creating VideoPlayer');
6318e41f4b71Sopenharmony_ci  } else {
6319e41f4b71Sopenharmony_ci    console.error(`Failed to create VideoPlayer, error:${error}`);
6320e41f4b71Sopenharmony_ci  }
6321e41f4b71Sopenharmony_ci});
6322e41f4b71Sopenharmony_cilet seekTime: number = 5000;
6323e41f4b71Sopenharmony_ciif (videoPlayer) {
6324e41f4b71Sopenharmony_ci  (videoPlayer as media.VideoPlayer).seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC, (err: BusinessError, result: number) => {
6325e41f4b71Sopenharmony_ci    if (err) {
6326e41f4b71Sopenharmony_ci      console.error('Failed to do seek!');
6327e41f4b71Sopenharmony_ci    } else {
6328e41f4b71Sopenharmony_ci      console.info('Succeeded in doing seek!');
6329e41f4b71Sopenharmony_ci    }
6330e41f4b71Sopenharmony_ci  });
6331e41f4b71Sopenharmony_ci}
6332e41f4b71Sopenharmony_ci```
6333e41f4b71Sopenharmony_ci
6334e41f4b71Sopenharmony_ci### seek<sup>(deprecated)</sup>
6335e41f4b71Sopenharmony_ci
6336e41f4b71Sopenharmony_ciseek(timeMs: number, mode?:SeekMode): Promise\<number>
6337e41f4b71Sopenharmony_ci
6338e41f4b71Sopenharmony_ciSeeks to the specified playback position. If **mode** is not specified, the previous key frame at the specified position is played. This API uses a promise to return the result.
6339e41f4b71Sopenharmony_ci
6340e41f4b71Sopenharmony_ci> **NOTE**
6341e41f4b71Sopenharmony_ci>
6342e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.seek](#seek9) instead.
6343e41f4b71Sopenharmony_ci
6344e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6345e41f4b71Sopenharmony_ci
6346e41f4b71Sopenharmony_ci**Parameters**
6347e41f4b71Sopenharmony_ci
6348e41f4b71Sopenharmony_ci| Name| Type                  | Mandatory| Description                                                        |
6349e41f4b71Sopenharmony_ci| ------ | ---------------------- | ---- | ------------------------------------------------------------ |
6350e41f4b71Sopenharmony_ci| timeMs | number                 | Yes  | Position to seek to, in ms. The value range is [0, duration].|
6351e41f4b71Sopenharmony_ci| mode   | [SeekMode](#seekmode8) | No  | Seek mode based on the video I frame. The default value is **SEEK_PREV_SYNC**.           |
6352e41f4b71Sopenharmony_ci
6353e41f4b71Sopenharmony_ci**Return value**
6354e41f4b71Sopenharmony_ci
6355e41f4b71Sopenharmony_ci| Type            | Description                                       |
6356e41f4b71Sopenharmony_ci| ---------------- | ------------------------------------------- |
6357e41f4b71Sopenharmony_ci| Promise\<number>| Promise used to return the playback position, in ms.|
6358e41f4b71Sopenharmony_ci
6359e41f4b71Sopenharmony_ci**Example**
6360e41f4b71Sopenharmony_ci
6361e41f4b71Sopenharmony_ci```ts
6362e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6363e41f4b71Sopenharmony_ci
6364e41f4b71Sopenharmony_cilet videoPlayer: media.VideoPlayer | null = null;
6365e41f4b71Sopenharmony_cimedia.createVideoPlayer((error: BusinessError, video: media.VideoPlayer) => {
6366e41f4b71Sopenharmony_ci  if (video != null) {
6367e41f4b71Sopenharmony_ci    videoPlayer = video;
6368e41f4b71Sopenharmony_ci    console.info('Succeeded in creating VideoPlayer');
6369e41f4b71Sopenharmony_ci  } else {
6370e41f4b71Sopenharmony_ci    console.error(`Failed to create VideoPlayer, error:${error}`);
6371e41f4b71Sopenharmony_ci  }
6372e41f4b71Sopenharmony_ci});
6373e41f4b71Sopenharmony_cilet seekTime: number = 5000;
6374e41f4b71Sopenharmony_ciif (videoPlayer) {
6375e41f4b71Sopenharmony_ci  (videoPlayer as media.VideoPlayer).seek(seekTime).then((seekDoneTime: number) => { // seekDoneTime indicates the position after the seek operation is complete.
6376e41f4b71Sopenharmony_ci    console.info('Succeeded in doing seek');
6377e41f4b71Sopenharmony_ci  }).catch((error: BusinessError) => {
6378e41f4b71Sopenharmony_ci    console.error(`video catchCallback, error:${error}`);
6379e41f4b71Sopenharmony_ci  });
6380e41f4b71Sopenharmony_ci
6381e41f4b71Sopenharmony_ci  (videoPlayer as media.VideoPlayer).seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC).then((seekDoneTime: number) => {
6382e41f4b71Sopenharmony_ci    console.info('Succeeded in doing seek');
6383e41f4b71Sopenharmony_ci  }).catch((error: BusinessError) => {
6384e41f4b71Sopenharmony_ci    console.error(`video catchCallback, error:${error}`);
6385e41f4b71Sopenharmony_ci  });
6386e41f4b71Sopenharmony_ci}
6387e41f4b71Sopenharmony_ci```
6388e41f4b71Sopenharmony_ci
6389e41f4b71Sopenharmony_ci### setVolume<sup>(deprecated)</sup>
6390e41f4b71Sopenharmony_ci
6391e41f4b71Sopenharmony_cisetVolume(vol: number, callback: AsyncCallback\<void>): void
6392e41f4b71Sopenharmony_ci
6393e41f4b71Sopenharmony_ciSets the volume. This API uses an asynchronous callback to return the result.
6394e41f4b71Sopenharmony_ci
6395e41f4b71Sopenharmony_ci> **NOTE**
6396e41f4b71Sopenharmony_ci>
6397e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.setVolume](#setvolume9) instead.
6398e41f4b71Sopenharmony_ci
6399e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6400e41f4b71Sopenharmony_ci
6401e41f4b71Sopenharmony_ci**Parameters**
6402e41f4b71Sopenharmony_ci
6403e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                                                        |
6404e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------------------------------------ |
6405e41f4b71Sopenharmony_ci| vol      | number               | Yes  | Relative volume. The value ranges from 0.00 to 1.00. The value **1.00** indicates the maximum volume (100%).|
6406e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
6407e41f4b71Sopenharmony_ci
6408e41f4b71Sopenharmony_ci**Example**
6409e41f4b71Sopenharmony_ci
6410e41f4b71Sopenharmony_ci```ts
6411e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6412e41f4b71Sopenharmony_ci
6413e41f4b71Sopenharmony_cilet vol: number = 0.5;
6414e41f4b71Sopenharmony_civideoPlayer.setVolume(vol, (err: BusinessError) => {
6415e41f4b71Sopenharmony_ci  if (err) {
6416e41f4b71Sopenharmony_ci    console.error('Failed to set Volume!');
6417e41f4b71Sopenharmony_ci  } else {
6418e41f4b71Sopenharmony_ci    console.info('Succeeded in setting Volume!');
6419e41f4b71Sopenharmony_ci  }
6420e41f4b71Sopenharmony_ci});
6421e41f4b71Sopenharmony_ci```
6422e41f4b71Sopenharmony_ci
6423e41f4b71Sopenharmony_ci### setVolume<sup>(deprecated)</sup>
6424e41f4b71Sopenharmony_ci
6425e41f4b71Sopenharmony_cisetVolume(vol: number): Promise\<void>
6426e41f4b71Sopenharmony_ci
6427e41f4b71Sopenharmony_ciSets the volume. This API uses a promise to return the result.
6428e41f4b71Sopenharmony_ci
6429e41f4b71Sopenharmony_ci> **NOTE**
6430e41f4b71Sopenharmony_ci>
6431e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.setVolume](#setvolume9) instead.
6432e41f4b71Sopenharmony_ci
6433e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6434e41f4b71Sopenharmony_ci
6435e41f4b71Sopenharmony_ci**Parameters**
6436e41f4b71Sopenharmony_ci
6437e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                        |
6438e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
6439e41f4b71Sopenharmony_ci| vol    | number | Yes  | Relative volume. The value ranges from 0.00 to 1.00. The value **1.00** indicates the maximum volume (100%).|
6440e41f4b71Sopenharmony_ci
6441e41f4b71Sopenharmony_ci**Return value**
6442e41f4b71Sopenharmony_ci
6443e41f4b71Sopenharmony_ci| Type          | Description                     |
6444e41f4b71Sopenharmony_ci| -------------- | ------------------------- |
6445e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
6446e41f4b71Sopenharmony_ci
6447e41f4b71Sopenharmony_ci**Example**
6448e41f4b71Sopenharmony_ci
6449e41f4b71Sopenharmony_ci```ts
6450e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6451e41f4b71Sopenharmony_ci
6452e41f4b71Sopenharmony_cilet vol: number = 0.5;
6453e41f4b71Sopenharmony_civideoPlayer.setVolume(vol).then(() => {
6454e41f4b71Sopenharmony_ci  console.info('Succeeded in setting Volume');
6455e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
6456e41f4b71Sopenharmony_ci  console.error(`video catchCallback, error:${error}`);
6457e41f4b71Sopenharmony_ci});
6458e41f4b71Sopenharmony_ci```
6459e41f4b71Sopenharmony_ci
6460e41f4b71Sopenharmony_ci### release<sup>(deprecated)</sup>
6461e41f4b71Sopenharmony_ci
6462e41f4b71Sopenharmony_cirelease(callback: AsyncCallback\<void>): void
6463e41f4b71Sopenharmony_ci
6464e41f4b71Sopenharmony_ciReleases the video playback resources. This API uses an asynchronous callback to return the result.
6465e41f4b71Sopenharmony_ci
6466e41f4b71Sopenharmony_ci> **NOTE**
6467e41f4b71Sopenharmony_ci>
6468e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.release](#release9) instead.
6469e41f4b71Sopenharmony_ci
6470e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6471e41f4b71Sopenharmony_ci
6472e41f4b71Sopenharmony_ci**Parameters**
6473e41f4b71Sopenharmony_ci
6474e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                    |
6475e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------ |
6476e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
6477e41f4b71Sopenharmony_ci
6478e41f4b71Sopenharmony_ci**Example**
6479e41f4b71Sopenharmony_ci
6480e41f4b71Sopenharmony_ci```ts
6481e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6482e41f4b71Sopenharmony_ci
6483e41f4b71Sopenharmony_civideoPlayer.release((err: BusinessError) => {
6484e41f4b71Sopenharmony_ci  if (err) {
6485e41f4b71Sopenharmony_ci    console.error('Failed to release!');
6486e41f4b71Sopenharmony_ci  } else {
6487e41f4b71Sopenharmony_ci    console.info('Succeeded in releasing!');
6488e41f4b71Sopenharmony_ci  }
6489e41f4b71Sopenharmony_ci});
6490e41f4b71Sopenharmony_ci```
6491e41f4b71Sopenharmony_ci
6492e41f4b71Sopenharmony_ci### release<sup>(deprecated)</sup>
6493e41f4b71Sopenharmony_ci
6494e41f4b71Sopenharmony_cirelease(): Promise\<void>
6495e41f4b71Sopenharmony_ci
6496e41f4b71Sopenharmony_ciReleases the video playback resources. This API uses a promise to return the result.
6497e41f4b71Sopenharmony_ci
6498e41f4b71Sopenharmony_ci> **NOTE**
6499e41f4b71Sopenharmony_ci>
6500e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.release](#release9-1) instead.
6501e41f4b71Sopenharmony_ci
6502e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6503e41f4b71Sopenharmony_ci
6504e41f4b71Sopenharmony_ci**Return value**
6505e41f4b71Sopenharmony_ci
6506e41f4b71Sopenharmony_ci| Type          | Description                         |
6507e41f4b71Sopenharmony_ci| -------------- | ----------------------------- |
6508e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
6509e41f4b71Sopenharmony_ci
6510e41f4b71Sopenharmony_ci**Example**
6511e41f4b71Sopenharmony_ci
6512e41f4b71Sopenharmony_ci```ts
6513e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6514e41f4b71Sopenharmony_ci
6515e41f4b71Sopenharmony_civideoPlayer.release().then(() => {
6516e41f4b71Sopenharmony_ci  console.info('Succeeded in releasing');
6517e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
6518e41f4b71Sopenharmony_ci  console.error(`video catchCallback, error:${error}`);
6519e41f4b71Sopenharmony_ci});
6520e41f4b71Sopenharmony_ci```
6521e41f4b71Sopenharmony_ci
6522e41f4b71Sopenharmony_ci### getTrackDescription<sup>(deprecated)</sup>
6523e41f4b71Sopenharmony_ci
6524e41f4b71Sopenharmony_cigetTrackDescription(callback: AsyncCallback\<Array\<MediaDescription>>): void
6525e41f4b71Sopenharmony_ci
6526e41f4b71Sopenharmony_ciObtains the video track information. This API uses an asynchronous callback to return the result.
6527e41f4b71Sopenharmony_ci
6528e41f4b71Sopenharmony_ci> **NOTE**
6529e41f4b71Sopenharmony_ci>
6530e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.getTrackDescription](#gettrackdescription9) instead.
6531e41f4b71Sopenharmony_ci
6532e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6533e41f4b71Sopenharmony_ci
6534e41f4b71Sopenharmony_ci**Parameters**
6535e41f4b71Sopenharmony_ci
6536e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory| Description                                      |
6537e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------ |
6538e41f4b71Sopenharmony_ci| callback | AsyncCallback\<Array\<[MediaDescription](#mediadescription8)>> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the MediaDescription array obtained; otherwise, **err** is an error object.|
6539e41f4b71Sopenharmony_ci
6540e41f4b71Sopenharmony_ci**Example**
6541e41f4b71Sopenharmony_ci
6542e41f4b71Sopenharmony_ci```ts
6543e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6544e41f4b71Sopenharmony_ci
6545e41f4b71Sopenharmony_civideoPlayer.getTrackDescription((error: BusinessError, arrList: Array<media.MediaDescription>) => {
6546e41f4b71Sopenharmony_ci  if ((arrList) != null) {
6547e41f4b71Sopenharmony_ci    console.info('Succeeded in getting TrackDescription');
6548e41f4b71Sopenharmony_ci  } else {
6549e41f4b71Sopenharmony_ci    console.error(`Failed to get TrackDescription, error:${error}`);
6550e41f4b71Sopenharmony_ci  }
6551e41f4b71Sopenharmony_ci});
6552e41f4b71Sopenharmony_ci```
6553e41f4b71Sopenharmony_ci
6554e41f4b71Sopenharmony_ci### getTrackDescription<sup>(deprecated)</sup>
6555e41f4b71Sopenharmony_ci
6556e41f4b71Sopenharmony_cigetTrackDescription(): Promise\<Array\<MediaDescription>>
6557e41f4b71Sopenharmony_ci
6558e41f4b71Sopenharmony_ciObtains the video track information. This API uses a promise to return the result.
6559e41f4b71Sopenharmony_ci
6560e41f4b71Sopenharmony_ci> **NOTE**
6561e41f4b71Sopenharmony_ci>
6562e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.getTrackDescription](#gettrackdescription9-1) instead.
6563e41f4b71Sopenharmony_ci
6564e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6565e41f4b71Sopenharmony_ci
6566e41f4b71Sopenharmony_ci**Return value**
6567e41f4b71Sopenharmony_ci
6568e41f4b71Sopenharmony_ci| Type                                                  | Description                                           |
6569e41f4b71Sopenharmony_ci| ------------------------------------------------------ | ----------------------------------------------- |
6570e41f4b71Sopenharmony_ci| Promise<Array<[MediaDescription](#mediadescription8)>> | Promise used to return the MediaDescription array that holds the video track information.|
6571e41f4b71Sopenharmony_ci
6572e41f4b71Sopenharmony_ci**Example**
6573e41f4b71Sopenharmony_ci
6574e41f4b71Sopenharmony_ci```ts
6575e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6576e41f4b71Sopenharmony_ci
6577e41f4b71Sopenharmony_civideoPlayer.getTrackDescription().then((arrList: Array<media.MediaDescription>) => {
6578e41f4b71Sopenharmony_ci  if (arrList != null) {
6579e41f4b71Sopenharmony_ci    console.info('Succeeded in getting TrackDescription');
6580e41f4b71Sopenharmony_ci  } else {
6581e41f4b71Sopenharmony_ci    console.error('Failed to get TrackDescription');
6582e41f4b71Sopenharmony_ci  }
6583e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
6584e41f4b71Sopenharmony_ci  console.error(`video catchCallback, error:${error}`);
6585e41f4b71Sopenharmony_ci});
6586e41f4b71Sopenharmony_ci```
6587e41f4b71Sopenharmony_ci
6588e41f4b71Sopenharmony_ci### setSpeed<sup>(deprecated)</sup>
6589e41f4b71Sopenharmony_ci
6590e41f4b71Sopenharmony_cisetSpeed(speed: number, callback: AsyncCallback\<number>): void
6591e41f4b71Sopenharmony_ci
6592e41f4b71Sopenharmony_ciSets the playback speed. This API uses an asynchronous callback to return the result.
6593e41f4b71Sopenharmony_ci
6594e41f4b71Sopenharmony_ci> **NOTE**
6595e41f4b71Sopenharmony_ci>
6596e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.setSpeed](#setspeed9) instead.
6597e41f4b71Sopenharmony_ci
6598e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6599e41f4b71Sopenharmony_ci
6600e41f4b71Sopenharmony_ci**Parameters**
6601e41f4b71Sopenharmony_ci
6602e41f4b71Sopenharmony_ci| Name  | Type                  | Mandatory| Description                                                      |
6603e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ---------------------------------------------------------- |
6604e41f4b71Sopenharmony_ci| speed    | number                 | Yes  | Video playback speed. For details, see [PlaybackSpeed](#playbackspeed8).|
6605e41f4b71Sopenharmony_ci| callback | AsyncCallback\<number> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the playback speed; otherwise, **err** is an error object.                                  |
6606e41f4b71Sopenharmony_ci
6607e41f4b71Sopenharmony_ci**Example**
6608e41f4b71Sopenharmony_ci
6609e41f4b71Sopenharmony_ci```ts
6610e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6611e41f4b71Sopenharmony_ci
6612e41f4b71Sopenharmony_cilet videoPlayer: media.VideoPlayer | null = null;
6613e41f4b71Sopenharmony_cimedia.createVideoPlayer((error: BusinessError, video: media.VideoPlayer) => {
6614e41f4b71Sopenharmony_ci  if (video != null) {
6615e41f4b71Sopenharmony_ci    videoPlayer = video;
6616e41f4b71Sopenharmony_ci    console.info('Succeeded in creating VideoPlayer');
6617e41f4b71Sopenharmony_ci  } else {
6618e41f4b71Sopenharmony_ci    console.error(`Failed to create VideoPlayer, error:${error}`);
6619e41f4b71Sopenharmony_ci  }
6620e41f4b71Sopenharmony_ci});
6621e41f4b71Sopenharmony_cilet speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X;
6622e41f4b71Sopenharmony_ciif (videoPlayer) {
6623e41f4b71Sopenharmony_ci  (videoPlayer as media.VideoPlayer).setSpeed(speed, (err: BusinessError, result: number) => {
6624e41f4b71Sopenharmony_ci    if (err) {
6625e41f4b71Sopenharmony_ci      console.error('Failed to set Speed!');
6626e41f4b71Sopenharmony_ci    } else {
6627e41f4b71Sopenharmony_ci      console.info('Succeeded in setting Speed!');
6628e41f4b71Sopenharmony_ci    }
6629e41f4b71Sopenharmony_ci  });
6630e41f4b71Sopenharmony_ci}
6631e41f4b71Sopenharmony_ci```
6632e41f4b71Sopenharmony_ci
6633e41f4b71Sopenharmony_ci### setSpeed<sup>(deprecated)</sup>
6634e41f4b71Sopenharmony_ci
6635e41f4b71Sopenharmony_cisetSpeed(speed: number): Promise\<number>
6636e41f4b71Sopenharmony_ci
6637e41f4b71Sopenharmony_ciSets the playback speed. This API uses a promise to return the result.
6638e41f4b71Sopenharmony_ci
6639e41f4b71Sopenharmony_ci> **NOTE**
6640e41f4b71Sopenharmony_ci>
6641e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.setSpeed](#setspeed9) instead.
6642e41f4b71Sopenharmony_ci
6643e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6644e41f4b71Sopenharmony_ci
6645e41f4b71Sopenharmony_ci**Parameters**
6646e41f4b71Sopenharmony_ci
6647e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                                      |
6648e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------------------------------------------------------- |
6649e41f4b71Sopenharmony_ci| speed  | number | Yes  | Video playback speed. For details, see [PlaybackSpeed](#playbackspeed8).|
6650e41f4b71Sopenharmony_ci
6651e41f4b71Sopenharmony_ci**Return value**
6652e41f4b71Sopenharmony_ci
6653e41f4b71Sopenharmony_ci| Type            | Description                                                        |
6654e41f4b71Sopenharmony_ci| ---------------- | ------------------------------------------------------------ |
6655e41f4b71Sopenharmony_ci| Promise\<number>| Promise used to return the playback speed. For details, see [PlaybackSpeed](#playbackspeed8).|
6656e41f4b71Sopenharmony_ci
6657e41f4b71Sopenharmony_ci**Example**
6658e41f4b71Sopenharmony_ci
6659e41f4b71Sopenharmony_ci```ts
6660e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6661e41f4b71Sopenharmony_ci
6662e41f4b71Sopenharmony_cilet videoPlayer: media.VideoPlayer | null = null;
6663e41f4b71Sopenharmony_cimedia.createVideoPlayer((error: BusinessError, video: media.VideoPlayer) => {
6664e41f4b71Sopenharmony_ci  if (video != null) {
6665e41f4b71Sopenharmony_ci    videoPlayer = video;
6666e41f4b71Sopenharmony_ci    console.info('Succeeded in creating VideoPlayer');
6667e41f4b71Sopenharmony_ci  } else {
6668e41f4b71Sopenharmony_ci    console.error(`Failed to create VideoPlayer, error:${error}`);
6669e41f4b71Sopenharmony_ci  }
6670e41f4b71Sopenharmony_ci});
6671e41f4b71Sopenharmony_cilet speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X;
6672e41f4b71Sopenharmony_ciif (videoPlayer) {
6673e41f4b71Sopenharmony_ci  (videoPlayer as media.VideoPlayer).setSpeed(speed).then((result: number) => {
6674e41f4b71Sopenharmony_ci    console.info('Succeeded in setting Speed');
6675e41f4b71Sopenharmony_ci  }).catch((error: BusinessError) => {
6676e41f4b71Sopenharmony_ci    console.error(`Failed to set Speed, error:${error}`);//todo:: error
6677e41f4b71Sopenharmony_ci  });
6678e41f4b71Sopenharmony_ci}
6679e41f4b71Sopenharmony_ci```
6680e41f4b71Sopenharmony_ci
6681e41f4b71Sopenharmony_ci### on('playbackCompleted')<sup>(deprecated)</sup>
6682e41f4b71Sopenharmony_ci
6683e41f4b71Sopenharmony_cion(type: 'playbackCompleted', callback: Callback\<void>): void
6684e41f4b71Sopenharmony_ci
6685e41f4b71Sopenharmony_ciSubscribes to the video playback completion event.
6686e41f4b71Sopenharmony_ci
6687e41f4b71Sopenharmony_ci> **NOTE**
6688e41f4b71Sopenharmony_ci>
6689e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.on('stateChange')](#onstatechange9) instead.
6690e41f4b71Sopenharmony_ci
6691e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6692e41f4b71Sopenharmony_ci
6693e41f4b71Sopenharmony_ci**Parameters**
6694e41f4b71Sopenharmony_ci
6695e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                       |
6696e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ----------------------------------------------------------- |
6697e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'playbackCompleted'** in this case.|
6698e41f4b71Sopenharmony_ci| callback | Callback\<void> | Yes  | Callback invoked when the event is triggered.                                 |
6699e41f4b71Sopenharmony_ci
6700e41f4b71Sopenharmony_ci**Example**
6701e41f4b71Sopenharmony_ci
6702e41f4b71Sopenharmony_ci```ts
6703e41f4b71Sopenharmony_civideoPlayer.on('playbackCompleted', () => {
6704e41f4b71Sopenharmony_ci  console.info('playbackCompleted called!');
6705e41f4b71Sopenharmony_ci});
6706e41f4b71Sopenharmony_ci```
6707e41f4b71Sopenharmony_ci
6708e41f4b71Sopenharmony_ci### on('bufferingUpdate')<sup>(deprecated)</sup>
6709e41f4b71Sopenharmony_ci
6710e41f4b71Sopenharmony_cion(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: number) => void): void
6711e41f4b71Sopenharmony_ci
6712e41f4b71Sopenharmony_ciSubscribes to the video buffering update event. This API works only under online playback.
6713e41f4b71Sopenharmony_ci
6714e41f4b71Sopenharmony_ci> **NOTE**
6715e41f4b71Sopenharmony_ci>
6716e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.on('bufferingUpdate')](#onbufferingupdate9) instead.
6717e41f4b71Sopenharmony_ci
6718e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6719e41f4b71Sopenharmony_ci
6720e41f4b71Sopenharmony_ci**Parameters**
6721e41f4b71Sopenharmony_ci
6722e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
6723e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
6724e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'bufferingUpdate'** in this case.       |
6725e41f4b71Sopenharmony_ci| callback | function | Yes  | Callback invoked when the event is triggered.<br>The value of [BufferingInfoType](#bufferinginfotype8) is fixed at **0**.|
6726e41f4b71Sopenharmony_ci
6727e41f4b71Sopenharmony_ci**Example**
6728e41f4b71Sopenharmony_ci
6729e41f4b71Sopenharmony_ci```ts
6730e41f4b71Sopenharmony_civideoPlayer.on('bufferingUpdate', (infoType: media.BufferingInfoType, value: number) => {
6731e41f4b71Sopenharmony_ci  console.info('video bufferingInfo type: ' + infoType);
6732e41f4b71Sopenharmony_ci  console.info('video bufferingInfo value: ' + value);
6733e41f4b71Sopenharmony_ci});
6734e41f4b71Sopenharmony_ci```
6735e41f4b71Sopenharmony_ci
6736e41f4b71Sopenharmony_ci### on('startRenderFrame')<sup>(deprecated)</sup>
6737e41f4b71Sopenharmony_ci
6738e41f4b71Sopenharmony_cion(type: 'startRenderFrame', callback: Callback\<void>): void
6739e41f4b71Sopenharmony_ci
6740e41f4b71Sopenharmony_ciSubscribes to the frame rendering start event.
6741e41f4b71Sopenharmony_ci
6742e41f4b71Sopenharmony_ci> **NOTE**
6743e41f4b71Sopenharmony_ci>
6744e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.on('startRenderFrame')](#onstartrenderframe9) instead.
6745e41f4b71Sopenharmony_ci
6746e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6747e41f4b71Sopenharmony_ci
6748e41f4b71Sopenharmony_ci**Parameters**
6749e41f4b71Sopenharmony_ci
6750e41f4b71Sopenharmony_ci| Name  | Type           | Mandatory| Description                                                        |
6751e41f4b71Sopenharmony_ci| -------- | --------------- | ---- | ------------------------------------------------------------ |
6752e41f4b71Sopenharmony_ci| type     | string          | Yes  | Event type, which is **'startRenderFrame'** in this case.|
6753e41f4b71Sopenharmony_ci| callback | Callback\<void> | Yes  | Callback invoked when the event is triggered.                          |
6754e41f4b71Sopenharmony_ci
6755e41f4b71Sopenharmony_ci**Example**
6756e41f4b71Sopenharmony_ci
6757e41f4b71Sopenharmony_ci```ts
6758e41f4b71Sopenharmony_civideoPlayer.on('startRenderFrame', () => {
6759e41f4b71Sopenharmony_ci  console.info('startRenderFrame called!');
6760e41f4b71Sopenharmony_ci});
6761e41f4b71Sopenharmony_ci```
6762e41f4b71Sopenharmony_ci
6763e41f4b71Sopenharmony_ci### on('videoSizeChanged')<sup>(deprecated)</sup>
6764e41f4b71Sopenharmony_ci
6765e41f4b71Sopenharmony_cion(type: 'videoSizeChanged', callback: (width: number, height: number) => void): void
6766e41f4b71Sopenharmony_ci
6767e41f4b71Sopenharmony_ciSubscribes to the video width and height change event.
6768e41f4b71Sopenharmony_ci
6769e41f4b71Sopenharmony_ci> **NOTE**
6770e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.on('videoSizeChange')](#onvideosizechange9) instead.
6771e41f4b71Sopenharmony_ci
6772e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6773e41f4b71Sopenharmony_ci
6774e41f4b71Sopenharmony_ci**Parameters**
6775e41f4b71Sopenharmony_ci
6776e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
6777e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
6778e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'videoSizeChanged'** in this case.|
6779e41f4b71Sopenharmony_ci| callback | function | Yes  | Callback invoked when the event is triggered. **width** indicates the video width, and **height** indicates the video height.   |
6780e41f4b71Sopenharmony_ci
6781e41f4b71Sopenharmony_ci**Example**
6782e41f4b71Sopenharmony_ci
6783e41f4b71Sopenharmony_ci```ts
6784e41f4b71Sopenharmony_civideoPlayer.on('videoSizeChanged', (width: number, height: number) => {
6785e41f4b71Sopenharmony_ci  console.info('video width is: ' + width);
6786e41f4b71Sopenharmony_ci  console.info('video height is: ' + height);
6787e41f4b71Sopenharmony_ci});
6788e41f4b71Sopenharmony_ci```
6789e41f4b71Sopenharmony_ci### on('audioInterrupt')<sup>(deprecated)</sup>
6790e41f4b71Sopenharmony_ci
6791e41f4b71Sopenharmony_cion(type: 'audioInterrupt', callback: (info: audio.InterruptEvent) => void): void
6792e41f4b71Sopenharmony_ci
6793e41f4b71Sopenharmony_ciSubscribes to the audio interruption event. For details, see [audio.InterruptEvent](../apis-audio-kit/js-apis-audio.md#interruptevent9).
6794e41f4b71Sopenharmony_ci
6795e41f4b71Sopenharmony_ci> **NOTE**
6796e41f4b71Sopenharmony_ci>
6797e41f4b71Sopenharmony_ci> This API is supported in API version 9 and deprecated since API version 9. You are advised to use [AVPlayer.on('audioInterrupt')](#onaudiointerrupt9) instead.
6798e41f4b71Sopenharmony_ci
6799e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6800e41f4b71Sopenharmony_ci
6801e41f4b71Sopenharmony_ci**Parameters**
6802e41f4b71Sopenharmony_ci
6803e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory| Description                                                    |
6804e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- |
6805e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type, which is **'audioInterrupt'** in this case.|
6806e41f4b71Sopenharmony_ci| callback | function | Yes  | Callback invoked when the event is triggered.                              |
6807e41f4b71Sopenharmony_ci
6808e41f4b71Sopenharmony_ci**Example**
6809e41f4b71Sopenharmony_ci
6810e41f4b71Sopenharmony_ci```ts
6811e41f4b71Sopenharmony_ciimport { audio } from '@kit.AudioKit';
6812e41f4b71Sopenharmony_ci
6813e41f4b71Sopenharmony_civideoPlayer.on('audioInterrupt', (info: audio.InterruptEvent) => {
6814e41f4b71Sopenharmony_ci  console.info('audioInterrupt called,and InterruptEvent info is:' + info)
6815e41f4b71Sopenharmony_ci})
6816e41f4b71Sopenharmony_ci```
6817e41f4b71Sopenharmony_ci
6818e41f4b71Sopenharmony_ci### on('error')<sup>(deprecated)</sup>
6819e41f4b71Sopenharmony_ci
6820e41f4b71Sopenharmony_cion(type: 'error', callback: ErrorCallback): void
6821e41f4b71Sopenharmony_ci
6822e41f4b71Sopenharmony_ciSubscribes to video playback error events. After an error event is reported, you must handle the event and exit the playback.
6823e41f4b71Sopenharmony_ci
6824e41f4b71Sopenharmony_ci> **NOTE**
6825e41f4b71Sopenharmony_ci>
6826e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.on('error')](#onerror9) instead.
6827e41f4b71Sopenharmony_ci
6828e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6829e41f4b71Sopenharmony_ci
6830e41f4b71Sopenharmony_ci**Parameters**
6831e41f4b71Sopenharmony_ci
6832e41f4b71Sopenharmony_ci| Name  | Type         | Mandatory| Description                                                        |
6833e41f4b71Sopenharmony_ci| -------- | ------------- | ---- | ------------------------------------------------------------ |
6834e41f4b71Sopenharmony_ci| type     | string        | Yes  | Event type, which is **'error'** in this case.<br>This event is triggered when an error occurs during video playback.|
6835e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes  | Callback invoked when the event is triggered.                                      |
6836e41f4b71Sopenharmony_ci
6837e41f4b71Sopenharmony_ci**Example**
6838e41f4b71Sopenharmony_ci
6839e41f4b71Sopenharmony_ci```ts
6840e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6841e41f4b71Sopenharmony_ci
6842e41f4b71Sopenharmony_civideoPlayer.on('error', (error: BusinessError) => {  // Set the 'error' event callback.
6843e41f4b71Sopenharmony_ci  console.error(`video error called, error: ${error}`);
6844e41f4b71Sopenharmony_ci});
6845e41f4b71Sopenharmony_civideoPlayer.url = 'fd://error';  // Set an incorrect URL to trigger the 'error' event.
6846e41f4b71Sopenharmony_ci```
6847e41f4b71Sopenharmony_ci
6848e41f4b71Sopenharmony_ci## VideoPlayState<sup>(deprecated)</sup>
6849e41f4b71Sopenharmony_ci
6850e41f4b71Sopenharmony_citype VideoPlayState = 'idle' | 'prepared' | 'playing' | 'paused' | 'stopped' | 'error'
6851e41f4b71Sopenharmony_ci
6852e41f4b71Sopenharmony_ciEnumerates the video playback states. You can obtain the state through the **state** attribute.
6853e41f4b71Sopenharmony_ci
6854e41f4b71Sopenharmony_ci> **NOTE**
6855e41f4b71Sopenharmony_ci>
6856e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayerState](#avplayerstate9) instead.
6857e41f4b71Sopenharmony_ci
6858e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
6859e41f4b71Sopenharmony_ci
6860e41f4b71Sopenharmony_ci| Type    | Description          |
6861e41f4b71Sopenharmony_ci| -------- | -------------- |
6862e41f4b71Sopenharmony_ci| 'idle'     | The video player is idle.|
6863e41f4b71Sopenharmony_ci| 'prepared' | Video playback is being prepared.|
6864e41f4b71Sopenharmony_ci| 'playing'  | Video playback is in progress.|
6865e41f4b71Sopenharmony_ci| 'paused'   | Video playback is paused.|
6866e41f4b71Sopenharmony_ci| 'stopped'  | Video playback is stopped.|
6867e41f4b71Sopenharmony_ci| 'error'    | Video playback is in the error state.    |
6868e41f4b71Sopenharmony_ci
6869e41f4b71Sopenharmony_ci## AudioRecorder<sup>(deprecated)</sup>
6870e41f4b71Sopenharmony_ci
6871e41f4b71Sopenharmony_ci> **NOTE**
6872e41f4b71Sopenharmony_ci>
6873e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVRecorder](#avrecorder9) instead.
6874e41f4b71Sopenharmony_ci
6875e41f4b71Sopenharmony_ciImplements audio recording. Before calling any API of **AudioRecorder**, you must use [createAudioRecorder()](#mediacreateaudiorecorderdeprecated) to create an **AudioRecorder** instance.
6876e41f4b71Sopenharmony_ci
6877e41f4b71Sopenharmony_ci### prepare<sup>(deprecated)</sup>
6878e41f4b71Sopenharmony_ci
6879e41f4b71Sopenharmony_ciprepare(config: AudioRecorderConfig): void
6880e41f4b71Sopenharmony_ci
6881e41f4b71Sopenharmony_ciPrepares for recording.
6882e41f4b71Sopenharmony_ci
6883e41f4b71Sopenharmony_ci> **NOTE**
6884e41f4b71Sopenharmony_ci>
6885e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVRecorder.prepare](#prepare9-2) instead.
6886e41f4b71Sopenharmony_ci
6887e41f4b71Sopenharmony_ci**Required permissions:** ohos.permission.MICROPHONE
6888e41f4b71Sopenharmony_ci
6889e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioRecorder
6890e41f4b71Sopenharmony_ci
6891e41f4b71Sopenharmony_ci**Parameters**
6892e41f4b71Sopenharmony_ci
6893e41f4b71Sopenharmony_ci| Name| Type                                       | Mandatory| Description                                                        |
6894e41f4b71Sopenharmony_ci| ------ | ------------------------------------------- | ---- | ------------------------------------------------------------ |
6895e41f4b71Sopenharmony_ci| config | [AudioRecorderConfig](#audiorecorderconfigdeprecated) | Yes  | Audio recording parameters, including the audio output URI, encoding format, sampling rate, number of audio channels, and output format.|
6896e41f4b71Sopenharmony_ci
6897e41f4b71Sopenharmony_ci**Error codes**
6898e41f4b71Sopenharmony_ci
6899e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
6900e41f4b71Sopenharmony_ci
6901e41f4b71Sopenharmony_ci| ID| Error Message             |
6902e41f4b71Sopenharmony_ci| -------- | --------------------- |
6903e41f4b71Sopenharmony_ci| 201      | permission denied     |
6904e41f4b71Sopenharmony_ci
6905e41f4b71Sopenharmony_ci**Example**
6906e41f4b71Sopenharmony_ci
6907e41f4b71Sopenharmony_ci```ts
6908e41f4b71Sopenharmony_cilet audioRecorderConfig: media.AudioRecorderConfig = {
6909e41f4b71Sopenharmony_ci  audioEncoder : media.AudioEncoder.AAC_LC,
6910e41f4b71Sopenharmony_ci  audioEncodeBitRate : 22050,
6911e41f4b71Sopenharmony_ci  audioSampleRate : 22050,
6912e41f4b71Sopenharmony_ci  numberOfChannels : 2,
6913e41f4b71Sopenharmony_ci  format : media.AudioOutputFormat.AAC_ADTS,
6914e41f4b71Sopenharmony_ci  uri : 'fd://1',       // The file must be created by the caller and granted with proper permissions.
6915e41f4b71Sopenharmony_ci  location : { latitude : 30, longitude : 130},
6916e41f4b71Sopenharmony_ci}
6917e41f4b71Sopenharmony_ciaudioRecorder.on('prepare', () => {    // Set the 'prepare' event callback.
6918e41f4b71Sopenharmony_ci  console.info('prepare called');
6919e41f4b71Sopenharmony_ci});
6920e41f4b71Sopenharmony_ciaudioRecorder.prepare(audioRecorderConfig);
6921e41f4b71Sopenharmony_ci```
6922e41f4b71Sopenharmony_ci
6923e41f4b71Sopenharmony_ci### start<sup>(deprecated)</sup>
6924e41f4b71Sopenharmony_ci
6925e41f4b71Sopenharmony_cistart(): void
6926e41f4b71Sopenharmony_ci
6927e41f4b71Sopenharmony_ciStarts audio recording. This API can be called only after the **'prepare'** event is triggered.
6928e41f4b71Sopenharmony_ci
6929e41f4b71Sopenharmony_ci> **NOTE**
6930e41f4b71Sopenharmony_ci>
6931e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVRecorder.start](#start9) instead.
6932e41f4b71Sopenharmony_ci
6933e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioRecorder
6934e41f4b71Sopenharmony_ci
6935e41f4b71Sopenharmony_ci**Example**
6936e41f4b71Sopenharmony_ci
6937e41f4b71Sopenharmony_ci```ts
6938e41f4b71Sopenharmony_ciaudioRecorder.on('start', () => {    // Set the 'start' event callback.
6939e41f4b71Sopenharmony_ci  console.info('audio recorder start called');
6940e41f4b71Sopenharmony_ci});
6941e41f4b71Sopenharmony_ciaudioRecorder.start();
6942e41f4b71Sopenharmony_ci```
6943e41f4b71Sopenharmony_ci
6944e41f4b71Sopenharmony_ci### pause<sup>(deprecated)</sup>
6945e41f4b71Sopenharmony_ci
6946e41f4b71Sopenharmony_cipause():void
6947e41f4b71Sopenharmony_ci
6948e41f4b71Sopenharmony_ciPauses audio recording. This API can be called only after the **'start'** event is triggered.
6949e41f4b71Sopenharmony_ci
6950e41f4b71Sopenharmony_ci> **NOTE**
6951e41f4b71Sopenharmony_ci>
6952e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVRecorder.pause](#pause9-2) instead.
6953e41f4b71Sopenharmony_ci
6954e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioRecorder
6955e41f4b71Sopenharmony_ci
6956e41f4b71Sopenharmony_ci**Example**
6957e41f4b71Sopenharmony_ci
6958e41f4b71Sopenharmony_ci```ts
6959e41f4b71Sopenharmony_ciaudioRecorder.on('pause', () => {    // Set the 'pause' event callback.
6960e41f4b71Sopenharmony_ci  console.info('audio recorder pause called');
6961e41f4b71Sopenharmony_ci});
6962e41f4b71Sopenharmony_ciaudioRecorder.pause();
6963e41f4b71Sopenharmony_ci```
6964e41f4b71Sopenharmony_ci
6965e41f4b71Sopenharmony_ci### resume<sup>(deprecated)</sup>
6966e41f4b71Sopenharmony_ci
6967e41f4b71Sopenharmony_ciresume():void
6968e41f4b71Sopenharmony_ci
6969e41f4b71Sopenharmony_ciResumes audio recording. This API can be called only after the **'pause'** event is triggered.
6970e41f4b71Sopenharmony_ci
6971e41f4b71Sopenharmony_ci> **NOTE**
6972e41f4b71Sopenharmony_ci>
6973e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVRecorder.resume](#resume9) instead.
6974e41f4b71Sopenharmony_ci
6975e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioRecorder
6976e41f4b71Sopenharmony_ci
6977e41f4b71Sopenharmony_ci**Example**
6978e41f4b71Sopenharmony_ci
6979e41f4b71Sopenharmony_ci```ts
6980e41f4b71Sopenharmony_ciaudioRecorder.on('resume', () => { // Set the 'resume' event callback.
6981e41f4b71Sopenharmony_ci  console.info('audio recorder resume called');
6982e41f4b71Sopenharmony_ci});
6983e41f4b71Sopenharmony_ciaudioRecorder.resume();
6984e41f4b71Sopenharmony_ci```
6985e41f4b71Sopenharmony_ci
6986e41f4b71Sopenharmony_ci### stop<sup>(deprecated)</sup>
6987e41f4b71Sopenharmony_ci
6988e41f4b71Sopenharmony_cistop(): void
6989e41f4b71Sopenharmony_ci
6990e41f4b71Sopenharmony_ciStops audio recording.
6991e41f4b71Sopenharmony_ci
6992e41f4b71Sopenharmony_ci> **NOTE**
6993e41f4b71Sopenharmony_ci>
6994e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVRecorder.stop](#stop9-2) instead.
6995e41f4b71Sopenharmony_ci
6996e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioRecorder
6997e41f4b71Sopenharmony_ci
6998e41f4b71Sopenharmony_ci**Example**
6999e41f4b71Sopenharmony_ci
7000e41f4b71Sopenharmony_ci```ts
7001e41f4b71Sopenharmony_ciaudioRecorder.on('stop', () => {    // Set the 'stop' event callback.
7002e41f4b71Sopenharmony_ci  console.info('audio recorder stop called');
7003e41f4b71Sopenharmony_ci});
7004e41f4b71Sopenharmony_ciaudioRecorder.stop();
7005e41f4b71Sopenharmony_ci```
7006e41f4b71Sopenharmony_ci
7007e41f4b71Sopenharmony_ci### release<sup>(deprecated)</sup>
7008e41f4b71Sopenharmony_ci
7009e41f4b71Sopenharmony_cirelease(): void
7010e41f4b71Sopenharmony_ci
7011e41f4b71Sopenharmony_ciReleases the audio recording resources.
7012e41f4b71Sopenharmony_ci
7013e41f4b71Sopenharmony_ci> **NOTE**
7014e41f4b71Sopenharmony_ci>
7015e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVRecorder.release](#release9-2) instead.
7016e41f4b71Sopenharmony_ci
7017e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioRecorder
7018e41f4b71Sopenharmony_ci
7019e41f4b71Sopenharmony_ci**Example**
7020e41f4b71Sopenharmony_ci
7021e41f4b71Sopenharmony_ci```ts
7022e41f4b71Sopenharmony_ciaudioRecorder.on('release', () => {    // Set the 'release' event callback.
7023e41f4b71Sopenharmony_ci  console.info('audio recorder release called');
7024e41f4b71Sopenharmony_ci});
7025e41f4b71Sopenharmony_ciaudioRecorder.release();
7026e41f4b71Sopenharmony_ciaudioRecorder = undefined;
7027e41f4b71Sopenharmony_ci```
7028e41f4b71Sopenharmony_ci
7029e41f4b71Sopenharmony_ci### reset<sup>(deprecated)</sup>
7030e41f4b71Sopenharmony_ci
7031e41f4b71Sopenharmony_cireset(): void
7032e41f4b71Sopenharmony_ci
7033e41f4b71Sopenharmony_ciResets audio recording.
7034e41f4b71Sopenharmony_ci
7035e41f4b71Sopenharmony_ciBefore resetting audio recording, you must call **stop()** to stop recording. After audio recording is reset, you must call **prepare()** to set the recording configurations for another recording.
7036e41f4b71Sopenharmony_ci
7037e41f4b71Sopenharmony_ci> **NOTE**
7038e41f4b71Sopenharmony_ci>
7039e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVRecorder.reset](#reset9-2) instead.
7040e41f4b71Sopenharmony_ci
7041e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioRecorder
7042e41f4b71Sopenharmony_ci
7043e41f4b71Sopenharmony_ci**Example**
7044e41f4b71Sopenharmony_ci
7045e41f4b71Sopenharmony_ci```ts
7046e41f4b71Sopenharmony_ciaudioRecorder.on('reset', () => {    // Set the 'reset' event callback.
7047e41f4b71Sopenharmony_ci  console.info('audio recorder reset called');
7048e41f4b71Sopenharmony_ci});
7049e41f4b71Sopenharmony_ciaudioRecorder.reset();
7050e41f4b71Sopenharmony_ci```
7051e41f4b71Sopenharmony_ci
7052e41f4b71Sopenharmony_ci### on('prepare' | 'start' | 'pause' | 'resume' | 'stop' | 'release' | 'reset')<sup>(deprecated)</sup>
7053e41f4b71Sopenharmony_ci
7054e41f4b71Sopenharmony_cion(type: 'prepare' | 'start' | 'pause' | 'resume' | 'stop' | 'release' | 'reset', callback: () => void): void
7055e41f4b71Sopenharmony_ci
7056e41f4b71Sopenharmony_ciSubscribes to the audio recording events.
7057e41f4b71Sopenharmony_ci
7058e41f4b71Sopenharmony_ci> **NOTE**
7059e41f4b71Sopenharmony_ci>
7060e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVRecorder.on('stateChange')](#onstatechange9-1) instead.
7061e41f4b71Sopenharmony_ci
7062e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioRecorder
7063e41f4b71Sopenharmony_ci
7064e41f4b71Sopenharmony_ci**Parameters**
7065e41f4b71Sopenharmony_ci
7066e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
7067e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
7068e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type. The following events are supported: 'prepare'\|'start'\|  'pause' \| 'resume' \|'stop'\|'release'\|'reset'<br>- 'prepare': triggered when the **prepare()** API is called and the audio recording parameters are set.<br>- 'start': triggered when the **start()** API is called and audio recording starts.<br>- 'pause': triggered when the **pause()** API is called and audio recording is paused.<br>- 'resume': triggered when the **resume()** API is called and audio recording is resumed.<br>- 'stop': triggered when the **stop()** API is called and audio recording stops.<br>- 'release': triggered when the **release()** API is called and the recording resources are released.<br>- 'reset': triggered when the **reset()** API is called and audio recording is reset.|
7069e41f4b71Sopenharmony_ci| callback | ()=>void | Yes  | Callback invoked when the event is triggered.                                          |
7070e41f4b71Sopenharmony_ci
7071e41f4b71Sopenharmony_ci**Example**
7072e41f4b71Sopenharmony_ci
7073e41f4b71Sopenharmony_ci```ts
7074e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7075e41f4b71Sopenharmony_ci
7076e41f4b71Sopenharmony_cilet audioRecorder: media.AudioRecorder = media.createAudioRecorder(); // Create an AudioRecorder instance.
7077e41f4b71Sopenharmony_cilet audioRecorderConfig: media.AudioRecorderConfig = {
7078e41f4b71Sopenharmony_ci  audioEncoder : media.AudioEncoder.AAC_LC,
7079e41f4b71Sopenharmony_ci  audioEncodeBitRate : 22050,
7080e41f4b71Sopenharmony_ci  audioSampleRate : 22050,
7081e41f4b71Sopenharmony_ci  numberOfChannels : 2,
7082e41f4b71Sopenharmony_ci  format : media.AudioOutputFormat.AAC_ADTS,
7083e41f4b71Sopenharmony_ci  uri : 'fd://xx',  // The file must be created by the caller and granted with proper permissions.
7084e41f4b71Sopenharmony_ci  location : { latitude : 30, longitude : 130}
7085e41f4b71Sopenharmony_ci}
7086e41f4b71Sopenharmony_ciaudioRecorder.on('error', (error: BusinessError) => {  // Set the 'error' event callback.
7087e41f4b71Sopenharmony_ci  console.error(`audio error called, error: ${error}`);
7088e41f4b71Sopenharmony_ci});
7089e41f4b71Sopenharmony_ciaudioRecorder.on('prepare', () => {  // Set the 'prepare' event callback.
7090e41f4b71Sopenharmony_ci  console.info('prepare called');
7091e41f4b71Sopenharmony_ci  audioRecorder.start();  // // Start recording and trigger the 'start' event callback.
7092e41f4b71Sopenharmony_ci});
7093e41f4b71Sopenharmony_ciaudioRecorder.on('start', () => {  // Set the 'start' event callback.
7094e41f4b71Sopenharmony_ci  console.info('audio recorder start called');
7095e41f4b71Sopenharmony_ci});
7096e41f4b71Sopenharmony_ciaudioRecorder.on('pause', () => {  // Set the 'pause' event callback.
7097e41f4b71Sopenharmony_ci  console.info('audio recorder pause called');
7098e41f4b71Sopenharmony_ci});
7099e41f4b71Sopenharmony_ciaudioRecorder.on('resume', () => {  // Set the 'resume' event callback.
7100e41f4b71Sopenharmony_ci  console.info('audio recorder resume called');
7101e41f4b71Sopenharmony_ci});
7102e41f4b71Sopenharmony_ciaudioRecorder.on('stop', () => {  // Set the 'stop' event callback.
7103e41f4b71Sopenharmony_ci  console.info('audio recorder stop called');
7104e41f4b71Sopenharmony_ci});
7105e41f4b71Sopenharmony_ciaudioRecorder.on('release', () => {  // Set the 'release' event callback.
7106e41f4b71Sopenharmony_ci  console.info('audio recorder release called');
7107e41f4b71Sopenharmony_ci});
7108e41f4b71Sopenharmony_ciaudioRecorder.on('reset', () => {  // Set the 'reset' event callback.
7109e41f4b71Sopenharmony_ci  console.info('audio recorder reset called');
7110e41f4b71Sopenharmony_ci});
7111e41f4b71Sopenharmony_ciaudioRecorder.prepare(audioRecorderConfig)  // // Set recording parameters and trigger the 'prepare' event callback.
7112e41f4b71Sopenharmony_ci```
7113e41f4b71Sopenharmony_ci
7114e41f4b71Sopenharmony_ci### on('error')<sup>(deprecated)</sup>
7115e41f4b71Sopenharmony_ci
7116e41f4b71Sopenharmony_cion(type: 'error', callback: ErrorCallback): void
7117e41f4b71Sopenharmony_ci
7118e41f4b71Sopenharmony_ciSubscribes to audio recording error events. After an error event is reported, you must handle the event and exit the recording.
7119e41f4b71Sopenharmony_ci
7120e41f4b71Sopenharmony_ci> **NOTE**
7121e41f4b71Sopenharmony_ci>
7122e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVRecorder.on('error')](#onerror9-1) instead.
7123e41f4b71Sopenharmony_ci
7124e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioRecorder
7125e41f4b71Sopenharmony_ci
7126e41f4b71Sopenharmony_ci**Parameters**
7127e41f4b71Sopenharmony_ci
7128e41f4b71Sopenharmony_ci| Name  | Type         | Mandatory| Description                                                        |
7129e41f4b71Sopenharmony_ci| -------- | ------------- | ---- | ------------------------------------------------------------ |
7130e41f4b71Sopenharmony_ci| type     | string        | Yes  | Event type, which is **'error'** in this case.<br>This event is triggered when an error occurs during audio recording.|
7131e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes  | Callback invoked when the event is triggered.                                      |
7132e41f4b71Sopenharmony_ci
7133e41f4b71Sopenharmony_ci**Example**
7134e41f4b71Sopenharmony_ci
7135e41f4b71Sopenharmony_ci```ts
7136e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7137e41f4b71Sopenharmony_ci
7138e41f4b71Sopenharmony_cilet audioRecorderConfig: media.AudioRecorderConfig = {
7139e41f4b71Sopenharmony_ci  audioEncoder : media.AudioEncoder.AAC_LC,
7140e41f4b71Sopenharmony_ci  audioEncodeBitRate : 22050,
7141e41f4b71Sopenharmony_ci  audioSampleRate : 22050,
7142e41f4b71Sopenharmony_ci  numberOfChannels : 2,
7143e41f4b71Sopenharmony_ci  format : media.AudioOutputFormat.AAC_ADTS,
7144e41f4b71Sopenharmony_ci  uri : 'fd://xx',   // The file must be created by the caller and granted with proper permissions.
7145e41f4b71Sopenharmony_ci  location : { latitude : 30, longitude : 130}
7146e41f4b71Sopenharmony_ci}
7147e41f4b71Sopenharmony_ciaudioRecorder.on('error', (error: BusinessError) => {  // Set the 'error' event callback.
7148e41f4b71Sopenharmony_ci  console.error(`audio error called, error: ${error}`);
7149e41f4b71Sopenharmony_ci});
7150e41f4b71Sopenharmony_ciaudioRecorder.prepare(audioRecorderConfig);  // // Do not set any parameter in prepare and trigger the 'error' event callback.
7151e41f4b71Sopenharmony_ci```
7152e41f4b71Sopenharmony_ci
7153e41f4b71Sopenharmony_ci## AudioRecorderConfig<sup>(deprecated)</sup>
7154e41f4b71Sopenharmony_ci
7155e41f4b71Sopenharmony_ci> **NOTE**
7156e41f4b71Sopenharmony_ci>
7157e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVRecorderConfig](#avrecorderconfig9) instead.
7158e41f4b71Sopenharmony_ci
7159e41f4b71Sopenharmony_ciDescribes audio recording configurations.
7160e41f4b71Sopenharmony_ci
7161e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioRecorder
7162e41f4b71Sopenharmony_ci
7163e41f4b71Sopenharmony_ci| Name                               | Type                                        | Mandatory| Description                                                        |
7164e41f4b71Sopenharmony_ci| ----------------------------------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
7165e41f4b71Sopenharmony_ci| audioEncoder                        | [AudioEncoder](#audioencoderdeprecated)                | No  | Audio encoding format. The default value is **AAC_LC**.<br>**Note**: This parameter is deprecated since API version 8. Use **audioEncoderMime** instead.|
7166e41f4b71Sopenharmony_ci| audioEncodeBitRate                  | number                                       | No  | Audio encoding bit rate. The default value is **48000**.                             |
7167e41f4b71Sopenharmony_ci| audioSampleRate                     | number                                       | No  | Audio sampling rate. The default value is **48000**.<br>Variable bit rate. The bit rate is for reference only.                             |
7168e41f4b71Sopenharmony_ci| numberOfChannels                    | number                                       | No  | Number of audio channels. The default value is **2**.                                 |
7169e41f4b71Sopenharmony_ci| format                              | [AudioOutputFormat](#audiooutputformatdeprecated)      | No  | Audio output format. The default value is **MPEG_4**.<br>**Note**: This parameter is deprecated since API version 8. Use **fileFormat** instead.|
7170e41f4b71Sopenharmony_ci| location                            | [Location](#location)                        | No  | Geographical location of the recorded audio.                                        |
7171e41f4b71Sopenharmony_ci| uri                                 | string                                       | Yes  | Audio output URI. Supported: fd://xx (fd number)<br>![](figures/en-us_image_url.png) <br>The file must be created by the caller and granted with proper permissions.|
7172e41f4b71Sopenharmony_ci| audioEncoderMime<sup>8+</sup>       | [CodecMimeType](#codecmimetype8)             | No  | Container encoding format.                                              |
7173e41f4b71Sopenharmony_ci| fileFormat<sup>8+</sup>             | [ContainerFormatType](#containerformattype8) | No  | Audio encoding format.                                              |
7174e41f4b71Sopenharmony_ci
7175e41f4b71Sopenharmony_ci## AudioEncoder<sup>(deprecated)</sup>
7176e41f4b71Sopenharmony_ci
7177e41f4b71Sopenharmony_ci> **NOTE**
7178e41f4b71Sopenharmony_ci>
7179e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 8. You are advised to use [CodecMimeType](#codecmimetype8) instead.
7180e41f4b71Sopenharmony_ci
7181e41f4b71Sopenharmony_ciEnumerates the audio encoding formats.
7182e41f4b71Sopenharmony_ci
7183e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioRecorder
7184e41f4b71Sopenharmony_ci
7185e41f4b71Sopenharmony_ci| Name   | Value  | Description                                                        |
7186e41f4b71Sopenharmony_ci| ------- | ---- | ------------------------------------------------------------ |
7187e41f4b71Sopenharmony_ci| DEFAULT | 0    | Default encoding format.<br>This API is defined but not implemented yet.             |
7188e41f4b71Sopenharmony_ci| AMR_NB  | 1    | AMR-NB.<br>This API is defined but not implemented yet.|
7189e41f4b71Sopenharmony_ci| AMR_WB  | 2    | Adaptive Multi Rate-Wide Band Speech Codec (AMR-WB).<br>This API is defined but not implemented yet.|
7190e41f4b71Sopenharmony_ci| AAC_LC  | 3    | Advanced Audio Coding Low Complexity (AAC-LC).|
7191e41f4b71Sopenharmony_ci| HE_AAC  | 4    | High-Efficiency Advanced Audio Coding (HE_AAC).<br>This API is defined but not implemented yet.|
7192e41f4b71Sopenharmony_ci
7193e41f4b71Sopenharmony_ci## AudioOutputFormat<sup>(deprecated)</sup>
7194e41f4b71Sopenharmony_ci
7195e41f4b71Sopenharmony_ci> **NOTE**
7196e41f4b71Sopenharmony_ci>
7197e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 8. You are advised to use [ContainerFormatType](#containerformattype8) instead.
7198e41f4b71Sopenharmony_ci
7199e41f4b71Sopenharmony_ciEnumerates the audio output formats.
7200e41f4b71Sopenharmony_ci
7201e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AudioRecorder
7202e41f4b71Sopenharmony_ci
7203e41f4b71Sopenharmony_ci| Name    | Value  | Description                                                        |
7204e41f4b71Sopenharmony_ci| -------- | ---- | ------------------------------------------------------------ |
7205e41f4b71Sopenharmony_ci| DEFAULT  | 0    | Default output format.<br>This API is defined but not implemented yet.             |
7206e41f4b71Sopenharmony_ci| MPEG_4   | 2    | MPEG-4.                                          |
7207e41f4b71Sopenharmony_ci| AMR_NB   | 3    | AMR_NB.<br>This API is defined but not implemented yet.         |
7208e41f4b71Sopenharmony_ci| AMR_WB   | 4    | AMR_WB.<br>This API is defined but not implemented yet.         |
7209e41f4b71Sopenharmony_ci| AAC_ADTS | 6    | Audio Data Transport Stream (ADTS), which is a transport stream format of AAC-based audio.|
7210e41f4b71Sopenharmony_ci
7211e41f4b71Sopenharmony_ci
7212e41f4b71Sopenharmony_ci## media.createAVImageGenerator<sup>12+</sup>
7213e41f4b71Sopenharmony_ci
7214e41f4b71Sopenharmony_cicreateAVImageGenerator(callback: AsyncCallback\<AVImageGenerator>): void
7215e41f4b71Sopenharmony_ci
7216e41f4b71Sopenharmony_ciCreates an **AVImageGenerator** instance. This API uses an asynchronous callback to return the result.
7217e41f4b71Sopenharmony_ci
7218e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVImageGenerator
7219e41f4b71Sopenharmony_ci
7220e41f4b71Sopenharmony_ci**Parameters**
7221e41f4b71Sopenharmony_ci
7222e41f4b71Sopenharmony_ci| Name  | Type                                 | Mandatory| Description                                                        |
7223e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ------------------------------------------------------------ |
7224e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[AVImageGenerator](#avimagegenerator12)> | Yes  | Callback used to return the result. If the operation is successful, an **AVImageGenerator** instance is returned; otherwise, **null** is returned. The API can be used to obtain a video thumbnail.|
7225e41f4b71Sopenharmony_ci
7226e41f4b71Sopenharmony_ci**Error codes**
7227e41f4b71Sopenharmony_ci
7228e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
7229e41f4b71Sopenharmony_ci
7230e41f4b71Sopenharmony_ci| ID| Error Message                      |
7231e41f4b71Sopenharmony_ci| -------- | ------------------------------ |
7232e41f4b71Sopenharmony_ci| 5400101  | No memory. Returned by callback. |
7233e41f4b71Sopenharmony_ci
7234e41f4b71Sopenharmony_ci**Example**
7235e41f4b71Sopenharmony_ci
7236e41f4b71Sopenharmony_ci```ts
7237e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7238e41f4b71Sopenharmony_ci
7239e41f4b71Sopenharmony_cilet avImageGenerator: media.AVImageGenerator;
7240e41f4b71Sopenharmony_cimedia.createAVImageGenerator((error: BusinessError, generator: media.AVImageGenerator) => {
7241e41f4b71Sopenharmony_ci  if (generator != null) {
7242e41f4b71Sopenharmony_ci    avImageGenerator = generator;
7243e41f4b71Sopenharmony_ci    console.info('Succeeded in creating AVImageGenerator');
7244e41f4b71Sopenharmony_ci  } else {
7245e41f4b71Sopenharmony_ci    console.error(`Failed to creat AVImageGenerator, error message:${error.message}`);
7246e41f4b71Sopenharmony_ci  }
7247e41f4b71Sopenharmony_ci});
7248e41f4b71Sopenharmony_ci```
7249e41f4b71Sopenharmony_ci
7250e41f4b71Sopenharmony_ci## media.createAVImageGenerator<sup>12+</sup>
7251e41f4b71Sopenharmony_ci
7252e41f4b71Sopenharmony_cicreateAVImageGenerator(): Promise\<AVImageGenerator>
7253e41f4b71Sopenharmony_ci
7254e41f4b71Sopenharmony_ciCreates an **AVImageGenerator** instance. This API uses a promise to return the result.
7255e41f4b71Sopenharmony_ci
7256e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVImageGenerator
7257e41f4b71Sopenharmony_ci
7258e41f4b71Sopenharmony_ci**Return value**
7259e41f4b71Sopenharmony_ci
7260e41f4b71Sopenharmony_ci| Type                           | Description                                                        |
7261e41f4b71Sopenharmony_ci| ------------------------------- | ------------------------------------------------------------ |
7262e41f4b71Sopenharmony_ci| Promise\<[AVImageGenerator](#avimagegenerator12)> | Promise used to return the result. If the operation is successful, an **AVImageGenerator** instance is returned; otherwise, **null** is returned. The API can be used to obtain a video thumbnail.|
7263e41f4b71Sopenharmony_ci
7264e41f4b71Sopenharmony_ci**Error codes**
7265e41f4b71Sopenharmony_ci
7266e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
7267e41f4b71Sopenharmony_ci
7268e41f4b71Sopenharmony_ci| ID| Error Message                     |
7269e41f4b71Sopenharmony_ci| -------- | ----------------------------- |
7270e41f4b71Sopenharmony_ci| 5400101  | No memory. Returned by promise. |
7271e41f4b71Sopenharmony_ci
7272e41f4b71Sopenharmony_ci**Example**
7273e41f4b71Sopenharmony_ci
7274e41f4b71Sopenharmony_ci```ts
7275e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7276e41f4b71Sopenharmony_ci
7277e41f4b71Sopenharmony_cilet avImageGenerator: media.AVImageGenerator;
7278e41f4b71Sopenharmony_cimedia.createAVImageGenerator().then((generator: media.AVImageGenerator) => {
7279e41f4b71Sopenharmony_ci  if (generator != null) {
7280e41f4b71Sopenharmony_ci    avImageGenerator = generator;
7281e41f4b71Sopenharmony_ci    console.info('Succeeded in creating AVImageGenerator');
7282e41f4b71Sopenharmony_ci  } else {
7283e41f4b71Sopenharmony_ci    console.error('Failed to creat AVImageGenerator');
7284e41f4b71Sopenharmony_ci  }
7285e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
7286e41f4b71Sopenharmony_ci  console.error(`Failed to creat AVImageGenerator, error message:${error.message}`);
7287e41f4b71Sopenharmony_ci});
7288e41f4b71Sopenharmony_ci```
7289e41f4b71Sopenharmony_ci
7290e41f4b71Sopenharmony_ci## AVImageGenerator<sup>12+</sup>
7291e41f4b71Sopenharmony_ci
7292e41f4b71Sopenharmony_ciProvides APIs to obtain a thumbnail from a video. Before calling any API of **AVImageGenerator**, you must use [createAVImageGenerator()](#mediacreateavimagegenerator12) to create an **AVImageGenerator** instance.
7293e41f4b71Sopenharmony_ci
7294e41f4b71Sopenharmony_ciFor details about the demo for obtaining video thumbnails, see [Obtaining Video Thumbnails](../../media/media/avimagegenerator.md).
7295e41f4b71Sopenharmony_ci
7296e41f4b71Sopenharmony_ci### Attributes
7297e41f4b71Sopenharmony_ci
7298e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVImageGenerator
7299e41f4b71Sopenharmony_ci
7300e41f4b71Sopenharmony_ci| Name                                               | Type                                                        | Readable| Writable| Description                                                        |
7301e41f4b71Sopenharmony_ci| --------------------------------------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
7302e41f4b71Sopenharmony_ci| fdSrc<sup>12+</sup>                                  | [AVFileDescriptor](js-apis-media.md#avfiledescriptor9)                       | Yes  | Yes  | Media file descriptor, which specifies the data source.<br> **Example:**<br>There is a media file that stores continuous assets, the address offset is 0, and the byte length is 100. Its file descriptor is **AVFileDescriptor {fd = resourceHandle; offset = 0; length = 100; }**.<br>**NOTE**<br> - After the resource handle (FD) is transferred to an **AVImageGenerator** instance, do not use the resource handle to perform other read and write operations, including but not limited to transferring this handle to other **AVPlayer**, **AVMetadataExtractor**, **AVImageGenerator**, or **AVTranscoder** instance. Competition occurs when multiple AVImageGenerator use the same resource handle to read and write files at the same time, resulting in errors in obtaining data.|
7303e41f4b71Sopenharmony_ci
7304e41f4b71Sopenharmony_ci### fetchFrameByTime<sup>12+</sup>
7305e41f4b71Sopenharmony_ci
7306e41f4b71Sopenharmony_cifetchFrameByTime(timeUs: number, options: AVImageQueryOptions, param: PixelMapParams, callback: AsyncCallback\<image.PixelMap>): void
7307e41f4b71Sopenharmony_ci
7308e41f4b71Sopenharmony_ciObtains a video thumbnail. This API uses an asynchronous callback to return the result.
7309e41f4b71Sopenharmony_ci
7310e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVImageGenerator
7311e41f4b71Sopenharmony_ci
7312e41f4b71Sopenharmony_ci**Parameters**
7313e41f4b71Sopenharmony_ci
7314e41f4b71Sopenharmony_ci| Name  | Type                                        | Mandatory| Description                               |
7315e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | ----------------------------------- |
7316e41f4b71Sopenharmony_ci| timeUs | number                   | Yes  | Time of the video for which a thumbnail is to be obtained, in μs.|
7317e41f4b71Sopenharmony_ci| options | [AVImageQueryOptions](#avimagequeryoptions12)     | Yes  | Relationship between the time passed in and the video frame.|
7318e41f4b71Sopenharmony_ci| param | [PixelMapParams](#pixelmapparams12)     | Yes  | Format parameters of the thumbnail to be obtained.|
7319e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)>   | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the **PixelMap** instance obtained; otherwise, **err** is an error object.|
7320e41f4b71Sopenharmony_ci
7321e41f4b71Sopenharmony_ci**Error codes**
7322e41f4b71Sopenharmony_ci
7323e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
7324e41f4b71Sopenharmony_ci
7325e41f4b71Sopenharmony_ci| ID| Error Message                                  |
7326e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
7327e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Returned by callback. |
7328e41f4b71Sopenharmony_ci| 5400106  | Unsupported format. Returned by callback.  |
7329e41f4b71Sopenharmony_ci
7330e41f4b71Sopenharmony_ci**Example**
7331e41f4b71Sopenharmony_ci
7332e41f4b71Sopenharmony_ci```ts
7333e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7334e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit';
7335e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
7336e41f4b71Sopenharmony_ci
7337e41f4b71Sopenharmony_cilet avImageGenerator: media.AVImageGenerator | undefined = undefined;
7338e41f4b71Sopenharmony_cilet pixel_map : image.PixelMap | undefined = undefined;
7339e41f4b71Sopenharmony_ci
7340e41f4b71Sopenharmony_ci// Initialize input parameters.
7341e41f4b71Sopenharmony_cilet timeUs: number = 0
7342e41f4b71Sopenharmony_ci
7343e41f4b71Sopenharmony_cilet queryOption: media.AVImageQueryOptions = media.AVImageQueryOptions.AV_IMAGE_QUERY_NEXT_SYNC
7344e41f4b71Sopenharmony_ci
7345e41f4b71Sopenharmony_cilet param: media.PixelMapParams = {
7346e41f4b71Sopenharmony_ci  width : 300,
7347e41f4b71Sopenharmony_ci  height : 300,
7348e41f4b71Sopenharmony_ci}
7349e41f4b71Sopenharmony_ci
7350e41f4b71Sopenharmony_ci// Obtain the thumbnail.
7351e41f4b71Sopenharmony_cimedia.createAVImageGenerator((err: BusinessError, generator: media.AVImageGenerator) => {
7352e41f4b71Sopenharmony_ci  if(generator != null){
7353e41f4b71Sopenharmony_ci    avImageGenerator = generator;
7354e41f4b71Sopenharmony_ci    console.info(`Succeeded in creating AVImageGenerator`);
7355e41f4b71Sopenharmony_ci    avImageGenerator.fetchFrameByTime(timeUs, queryOption, param, (error: BusinessError, pixelMap) => {
7356e41f4b71Sopenharmony_ci      if (error) {
7357e41f4b71Sopenharmony_ci        console.error(`Failed to fetch FrameByTime, err = ${JSON.stringify(error)}`)
7358e41f4b71Sopenharmony_ci        return
7359e41f4b71Sopenharmony_ci      }
7360e41f4b71Sopenharmony_ci      pixel_map = pixelMap;
7361e41f4b71Sopenharmony_ci    });
7362e41f4b71Sopenharmony_ci  } else {
7363e41f4b71Sopenharmony_ci    console.error(`Failed to creat AVImageGenerator, error message:${err.message}`);
7364e41f4b71Sopenharmony_ci  };
7365e41f4b71Sopenharmony_ci});
7366e41f4b71Sopenharmony_ci```
7367e41f4b71Sopenharmony_ci
7368e41f4b71Sopenharmony_ci### fetchFrameByTime<sup>12+</sup>
7369e41f4b71Sopenharmony_ci
7370e41f4b71Sopenharmony_cifetchFrameByTime(timeUs: number, options: AVImageQueryOptions, param: PixelMapParams): Promise<image.PixelMap>
7371e41f4b71Sopenharmony_ci
7372e41f4b71Sopenharmony_ciObtains a video thumbnail. This API uses a promise to return the result.
7373e41f4b71Sopenharmony_ci
7374e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVImageGenerator
7375e41f4b71Sopenharmony_ci
7376e41f4b71Sopenharmony_ci**Parameters**
7377e41f4b71Sopenharmony_ci
7378e41f4b71Sopenharmony_ci| Name  | Type                                        | Mandatory| Description                               |
7379e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | ----------------------------------- |
7380e41f4b71Sopenharmony_ci| timeUs | number                   | Yes  | Time of the video for which a thumbnail is to be obtained, in μs.|
7381e41f4b71Sopenharmony_ci| options | [AVImageQueryOptions](#avimagequeryoptions12)     | Yes  | Relationship between the time passed in and the video frame.|
7382e41f4b71Sopenharmony_ci| param | [PixelMapParams](#pixelmapparams12)    | Yes  | Format parameters of the thumbnail to be obtained.|
7383e41f4b71Sopenharmony_ci
7384e41f4b71Sopenharmony_ci**Return value**
7385e41f4b71Sopenharmony_ci
7386e41f4b71Sopenharmony_ci| Type          | Description                                    |
7387e41f4b71Sopenharmony_ci| -------------- | ---------------------------------------- |
7388e41f4b71Sopenharmony_ci| Promise\<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Promise used to return the video thumbnail.|
7389e41f4b71Sopenharmony_ci
7390e41f4b71Sopenharmony_ci**Error codes**
7391e41f4b71Sopenharmony_ci
7392e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
7393e41f4b71Sopenharmony_ci
7394e41f4b71Sopenharmony_ci| ID| Error Message                                 |
7395e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
7396e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Returned by promise. |
7397e41f4b71Sopenharmony_ci| 5400106  | Unsupported format. Returned by promise.  |
7398e41f4b71Sopenharmony_ci
7399e41f4b71Sopenharmony_ci**Example**
7400e41f4b71Sopenharmony_ci
7401e41f4b71Sopenharmony_ci```ts
7402e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7403e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit';
7404e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
7405e41f4b71Sopenharmony_ci
7406e41f4b71Sopenharmony_cilet avImageGenerator: media.AVImageGenerator | undefined = undefined;
7407e41f4b71Sopenharmony_cilet pixel_map : image.PixelMap | undefined = undefined;
7408e41f4b71Sopenharmony_ci
7409e41f4b71Sopenharmony_ci// Initialize input parameters.
7410e41f4b71Sopenharmony_cilet timeUs: number = 0
7411e41f4b71Sopenharmony_ci
7412e41f4b71Sopenharmony_cilet queryOption: media.AVImageQueryOptions = media.AVImageQueryOptions.AV_IMAGE_QUERY_NEXT_SYNC
7413e41f4b71Sopenharmony_ci
7414e41f4b71Sopenharmony_cilet param: media.PixelMapParams = {
7415e41f4b71Sopenharmony_ci  width : 300,
7416e41f4b71Sopenharmony_ci  height : 300,
7417e41f4b71Sopenharmony_ci}
7418e41f4b71Sopenharmony_ci
7419e41f4b71Sopenharmony_ci// Obtain the thumbnail.
7420e41f4b71Sopenharmony_cimedia.createAVImageGenerator((err: BusinessError, generator: media.AVImageGenerator) => {
7421e41f4b71Sopenharmony_ci  if(generator != null){
7422e41f4b71Sopenharmony_ci    avImageGenerator = generator;
7423e41f4b71Sopenharmony_ci    console.info(`Succeeded in creating AVImageGenerator`);
7424e41f4b71Sopenharmony_ci    avImageGenerator.fetchFrameByTime(timeUs, queryOption, param).then((pixelMap: image.PixelMap) => {
7425e41f4b71Sopenharmony_ci      pixel_map = pixelMap;
7426e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
7427e41f4b71Sopenharmony_ci      console.error(`Failed to fetch FrameByTime, error message:${error.message}`);
7428e41f4b71Sopenharmony_ci    });
7429e41f4b71Sopenharmony_ci  } else {
7430e41f4b71Sopenharmony_ci    console.error(`Failed to creat AVImageGenerator, error message:${err.message}`);
7431e41f4b71Sopenharmony_ci  };
7432e41f4b71Sopenharmony_ci});
7433e41f4b71Sopenharmony_ci```
7434e41f4b71Sopenharmony_ci
7435e41f4b71Sopenharmony_ci### release<sup>12+</sup>
7436e41f4b71Sopenharmony_ci
7437e41f4b71Sopenharmony_cirelease(callback: AsyncCallback\<void>): void
7438e41f4b71Sopenharmony_ci
7439e41f4b71Sopenharmony_ciReleases this **AVMetadataExtractor** instance. This API uses an asynchronous callback to return the result.
7440e41f4b71Sopenharmony_ci
7441e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVImageGenerator
7442e41f4b71Sopenharmony_ci
7443e41f4b71Sopenharmony_ci**Parameters**
7444e41f4b71Sopenharmony_ci
7445e41f4b71Sopenharmony_ci| Name  | Type                                        | Mandatory| Description                               |
7446e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | ----------------------------------- |
7447e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>                   | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
7448e41f4b71Sopenharmony_ci
7449e41f4b71Sopenharmony_ci**Error codes**
7450e41f4b71Sopenharmony_ci
7451e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
7452e41f4b71Sopenharmony_ci
7453e41f4b71Sopenharmony_ci| ID| Error Message                                  |
7454e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
7455e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Returned by callback. |
7456e41f4b71Sopenharmony_ci
7457e41f4b71Sopenharmony_ci**Example**
7458e41f4b71Sopenharmony_ci
7459e41f4b71Sopenharmony_ci```ts
7460e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7461e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit';
7462e41f4b71Sopenharmony_ci
7463e41f4b71Sopenharmony_cilet avImageGenerator: media.AVImageGenerator | undefined = undefined;
7464e41f4b71Sopenharmony_ci
7465e41f4b71Sopenharmony_ci// Release the instance.
7466e41f4b71Sopenharmony_cimedia.createAVImageGenerator((err: BusinessError, generator: media.AVImageGenerator) => {
7467e41f4b71Sopenharmony_ci  if(generator != null){
7468e41f4b71Sopenharmony_ci    avImageGenerator = generator;
7469e41f4b71Sopenharmony_ci    console.info(`Succeeded in creating AVImageGenerator`);
7470e41f4b71Sopenharmony_ci    avImageGenerator.release((error: BusinessError) => {
7471e41f4b71Sopenharmony_ci      if (error) {
7472e41f4b71Sopenharmony_ci        console.error(`Failed to release, err = ${JSON.stringify(error)}`);
7473e41f4b71Sopenharmony_ci        return;
7474e41f4b71Sopenharmony_ci      }
7475e41f4b71Sopenharmony_ci      console.info(`Succeeded in releasing`);
7476e41f4b71Sopenharmony_ci    });
7477e41f4b71Sopenharmony_ci  } else {
7478e41f4b71Sopenharmony_ci    console.error(`Failed to creat AVImageGenerator, error message:${err.message}`);
7479e41f4b71Sopenharmony_ci  };
7480e41f4b71Sopenharmony_ci});
7481e41f4b71Sopenharmony_ci```
7482e41f4b71Sopenharmony_ci
7483e41f4b71Sopenharmony_ci### release<sup>12+</sup>
7484e41f4b71Sopenharmony_ci
7485e41f4b71Sopenharmony_cirelease(): Promise\<void>
7486e41f4b71Sopenharmony_ci
7487e41f4b71Sopenharmony_ciReleases this **AVMetadataExtractor** instance. This API uses a promise to return the result.
7488e41f4b71Sopenharmony_ci
7489e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVImageGenerator
7490e41f4b71Sopenharmony_ci
7491e41f4b71Sopenharmony_ci**Return value**
7492e41f4b71Sopenharmony_ci
7493e41f4b71Sopenharmony_ci| Type          | Description                                    |
7494e41f4b71Sopenharmony_ci| -------------- | ---------------------------------------- |
7495e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
7496e41f4b71Sopenharmony_ci
7497e41f4b71Sopenharmony_ci**Error codes**
7498e41f4b71Sopenharmony_ci
7499e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
7500e41f4b71Sopenharmony_ci
7501e41f4b71Sopenharmony_ci| ID| Error Message                                 |
7502e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
7503e41f4b71Sopenharmony_ci| 5400102  | Operation not allowed. Returned by promise. |
7504e41f4b71Sopenharmony_ci
7505e41f4b71Sopenharmony_ci**Example**
7506e41f4b71Sopenharmony_ci
7507e41f4b71Sopenharmony_ci```ts
7508e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7509e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit';
7510e41f4b71Sopenharmony_ci
7511e41f4b71Sopenharmony_cilet avImageGenerator: media.AVImageGenerator | undefined = undefined;
7512e41f4b71Sopenharmony_ci
7513e41f4b71Sopenharmony_ci// Release the instance.
7514e41f4b71Sopenharmony_cimedia.createAVImageGenerator((err: BusinessError, generator: media.AVImageGenerator) => {
7515e41f4b71Sopenharmony_ci  if(generator != null){
7516e41f4b71Sopenharmony_ci    avImageGenerator = generator;
7517e41f4b71Sopenharmony_ci    console.info(`Succeeded in creating AVImageGenerator`);
7518e41f4b71Sopenharmony_ci    avImageGenerator.release().then(() => {
7519e41f4b71Sopenharmony_ci      console.info(`Succeeded in releasing.`);
7520e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
7521e41f4b71Sopenharmony_ci      console.error(`Failed to release, error message:${error.message}`);
7522e41f4b71Sopenharmony_ci    });
7523e41f4b71Sopenharmony_ci  } else {
7524e41f4b71Sopenharmony_ci    console.error(`Failed to creat AVImageGenerator, error message:${err.message}`);
7525e41f4b71Sopenharmony_ci  };
7526e41f4b71Sopenharmony_ci});
7527e41f4b71Sopenharmony_ci```
7528e41f4b71Sopenharmony_ci
7529e41f4b71Sopenharmony_ci## AVImageQueryOptions<sup>12+</sup>
7530e41f4b71Sopenharmony_ci
7531e41f4b71Sopenharmony_ciEnumerates the relationship between the video frame and the time at which the video thumbnail is obtained.
7532e41f4b71Sopenharmony_ci
7533e41f4b71Sopenharmony_ciThe time passed in for obtaining the thumbnail may be different from the time of the video frame for which the thumbnail is actually obtained. Therefore, you need to specify their relationship.
7534e41f4b71Sopenharmony_ci
7535e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVImageGenerator
7536e41f4b71Sopenharmony_ci
7537e41f4b71Sopenharmony_ci| Name                    | Value             | Description                                                        |
7538e41f4b71Sopenharmony_ci| ------------------------ | --------------- | ------------------------------------------------------------ |
7539e41f4b71Sopenharmony_ci| AV_IMAGE_QUERY_NEXT_SYNC       | 0   | The key frame at or next to the specified time is selected.                      |
7540e41f4b71Sopenharmony_ci| AV_IMAGE_QUERY_PREVIOUS_SYNC        | 1    | The key frame at or prior to the specified time is selected.|
7541e41f4b71Sopenharmony_ci| AV_IMAGE_QUERY_CLOSEST_SYNC        | 2    | The key frame closest to the specified time is selected.                |
7542e41f4b71Sopenharmony_ci| AV_IMAGE_QUERY_CLOSEST             | 3    | The frame (not necessarily a key frame) closest to the specified time is selected.|
7543e41f4b71Sopenharmony_ci
7544e41f4b71Sopenharmony_ci## PixelMapParams<sup>12+</sup>
7545e41f4b71Sopenharmony_ci
7546e41f4b71Sopenharmony_ciDefines the format parameters of the video thumbnail to be obtained.
7547e41f4b71Sopenharmony_ci
7548e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVImageGenerator
7549e41f4b71Sopenharmony_ci
7550e41f4b71Sopenharmony_ci| Name  | Type  | Readable| Writable| Description                                                                           |
7551e41f4b71Sopenharmony_ci|--------|--------|------|------|---------------------------------------------------------------------------------|
7552e41f4b71Sopenharmony_ci| width  | number | Yes  | Yes  | Width of the thumbnail. The value must be greater than 0 and less than or equal to the width of the original video. Otherwise, the returned thumbnail will not be scaled.|
7553e41f4b71Sopenharmony_ci| height | number | Yes  | Yes  | Height of the thumbnail. The value must be greater than 0 and less than or equal to the height of the original video. Otherwise, the returned thumbnail will not be scaled.|
7554e41f4b71Sopenharmony_ci
7555e41f4b71Sopenharmony_ci## media.createMediaSourceWithUrl<sup>12+</sup>
7556e41f4b71Sopenharmony_ci
7557e41f4b71Sopenharmony_cicreateMediaSourceWithUrl(url: string, headers?: Record\<string, string>): MediaSource
7558e41f4b71Sopenharmony_ci
7559e41f4b71Sopenharmony_ciCreates a media source for streaming media to be pre-downloaded.
7560e41f4b71Sopenharmony_ci
7561e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
7562e41f4b71Sopenharmony_ci
7563e41f4b71Sopenharmony_ci**Parameters**
7564e41f4b71Sopenharmony_ci
7565e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                |
7566e41f4b71Sopenharmony_ci| -------- | -------- | ---- | -------------------- |
7567e41f4b71Sopenharmony_ci| url | string | Yes  | - URL of the media source. The following streaming media formats are supported: HLS, HTTP-FLV, DASH, and HTTPS.<br> - FD path of the local M3U8 file. |
7568e41f4b71Sopenharmony_ci| headers | Record\<string, string> | No  | HTTP header customized for streaming media pre-download.|
7569e41f4b71Sopenharmony_ci
7570e41f4b71Sopenharmony_ci**Return value**
7571e41f4b71Sopenharmony_ci
7572e41f4b71Sopenharmony_ci| Type          | Description                                      |
7573e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------ |
7574e41f4b71Sopenharmony_ci| [MediaSource](#mediasource12) | **MediaSource** instance.|
7575e41f4b71Sopenharmony_ci
7576e41f4b71Sopenharmony_ci**Error codes**
7577e41f4b71Sopenharmony_ci
7578e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](errorcode-media.md).
7579e41f4b71Sopenharmony_ci
7580e41f4b71Sopenharmony_ci| ID| Error Message                                 |
7581e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
7582e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |
7583e41f4b71Sopenharmony_ci| 5400101  | No memory.  |
7584e41f4b71Sopenharmony_ci
7585e41f4b71Sopenharmony_ci**Example 1**
7586e41f4b71Sopenharmony_ci
7587e41f4b71Sopenharmony_ci```ts
7588e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit';
7589e41f4b71Sopenharmony_ci
7590e41f4b71Sopenharmony_cilet headers: Record<string, string> = {"User-Agent" : "User-Agent-Value"};
7591e41f4b71Sopenharmony_cilet mediaSource : media.MediaSource = media.createMediaSourceWithUrl("http://xxx",  headers);
7592e41f4b71Sopenharmony_ci```
7593e41f4b71Sopenharmony_ci
7594e41f4b71Sopenharmony_ci**Example 2**
7595e41f4b71Sopenharmony_ci
7596e41f4b71Sopenharmony_ci```ts
7597e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit';
7598e41f4b71Sopenharmony_ciimport { common } from '@kit.AbilityKit';
7599e41f4b71Sopenharmony_ciimport { resourceManager } from '@kit.LocalizationKit';
7600e41f4b71Sopenharmony_ci
7601e41f4b71Sopenharmony_cilet context = getContext(this) as common.UIAbilityContext;
7602e41f4b71Sopenharmony_cilet mgr = context.resourceManager;
7603e41f4b71Sopenharmony_cilet fileDescriptor = await mgr.getRawFd("xxx.m3u8");
7604e41f4b71Sopenharmony_ci
7605e41f4b71Sopenharmony_cilet fd:string = fileDescriptor.fd.toString();
7606e41f4b71Sopenharmony_cilet offset:string = fileDescriptor.offset.toString();
7607e41f4b71Sopenharmony_cilet length:string = fileDescriptor.length.toString();
7608e41f4b71Sopenharmony_cilet fdUrl:string = "fd://" + fd + "?offset=" + offset + "&size=" + length;
7609e41f4b71Sopenharmony_ci
7610e41f4b71Sopenharmony_cilet headers: Record<string, string> = {"User-Agent" : "User-Agent-Value"};
7611e41f4b71Sopenharmony_cilet mediaSource : media.MediaSource = media.createMediaSourceWithUrl(fdUrl,  headers);
7612e41f4b71Sopenharmony_ci
7613e41f4b71Sopenharmony_cilet mimeType : media.AVMimeTypes = media.AVMimeTypes.APPLICATION_M3U8;
7614e41f4b71Sopenharmony_cimediaSource.setMimeType(mimeType);
7615e41f4b71Sopenharmony_ci
7616e41f4b71Sopenharmony_ci```
7617e41f4b71Sopenharmony_ci
7618e41f4b71Sopenharmony_ci## MediaSource<sup>12+</sup>
7619e41f4b71Sopenharmony_ci
7620e41f4b71Sopenharmony_ciDefines the media data information, which is from [createMediaSourceWithUrl](#mediacreatemediasourcewithurl12).
7621e41f4b71Sopenharmony_ci
7622e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
7623e41f4b71Sopenharmony_ci
7624e41f4b71Sopenharmony_ci### setMimeType<sup>12+</sup>
7625e41f4b71Sopenharmony_ci
7626e41f4b71Sopenharmony_cisetMimeType(mimeType: AVMimeTypes): void
7627e41f4b71Sopenharmony_ci
7628e41f4b71Sopenharmony_ciSets the MIME type to help the player process extended media sources.
7629e41f4b71Sopenharmony_ci
7630e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
7631e41f4b71Sopenharmony_ci
7632e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
7633e41f4b71Sopenharmony_ci
7634e41f4b71Sopenharmony_ci**Parameters**
7635e41f4b71Sopenharmony_ci
7636e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                |
7637e41f4b71Sopenharmony_ci| -------- | -------- | ---- | -------------------- |
7638e41f4b71Sopenharmony_ci| mimeType | [AVMimeTypes](#mediasource12) | Yes  | MIME type.|
7639e41f4b71Sopenharmony_ci
7640e41f4b71Sopenharmony_ci## AVMimeTypes<sup>12+</sup>
7641e41f4b71Sopenharmony_ci
7642e41f4b71Sopenharmony_ciEnumerates the MIME type, which is set by using [setMimeType](#setmimetype12).
7643e41f4b71Sopenharmony_ci
7644e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
7645e41f4b71Sopenharmony_ci
7646e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
7647e41f4b71Sopenharmony_ci
7648e41f4b71Sopenharmony_ci
7649e41f4b71Sopenharmony_ci| Name      | Value  | Description                                                        |
7650e41f4b71Sopenharmony_ci| ---------- | ---- | ------------------------------------------------------------ |
7651e41f4b71Sopenharmony_ci| APPLICATION_M3U8       | application/m3u8    | Local M3U8 file.|
7652e41f4b71Sopenharmony_ci
7653e41f4b71Sopenharmony_ci
7654e41f4b71Sopenharmony_ci## PlaybackStrategy<sup>12+</sup>
7655e41f4b71Sopenharmony_ci
7656e41f4b71Sopenharmony_ciDescribes the playback strategy.
7657e41f4b71Sopenharmony_ci
7658e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.Core
7659e41f4b71Sopenharmony_ci
7660e41f4b71Sopenharmony_ci| Name | Type    | Mandatory| Description                |
7661e41f4b71Sopenharmony_ci| -------- | -------- | ---- | -------------------- |
7662e41f4b71Sopenharmony_ci| preferredWidth| number | No  | Preferred width, which is of the int type, for example, **1080**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
7663e41f4b71Sopenharmony_ci| preferredHeight | number | No  | Preferred height, which is of the int type, for example, **1920**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
7664e41f4b71Sopenharmony_ci| preferredBufferDuration | number | No | Preferred buffer duration, in seconds. The value ranges from 1 to 20.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
7665e41f4b71Sopenharmony_ci| preferredHdr | boolean | No  | Whether HDR is preferred. The value **true** means that HDR is preferred, and **false** means the opposite.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
7666e41f4b71Sopenharmony_ci| mutedMediaType | [MediaType](#mediatype8) | No| Media type for muted playback. Only **MediaType.MEDIA_TYPE_AUD** can be set.|
7667e41f4b71Sopenharmony_ci| preferredAudioLanguage | string | No| Preferred audio track language. Set this parameter based on service requirements in DASH scenarios. In non-DASH scenarios, this parameter is not invoked, and you are advised to retain the default value.|
7668e41f4b71Sopenharmony_ci| preferredSubtitleLanguage | string | No| Preferred subtitle language. Set this parameter based on service requirements in DASH scenarios. In non-DASH scenarios, this parameter is not invoked, and you are advised to retain the default value.|
7669e41f4b71Sopenharmony_ci
7670e41f4b71Sopenharmony_ci## AVScreenCaptureRecordPreset<sup>12+</sup>
7671e41f4b71Sopenharmony_ci
7672e41f4b71Sopenharmony_ciEnumerates the encoding and container formats used during screen capture.
7673e41f4b71Sopenharmony_ci
7674e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
7675e41f4b71Sopenharmony_ci
7676e41f4b71Sopenharmony_ci| Name                             | Value  | Description                                        |
7677e41f4b71Sopenharmony_ci| --------------------------------- | ---- | -------------------------------------------- |
7678e41f4b71Sopenharmony_ci| SCREEN_RECORD_PRESET_H264_AAC_MP4 | 0    | The H.264 video encoding format, AAC audio encoding format, and MP4 container format are used.|
7679e41f4b71Sopenharmony_ci| SCREEN_RECORD_PRESET_H265_AAC_MP4 | 1    | The H.265 video encoding format, AAC audio encoding format, and MP4 container format are used.|
7680e41f4b71Sopenharmony_ci
7681e41f4b71Sopenharmony_ci## AVScreenCaptureStateCode<sup>12+</sup>
7682e41f4b71Sopenharmony_ci
7683e41f4b71Sopenharmony_ciEnumerates the screen capture states used in callbacks.
7684e41f4b71Sopenharmony_ci
7685e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
7686e41f4b71Sopenharmony_ci
7687e41f4b71Sopenharmony_ci| Name                                    | Value  | Description                    |
7688e41f4b71Sopenharmony_ci| ---------------------------------------- | ---- | ------------------------ |
7689e41f4b71Sopenharmony_ci| SCREENCAPTURE_STATE_STARTED              | 0    | Screen capture is started.            |
7690e41f4b71Sopenharmony_ci| SCREENCAPTURE_STATE_CANCELED             | 1    | Screen capture is canceled.            |
7691e41f4b71Sopenharmony_ci| SCREENCAPTURE_STATE_STOPPED_BY_USER      | 2    | Screen capture is manually stopped by the user.    |
7692e41f4b71Sopenharmony_ci| SCREENCAPTURE_STATE_INTERRUPTED_BY_OTHER | 3    | Screen capture is interrupted by another screen capture.    |
7693e41f4b71Sopenharmony_ci| SCREENCAPTURE_STATE_STOPPED_BY_CALL      | 4    | Screen capture is interrupted by an incoming call.        |
7694e41f4b71Sopenharmony_ci| SCREENCAPTURE_STATE_MIC_UNAVAILABLE      | 5    | The microphone is unavailable during screen capture.|
7695e41f4b71Sopenharmony_ci| SCREENCAPTURE_STATE_MIC_MUTED_BY_USER    | 6    | The microphone is muted by the user.      |
7696e41f4b71Sopenharmony_ci| SCREENCAPTURE_STATE_MIC_UNMUTED_BY_USER  | 7    | The microphone is unmuted by the user.      |
7697e41f4b71Sopenharmony_ci| SCREENCAPTURE_STATE_ENTER_PRIVATE_SCENE  | 8    | The system enters a privacy page during screen capture.      |
7698e41f4b71Sopenharmony_ci| SCREENCAPTURE_STATE_EXIT_PRIVATE_SCENE   | 9    | The system exits a privacy page during screen capture.      |
7699e41f4b71Sopenharmony_ci| SCREENCAPTURE_STATE_STOPPED_BY_USER_SWITCHES   | 10    | Screen capture is interrupted by system user switchover.      |
7700e41f4b71Sopenharmony_ci
7701e41f4b71Sopenharmony_ci## AVScreenCaptureRecordConfig<sup>12+</sup>
7702e41f4b71Sopenharmony_ci
7703e41f4b71Sopenharmony_ciDefines the screen capture parameters.
7704e41f4b71Sopenharmony_ci
7705e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
7706e41f4b71Sopenharmony_ci
7707e41f4b71Sopenharmony_ci| Name             | Type                                                        | Mandatory| Description                                                        |
7708e41f4b71Sopenharmony_ci| ----------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
7709e41f4b71Sopenharmony_ci| fd                | number                                                       | Yes  | FD of the file output.                                          |
7710e41f4b71Sopenharmony_ci| frameWidth        | number                                                       | No  | Video width, in px. The default value varies according to the display in use.|
7711e41f4b71Sopenharmony_ci| frameHeight       | number                                                       | No  | Video height, in px. The default value varies according to the display in use.|
7712e41f4b71Sopenharmony_ci| videoBitrate      | number                                                       | No  | Video bit rate. The default value is **10000000**.                            |
7713e41f4b71Sopenharmony_ci| audioSampleRate   | number                                                       | No  | Audio sampling rate. This value is used for both internal capture and external capture (using microphones). Only **48000** (default value) and **16000** are supported.|
7714e41f4b71Sopenharmony_ci| audioChannelCount | number                                                       | No  | Number of audio channels. This value is used for both internal capture and external capture (using microphones). Only **1** and **2** (default) are supported.|
7715e41f4b71Sopenharmony_ci| audioBitrate      | number                                                       | No  | Audio bit rate. This value is used for both internal capture and external capture (using microphones). The default value is **96000**.|
7716e41f4b71Sopenharmony_ci| preset            | [AVScreenCaptureRecordPreset](#avscreencapturerecordpreset12) | No  | Encoding and container format used. The default value is **SCREEN_RECORD_PRESET_H264_AAC_MP4**.|
7717e41f4b71Sopenharmony_ci
7718e41f4b71Sopenharmony_ci## AVScreenCaptureRecorder<sup>12+</sup>
7719e41f4b71Sopenharmony_ci
7720e41f4b71Sopenharmony_ciProvides APIs to manage screen capture. Before calling any API in **AVScreenCaptureRecorder**, you must use [createAVScreenCaptureRecorder()](#mediacreateavscreencapturerecorder12) to create an **AVScreenCaptureRecorder** instance.
7721e41f4b71Sopenharmony_ci
7722e41f4b71Sopenharmony_ci### init<sup>12+</sup>
7723e41f4b71Sopenharmony_ci
7724e41f4b71Sopenharmony_ciinit(config: AVScreenCaptureRecordConfig): Promise\<void>
7725e41f4b71Sopenharmony_ci
7726e41f4b71Sopenharmony_ciInitializes screen capture and sets screen capture parameters. This API uses a promise to return the result.
7727e41f4b71Sopenharmony_ci
7728e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
7729e41f4b71Sopenharmony_ci
7730e41f4b71Sopenharmony_ci**Parameters**
7731e41f4b71Sopenharmony_ci
7732e41f4b71Sopenharmony_ci| Name| Type                                                        | Mandatory| Description                    |
7733e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------ |
7734e41f4b71Sopenharmony_ci| config | [AVScreenCaptureRecordConfig](#avscreencapturerecordconfig12) | Yes  | Screen capture parameters to set.|
7735e41f4b71Sopenharmony_ci
7736e41f4b71Sopenharmony_ci**Return value**
7737e41f4b71Sopenharmony_ci
7738e41f4b71Sopenharmony_ci| Type          | Description                               |
7739e41f4b71Sopenharmony_ci| -------------- | ----------------------------------- |
7740e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
7741e41f4b71Sopenharmony_ci
7742e41f4b71Sopenharmony_ci**Error codes**
7743e41f4b71Sopenharmony_ci
7744e41f4b71Sopenharmony_ci| ID| Error Message                                      |
7745e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------- |
7746e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. Return by promise. |
7747e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by promise.                   |
7748e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise.               |
7749e41f4b71Sopenharmony_ci
7750e41f4b71Sopenharmony_ci**Example**
7751e41f4b71Sopenharmony_ci
7752e41f4b71Sopenharmony_ci```ts
7753e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7754e41f4b71Sopenharmony_ci
7755e41f4b71Sopenharmony_cilet avCaptureConfig: media.AVScreenCaptureRecordConfig = {
7756e41f4b71Sopenharmony_ci    fd: 0, // Before passing in an FD to this parameter, the file must be created by the caller and granted with the write permissions.
7757e41f4b71Sopenharmony_ci    frameWidth: 640,
7758e41f4b71Sopenharmony_ci    frameHeight: 480
7759e41f4b71Sopenharmony_ci    // Add other parameters.
7760e41f4b71Sopenharmony_ci}
7761e41f4b71Sopenharmony_ci
7762e41f4b71Sopenharmony_ciavScreenCaptureRecorder.init(avCaptureConfig).then(() => {
7763e41f4b71Sopenharmony_ci    console.info('Succeeded in initing avScreenCaptureRecorder');
7764e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
7765e41f4b71Sopenharmony_ci    console.info('Failed to init avScreenCaptureRecorder, error: ' + err.message);
7766e41f4b71Sopenharmony_ci})
7767e41f4b71Sopenharmony_ci```
7768e41f4b71Sopenharmony_ci
7769e41f4b71Sopenharmony_ci### startRecording<sup>12+</sup>
7770e41f4b71Sopenharmony_ci
7771e41f4b71Sopenharmony_cistartRecording(): Promise\<void>
7772e41f4b71Sopenharmony_ci
7773e41f4b71Sopenharmony_ciStarts screen capture. This API uses a promise to return the result.
7774e41f4b71Sopenharmony_ci
7775e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
7776e41f4b71Sopenharmony_ci
7777e41f4b71Sopenharmony_ci**Return value**
7778e41f4b71Sopenharmony_ci
7779e41f4b71Sopenharmony_ci| Type          | Description                            |
7780e41f4b71Sopenharmony_ci| -------------- | -------------------------------- |
7781e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
7782e41f4b71Sopenharmony_ci
7783e41f4b71Sopenharmony_ci**Error codes**
7784e41f4b71Sopenharmony_ci
7785e41f4b71Sopenharmony_ci| ID| Error Message                        |
7786e41f4b71Sopenharmony_ci| -------- | -------------------------------- |
7787e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by promise.     |
7788e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise. |
7789e41f4b71Sopenharmony_ci
7790e41f4b71Sopenharmony_ci**Example**
7791e41f4b71Sopenharmony_ci
7792e41f4b71Sopenharmony_ci```ts
7793e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7794e41f4b71Sopenharmony_ci
7795e41f4b71Sopenharmony_ciavScreenCaptureRecorder.startRecording().then(() => {
7796e41f4b71Sopenharmony_ci    console.info('Succeeded in starting avScreenCaptureRecorder');
7797e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
7798e41f4b71Sopenharmony_ci    console.info('Failed to start avScreenCaptureRecorder, error: ' + err.message);
7799e41f4b71Sopenharmony_ci})
7800e41f4b71Sopenharmony_ci```
7801e41f4b71Sopenharmony_ci
7802e41f4b71Sopenharmony_ci### stopRecording<sup>12+</sup>
7803e41f4b71Sopenharmony_ci
7804e41f4b71Sopenharmony_cistopRecording(): Promise\<void>
7805e41f4b71Sopenharmony_ci
7806e41f4b71Sopenharmony_ciStops screen capture. This API uses a promise to return the result.
7807e41f4b71Sopenharmony_ci
7808e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
7809e41f4b71Sopenharmony_ci
7810e41f4b71Sopenharmony_ci**Return value**
7811e41f4b71Sopenharmony_ci
7812e41f4b71Sopenharmony_ci| Type          | Description                             |
7813e41f4b71Sopenharmony_ci| -------------- | --------------------------------- |
7814e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
7815e41f4b71Sopenharmony_ci
7816e41f4b71Sopenharmony_ci**Error codes**
7817e41f4b71Sopenharmony_ci
7818e41f4b71Sopenharmony_ci| ID| Error Message                        |
7819e41f4b71Sopenharmony_ci| -------- | -------------------------------- |
7820e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by promise.     |
7821e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise. |
7822e41f4b71Sopenharmony_ci
7823e41f4b71Sopenharmony_ci**Example**
7824e41f4b71Sopenharmony_ci
7825e41f4b71Sopenharmony_ci```ts
7826e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7827e41f4b71Sopenharmony_ci
7828e41f4b71Sopenharmony_ciavScreenCaptureRecorder.stopRecording().then(() => {
7829e41f4b71Sopenharmony_ci    console.info('Succeeded in stopping avScreenCaptureRecorder');
7830e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
7831e41f4b71Sopenharmony_ci    console.info('Failed to stop avScreenCaptureRecorder, error: ' + err.message);
7832e41f4b71Sopenharmony_ci})
7833e41f4b71Sopenharmony_ci```
7834e41f4b71Sopenharmony_ci
7835e41f4b71Sopenharmony_ci### skipPrivacyMode<sup>12+</sup>
7836e41f4b71Sopenharmony_ci
7837e41f4b71Sopenharmony_ciskipPrivacyMode(windowIDs: Array\<number>): Promise\<void>
7838e41f4b71Sopenharmony_ci
7839e41f4b71Sopenharmony_ciDuring screen capture, the application can exempt its privacy windows from security purposes. This API uses a promise to return the result.
7840e41f4b71Sopenharmony_ci
7841e41f4b71Sopenharmony_ciFor example, if a user enters a password in this application during screen capture, the application will not display a black screen.
7842e41f4b71Sopenharmony_ci
7843e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
7844e41f4b71Sopenharmony_ci
7845e41f4b71Sopenharmony_ci**Parameters**
7846e41f4b71Sopenharmony_ci
7847e41f4b71Sopenharmony_ci| Name| Type   | Mandatory| Description                                                     |
7848e41f4b71Sopenharmony_ci| ------ | ------- | ---- | --------------------------------------------------------- |
7849e41f4b71Sopenharmony_ci| windowIDs | Array\<number> | Yes  | IDs of windows that require privacy exemption, including the main window IDs and subwindow IDs. For details about how to obtain window properties, see [Window API Reference](../apis-arkui/js-apis-window.md#getwindowproperties9).|
7850e41f4b71Sopenharmony_ci
7851e41f4b71Sopenharmony_ci**Return value**
7852e41f4b71Sopenharmony_ci
7853e41f4b71Sopenharmony_ci| Type          | Description                            |
7854e41f4b71Sopenharmony_ci| -------------- | -------------------------------- |
7855e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the window IDs.|
7856e41f4b71Sopenharmony_ci
7857e41f4b71Sopenharmony_ci**Error codes**
7858e41f4b71Sopenharmony_ci
7859e41f4b71Sopenharmony_ci| ID| Error Message                        |
7860e41f4b71Sopenharmony_ci| -------- | -------------------------------- |
7861e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by promise.     |
7862e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise. |
7863e41f4b71Sopenharmony_ci
7864e41f4b71Sopenharmony_ci**Example**
7865e41f4b71Sopenharmony_ci
7866e41f4b71Sopenharmony_ci```ts
7867e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7868e41f4b71Sopenharmony_ci
7869e41f4b71Sopenharmony_cilet windowIDs = [];
7870e41f4b71Sopenharmony_ciavScreenCaptureRecorder.skipPrivacyMode(windowIDs).then(() => {
7871e41f4b71Sopenharmony_ci    console.info('Succeeded in skipping privacy mode');
7872e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
7873e41f4b71Sopenharmony_ci    console.info('Failed to skip privacy mode, error: ' + err.message);
7874e41f4b71Sopenharmony_ci})
7875e41f4b71Sopenharmony_ci```
7876e41f4b71Sopenharmony_ci
7877e41f4b71Sopenharmony_ci### setMicEnabled<sup>12+</sup>
7878e41f4b71Sopenharmony_ci
7879e41f4b71Sopenharmony_cisetMicEnabled(enable: boolean): Promise\<void>
7880e41f4b71Sopenharmony_ci
7881e41f4b71Sopenharmony_ciEnables or disables the microphone. This API uses a promise to return the result.
7882e41f4b71Sopenharmony_ci
7883e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
7884e41f4b71Sopenharmony_ci
7885e41f4b71Sopenharmony_ci**Parameters**
7886e41f4b71Sopenharmony_ci
7887e41f4b71Sopenharmony_ci| Name| Type   | Mandatory| Description                                                     |
7888e41f4b71Sopenharmony_ci| ------ | ------- | ---- | --------------------------------------------------------- |
7889e41f4b71Sopenharmony_ci| enable | boolean | Yes  | Whether to enable or disable the microphone. The value **true** means to enable the microphone, and **false** means the opposite.|
7890e41f4b71Sopenharmony_ci
7891e41f4b71Sopenharmony_ci**Return value**
7892e41f4b71Sopenharmony_ci
7893e41f4b71Sopenharmony_ci| Type          | Description                                   |
7894e41f4b71Sopenharmony_ci| -------------- | --------------------------------------- |
7895e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
7896e41f4b71Sopenharmony_ci
7897e41f4b71Sopenharmony_ci**Error codes**
7898e41f4b71Sopenharmony_ci
7899e41f4b71Sopenharmony_ci| ID| Error Message                        |
7900e41f4b71Sopenharmony_ci| -------- | -------------------------------- |
7901e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by promise.     |
7902e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise. |
7903e41f4b71Sopenharmony_ci
7904e41f4b71Sopenharmony_ci**Example**
7905e41f4b71Sopenharmony_ci
7906e41f4b71Sopenharmony_ci```ts
7907e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7908e41f4b71Sopenharmony_ci
7909e41f4b71Sopenharmony_ciavScreenCaptureRecorder.setMicEnabled(true).then(() => {
7910e41f4b71Sopenharmony_ci    console.info('Succeeded in setMicEnabled avScreenCaptureRecorder');
7911e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
7912e41f4b71Sopenharmony_ci    console.info('Failed to setMicEnabled avScreenCaptureRecorder, error: ' + err.message);
7913e41f4b71Sopenharmony_ci})
7914e41f4b71Sopenharmony_ci```
7915e41f4b71Sopenharmony_ci
7916e41f4b71Sopenharmony_ci### release<sup>12+</sup>
7917e41f4b71Sopenharmony_ci
7918e41f4b71Sopenharmony_cirelease(): Promise\<void>
7919e41f4b71Sopenharmony_ci
7920e41f4b71Sopenharmony_ciReleases this **AVScreenCaptureRecorder** instance. This API uses a promise to return the result.
7921e41f4b71Sopenharmony_ci
7922e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
7923e41f4b71Sopenharmony_ci
7924e41f4b71Sopenharmony_ci**Return value**
7925e41f4b71Sopenharmony_ci
7926e41f4b71Sopenharmony_ci| Type          | Description                             |
7927e41f4b71Sopenharmony_ci| -------------- | --------------------------------- |
7928e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
7929e41f4b71Sopenharmony_ci
7930e41f4b71Sopenharmony_ci**Error codes**
7931e41f4b71Sopenharmony_ci
7932e41f4b71Sopenharmony_ci| ID| Error Message                        |
7933e41f4b71Sopenharmony_ci| -------- | -------------------------------- |
7934e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by promise.     |
7935e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by promise. |
7936e41f4b71Sopenharmony_ci
7937e41f4b71Sopenharmony_ci**Example**
7938e41f4b71Sopenharmony_ci
7939e41f4b71Sopenharmony_ci```ts
7940e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7941e41f4b71Sopenharmony_ci
7942e41f4b71Sopenharmony_ciavScreenCaptureRecorder.release().then(() => {
7943e41f4b71Sopenharmony_ci    console.info('Succeeded in releasing avScreenCaptureRecorder');
7944e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
7945e41f4b71Sopenharmony_ci    console.info('Faile to release avScreenCaptureRecorder, error: ' + err.message);
7946e41f4b71Sopenharmony_ci})
7947e41f4b71Sopenharmony_ci```
7948e41f4b71Sopenharmony_ci
7949e41f4b71Sopenharmony_ci### on('stateChange')<sup>12+</sup>
7950e41f4b71Sopenharmony_ci
7951e41f4b71Sopenharmony_cion(type: 'stateChange', callback: Callback\<AVScreenCaptureStateCode>): void
7952e41f4b71Sopenharmony_ci
7953e41f4b71Sopenharmony_ciSubscribes to screen capture state changes. An application can subscribe to only one screen capture state change event. When the application initiates multiple subscriptions to this event, the last subscription prevails.
7954e41f4b71Sopenharmony_ci
7955e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
7956e41f4b71Sopenharmony_ci
7957e41f4b71Sopenharmony_ci**Parameters**
7958e41f4b71Sopenharmony_ci
7959e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
7960e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
7961e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'stateChange'** in this case.           |
7962e41f4b71Sopenharmony_ci| callback | function | Yes  | Callback invoked when the event is triggered. [AVScreenCaptureStateCode](#avscreencapturestatecode12) indicates the new state.|
7963e41f4b71Sopenharmony_ci
7964e41f4b71Sopenharmony_ci**Example**
7965e41f4b71Sopenharmony_ci
7966e41f4b71Sopenharmony_ci```ts
7967e41f4b71Sopenharmony_ciavScreenCaptureRecorder.on('stateChange', (state: media.AVScreenCaptureStateCode) => {
7968e41f4b71Sopenharmony_ci    console.info('avScreenCaptureRecorder stateChange to ' + state);
7969e41f4b71Sopenharmony_ci})
7970e41f4b71Sopenharmony_ci```
7971e41f4b71Sopenharmony_ci
7972e41f4b71Sopenharmony_ci### on('error')<sup>12+</sup>
7973e41f4b71Sopenharmony_ci
7974e41f4b71Sopenharmony_cion(type: 'error', callback: ErrorCallback): void
7975e41f4b71Sopenharmony_ci
7976e41f4b71Sopenharmony_ciSubscribes to AVScreenCaptureRecorder errors. You can handle the errors based on the application logic. An application can subscribe to only one AVScreenCaptureRecorder error event. When the application initiates multiple subscriptions to this event, the last subscription prevails.
7977e41f4b71Sopenharmony_ci
7978e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
7979e41f4b71Sopenharmony_ci
7980e41f4b71Sopenharmony_ci**Parameters**
7981e41f4b71Sopenharmony_ci
7982e41f4b71Sopenharmony_ci| Name  | Type         | Mandatory| Description                                   |
7983e41f4b71Sopenharmony_ci| -------- | ------------- | ---- | --------------------------------------- |
7984e41f4b71Sopenharmony_ci| type     | string        | Yes  | Event type, which is **'error'** in this case.|
7985e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes  | Callback invoked when the event is triggered.                 |
7986e41f4b71Sopenharmony_ci
7987e41f4b71Sopenharmony_ci**Error codes**
7988e41f4b71Sopenharmony_ci
7989e41f4b71Sopenharmony_ci| ID| Error Message                        |
7990e41f4b71Sopenharmony_ci| -------- | -------------------------------- |
7991e41f4b71Sopenharmony_ci| 201      | permission denied.     |
7992e41f4b71Sopenharmony_ci| 5400103  | IO error. Return by ErrorCallback. |
7993e41f4b71Sopenharmony_ci| 5400105  | Service died. Return by ErrorCallback. |
7994e41f4b71Sopenharmony_ci
7995e41f4b71Sopenharmony_ci**Example**
7996e41f4b71Sopenharmony_ci
7997e41f4b71Sopenharmony_ci```ts
7998e41f4b71Sopenharmony_ciavScreenCaptureRecorder.on('error', (err: BusinessError) => {
7999e41f4b71Sopenharmony_ci    console.error('avScreenCaptureRecorder error:' + err.message);
8000e41f4b71Sopenharmony_ci})
8001e41f4b71Sopenharmony_ci```
8002e41f4b71Sopenharmony_ci
8003e41f4b71Sopenharmony_ci### off('stateChange')<sup>12+</sup>
8004e41f4b71Sopenharmony_ci
8005e41f4b71Sopenharmony_ci off(type: 'stateChange', callback?: Callback\<AVScreenCaptureStateCode>): void
8006e41f4b71Sopenharmony_ci
8007e41f4b71Sopenharmony_ciUnsubscribes from screen capture state changes. You can specify a callback to cancel the specified subscription.
8008e41f4b71Sopenharmony_ci
8009e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
8010e41f4b71Sopenharmony_ci
8011e41f4b71Sopenharmony_ci**Parameters**
8012e41f4b71Sopenharmony_ci
8013e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                        |
8014e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ------------------------------------------------------------ |
8015e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'stateChange'** in this case.           |
8016e41f4b71Sopenharmony_ci| callback | function | No  | Callback used for unsubscription. [AVScreenCaptureStateCode](#avscreencapturestatecode12) indicates the new state. If this parameter is not specified, the last subscription is canceled.|
8017e41f4b71Sopenharmony_ci
8018e41f4b71Sopenharmony_ci**Example**
8019e41f4b71Sopenharmony_ci
8020e41f4b71Sopenharmony_ci```ts
8021e41f4b71Sopenharmony_ciavScreenCaptureRecorder.off('stateChange');
8022e41f4b71Sopenharmony_ci```
8023e41f4b71Sopenharmony_ci
8024e41f4b71Sopenharmony_ci### off('error')<sup>12+</sup>
8025e41f4b71Sopenharmony_ci
8026e41f4b71Sopenharmony_cioff(type: 'error', callback?: ErrorCallback): void
8027e41f4b71Sopenharmony_ci
8028e41f4b71Sopenharmony_ciUnsubscribes from AVScreenCaptureRecorder errors. You can specify a callback to cancel the specified subscription.
8029e41f4b71Sopenharmony_ci
8030e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture
8031e41f4b71Sopenharmony_ci
8032e41f4b71Sopenharmony_ci**Parameters**
8033e41f4b71Sopenharmony_ci
8034e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory| Description                                                      |
8035e41f4b71Sopenharmony_ci| -------- | -------- | ---- | ---------------------------------------------------------- |
8036e41f4b71Sopenharmony_ci| type     | string   | Yes  | Event type, which is **'error'** in this case.               |
8037e41f4b71Sopenharmony_ci| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | No  | Callback used for unsubscription. If this parameter is not specified, the last subscription is canceled.|
8038e41f4b71Sopenharmony_ci
8039e41f4b71Sopenharmony_ci**Example**
8040e41f4b71Sopenharmony_ci
8041e41f4b71Sopenharmony_ci```ts
8042e41f4b71Sopenharmony_ciavScreenCaptureRecorder.off('error');
8043e41f4b71Sopenharmony_ci```
8044