• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.multimedia.audio (Audio Management)
2
3The **Audio** module provides basic audio management capabilities, including audio volume and audio device management, and audio data collection and rendering.
4
5This module provides the following common audio-related functions:
6
7- [AudioManager](#audiomanager): audio management.
8- [AudioRenderer](#audiorenderer8): audio rendering, used to play Pulse Code Modulation (PCM) audio data.
9- [AudioCapturer](#audiocapturer8): audio capture, used to record PCM audio data.
10- [TonePlayer](#toneplayer9): tone player, used to manage and play Dual Tone Multi Frequency (DTMF) tones, such as dial tones and ringback tones.
11
12> **NOTE**
13>
14> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
15
16## Modules to Import
17
18```ts
19import audio from '@ohos.multimedia.audio';
20```
21
22## Constants
23
24| Name                                   | Type     | Readable | Writable| Description              |
25| --------------------------------------- | ----------| ---- | ---- | ------------------ |
26| LOCAL_NETWORK_ID<sup>9+</sup>           | string    | Yes  | No  | Network ID of the local device.<br>This is a system API.<br>**System capability**: SystemCapability.Multimedia.Audio.Device |
27| DEFAULT_VOLUME_GROUP_ID<sup>9+</sup>    | number    | Yes  | No  | Default volume group ID.<br>**System capability**: SystemCapability.Multimedia.Audio.Volume      |
28| DEFAULT_INTERRUPT_GROUP_ID<sup>9+</sup> | number    | Yes  | No  | Default audio interruption group ID.<br>**System capability**: SystemCapability.Multimedia.Audio.Interrupt      |
29
30**Example**
31
32```ts
33import audio from '@ohos.multimedia.audio';
34
35const defaultVolumeGroupId = audio.DEFAULT_VOLUME_GROUP_ID;
36const defaultInterruptGroupId = audio.DEFAULT_INTERRUPT_GROUP_ID;
37```
38
39## audio.getAudioManager
40
41getAudioManager(): AudioManager
42
43Obtains an **AudioManager** instance.
44
45**System capability**: SystemCapability.Multimedia.Audio.Core
46
47**Return value**
48
49| Type                         | Description        |
50| ----------------------------- | ------------ |
51| [AudioManager](#audiomanager) | **AudioManager** instance.|
52
53**Example**
54```ts
55import audio from '@ohos.multimedia.audio';
56
57let audioManager = audio.getAudioManager();
58```
59
60## audio.createAudioRenderer<sup>8+</sup>
61
62createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\<AudioRenderer>): void
63
64Creates an **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
65
66**System capability**: SystemCapability.Multimedia.Audio.Renderer
67
68**Parameters**
69
70| Name  | Type                                           | Mandatory| Description            |
71| -------- | ----------------------------------------------- | ---- | ---------------- |
72| options  | [AudioRendererOptions](#audiorendereroptions8)  | Yes  | Renderer configurations.    |
73| callback | AsyncCallback<[AudioRenderer](#audiorenderer8)> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the **AudioRenderer** instance obtained; otherwise, **err** is an error object.|
74
75**Example**
76
77```ts
78import audio from '@ohos.multimedia.audio';
79
80let audioStreamInfo: audio.AudioStreamInfo = {
81  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
82  channels: audio.AudioChannel.CHANNEL_1,
83  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
84  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
85}
86
87let audioRendererInfo: audio.AudioRendererInfo = {
88  usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
89  rendererFlags: 0
90}
91
92let audioRendererOptions: audio.AudioRendererOptions = {
93  streamInfo: audioStreamInfo,
94  rendererInfo: audioRendererInfo
95}
96
97audio.createAudioRenderer(audioRendererOptions,(err, data) => {
98  if (err) {
99    console.error(`AudioRenderer Created: Error: ${err}`);
100  } else {
101    console.info('AudioRenderer Created: Success: SUCCESS');
102    let audioRenderer = data;
103  }
104});
105```
106
107## audio.createAudioRenderer<sup>8+</sup>
108
109createAudioRenderer(options: AudioRendererOptions): Promise<AudioRenderer\>
110
111Creates an **AudioRenderer** instance. This API uses a promise to return the result.
112
113**System capability**: SystemCapability.Multimedia.Audio.Renderer
114
115**Parameters**
116
117| Name | Type                                          | Mandatory| Description        |
118| :------ | :--------------------------------------------- | :--- | :----------- |
119| options | [AudioRendererOptions](#audiorendereroptions8) | Yes  | Renderer configurations.|
120
121**Return value**
122
123| Type                                     | Description            |
124| ----------------------------------------- | ---------------- |
125| Promise<[AudioRenderer](#audiorenderer8)> | Promise used to return the **AudioRenderer** instance.|
126
127**Example**
128
129```ts
130import audio from '@ohos.multimedia.audio';
131import { BusinessError } from '@ohos.base';
132
133let audioStreamInfo: audio.AudioStreamInfo = {
134  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
135  channels: audio.AudioChannel.CHANNEL_1,
136  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
137  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
138}
139
140let audioRendererInfo: audio.AudioRendererInfo = {
141  usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
142  rendererFlags: 0
143}
144
145let audioRendererOptions: audio.AudioRendererOptions = {
146  streamInfo: audioStreamInfo,
147  rendererInfo: audioRendererInfo
148}
149
150let audioRenderer: audio.AudioRenderer;
151audio.createAudioRenderer(audioRendererOptions).then((data) => {
152  audioRenderer = data;
153  console.info('AudioFrameworkRenderLog: AudioRenderer Created : Success : Stream Type: SUCCESS');
154}).catch((err: BusinessError) => {
155  console.error(`AudioFrameworkRenderLog: AudioRenderer Created : ERROR : ${err}`);
156});
157```
158
159## audio.createAudioCapturer<sup>8+</sup>
160
161createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback<AudioCapturer\>): void
162
163Creates an **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
164
165**System capability**: SystemCapability.Multimedia.Audio.Capturer
166
167**Required permissions**: ohos.permission.MICROPHONE
168
169This permission is required only when [SourceType](#sourcetype) is set to **SOURCE_TYPE_MIC**.
170
171**Parameters**
172
173| Name  | Type                                           | Mandatory| Description            |
174| :------- | :---------------------------------------------- | :--- | :--------------- |
175| options  | [AudioCapturerOptions](#audiocaptureroptions8)  | Yes  | Capturer configurations.|
176| callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the **AudioCapturer** instance obtained; otherwise, **err** is an error object.|
177
178**Example**
179
180```ts
181import audio from '@ohos.multimedia.audio';
182
183let audioStreamInfo: audio.AudioStreamInfo = {
184  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
185  channels: audio.AudioChannel.CHANNEL_2,
186  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
187  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
188}
189
190let audioCapturerInfo: audio.AudioCapturerInfo = {
191  source: audio.SourceType.SOURCE_TYPE_MIC,
192  capturerFlags: 0
193}
194
195let audioCapturerOptions: audio.AudioCapturerOptions = {
196  streamInfo: audioStreamInfo,
197  capturerInfo: audioCapturerInfo
198}
199
200audio.createAudioCapturer(audioCapturerOptions, (err, data) => {
201  if (err) {
202    console.error(`AudioCapturer Created : Error: ${err}`);
203  } else {
204    console.info('AudioCapturer Created : Success : SUCCESS');
205    let audioCapturer = data;
206  }
207});
208```
209
210## audio.createAudioCapturer<sup>8+</sup>
211
212createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\>
213
214Creates an **AudioCapturer** instance. This API uses a promise to return the result.
215
216**System capability**: SystemCapability.Multimedia.Audio.Capturer
217
218**Required permissions**: ohos.permission.MICROPHONE
219
220This permission is required only when [SourceType](#sourcetype) is set to **SOURCE_TYPE_MIC**.
221
222**Parameters**
223
224| Name | Type                                          | Mandatory| Description            |
225| :------ | :--------------------------------------------- | :--- | :--------------- |
226| options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes  | Capturer configurations.|
227
228**Return value**
229
230| Type                                     | Description          |
231| ----------------------------------------- | -------------- |
232| Promise<[AudioCapturer](#audiocapturer8)> | Promise used to return the **AudioCapturer** instance.|
233
234**Example**
235
236```ts
237import audio from '@ohos.multimedia.audio';
238import { BusinessError } from '@ohos.base';
239
240let audioStreamInfo: audio.AudioStreamInfo = {
241  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
242  channels: audio.AudioChannel.CHANNEL_2,
243  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
244  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
245}
246
247let audioCapturerInfo: audio.AudioCapturerInfo = {
248  source: audio.SourceType.SOURCE_TYPE_MIC,
249  capturerFlags: 0
250}
251
252let audioCapturerOptions:audio.AudioCapturerOptions = {
253  streamInfo: audioStreamInfo,
254  capturerInfo: audioCapturerInfo
255}
256
257let audioCapturer: audio.AudioCapturer;
258audio.createAudioCapturer(audioCapturerOptions).then((data) => {
259  audioCapturer = data;
260  console.info('AudioCapturer Created : Success : Stream Type: SUCCESS');
261}).catch((err: BusinessError) => {
262  console.error(`AudioCapturer Created : ERROR : ${err}`);
263});
264```
265
266## audio.createTonePlayer<sup>9+</sup>
267
268createTonePlayer(options: AudioRendererInfo, callback: AsyncCallback&lt;TonePlayer&gt;): void
269
270Creates a **TonePlayer** instance. This API uses an asynchronous callback to return the result.
271
272**System capability**: SystemCapability.Multimedia.Audio.Tone
273
274**System API**: This is a system API.
275
276**Parameters**
277
278| Name  | Type                                            | Mandatory| Description           |
279| -------- | ----------------------------------------------- | ---- | -------------- |
280| options  | [AudioRendererInfo](#audiorendererinfo8)        | Yes  | Audio renderer information.|
281| callback | AsyncCallback<[TonePlayer](#toneplayer9)>       | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the **TonePlayer** instance obtained; otherwise, **err** is an error object.|
282
283**Example**
284
285```ts
286import audio from '@ohos.multimedia.audio';
287
288let audioRendererInfo: audio.AudioRendererInfo = {
289  usage : audio.StreamUsage.STREAM_USAGE_DTMF,
290  rendererFlags : 0
291}
292let tonePlayer: audio.TonePlayer;
293
294audio.createTonePlayer(audioRendererInfo, (err, data) => {
295  console.info(`callback call createTonePlayer: audioRendererInfo: ${audioRendererInfo}`);
296  if (err) {
297    console.error(`callback call createTonePlayer return error: ${err.message}`);
298  } else {
299    console.info(`callback call createTonePlayer return data: ${data}`);
300    tonePlayer = data;
301  }
302});
303```
304
305## audio.createTonePlayer<sup>9+</sup>
306
307createTonePlayer(options: AudioRendererInfo): Promise&lt;TonePlayer&gt;
308
309Creates a **TonePlayer** instance. This API uses a promise to return the result.
310
311**System capability**: SystemCapability.Multimedia.Audio.Tone
312
313**System API**: This is a system API.
314
315**Parameters**
316
317| Name | Type                                          | Mandatory| Description        |
318| :------ | :---------------------------------------------| :--- | :----------- |
319| options | [AudioRendererInfo](#audiorendererinfo8)      | Yes  | Audio renderer information.|
320
321**Return value**
322
323| Type                                     | Description                            |
324| ----------------------------------------- | -------------------------------- |
325| Promise<[TonePlayer](#toneplayer9)>       | Promise used to return the **TonePlayer** instance.|
326
327**Example**
328
329```ts
330import audio from '@ohos.multimedia.audio';
331
332let tonePlayer: audio.TonePlayer;
333async function createTonePlayerBefore(){
334  let audioRendererInfo: audio.AudioRendererInfo = {
335    usage : audio.StreamUsage.STREAM_USAGE_DTMF,
336    rendererFlags : 0
337  }
338  tonePlayer = await audio.createTonePlayer(audioRendererInfo);
339}
340```
341
342## AudioVolumeType
343
344Enumerates the audio stream types.
345
346**System capability**: SystemCapability.Multimedia.Audio.Volume
347
348| Name                        | Value     | Description      |
349| ---------------------------- | ------ | ---------- |
350| VOICE_CALL<sup>8+</sup>      | 0      | Audio stream for voice calls.|
351| RINGTONE                     | 2      | Audio stream for ringtones.    |
352| MEDIA                        | 3      | Audio stream for media purpose.    |
353| ALARM<sup>10+</sup>          | 4      | Audio stream for alarming.    |
354| ACCESSIBILITY<sup>10+</sup>  | 5      | Audio stream for accessibility.  |
355| VOICE_ASSISTANT<sup>8+</sup> | 9      | Audio stream for voice assistant.|
356| ULTRASONIC<sup>10+</sup>     | 10     | Audio stream for ultrasonic.<br>This is a system API.|
357| ALL<sup>9+</sup>             | 100    | All public audio streams.<br>This is a system API.|
358
359## InterruptRequestResultType<sup>9+</sup>
360
361Enumerates the result types of audio interruption requests.
362
363**System capability**: SystemCapability.Multimedia.Audio.Interrupt
364
365**System API**: This is a system API.
366
367| Name                        | Value     | Description      |
368| ---------------------------- | ------ | ---------- |
369| INTERRUPT_REQUEST_GRANT      | 0      | The audio interruption request is accepted.|
370| INTERRUPT_REQUEST_REJECT     | 1      | The audio interruption request is denied. There may be a stream with a higher priority.|
371
372## InterruptMode<sup>9+</sup>
373
374Enumerates the audio interruption modes.
375
376**System capability**: SystemCapability.Multimedia.Audio.Interrupt
377
378| Name                        | Value     | Description      |
379| ---------------------------- | ------ | ---------- |
380| SHARE_MODE                   | 0      | Shared mode.|
381| INDEPENDENT_MODE             | 1      | Independent mode.|
382
383## DeviceFlag
384
385Enumerates the audio device flags.
386
387**System capability**: SystemCapability.Multimedia.Audio.Device
388
389| Name                           |  Value    | Description                       |
390| ------------------------------- | ------ |---------------------------|
391| NONE_DEVICES_FLAG<sup>9+</sup>  | 0      | No device is available.<br>This is a system API.       |
392| OUTPUT_DEVICES_FLAG             | 1      | Output device.                    |
393| INPUT_DEVICES_FLAG              | 2      | Input device.                    |
394| ALL_DEVICES_FLAG                | 3      | All devices.                    |
395| DISTRIBUTED_OUTPUT_DEVICES_FLAG<sup>9+</sup> | 4   | Distributed output device.<br>This is a system API.   |
396| DISTRIBUTED_INPUT_DEVICES_FLAG<sup>9+</sup>  | 8   | Distributed input device.<br>This is a system API.   |
397| ALL_DISTRIBUTED_DEVICES_FLAG<sup>9+</sup>    | 12  | Distributed input and output device.<br>This is a system API.|
398
399## DeviceUsage<sup>11+</sup>
400
401Enumerates the audio device flags.
402
403**System capability**: SystemCapability.Multimedia.Audio.Device
404
405**System API**: This is a system API.
406
407| Name                           |  Value    | Description                       |
408| ------------------------------- | ------ |---------------------------|
409| MEDIA_OUTPUT_DEVICES<sup>11+</sup> | 1      | Media output device.|
410| MEDIA_INPUT_DEVICES<sup>11+</sup>  | 2      | Media input device.|
411| ALL_MEDIA_DEVICES<sup>11+</sup>    | 3      | All media devices.|
412| CALL_OUTPUT_DEVICES<sup>11+</sup>  | 4      | Call output device.|
413| CALL_INPUT_DEVICES<sup>11+</sup>   | 8      | Call input device.|
414| ALL_CALL_DEVICES<sup>11+</sup>     | 12     | All call devices.|
415
416## DeviceRole
417
418Enumerates the audio device roles.
419
420**System capability**: SystemCapability.Multimedia.Audio.Device
421
422| Name         |  Value   | Description          |
423| ------------- | ------ | -------------- |
424| INPUT_DEVICE  | 1      | Input role.|
425| OUTPUT_DEVICE | 2      | Output role.|
426
427## DeviceType
428
429Enumerates the audio device types.
430
431**System capability**: SystemCapability.Multimedia.Audio.Device
432
433| Name                | Value    | Description                                                     |
434| ---------------------| ------ | --------------------------------------------------------- |
435| INVALID              | 0      | Invalid device.                                               |
436| EARPIECE             | 1      | Earpiece.                                                   |
437| SPEAKER              | 2      | Speaker.                                                 |
438| WIRED_HEADSET        | 3      | Wired headset with a microphone.                                     |
439| WIRED_HEADPHONES     | 4      | Wired headset without microphone.                                     |
440| BLUETOOTH_SCO        | 7      | Bluetooth device using Synchronous Connection Oriented (SCO) links.     |
441| BLUETOOTH_A2DP       | 8      | Bluetooth device using Advanced Audio Distribution Profile (A2DP) links.|
442| MIC                  | 15     | Microphone.                                                 |
443| USB_HEADSET          | 22     | USB Type-C headset.                                      |
444| DEFAULT<sup>9+</sup> | 1000   | Default device type.                                           |
445
446## CommunicationDeviceType<sup>9+</sup>
447
448Enumerates the device types used for communication.
449
450**System capability**: SystemCapability.Multimedia.Audio.Communication
451
452| Name         | Value    | Description         |
453| ------------- | ------ | -------------|
454| SPEAKER       | 2      | Speaker.     |
455
456## AudioRingMode
457
458Enumerates the ringer modes.
459
460**System capability**: SystemCapability.Multimedia.Audio.Communication
461
462| Name               |  Value   | Description      |
463| ------------------- | ------ | ---------- |
464| RINGER_MODE_SILENT  | 0      | Silent mode.|
465| RINGER_MODE_VIBRATE | 1      | Vibration mode.|
466| RINGER_MODE_NORMAL  | 2      | Normal mode.|
467
468## AudioSampleFormat<sup>8+</sup>
469
470Enumerates the audio sample formats.
471
472**System capability**: SystemCapability.Multimedia.Audio.Core
473
474| Name                               |  Value   | Description                      |
475| ---------------------------------- | ------ | -------------------------- |
476| SAMPLE_FORMAT_INVALID              | -1     | Invalid format.                |
477| SAMPLE_FORMAT_U8                   | 0      | Unsigned 8-bit integer.           |
478| SAMPLE_FORMAT_S16LE                | 1      | Signed 16-bit integer, little endian.|
479| SAMPLE_FORMAT_S24LE                | 2      | Signed 24-bit integer, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
480| SAMPLE_FORMAT_S32LE                | 3      | Signed 32-bit integer, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
481| SAMPLE_FORMAT_F32LE<sup>9+</sup>   | 4      | Signed 32-bit floating point number, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
482
483## AudioErrors<sup>9+</sup>
484
485Enumerates the audio error codes.
486
487**System capability**: SystemCapability.Multimedia.Audio.Core
488
489| Name                | Value     | Description        |
490| ---------------------| --------| ----------------- |
491| ERROR_INVALID_PARAM  | 6800101 | Invalid parameter.        |
492| ERROR_NO_MEMORY      | 6800102 | Memory allocation failure.    |
493| ERROR_ILLEGAL_STATE  | 6800103 | Unsupported state.      |
494| ERROR_UNSUPPORTED    | 6800104 | Unsupported parameter value.   |
495| ERROR_TIMEOUT        | 6800105 | Processing timeout.        |
496| ERROR_STREAM_LIMIT   | 6800201 | Too many audio streams.|
497| ERROR_SYSTEM         | 6800301 | System error.    |
498
499## AudioChannel<sup>8+</sup>
500
501Enumerates the audio channels.
502
503**System capability**: SystemCapability.Multimedia.Audio.Core
504
505| Name     |  Value      | Description  |
506| --------- | -------- |------|
507| CHANNEL_1 | 0x1 << 0 | One audio channel (mono).|
508| CHANNEL_2 | 0x1 << 1 | Two audio channels (stereo).|
509| CHANNEL_3<sup>11+</sup> | 3 | Three audio channels.|
510| CHANNEL_4<sup>11+</sup> | 4 | Four audio channels.|
511| CHANNEL_5<sup>11+</sup> | 5 | Five audio channels.|
512| CHANNEL_6<sup>11+</sup> | 6 | Six audio channels.|
513| CHANNEL_7<sup>11+</sup> | 7 | Seven audio channels.|
514| CHANNEL_8<sup>11+</sup> | 8 | Eight audio channels.|
515| CHANNEL_9<sup>11+</sup> | 9 | Nine audio channels.|
516| CHANNEL_10<sup>11+</sup> | 10 | Ten audio channels.|
517| CHANNEL_12<sup>11+</sup> | 12 | Twelve audio channels.|
518| CHANNEL_14<sup>11+</sup> | 14 | Fourteen audio channels.|
519| CHANNEL_16<sup>11+</sup> | 16 | Sixteen audio channels.|
520
521## AudioSamplingRate<sup>8+</sup>
522
523Enumerates the audio sampling rates. The sampling rates supported vary according to the device in use.
524
525**System capability**: SystemCapability.Multimedia.Audio.Core
526
527| Name             |  Value   | Description           |
528| ----------------- | ------ | --------------- |
529| SAMPLE_RATE_8000  | 8000   | The sampling rate is 8000. |
530| SAMPLE_RATE_11025 | 11025  | The sampling rate is 11025.|
531| SAMPLE_RATE_12000 | 12000  | The sampling rate is 12000.|
532| SAMPLE_RATE_16000 | 16000  | The sampling rate is 16000.|
533| SAMPLE_RATE_22050 | 22050  | The sampling rate is 22050.|
534| SAMPLE_RATE_24000 | 24000  | The sampling rate is 24000.|
535| SAMPLE_RATE_32000 | 32000  | The sampling rate is 32000.|
536| SAMPLE_RATE_44100 | 44100  | The sampling rate is 44100.|
537| SAMPLE_RATE_48000 | 48000  | The sampling rate is 48000.|
538| SAMPLE_RATE_64000 | 64000  | The sampling rate is 64000.|
539| SAMPLE_RATE_96000 | 96000  | The sampling rate is 96000.|
540
541## AudioEncodingType<sup>8+</sup>
542
543Enumerates the audio encoding types.
544
545**System capability**: SystemCapability.Multimedia.Audio.Core
546
547| Name                 |  Value   | Description     |
548| --------------------- | ------ | --------- |
549| ENCODING_TYPE_INVALID | -1     | Invalid.   |
550| ENCODING_TYPE_RAW     | 0      | PCM encoding.|
551
552## AudioChannelLayout<sup>11+</sup>
553
554Enumerates the audio channel layouts.
555
556**System capability**: SystemCapability.Multimedia.Audio.Core
557
558| Name                           |  Value             | Description                                         |
559| ------------------------------ | ---------------- | --------------------------------------------- |
560| CH_LAYOUT_UNKNOWN              | 0x0              | Unknown.                                |
561| CH_LAYOUT_MONO                 | 0x4              | Mono.                              |
562| CH_LAYOUT_STEREO               | 0x3              | Stereo.                            |
563| CH_LAYOUT_STEREO_DOWNMIX       | 0x60000000       | Stereo downmix.                    |
564| CH_LAYOUT_2POINT1              | 0xB              | 2.1.                               |
565| CH_LAYOUT_3POINT0              | 0x103            | 3.0.                               |
566| CH_LAYOUT_SURROUND             | 0x7              | Surround.                          |
567| CH_LAYOUT_3POINT1              | 0xF              | 3.1.                               |
568| CH_LAYOUT_4POINT0              | 0x107            | 4.0.                               |
569| CH_LAYOUT_QUAD                 | 0x33             | Quad.                              |
570| CH_LAYOUT_QUAD_SIDE            | 0x603            | Quad side.                         |
571| CH_LAYOUT_2POINT0POINT2        | 0x3000000003     | 2.0.2.                             |
572| CH_LAYOUT_AMB_ORDER1_ACN_N3D   | 0x100000000001   | First-order FOA file in ACN_N3D (ITU standards). |
573| CH_LAYOUT_AMB_ORDER1_ACN_SN3D  | 0x100000001001   | First-order FOA file in ACN_SN3D (ITU standards).|
574| CH_LAYOUT_AMB_ORDER1_FUMA      | 0x100000000101   | First-order FOA file in FUMA (ITU standards).    |
575| CH_LAYOUT_4POINT1              | 0x10F            | 4.1.                                 |
576| CH_LAYOUT_5POINT0              | 0x607            | 5.0.                               |
577| CH_LAYOUT_5POINT0_BACK         | 0x37             | 5.0 back.                          |
578| CH_LAYOUT_2POINT1POINT2        | 0x300000000B     | 2.1.2.                             |
579| CH_LAYOUT_3POINT0POINT2        | 0x3000000007     | 3.0.2.                             |
580| CH_LAYOUT_5POINT1              | 0x60F            | 5.1.                               |
581| CH_LAYOUT_5POINT1_BACK         | 0x3F             | 5.1 back.                          |
582| CH_LAYOUT_6POINT0              | 0x707            | 6.0.                               |
583| CH_LAYOUT_HEXAGONAL            | 0x137            | Hexagonal.                         |
584| CH_LAYOUT_3POINT1POINT2        | 0x500F           | 3.1.2.                             |
585| CH_LAYOUT_6POINT0_FRONT        | 0x6C3            | 6.0 front.                         |
586| CH_LAYOUT_6POINT1              | 0x70F            | 6.1.                               |
587| CH_LAYOUT_6POINT1_BACK         | 0x13F            | 6.1 back.                          |
588| CH_LAYOUT_6POINT1_FRONT        | 0x6CB            | 6.1 front.                         |
589| CH_LAYOUT_7POINT0              | 0x637            | 7.0.                               |
590| CH_LAYOUT_7POINT0_FRONT        | 0x6C7            | 7.0 front.                         |
591| CH_LAYOUT_7POINT1              | 0x63F            | 7.1.                               |
592| CH_LAYOUT_OCTAGONAL            | 0x737            | Octagonal.                         |
593| CH_LAYOUT_5POINT1POINT2        | 0x300000060F     | 5.1.2.                             |
594| CH_LAYOUT_7POINT1_WIDE         | 0x6CF            | 7.1 wide.                          |
595| CH_LAYOUT_7POINT1_WIDE_BACK    | 0xFF             | 7.1 wide back.                     |
596| CH_LAYOUT_AMB_ORDER2_ACN_N3D   | 0x100000000002   | Second-order HOA file in ACN_N3D (ITU standards). |
597| CH_LAYOUT_AMB_ORDER2_ACN_SN3D  | 0x100000001002   | Second-order HOA file in ACN_SN3D (ITU standards).|
598| CH_LAYOUT_AMB_ORDER2_FUMA      | 0x100000000102   | Second-order HOA file in FUMA (ITU standards).    |
599| CH_LAYOUT_5POINT1POINT4        | 0x2D60F          | 5.1.4.                             |
600| CH_LAYOUT_7POINT1POINT2        | 0x300000063F     | 7.1.2.                             |
601| CH_LAYOUT_7POINT1POINT4        | 0x2D63F          | 7.1.4.                             |
602| CH_LAYOUT_10POINT2             | 0x180005737      | 10.2.                              |
603| CH_LAYOUT_9POINT1POINT4        | 0x18002D63F      | 9.1.4.                             |
604| CH_LAYOUT_9POINT1POINT6        | 0x318002D63F     | 9.1.6.                             |
605| CH_LAYOUT_HEXADECAGONAL        | 0x18003F737      | Hexadecagonal.                     |
606| CH_LAYOUT_AMB_ORDER3_ACN_N3D   | 0x100000000003   | Third-order HOA file in ACN_N3D (ITU standards). |
607| CH_LAYOUT_AMB_ORDER3_ACN_SN3D  | 0x100000001003   | Third-order HOA file in ACN_SN3D (ITU standards).|
608| CH_LAYOUT_AMB_ORDER3_FUMA      | 0x100000000103   | Third-order HOA file in FUMA (ITU standards).    |
609
610## ContentType<sup>(deprecated)</sup>
611
612Enumerates the audio content types.
613
614> **NOTE**
615>
616> This API is supported since API version 7 and deprecated since API version 10. You are advised to use [StreamUsage](#streamusage) instead.
617
618**System capability**: SystemCapability.Multimedia.Audio.Core
619
620| Name                              |  Value   | Description      |
621| ---------------------------------- | ------ | ---------- |
622| CONTENT_TYPE_UNKNOWN               | 0      | Unknown content.|
623| CONTENT_TYPE_SPEECH                | 1      | Speech.    |
624| CONTENT_TYPE_MUSIC                 | 2      | Music.    |
625| CONTENT_TYPE_MOVIE                 | 3      | Movie.    |
626| CONTENT_TYPE_SONIFICATION          | 4      | Notification tone.  |
627| CONTENT_TYPE_RINGTONE<sup>8+</sup> | 5      | Ringtone.    |
628
629## StreamUsage
630
631Enumerates the audio stream usage.
632
633**System capability**: SystemCapability.Multimedia.Audio.Core
634
635| Name                                     |  Value   | Description                                                                                                                                         |
636| ------------------------------------------| ------ |---------------------------------------------------------------------------------------------------------------------------------------------|
637| STREAM_USAGE_UNKNOWN                      | 0      | Unknown usage.                                                                                                                                      |
638| STREAM_USAGE_MEDIA<sup>(deprecated)</sup>                        | 1      | Media.<br>This enumerated value is supported since API version 7 and deprecated since API version 10. You are advised to use **STREAM_USAGE_MUSIC**, **STREAM_USAGE_MOVIE**, **STREAM_USAGE_GAME**, or **STREAM_USAGE_AUDIOBOOK** instead.|
639| STREAM_USAGE_MUSIC<sup>10+</sup>          | 1      | Music.                                                                                                                                        |
640| STREAM_USAGE_VOICE_COMMUNICATION          | 2      | Voice communication.                                                                                                                                      |
641| STREAM_USAGE_VOICE_ASSISTANT<sup>9+</sup> | 3      | Voice assistant.                                                                                                                                      |
642| STREAM_USAGE_ALARM<sup>10+</sup>          | 4      | Alarming.                                                                                                                                        |
643| STREAM_USAGE_VOICE_MESSAGE<sup>10+</sup>  | 5      | Voice message.                                                                                                                                      |
644| STREAM_USAGE_NOTIFICATION_RINGTONE<sup>(deprecated)</sup>        | 6      | Notification tone.<br>This enumerated value is deprecated since API version 10. You are advised to use **STREAM_USAGE_RINGTONE** instead.                                                                         |
645| STREAM_USAGE_RINGTONE<sup>10+</sup>       | 6      | Ringtone.                                                                                                                                        |
646| STREAM_USAGE_NOTIFICATION<sup>10+</sup>   | 7      | Notification.                                                                                                                                        |
647| STREAM_USAGE_ACCESSIBILITY<sup>10+</sup>  | 8      | Accessibility.                                                                                                                                       |
648| STREAM_USAGE_SYSTEM<sup>10+</sup>         | 9      | System tone (such as screen lock sound effect or key tone).<br>This is a system API.                                                                                                              |
649| STREAM_USAGE_MOVIE<sup>10+</sup>          | 10     | Movie or video.                                                                                                                                     |
650| STREAM_USAGE_GAME<sup>10+</sup>           | 11     | Gaming.                                                                                                                                      |
651| STREAM_USAGE_AUDIOBOOK<sup>10+</sup>      | 12     | Audiobook.                                                                                                                                      |
652| STREAM_USAGE_NAVIGATION<sup>10+</sup>     | 13     | Navigation.                                                                                                                                        |
653| STREAM_USAGE_DTMF<sup>10+</sup>           | 14     | Dial tone.<br>This is a system API.                                                                                                                         |
654| STREAM_USAGE_ENFORCED_TONE<sup>10+</sup>  | 15     | Forcible tone (such as camera shutter sound effect).<br>This is a system API.                                                                                                                 |
655| STREAM_USAGE_ULTRASONIC<sup>10+</sup>     | 16     | Ultrasonic (currently provided only for MSDP).<br>This is a system API.                                                                                                           |
656
657
658## InterruptRequestType<sup>9+</sup>
659
660Enumerates the audio interruption request types.
661
662**System API**: This is a system API.
663
664**System capability**: SystemCapability.Multimedia.Audio.Interrupt
665
666| Name                              |  Value    | Description                      |
667| ---------------------------------- | ------ | ------------------------- |
668| INTERRUPT_REQUEST_TYPE_DEFAULT     | 0      |  Default type, which can be used to interrupt audio requests. |
669
670## AudioState<sup>8+</sup>
671
672Enumerates the audio states.
673
674**System capability**: SystemCapability.Multimedia.Audio.Core
675
676| Name          | Value    | Description            |
677| -------------- | ------ | ---------------- |
678| STATE_INVALID  | -1     | Invalid state.      |
679| STATE_NEW      | 0      | Creating instance state.|
680| STATE_PREPARED | 1      | Prepared.      |
681| STATE_RUNNING  | 2      | Running.|
682| STATE_STOPPED  | 3      | Stopped.      |
683| STATE_RELEASED | 4      | Released.      |
684| STATE_PAUSED   | 5      | Paused.      |
685
686## AudioEffectMode<sup>10+</sup>
687
688Enumerates the audio effect modes.
689
690**System capability**: SystemCapability.Multimedia.Audio.Renderer
691
692| Name              | Value    | Description      |
693| ------------------ | ------ | ---------- |
694| EFFECT_NONE        | 0      | The audio effect is disabled.|
695| EFFECT_DEFAULT     | 1      | The default audio effect is used.|
696
697## AudioRendererRate<sup>8+</sup>
698
699Enumerates the audio renderer rates.
700
701**System capability**: SystemCapability.Multimedia.Audio.Renderer
702
703| Name              | Value    | Description      |
704| ------------------ | ------ | ---------- |
705| RENDER_RATE_NORMAL | 0      | Normal rate.|
706| RENDER_RATE_DOUBLE | 1      | Double rate.   |
707| RENDER_RATE_HALF   | 2      | Half rate. |
708
709## InterruptType
710
711Enumerates the audio interruption types.
712
713**System capability**: SystemCapability.Multimedia.Audio.Renderer
714
715| Name                |  Value    | Description                  |
716| -------------------- | ------ | ---------------------- |
717| INTERRUPT_TYPE_BEGIN | 1      | Audio interruption started.|
718| INTERRUPT_TYPE_END   | 2      | Audio interruption ended.|
719
720## InterruptForceType<sup>9+</sup>
721
722Enumerates the types of force that causes audio interruption.
723
724**System capability**: SystemCapability.Multimedia.Audio.Renderer
725
726| Name           |  Value   | Description                                |
727| --------------- | ------ | ------------------------------------ |
728| INTERRUPT_FORCE | 0      | Forced action taken by the system.  |
729| INTERRUPT_SHARE | 1      | The application can choose to take action or ignore.|
730
731## InterruptHint
732
733Enumerates the hints provided along with audio interruption.
734
735**System capability**: SystemCapability.Multimedia.Audio.Renderer
736
737| Name                              |  Value    | Description                                        |
738| ---------------------------------- | ------ | -------------------------------------------- |
739| INTERRUPT_HINT_NONE<sup>8+</sup>   | 0      | None.                                    |
740| INTERRUPT_HINT_RESUME              | 1      | Resume the playback.                              |
741| INTERRUPT_HINT_PAUSE               | 2      | Paused/Pause the playback.                              |
742| INTERRUPT_HINT_STOP                | 3      | Stopped/Stop the playback.                              |
743| INTERRUPT_HINT_DUCK                | 4      | Ducked the playback. (In ducking, the audio volume is reduced, but not silenced.)|
744| INTERRUPT_HINT_UNDUCK<sup>8+</sup> | 5      | Unducked the playback.                              |
745
746## AudioStreamInfo<sup>8+</sup>
747
748Describes audio stream information.
749
750**System capability**: SystemCapability.Multimedia.Audio.Core
751
752| Name        | Type                                              | Mandatory| Description              |
753| ------------ | ------------------------------------------------- | ---- | ------------------ |
754| samplingRate | [AudioSamplingRate](#audiosamplingrate8)          | Yes  | Audio sampling rate.|
755| channels     | [AudioChannel](#audiochannel8)                    | Yes  | Number of audio channels.|
756| sampleFormat | [AudioSampleFormat](#audiosampleformat8)          | Yes  | Audio sample format.    |
757| encodingType | [AudioEncodingType](#audioencodingtype8)          | Yes  | Audio encoding type.    |
758| channelLayout<sup>11+</sup> | [AudioChannelLayout](#audiochannellayout11)  | No  | Audio channel layout.    |
759
760## AudioRendererInfo<sup>8+</sup>
761
762Describes audio renderer information.
763
764**System capability**: SystemCapability.Multimedia.Audio.Core
765
766| Name         | Type                       | Mandatory | Description            |
767| ------------- | --------------------------- | ---- | ---------------- |
768| content       | [ContentType](#contenttypedeprecated) | No  | Audio content type.<br>This parameter is mandatory in API versions 8 and 9 and optional since API version 10.|
769| usage         | [StreamUsage](#streamusage) | Yes  | Audio stream usage.|
770| rendererFlags | number                      | Yes  | Audio renderer flags.<br>The value **0** means a common audio renderer, and **1** means a low-latency audio renderer. Currently, the ArkTS APIs do not support the low-latency audio renderer.|
771
772## InterruptResult<sup>9+</sup>
773
774Describes the audio interruption result.
775
776**System capability**: SystemCapability.Multimedia.Audio.Interrupt
777
778**System API**: This is a system API.
779
780| Name         | Type                                                           | Mandatory| Description            |
781| --------------| -------------------------------------------------------------- | ---- | ---------------- |
782| requestResult | [InterruptRequestResultType](#interruptrequestresulttype9)     | Yes  | Audio interruption request type.|
783| interruptNode | number                                                         | Yes  | Node to interrupt.|
784
785## AudioRendererOptions<sup>8+</sup>
786
787Describes audio renderer configurations.
788
789| Name        | Type                                    | Mandatory | Description            |
790| ------------ | ---------------------------------------- | ---- | ---------------- |
791| streamInfo   | [AudioStreamInfo](#audiostreaminfo8)     | Yes  | Audio stream information.<br>**System capability**: SystemCapability.Multimedia.Audio.Renderer|
792| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes  | Audio renderer information.<br>**System capability**: SystemCapability.Multimedia.Audio.Renderer|
793| privacyType<sup>10+</sup> | [AudioPrivacyType](#audioprivacytype) | No| Whether the audio stream can be recorded by other applications. The default value is **0**.<br>**System capability**: SystemCapability.Multimedia.Audio.PlaybackCapture|
794
795## AudioPrivacyType<sup>10+</sup><a name="audioprivacytype"></a>
796
797Enumerates whether an audio stream can be recorded by other applications.
798
799**System capability**: SystemCapability.Multimedia.Audio.PlaybackCapture
800
801| Name                | Value  | Description                            |
802| -------------------- | ---- | -------------------------------- |
803| PRIVACY_TYPE_PUBLIC  | 0    | The audio stream can be recorded by other applications.  |
804| PRIVACY_TYPE_PRIVATE | 1    | The audio stream cannot be recorded by other applications.|
805
806## InterruptEvent<sup>9+</sup>
807
808Describes the interruption event received by the application when playback is interrupted.
809
810**System capability**: SystemCapability.Multimedia.Audio.Renderer
811
812| Name     | Type                                      |Mandatory  | Description                                |
813| --------- | ------------------------------------------ | ---- | ------------------------------------ |
814| eventType | [InterruptType](#interrupttype)            | Yes  | Whether the interruption has started or ended.        |
815| forceType | [InterruptForceType](#interruptforcetype9) | Yes  | Whether the interruption is taken by the system or to be taken by the application.|
816| hintType  | [InterruptHint](#interrupthint)            | Yes  | Hint provided along the interruption.                          |
817
818## VolumeEvent<sup>9+</sup>
819
820Describes the event received by the application when the volume is changed.
821
822**System capability**: SystemCapability.Multimedia.Audio.Volume
823
824| Name      | Type                               | Mandatory  | Description                                       |
825| ---------- | ----------------------------------- | ---- |-------------------------------------------|
826| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                   |
827| volume     | number                              | Yes  | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**. |
828| updateUi   | boolean                             | Yes  | Whether the volume change is shown on the UI. The value **true** means that the volume change is shown, and **false** means the opposite.            |
829| volumeGroupId | number                           | Yes  | Volume group ID. It can be used as an input parameter of **getGroupManager**.<br>This is a system API.|
830| networkId  | string                              | Yes  | Network ID.<br>This is a system API.                      |
831
832## MicStateChangeEvent<sup>9+</sup>
833
834Describes the event received by the application when the microphone mute status changes.
835
836**System capability**: SystemCapability.Multimedia.Audio.Device
837
838| Name      | Type                               | Mandatory| Description                                                    |
839| ---------- | ----------------------------------- | ---- |-------------------------------------------------------- |
840| mute | boolean | Yes  | Mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.         |
841
842## ConnectType<sup>9+</sup>
843
844Enumerates the types of connected devices.
845
846**System API**: This is a system API.
847
848**System capability**: SystemCapability.Multimedia.Audio.Volume
849
850| Name                           |  Value    | Description                  |
851| :------------------------------ | :----- | :--------------------- |
852| CONNECT_TYPE_LOCAL              | 1      | Local device.        |
853| CONNECT_TYPE_DISTRIBUTED        | 2      | Distributed device.           |
854
855## VolumeGroupInfos<sup>9+</sup>
856
857Describes the volume group information. The value is an array of [VolumeGroupInfo](#volumegroupinfo9) and is read-only.
858
859**System API**: This is a system API.
860
861**System capability**: SystemCapability.Multimedia.Audio.Volume
862
863## VolumeGroupInfo<sup>9+</sup>
864
865Describes the volume group information.
866
867**System API**: This is a system API.
868
869**System capability**: SystemCapability.Multimedia.Audio.Volume
870
871| Name                       | Type                      | Readable| Writable| Description      |
872| -------------------------- | -------------------------- | ---- | ---- | ---------- |
873| networkId<sup>9+</sup>     | string                     | Yes  | No  | Network ID of the device. |
874| groupId<sup>9+</sup>       | number                     | Yes  | No  | Group ID of the device.|
875| mappingId<sup>9+</sup>     | number                     | Yes  | No  | Group mapping ID.|
876| groupName<sup>9+</sup>     | string                     | Yes  | No  | Group name.|
877| type<sup>9+</sup>          | [ConnectType](#connecttype9)| Yes  | No  | Type of the connected device.|
878
879## DeviceChangeAction
880
881Describes the device connection status and device information.
882
883**System capability**: SystemCapability.Multimedia.Audio.Device
884
885| Name             | Type                                             | Mandatory| Description              |
886| :---------------- | :------------------------------------------------ | :--- | :----------------- |
887| type              | [DeviceChangeType](#devicechangetype)             | Yes  | Device connection status.|
888| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes  | Device information.        |
889
890## ChannelBlendMode<sup>11+</sup>
891
892Enumerates the audio channel blending modes.
893
894**System capability**: SystemCapability.Multimedia.Audio.Core
895
896| Name                                        |  Value    | Description                  |
897| :------------------------------------------- | :----- | :--------------------- |
898| MODE_DEFAULT | 0     | The audio channels are not blended. |
899| MODE_BLEND_LR | 1      | The left and right audio channels are blended.|
900| MODE_ALL_LEFT | 2      | The left channel is replicated into the right channel. |
901| MODE_ALL_RIGHT | 3 | The right channel is replicated into the left channel.|
902
903## AudioStreamDeviceChangeReason<sup>11+</sup>
904
905Enumerates the reasons for audio stream device changes.
906
907**System capability**: SystemCapability.Multimedia.Audio.Device
908
909| Name                                       |  Value    | Description             |
910|:------------------------------------------| :----- |:----------------|
911| REASON_UNKNOWN | 0 | Unknown reason.          |
912| REASON_NEW_DEVICE_AVAILABLE | 1 | A new device is available.        |
913| REASON_OLD_DEVICE_UNAVAILABLE | 2 | The old device is unavailable. When this reason is reported, the application should consider pausing audio playback.|
914| REASON_OVERRODE | 3 | Forcibly selected.|
915
916## AudioStreamDeviceChangeInfo<sup>11+</sup>
917
918Describes the event received by the application when the audio stream device changes.
919
920**System capability**: SystemCapability.Multimedia.Audio.Device
921
922| Name             | Type                                                               | Mandatory| Description              |
923| :---------------- |:------------------------------------------------------------------| :--- | :----------------- |
924| devices              | [AudioDeviceDescriptors](#audiodevicedescriptors)                 | Yes  | Device information.|
925| changeReason | [AudioStreamDeviceChangeReason](#audiostreamdevicechangereason11) | Yes  | Reason for the change.|
926
927## DeviceChangeType
928
929Enumerates the device connection statuses.
930
931**System capability**: SystemCapability.Multimedia.Audio.Device
932
933| Name      | Value  | Description          |
934| :--------- | :--- | :------------- |
935| CONNECT    | 0    | Connected.    |
936| DISCONNECT | 1    | Disconnected.|
937
938## AudioCapturerOptions<sup>8+</sup>
939
940Describes audio capturer configurations.
941
942| Name                               | Type                                                     | Mandatory| Description                                                        |
943| ----------------------------------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ |
944| streamInfo                          | [AudioStreamInfo](#audiostreaminfo8)                      | Yes  | Audio stream information.<br>**System capability**: SystemCapability.Multimedia.Audio.Capturer  |
945| capturerInfo                        | [AudioCapturerInfo](#audiocapturerinfo)                   | Yes  | Audio capturer information.<br>**System capability**: SystemCapability.Multimedia.Audio.Capturer       |
946| playbackCaptureConfig<sup>10+</sup> | [AudioPlaybackCaptureConfig](#audioplaybackcaptureconfig) | No  | Configuration of internal audio recording.<br>**System capability**: SystemCapability.Multimedia.Audio.PlaybackCapture|
947
948## AudioCapturerInfo<sup>8+</sup><a name="audiocapturerinfo"></a>
949
950Describes audio capturer information.
951
952**System capability**: SystemCapability.Multimedia.Audio.Core
953
954| Name         | Type                     | Mandatory| Description            |
955| :------------ | :------------------------ | :--- | :--------------- |
956| source        | [SourceType](#sourcetype) | Yes  | Audio source type.      |
957| capturerFlags | number                    | Yes  | Audio capturer flags.<br>The value **0** means a common audio capturer, and **1** means a low-latency audio capturer. Currently, the ArkTS APIs do not support the low-latency audio capturer.|
958
959## SourceType<sup>8+</sup><a name="sourcetype"></a>
960
961Enumerates the audio source types.
962
963| Name                                        |  Value    | Description                  |
964| :------------------------------------------- | :----- | :--------------------- |
965| SOURCE_TYPE_INVALID                          | -1     | Invalid audio source.<br>**System capability**: SystemCapability.Multimedia.Audio.Core |
966| SOURCE_TYPE_MIC                              | 0      | Mic source.<br>**System capability**: SystemCapability.Multimedia.Audio.Core|
967| SOURCE_TYPE_VOICE_RECOGNITION<sup>9+</sup>   | 1      | Voice recognition source.<br>**System capability**: SystemCapability.Multimedia.Audio.Core |
968| SOURCE_TYPE_PLAYBACK_CAPTURE<sup>10+</sup>   | 2 | Internal audio recording source.<br>**System capability**: SystemCapability.Multimedia.Audio.PlaybackCapture|
969| SOURCE_TYPE_WAKEUP <sup>10+</sup>            | 3 | Audio recording source in voice wake-up scenarios.<br>**System capability**: SystemCapability.Multimedia.Audio.Core<br>**Required permissions**: ohos.permission.MANAGE_INTELLIGENT_VOICE <br> This is a system API.|
970| SOURCE_TYPE_VOICE_CALL<sup>11+</sup>            | 4 | Audio source in voice calls.<br>**System capability**: SystemCapability.Multimedia.Audio.Core<br>**Required permissions**: ohos.permission.RECORD_VOICE_CALL <br> This is a system API.|
971| SOURCE_TYPE_VOICE_COMMUNICATION              | 7      | Voice communication source.<br>**System capability**: SystemCapability.Multimedia.Audio.Core|
972
973## AudioPlaybackCaptureConfig<sup>10+</sup><a name="audioplaybackcaptureconfig"></a>
974
975Defines the configuration of internal audio recording.
976
977**System capability**: SystemCapability.Multimedia.Audio.PlaybackCapture
978
979| Name         | Type                                         | Mandatory| Description                            |
980| ------------- | --------------------------------------------- | ---- | -------------------------------- |
981| filterOptions | [CaptureFilterOptions](#capturefilteroptions) | Yes  | Options for filtering the played audio streams to be recorded.|
982
983## CaptureFilterOptions<sup>10+</sup><a name="capturefilteroptions"></a>
984
985Defines the options for filtering the played audio streams to be recorded.
986
987**Required permissions**: ohos.permission.CAPTURE_VOICE_DOWNLINK_AUDIO
988
989This permission is required when an application wants to record a played audio stream for which **StreamUsage** is set to **SOURCE_TYPE_VOICE_COMMUNICATION**.
990
991**System capability**: SystemCapability.Multimedia.Audio.PlaybackCapture
992
993| Name  | Type                              | Mandatory| Description                                                        |
994| ------ | ---------------------------------- | ---- | ------------------------------------------------------------ |
995| usages | Array<[StreamUsage](#streamusage)> | Yes  | [StreamUsage](#streamusage) of the audio stream to be recorded. You can specify zero or more stream usages. If the array is empty, the audio stream for which **StreamUsage** is **STREAM_USAGE_MEDIA** is recorded by default.|
996
997## AudioScene<sup>8+</sup><a name="audioscene"></a>
998
999Enumerates the audio scenes.
1000
1001**System capability**: SystemCapability.Multimedia.Audio.Communication
1002
1003| Name                  |  Value    | Description                                         |
1004| :--------------------- | :----- | :-------------------------------------------- |
1005| AUDIO_SCENE_DEFAULT    | 0      | Default audio scene.                               |
1006| AUDIO_SCENE_RINGING    | 1      | Ringing audio scene.<br>This is a system API.|
1007| AUDIO_SCENE_PHONE_CALL | 2      | Phone call audio scene.<br>This is a system API.|
1008| AUDIO_SCENE_VOICE_CHAT | 3      | Voice chat audio scene.                               |
1009
1010## VolumeAdjustType<sup>10+</sup>
1011
1012Enumerates the volume adjustment types.
1013
1014**System API**: This is a system API.
1015
1016**System capability**: SystemCapability.Multimedia.Audio.Volume
1017
1018| Name                  |  Value    | Description                                         |
1019| :--------------------- | :----- | :-------------------------------------------- |
1020| VOLUME_UP              | 0      | Adjusts the volume upwards.<br>This is a system API.  |
1021| VOLUME_DOWN            | 1      | Adjusts the volume downwards.<br>This is a system API.  |
1022
1023## AudioManager
1024
1025Implements audio volume and audio device management. Before calling any API in **AudioManager**, you must use [getAudioManager](#audiogetaudiomanager) to create an **AudioManager** instance.
1026
1027### setAudioParameter
1028
1029setAudioParameter(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
1030
1031Sets an audio parameter. This API uses an asynchronous callback to return the result.
1032
1033This API is used to extend the audio configuration based on the hardware capability. The supported audio parameters vary according to the device and can be obtained from the device manual. The example below is for reference only.
1034
1035**Required permissions**: ohos.permission.MODIFY_AUDIO_SETTINGS
1036
1037**System capability**: SystemCapability.Multimedia.Audio.Core
1038
1039**Parameters**
1040
1041| Name  | Type                     | Mandatory| Description                    |
1042| -------- | ------------------------- | ---- | ------------------------ |
1043| key      | string                    | Yes  | Key of the audio parameter to set.  |
1044| value    | string                    | Yes  | Value of the audio parameter to set.  |
1045| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
1046
1047**Example**
1048
1049```ts
1050import { BusinessError } from '@ohos.base';
1051
1052audioManager.setAudioParameter('key_example', 'value_example', (err: BusinessError) => {
1053  if (err) {
1054    console.error(`Failed to set the audio parameter. ${err}`);
1055    return;
1056  }
1057  console.info('Callback invoked to indicate a successful setting of the audio parameter.');
1058});
1059```
1060
1061### setAudioParameter
1062
1063setAudioParameter(key: string, value: string): Promise&lt;void&gt;
1064
1065Sets an audio parameter. This API uses a promise to return the result.
1066
1067This API is used to extend the audio configuration based on the hardware capability. The supported audio parameters vary according to the device and can be obtained from the device manual. The example below is for reference only.
1068
1069**Required permissions**: ohos.permission.MODIFY_AUDIO_SETTINGS
1070
1071**System capability**: SystemCapability.Multimedia.Audio.Core
1072
1073**Parameters**
1074
1075| Name| Type  | Mandatory| Description                  |
1076| ------ | ------ | ---- | ---------------------- |
1077| key    | string | Yes  | Key of the audio parameter to set.|
1078| value  | string | Yes  | Value of the audio parameter to set.|
1079
1080**Return value**
1081
1082| Type               | Description                           |
1083| ------------------- | ------------------------------- |
1084| Promise&lt;void&gt; | Promise that returns no value.|
1085
1086**Example**
1087
1088```ts
1089audioManager.setAudioParameter('key_example', 'value_example').then(() => {
1090  console.info('Promise returned to indicate a successful setting of the audio parameter.');
1091});
1092```
1093
1094### getAudioParameter
1095
1096getAudioParameter(key: string, callback: AsyncCallback&lt;string&gt;): void
1097
1098Obtains the value of an audio parameter. This API uses an asynchronous callback to return the result.
1099
1100This API is used to extend the audio configuration based on the hardware capability. The supported audio parameters vary according to the device and can be obtained from the device manual. The example below is for reference only.
1101
1102**System capability**: SystemCapability.Multimedia.Audio.Core
1103
1104**Parameters**
1105
1106| Name  | Type                       | Mandatory| Description                        |
1107| -------- | --------------------------- | ---- | ---------------------------- |
1108| key      | string                      | Yes  | Key of the audio parameter whose value is to be obtained.      |
1109| callback | AsyncCallback&lt;string&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the audio parameter value obtained; otherwise, **err** is an error object.|
1110
1111**Example**
1112
1113```ts
1114import { BusinessError } from '@ohos.base';
1115
1116audioManager.getAudioParameter('key_example', (err: BusinessError, value: string) => {
1117  if (err) {
1118    console.error(`Failed to obtain the value of the audio parameter. ${err}`);
1119    return;
1120  }
1121  console.info(`Callback invoked to indicate that the value of the audio parameter is obtained ${value}.`);
1122});
1123```
1124
1125### getAudioParameter
1126
1127getAudioParameter(key: string): Promise&lt;string&gt;
1128
1129Obtains the value of an audio parameter. This API uses a promise to return the result.
1130
1131This API is used to extend the audio configuration based on the hardware capability. The supported audio parameters vary according to the device and can be obtained from the device manual. The example below is for reference only.
1132
1133**System capability**: SystemCapability.Multimedia.Audio.Core
1134
1135**Parameters**
1136
1137| Name| Type  | Mandatory| Description                  |
1138| ------ | ------ | ---- | ---------------------- |
1139| key    | string | Yes  | Key of the audio parameter whose value is to be obtained.|
1140
1141**Return value**
1142
1143| Type                 | Description                               |
1144| --------------------- | ----------------------------------- |
1145| Promise&lt;string&gt; | Promise used to return the value of the audio parameter.|
1146
1147**Example**
1148
1149```ts
1150audioManager.getAudioParameter('key_example').then((value: string) => {
1151  console.info(`Promise returned to indicate that the value of the audio parameter is obtained ${value}.`);
1152});
1153```
1154
1155### setAudioScene<sup>8+</sup>
1156
1157setAudioScene\(scene: AudioScene, callback: AsyncCallback<void\>\): void
1158
1159Sets an audio scene. This API uses an asynchronous callback to return the result.
1160
1161**System API**: This is a system API.
1162
1163**System capability**: SystemCapability.Multimedia.Audio.Communication
1164
1165**Parameters**
1166
1167| Name  | Type                                | Mandatory| Description                |
1168| :------- | :----------------------------------- | :--- | :------------------- |
1169| scene    | <a href="#audioscene">AudioScene</a> | Yes  | Audio scene to set.      |
1170| callback | AsyncCallback<void\>                 | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
1171
1172**Example**
1173
1174```ts
1175import { BusinessError } from '@ohos.base';
1176
1177audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err: BusinessError) => {
1178  if (err) {
1179    console.error(`Failed to set the audio scene mode. ${err}`);
1180    return;
1181  }
1182  console.info('Callback invoked to indicate a successful setting of the audio scene mode.');
1183});
1184```
1185
1186### setAudioScene<sup>8+</sup>
1187
1188setAudioScene\(scene: AudioScene\): Promise<void\>
1189
1190Sets an audio scene. This API uses a promise to return the result.
1191
1192**System API**: This is a system API.
1193
1194**System capability**: SystemCapability.Multimedia.Audio.Communication
1195
1196**Parameters**
1197
1198| Name| Type                                | Mandatory| Description          |
1199| :----- | :----------------------------------- | :--- | :------------- |
1200| scene  | <a href="#audioscene">AudioScene</a> | Yes  | Audio scene to set.|
1201
1202**Return value**
1203
1204| Type          | Description                |
1205| :------------- | :------------------- |
1206| Promise<void\> | Promise that returns no value.|
1207
1208**Example**
1209
1210```ts
1211import { BusinessError } from '@ohos.base';
1212
1213audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => {
1214  console.info('Promise returned to indicate a successful setting of the audio scene mode.');
1215}).catch ((err: BusinessError) => {
1216  console.error(`Failed to set the audio scene mode ${err}`);
1217});
1218```
1219
1220### getAudioScene<sup>8+</sup>
1221
1222getAudioScene\(callback: AsyncCallback<AudioScene\>\): void
1223
1224Obtains the audio scene. This API uses an asynchronous callback to return the result.
1225
1226**System capability**: SystemCapability.Multimedia.Audio.Communication
1227
1228**Parameters**
1229
1230| Name  | Type                                               | Mandatory| Description                        |
1231| :------- | :-------------------------------------------------- | :--- | :--------------------------- |
1232| callback | AsyncCallback<<a href="#audioscene">AudioScene</a>> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the audio scene obtained; otherwise, **err** is an error object.|
1233
1234**Example**
1235
1236```ts
1237import { BusinessError } from '@ohos.base';
1238
1239audioManager.getAudioScene((err: BusinessError, value: audio.AudioScene) => {
1240  if (err) {
1241    console.error(`Failed to obtain the audio scene mode. ${err}`);
1242    return;
1243  }
1244  console.info(`Callback invoked to indicate that the audio scene mode is obtained ${value}.`);
1245});
1246```
1247
1248### getAudioScene<sup>8+</sup>
1249
1250getAudioScene\(\): Promise<AudioScene\>
1251
1252Obtains the audio scene. This API uses a promise to return the result.
1253
1254**System capability**: SystemCapability.Multimedia.Audio.Communication
1255
1256**Return value**
1257
1258| Type                                         | Description                        |
1259| :-------------------------------------------- | :--------------------------- |
1260| Promise<<a href="#audioscene">AudioScene</a>> | Promise used to return the audio scene.|
1261
1262**Example**
1263
1264```ts
1265import { BusinessError } from '@ohos.base';
1266
1267audioManager.getAudioScene().then((value: audio.AudioScene) => {
1268  console.info(`Promise returned to indicate that the audio scene mode is obtained ${value}.`);
1269}).catch ((err: BusinessError) => {
1270  console.error(`Failed to obtain the audio scene mode ${err}`);
1271});
1272```
1273
1274### getAudioSceneSync<sup>10+</sup>
1275
1276getAudioSceneSync\(\): AudioScene
1277
1278Obtains the audio scene. This API returns the result synchronously.
1279
1280**System capability**: SystemCapability.Multimedia.Audio.Communication
1281
1282**Return value**
1283
1284| Type                                         | Description                        |
1285| :-------------------------------------------- | :--------------------------- |
1286| <a href="#audioscene">AudioScene</a> | Audio scene.|
1287
1288**Example**
1289
1290```ts
1291import { BusinessError } from '@ohos.base';
1292
1293try {
1294  let value: audio.AudioScene = audioManager.getAudioSceneSync();
1295  console.info(`indicate that the audio scene mode is obtained ${value}.`);
1296} catch (err) {
1297  let error = err as BusinessError;
1298  console.error(`Failed to obtain the audio scene mode ${error}`);
1299}
1300```
1301
1302### getVolumeManager<sup>9+</sup>
1303
1304getVolumeManager(): AudioVolumeManager
1305
1306Obtains an **AudioVolumeManager** instance.
1307
1308**System capability**: SystemCapability.Multimedia.Audio.Volume
1309
1310**Return value**
1311
1312| Type                                     | Description                         |
1313|-----------------------------------------| ----------------------------- |
1314| [AudioVolumeManager](#audiovolumemanager9) | **AudioVolumeManager** instance.|
1315
1316**Example**
1317
1318```ts
1319import audio from '@ohos.multimedia.audio';
1320
1321let audioVolumeManager: audio.AudioVolumeManager = audioManager.getVolumeManager();
1322```
1323
1324### getStreamManager<sup>9+</sup>
1325
1326getStreamManager(): AudioStreamManager
1327
1328Obtains an **AudioStreamManager** instance.
1329
1330**System capability**: SystemCapability.Multimedia.Audio.Core
1331
1332**Return value**
1333
1334| Type                                        | Description                         |
1335|--------------------------------------------| ----------------------------- |
1336| [AudioStreamManager](#audiostreammanager9) | **AudioStreamManager** instance.|
1337
1338**Example**
1339
1340```ts
1341import audio from '@ohos.multimedia.audio';
1342
1343let audioStreamManager: audio.AudioStreamManager = audioManager.getStreamManager();
1344```
1345
1346### getRoutingManager<sup>9+</sup>
1347
1348getRoutingManager(): AudioRoutingManager
1349
1350Obtains an **AudioRoutingManager** instance.
1351
1352**System capability**: SystemCapability.Multimedia.Audio.Device
1353
1354**Return value**
1355
1356| Type                                      | Description                         |
1357|------------------------------------------| ----------------------------- |
1358| [AudioRoutingManager](#audioroutingmanager9) | **AudioRoutingManager** instance.|
1359
1360**Example**
1361
1362```ts
1363import audio from '@ohos.multimedia.audio';
1364
1365let audioRoutingManager: audio.AudioRoutingManager = audioManager.getRoutingManager();
1366```
1367
1368### getSpatializationManager<sup>11+</sup>
1369
1370getSpatializationManager(): AudioSpatializationManager
1371
1372Obtains an **AudioSpatializationManager** instance.
1373
1374**System API**: This is a system API.
1375
1376**System capability**: SystemCapability.Multimedia.Audio.Spatialization
1377
1378**Return value**
1379
1380| Type                                      | Description                         |
1381|------------------------------------------| ----------------------------- |
1382| [AudioSpatializationManager](#audiospatializationmanager11) | **AudioSpatializationManager** instance.|
1383
1384**Error codes**
1385
1386For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
1387
1388| ID| Error Message|
1389| ------- | --------------------------------------------|
1390| 202     | Not system App.                             |
1391
1392**Example**
1393
1394```ts
1395import audio from '@ohos.multimedia.audio';
1396let audioSpatializationManager: audio.AudioSpatializationManager = audioManager.getSpatializationManager();
1397```
1398
1399### setVolume<sup>(deprecated)</sup>
1400
1401setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&lt;void&gt;): void
1402
1403Sets the volume for a stream. This API uses an asynchronous callback to return the result.
1404
1405> **NOTE**
1406>
1407> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setVolume](#setvolume9) in **AudioVolumeGroupManager**. The substitute API is available only for system applications.
1408
1409**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
1410
1411This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
1412
1413**System capability**: SystemCapability.Multimedia.Audio.Volume
1414
1415**Parameters**
1416
1417| Name    | Type                               | Mandatory| Description                                                    |
1418| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
1419| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
1420| volume     | number                              | Yes  | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
1421| callback   | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
1422
1423**Example**
1424
1425```ts
1426import { BusinessError } from '@ohos.base';
1427
1428audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err: BusinessError) => {
1429  if (err) {
1430    console.error(`Failed to set the volume. ${err}`);
1431    return;
1432  }
1433  console.info('Callback invoked to indicate a successful volume setting.');
1434});
1435```
1436
1437### setVolume<sup>(deprecated)</sup>
1438
1439setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
1440
1441Sets the volume for a stream. This API uses a promise to return the result.
1442
1443> **NOTE**
1444>
1445> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setVolume](#setvolume9) in **AudioVolumeGroupManager**. The substitute API is available only for system applications.
1446
1447**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
1448
1449This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
1450
1451**System capability**: SystemCapability.Multimedia.Audio.Volume
1452
1453**Parameters**
1454
1455| Name    | Type                               | Mandatory| Description                                                    |
1456| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
1457| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
1458| volume     | number                              | Yes  | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
1459
1460**Return value**
1461
1462| Type               | Description                         |
1463| ------------------- | ----------------------------- |
1464| Promise&lt;void&gt; | Promise that returns no value.|
1465
1466**Example**
1467
1468```ts
1469audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
1470  console.info('Promise returned to indicate a successful volume setting.');
1471});
1472```
1473
1474### getVolume<sup>(deprecated)</sup>
1475
1476getVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
1477
1478Obtains the volume of a stream. This API uses an asynchronous callback to return the result.
1479
1480> **NOTE**
1481>
1482> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getVolume](#getvolume9) in **AudioVolumeGroupManager**.
1483
1484**System capability**: SystemCapability.Multimedia.Audio.Volume
1485
1486**Parameters**
1487
1488| Name    | Type                               | Mandatory| Description              |
1489| ---------- | ----------------------------------- | ---- | ------------------ |
1490| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
1491| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the stream volume obtained; otherwise, **err** is an error object.|
1492
1493**Example**
1494
1495```ts
1496import { BusinessError } from '@ohos.base';
1497
1498audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
1499  if (err) {
1500    console.error(`Failed to obtain the volume. ${err}`);
1501    return;
1502  }
1503  console.info('Callback invoked to indicate that the volume is obtained.');
1504});
1505```
1506
1507### getVolume<sup>(deprecated)</sup>
1508
1509getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
1510
1511Obtains the volume of a stream. This API uses a promise to return the result.
1512
1513> **NOTE**
1514>
1515> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getVolume](#getvolume9) in **AudioVolumeGroupManager**.
1516
1517**System capability**: SystemCapability.Multimedia.Audio.Volume
1518
1519**Parameters**
1520
1521| Name    | Type                               | Mandatory| Description        |
1522| ---------- | ----------------------------------- | ---- | ------------ |
1523| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
1524
1525**Return value**
1526
1527| Type                 | Description                     |
1528| --------------------- | ------------------------- |
1529| Promise&lt;number&gt; | Promise used to return the volume.|
1530
1531**Example**
1532
1533```ts
1534audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value: number) => {
1535  console.info(`Promise returned to indicate that the volume is obtained ${value} .`);
1536});
1537```
1538
1539### getMinVolume<sup>(deprecated)</sup>
1540
1541getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
1542
1543Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the result.
1544
1545> **NOTE**
1546>
1547> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMinVolume](#getminvolume9) in **AudioVolumeGroupManager**.
1548
1549**System capability**: SystemCapability.Multimedia.Audio.Volume
1550
1551**Parameters**
1552
1553| Name    | Type                               | Mandatory| Description              |
1554| ---------- | ----------------------------------- | ---- | ------------------ |
1555| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
1556| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the minimum stream volume obtained; otherwise, **err** is an error object.|
1557
1558**Example**
1559
1560```ts
1561import { BusinessError } from '@ohos.base';
1562
1563audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
1564  if (err) {
1565    console.error(`Failed to obtain the minimum volume. ${err}`);
1566    return;
1567  }
1568  console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
1569});
1570```
1571
1572### getMinVolume<sup>(deprecated)</sup>
1573
1574getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
1575
1576Obtains the minimum volume allowed for a stream. This API uses a promise to return the result.
1577
1578> **NOTE**
1579>
1580> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMinVolume](#getminvolume9) in **AudioVolumeGroupManager**.
1581
1582**System capability**: SystemCapability.Multimedia.Audio.Volume
1583
1584**Parameters**
1585
1586| Name    | Type                               | Mandatory| Description        |
1587| ---------- | ----------------------------------- | ---- | ------------ |
1588| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
1589
1590**Return value**
1591
1592| Type                 | Description                     |
1593| --------------------- | ------------------------- |
1594| Promise&lt;number&gt; | Promise used to return the minimum volume.|
1595
1596**Example**
1597
1598```ts
1599audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value: number) => {
1600  console.info(`Promised returned to indicate that the minimum volume is obtained. ${value}`);
1601});
1602```
1603
1604### getMaxVolume<sup>(deprecated)</sup>
1605
1606getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
1607
1608Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the result.
1609
1610> **NOTE**
1611>
1612> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMaxVolume](#getmaxvolume9) in **AudioVolumeGroupManager**.
1613
1614**System capability**: SystemCapability.Multimedia.Audio.Volume
1615
1616**Parameters**
1617
1618| Name    | Type                               | Mandatory| Description                  |
1619| ---------- | ----------------------------------- | ---- | ---------------------- |
1620| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.          |
1621| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the maximum stream volume obtained; otherwise, **err** is an error object.|
1622
1623**Example**
1624
1625```ts
1626import { BusinessError } from '@ohos.base';
1627
1628audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
1629  if (err) {
1630    console.error(`Failed to obtain the maximum volume. ${err}`);
1631    return;
1632  }
1633  console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`);
1634});
1635```
1636
1637### getMaxVolume<sup>(deprecated)</sup>
1638
1639getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
1640
1641Obtains the maximum volume allowed for a stream. This API uses a promise to return the result.
1642
1643> **NOTE**
1644>
1645> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMaxVolume](#getmaxvolume9) in **AudioVolumeGroupManager**.
1646
1647**System capability**: SystemCapability.Multimedia.Audio.Volume
1648
1649**Parameters**
1650
1651| Name    | Type                               | Mandatory| Description        |
1652| ---------- | ----------------------------------- | ---- | ------------ |
1653| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
1654
1655**Return value**
1656
1657| Type                 | Description                         |
1658| --------------------- | ----------------------------- |
1659| Promise&lt;number&gt; | Promise used to return the maximum volume.|
1660
1661**Example**
1662
1663```ts
1664audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data: number) => {
1665  console.info('Promised returned to indicate that the maximum volume is obtained.');
1666});
1667```
1668
1669### mute<sup>(deprecated)</sup>
1670
1671mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
1672
1673Mutes or unmutes a stream. This API uses an asynchronous callback to return the result.
1674
1675> **NOTE**
1676>
1677> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [mute](#mute9) in **AudioVolumeGroupManager**. The substitute API is available only for system applications.
1678
1679**System capability**: SystemCapability.Multimedia.Audio.Volume
1680
1681**Parameters**
1682
1683| Name    | Type                               | Mandatory| Description                                 |
1684| ---------- | ----------------------------------- | ---- | ------------------------------------- |
1685| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                         |
1686| mute       | boolean                             | Yes  | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.|
1687| callback   | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
1688
1689**Example**
1690
1691```ts
1692import { BusinessError } from '@ohos.base';
1693
1694audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err: BusinessError) => {
1695  if (err) {
1696    console.error(`Failed to mute the stream. ${err}`);
1697    return;
1698  }
1699  console.info('Callback invoked to indicate that the stream is muted.');
1700});
1701```
1702
1703### mute<sup>(deprecated)</sup>
1704
1705mute(volumeType: AudioVolumeType, mute: boolean): Promise&lt;void&gt;
1706
1707Mutes or unmutes a stream. This API uses a promise to return the result.
1708
1709> **NOTE**
1710>
1711> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [mute](#mute9) in **AudioVolumeGroupManager**. The substitute API is available only for system applications.
1712
1713**System capability**: SystemCapability.Multimedia.Audio.Volume
1714
1715**Parameters**
1716
1717| Name    | Type                               | Mandatory| Description                                 |
1718| ---------- | ----------------------------------- | ---- | ------------------------------------- |
1719| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                         |
1720| mute       | boolean                             | Yes  | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.|
1721
1722**Return value**
1723
1724| Type               | Description                         |
1725| ------------------- | ----------------------------- |
1726| Promise&lt;void&gt; | Promise that returns no value.|
1727
1728**Example**
1729
1730
1731```ts
1732audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
1733  console.info('Promise returned to indicate that the stream is muted.');
1734});
1735```
1736
1737### isMute<sup>(deprecated)</sup>
1738
1739isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
1740
1741Checks whether a stream is muted. This API uses an asynchronous callback to return the result.
1742
1743> **NOTE**
1744>
1745> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMute](#ismute9) in **AudioVolumeGroupManager**.
1746
1747**System capability**: SystemCapability.Multimedia.Audio.Volume
1748
1749**Parameters**
1750
1751| Name    | Type                               | Mandatory| Description                                           |
1752| ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
1753| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                   |
1754| callback   | AsyncCallback&lt;boolean&gt;        | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true** if the stream is muted or **false** if not muted; otherwise, **err** is an error object.|
1755
1756**Example**
1757
1758```ts
1759import { BusinessError } from '@ohos.base';
1760
1761audioManager.isMute(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => {
1762  if (err) {
1763    console.error(`Failed to obtain the mute status. ${err}`);
1764    return;
1765  }
1766  console.info(`Callback invoked to indicate that the mute status of the stream is obtained. ${value}`);
1767});
1768```
1769
1770### isMute<sup>(deprecated)</sup>
1771
1772isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
1773
1774Checks whether a stream is muted. This API uses a promise to return the result.
1775
1776> **NOTE**
1777>
1778> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMute](#ismute9) in **AudioVolumeGroupManager**.
1779
1780**System capability**: SystemCapability.Multimedia.Audio.Volume
1781
1782**Parameters**
1783
1784| Name    | Type                               | Mandatory| Description        |
1785| ---------- | ----------------------------------- | ---- | ------------ |
1786| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
1787
1788**Return value**
1789
1790| Type                  | Description                                                  |
1791| ---------------------- | ------------------------------------------------------ |
1792| Promise&lt;boolean&gt; | Promise used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite.|
1793
1794**Example**
1795
1796```ts
1797audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value: boolean) => {
1798  console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`);
1799});
1800```
1801
1802### isActive<sup>(deprecated)</sup>
1803
1804isActive(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
1805
1806Checks whether a stream is active. This API uses an asynchronous callback to return the result.
1807
1808> **NOTE**
1809>
1810> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isActive](#isactive9) in **AudioStreamManager**.
1811
1812**System capability**: SystemCapability.Multimedia.Audio.Volume
1813
1814**Parameters**
1815
1816| Name    | Type                               | Mandatory| Description                                             |
1817| ---------- | ----------------------------------- | ---- | ------------------------------------------------- |
1818| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                     |
1819| callback   | AsyncCallback&lt;boolean&gt;        | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true** if the stream is active or **false** if not active; otherwise, **err** is an error object.|
1820
1821**Example**
1822
1823```ts
1824import { BusinessError } from '@ohos.base';
1825
1826audioManager.isActive(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => {
1827  if (err) {
1828    console.error(`Failed to obtain the active status of the stream. ${err}`);
1829    return;
1830  }
1831  console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`);
1832});
1833```
1834
1835### isActive<sup>(deprecated)</sup>
1836
1837isActive(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
1838
1839Checks whether a stream is active. This API uses a promise to return the result.
1840
1841> **NOTE**
1842>
1843> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isActive](#isactive9) in **AudioStreamManager**.
1844
1845**System capability**: SystemCapability.Multimedia.Audio.Volume
1846
1847**Parameters**
1848
1849| Name    | Type                               | Mandatory| Description        |
1850| ---------- | ----------------------------------- | ---- | ------------ |
1851| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
1852
1853**Return value**
1854
1855| Type                  | Description                                                    |
1856| ---------------------- | -------------------------------------------------------- |
1857| Promise&lt;boolean&gt; | Promise used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite.|
1858
1859**Example**
1860
1861```ts
1862audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value: boolean) => {
1863  console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`);
1864});
1865```
1866
1867### setRingerMode<sup>(deprecated)</sup>
1868
1869setRingerMode(mode: AudioRingMode, callback: AsyncCallback&lt;void&gt;): void
1870
1871Sets the ringer mode. This API uses an asynchronous callback to return the result.
1872
1873> **NOTE**
1874>
1875> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setRingerMode](#setringermode9) in **AudioVolumeGroupManager**. The substitute API is available only for system applications.
1876
1877**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
1878
1879This permission is required only for muting or unmuting the ringer.
1880
1881**System capability**: SystemCapability.Multimedia.Audio.Communication
1882
1883**Parameters**
1884
1885| Name  | Type                           | Mandatory| Description                    |
1886| -------- | ------------------------------- | ---- | ------------------------ |
1887| mode     | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.          |
1888| callback | AsyncCallback&lt;void&gt;       | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
1889
1890**Example**
1891
1892```ts
1893import { BusinessError } from '@ohos.base';
1894
1895audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err: BusinessError) => {
1896  if (err) {
1897    console.error(`Failed to set the ringer mode. ${err}`);
1898    return;
1899  }
1900  console.info('Callback invoked to indicate a successful setting of the ringer mode.');
1901});
1902```
1903
1904### setRingerMode<sup>(deprecated)</sup>
1905
1906setRingerMode(mode: AudioRingMode): Promise&lt;void&gt;
1907
1908Sets the ringer mode. This API uses a promise to return the result.
1909
1910> **NOTE**
1911>
1912> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setRingerMode](#setringermode9) in **AudioVolumeGroupManager**. The substitute API is available only for system applications.
1913
1914
1915**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
1916
1917This permission is required only for muting or unmuting the ringer.
1918
1919**System capability**: SystemCapability.Multimedia.Audio.Communication
1920
1921**Parameters**
1922
1923| Name| Type                           | Mandatory| Description          |
1924| ------ | ------------------------------- | ---- | -------------- |
1925| mode   | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.|
1926
1927**Return value**
1928
1929| Type               | Description                           |
1930| ------------------- | ------------------------------- |
1931| Promise&lt;void&gt; | Promise that returns no value.|
1932
1933**Example**
1934
1935```ts
1936audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
1937  console.info('Promise returned to indicate a successful setting of the ringer mode.');
1938});
1939```
1940
1941### getRingerMode<sup>(deprecated)</sup>
1942
1943getRingerMode(callback: AsyncCallback&lt;AudioRingMode&gt;): void
1944
1945Obtains the ringer mode. This API uses an asynchronous callback to return the result.
1946
1947> **NOTE**
1948>
1949> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getRingerMode](#getringermode9) in **AudioVolumeGroupManager**.
1950
1951**System capability**: SystemCapability.Multimedia.Audio.Communication
1952
1953**Parameters**
1954
1955| Name  | Type                                                | Mandatory| Description                    |
1956| -------- | ---------------------------------------------------- | ---- | ------------------------ |
1957| callback | AsyncCallback&lt;[AudioRingMode](#audioringmode)&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the ringer mode obtained; otherwise, **err** is an error object.|
1958
1959**Example**
1960
1961```ts
1962import { BusinessError } from '@ohos.base';
1963
1964audioManager.getRingerMode((err: BusinessError, value: audio.AudioRingMode) => {
1965  if (err) {
1966    console.error(`Failed to obtain the ringer mode. ${err}`);
1967    return;
1968  }
1969  console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`);
1970});
1971```
1972
1973### getRingerMode<sup>(deprecated)</sup>
1974
1975getRingerMode(): Promise&lt;AudioRingMode&gt;
1976
1977Obtains the ringer mode. This API uses a promise to return the result.
1978
1979> **NOTE**
1980>
1981> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getRingerMode](#getringermode9) in **AudioVolumeGroupManager**.
1982
1983**System capability**: SystemCapability.Multimedia.Audio.Communication
1984
1985**Return value**
1986
1987| Type                                          | Description                           |
1988| ---------------------------------------------- | ------------------------------- |
1989| Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise used to return the ringer mode.|
1990
1991**Example**
1992
1993```ts
1994audioManager.getRingerMode().then((value: audio.AudioRingMode) => {
1995  console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`);
1996});
1997```
1998
1999### getDevices<sup>(deprecated)</sup>
2000
2001getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
2002
2003Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the result.
2004
2005> **NOTE**
2006>
2007> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getDevices](#getdevices9) in **AudioRoutingManager**.
2008
2009**System capability**: SystemCapability.Multimedia.Audio.Device
2010
2011**Parameters**
2012
2013| Name    | Type                                                        | Mandatory| Description                |
2014| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
2015| deviceFlag | [DeviceFlag](#deviceflag)                                    | Yes  | Audio device flag.    |
2016| callback   | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the audio devices obtained; otherwise, **err** is an error object.|
2017
2018**Example**
2019```ts
2020import { BusinessError } from '@ohos.base';
2021
2022audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err: BusinessError, value: audio.AudioDeviceDescriptors) => {
2023  if (err) {
2024    console.error(`Failed to obtain the device list. ${err}`);
2025    return;
2026  }
2027  console.info('Callback invoked to indicate that the device list is obtained.');
2028});
2029```
2030
2031### getDevices<sup>(deprecated)</sup>
2032
2033getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
2034
2035Obtains the audio devices with a specific flag. This API uses a promise to return the result.
2036
2037> **NOTE**
2038>
2039> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getDevices](#getdevices9) in **AudioRoutingManager**.
2040
2041**System capability**: SystemCapability.Multimedia.Audio.Device
2042
2043**Parameters**
2044
2045| Name    | Type                     | Mandatory| Description            |
2046| ---------- | ------------------------- | ---- | ---------------- |
2047| deviceFlag | [DeviceFlag](#deviceflag) | Yes  | Audio device flag.|
2048
2049**Return value**
2050
2051| Type                                                        | Description                     |
2052| ------------------------------------------------------------ | ------------------------- |
2053| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the device list.|
2054
2055**Example**
2056
2057```ts
2058audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data: audio.AudioDeviceDescriptors) => {
2059  console.info('Promise returned to indicate that the device list is obtained.');
2060});
2061```
2062
2063### setDeviceActive<sup>(deprecated)</sup>
2064
2065setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
2066
2067Sets a device to the active state. This API uses an asynchronous callback to return the result.
2068
2069> **NOTE**
2070>
2071> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCommunicationDevice](#setcommunicationdevice9) in **AudioRoutingManager**.
2072
2073**System capability**: SystemCapability.Multimedia.Audio.Device
2074
2075**Parameters**
2076
2077| Name    | Type                                 | Mandatory| Description         |
2078| ---------- | ------------------------------------- | ---- |-------------|
2079| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes  | Active audio device type.  |
2080| active     | boolean                               | Yes  | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite.    |
2081| callback   | AsyncCallback&lt;void&gt;             | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
2082
2083**Example**
2084
2085```ts
2086import { BusinessError } from '@ohos.base';
2087
2088audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err: BusinessError) => {
2089  if (err) {
2090    console.error(`Failed to set the active status of the device. ${err}`);
2091    return;
2092  }
2093  console.info('Callback invoked to indicate that the device is set to the active status.');
2094});
2095```
2096
2097### setDeviceActive<sup>(deprecated)</sup>
2098
2099setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise&lt;void&gt;
2100
2101Sets a device to the active state. This API uses a promise to return the result.
2102
2103> **NOTE**
2104>
2105> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCommunicationDevice](#setcommunicationdevice9) in **AudioRoutingManager**.
2106
2107**System capability**: SystemCapability.Multimedia.Audio.Device
2108
2109**Parameters**
2110
2111| Name    | Type                                 | Mandatory| Description              |
2112| ---------- | ------------------------------------- | ---- | ------------------ |
2113| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes  | Active audio device type.|
2114| active     | boolean                               | Yes  | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite.    |
2115
2116**Return value**
2117
2118| Type               | Description                           |
2119| ------------------- | ------------------------------- |
2120| Promise&lt;void&gt; | Promise that returns no value.|
2121
2122**Example**
2123
2124
2125```ts
2126audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => {
2127  console.info('Promise returned to indicate that the device is set to the active status.');
2128});
2129```
2130
2131### isDeviceActive<sup>(deprecated)</sup>
2132
2133isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
2134
2135Checks whether a device is active. This API uses an asynchronous callback to return the result.
2136
2137> **NOTE**
2138>
2139> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isCommunicationDeviceActive](#iscommunicationdeviceactive9) in **AudioRoutingManager**.
2140
2141**System capability**: SystemCapability.Multimedia.Audio.Device
2142
2143**Parameters**
2144
2145| Name    | Type                                 | Mandatory| Description                    |
2146| ---------- | ------------------------------------- | ---- | ------------------------ |
2147| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes  | Active audio device type.      |
2148| callback   | AsyncCallback&lt;boolean&gt;          | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true** if the stream is active or **false** if not active; otherwise, **err** is an error object.|
2149
2150**Example**
2151
2152```ts
2153import { BusinessError } from '@ohos.base';
2154
2155audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err: BusinessError, value: boolean) => {
2156  if (err) {
2157    console.error(`Failed to obtain the active status of the device. ${err}`);
2158    return;
2159  }
2160  console.info('Callback invoked to indicate that the active status of the device is obtained.');
2161});
2162```
2163
2164### isDeviceActive<sup>(deprecated)</sup>
2165
2166isDeviceActive(deviceType: ActiveDeviceType): Promise&lt;boolean&gt;
2167
2168Checks whether a device is active. This API uses a promise to return the result.
2169
2170> **NOTE**
2171>
2172> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isCommunicationDeviceActive](#iscommunicationdeviceactive9) in **AudioRoutingManager**.
2173
2174**System capability**: SystemCapability.Multimedia.Audio.Device
2175
2176**Parameters**
2177
2178| Name    | Type                                 | Mandatory| Description              |
2179| ---------- | ------------------------------------- | ---- | ------------------ |
2180| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes  | Active audio device type.|
2181
2182**Return value**
2183
2184| Type                   | Description                           |
2185| ---------------------- |---------------------------------------|
2186| Promise&lt;boolean&gt; | Promise used to return the active status of the device. The value **true** means that the device is active, and **false** means the opposite. |
2187
2188**Example**
2189
2190```ts
2191audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value: boolean) => {
2192  console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
2193});
2194```
2195
2196### setMicrophoneMute<sup>(deprecated)</sup>
2197
2198setMicrophoneMute(mute: boolean, callback: AsyncCallback&lt;void&gt;): void
2199
2200Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result.
2201
2202> **NOTE**
2203>
2204> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setMicrophoneMute](#setmicrophonemute9) in **AudioVolumeGroupManager**.
2205
2206**Required permissions**: ohos.permission.MICROPHONE
2207
2208**System capability**: SystemCapability.Multimedia.Audio.Device
2209
2210**Parameters**
2211
2212| Name  | Type                     | Mandatory| Description                                         |
2213| -------- | ------------------------- | ---- | --------------------------------------------- |
2214| mute     | boolean                   | Yes  | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
2215| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
2216
2217**Example**
2218
2219```ts
2220import { BusinessError } from '@ohos.base';
2221
2222audioManager.setMicrophoneMute(true, (err: BusinessError) => {
2223  if (err) {
2224    console.error(`Failed to mute the microphone. ${err}`);
2225    return;
2226  }
2227  console.info('Callback invoked to indicate that the microphone is muted.');
2228});
2229```
2230
2231### setMicrophoneMute<sup>(deprecated)</sup>
2232
2233setMicrophoneMute(mute: boolean): Promise&lt;void&gt;
2234
2235Mutes or unmutes the microphone. This API uses a promise to return the result.
2236
2237> **NOTE**
2238>
2239> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setMicrophoneMute](#setmicrophonemute9) in **AudioVolumeGroupManager**.
2240
2241**Required permissions**: ohos.permission.MICROPHONE
2242
2243**System capability**: SystemCapability.Multimedia.Audio.Device
2244
2245**Parameters**
2246
2247| Name| Type   | Mandatory| Description                                         |
2248| ------ | ------- | ---- | --------------------------------------------- |
2249| mute   | boolean | Yes  | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
2250
2251**Return value**
2252
2253| Type               | Description                           |
2254| ------------------- | ------------------------------- |
2255| Promise&lt;void&gt; | Promise that returns no value.|
2256
2257**Example**
2258
2259```ts
2260audioManager.setMicrophoneMute(true).then(() => {
2261  console.info('Promise returned to indicate that the microphone is muted.');
2262});
2263```
2264
2265### isMicrophoneMute<sup>(deprecated)</sup>
2266
2267isMicrophoneMute(callback: AsyncCallback&lt;boolean&gt;): void
2268
2269Checks whether the microphone is muted. This API uses an asynchronous callback to return the result.
2270
2271> **NOTE**
2272>
2273> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMicrophoneMute](#ismicrophonemute9) in **AudioVolumeGroupManager**.
2274
2275**Required permissions**: ohos.permission.MICROPHONE
2276
2277**System capability**: SystemCapability.Multimedia.Audio.Device
2278
2279**Parameters**
2280
2281| Name  | Type                        | Mandatory| Description                                                   |
2282| -------- | ---------------------------- | ---- | ------------------------------------------------------- |
2283| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true** if the microphone is muted or **false** if not muted; otherwise, **err** is an error object.|
2284
2285**Example**
2286
2287```ts
2288import { BusinessError } from '@ohos.base';
2289
2290audioManager.isMicrophoneMute((err: BusinessError, value: boolean) => {
2291  if (err) {
2292    console.error(`Failed to obtain the mute status of the microphone. ${err}`);
2293    return;
2294  }
2295  console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`);
2296});
2297```
2298
2299### isMicrophoneMute<sup>(deprecated)</sup>
2300
2301isMicrophoneMute(): Promise&lt;boolean&gt;
2302
2303Checks whether the microphone is muted. This API uses a promise to return the result.
2304
2305> **NOTE**
2306>
2307> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMicrophoneMute](#ismicrophonemute9) in **AudioVolumeGroupManager**.
2308
2309**Required permissions**: ohos.permission.MICROPHONE
2310
2311**System capability**: SystemCapability.Multimedia.Audio.Device
2312
2313**Return value**
2314
2315| Type                  | Description                                                        |
2316| ---------------------- | ------------------------------------------------------------ |
2317| Promise&lt;boolean&gt; | Promise used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.|
2318
2319**Example**
2320
2321```ts
2322audioManager.isMicrophoneMute().then((value: boolean) => {
2323  console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`);
2324});
2325```
2326
2327### on('volumeChange')<sup>(deprecated)</sup>
2328
2329on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
2330
2331> **NOTE**
2332>
2333> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [on('volumeChange')](#onvolumechange9) in **AudioVolumeManager**.
2334
2335Subscribes to system volume change events. This API uses an asynchronous callback to return the result.
2336
2337**System API**: This is a system API.
2338
2339Currently, when multiple **AudioManager** instances are used in a single process, only the subscription of the last instance takes effect, and the subscription of other instances is overwritten (even if the last instance does not initiate a subscription). Therefore, you are advised to use a single **AudioManager** instance.
2340
2341**System capability**: SystemCapability.Multimedia.Audio.Volume
2342
2343**Parameters**
2344
2345| Name  | Type                                  | Mandatory| Description                                                        |
2346| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
2347| type     | string                                 | Yes  | Event type. The event **'volumeChange'** is triggered when the system volume is changed.|
2348| callback | Callback<[VolumeEvent](#volumeevent9)> | Yes  | Callback used to return the changed volume.|
2349
2350**Example**
2351
2352```ts
2353audioManager.on('volumeChange', (volumeEvent: audio.VolumeEvent) => {
2354  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
2355  console.info(`Volume level: ${volumeEvent.volume} `);
2356  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
2357});
2358```
2359
2360### on('ringerModeChange')<sup>(deprecated)</sup>
2361
2362on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void
2363
2364Subscribes to ringer mode change events. This API uses an asynchronous callback to return the result.
2365
2366> **NOTE**
2367>
2368> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [on('ringerModeChange')](#onringermodechange9) in **AudioVolumeGroupManager**.
2369
2370**System API**: This is a system API.
2371
2372**System capability**: SystemCapability.Multimedia.Audio.Communication
2373
2374**Parameters**
2375
2376| Name  | Type                                     | Mandatory| Description                                                        |
2377| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
2378| type     | string                                    | Yes  | Event type. The event **'ringerModeChange'** is triggered when the ringer mode is changed.|
2379| callback | Callback<[AudioRingMode](#audioringmode)> | Yes  | Callback used to return the changed ringer mode.                                                  |
2380
2381**Example**
2382
2383```ts
2384audioManager.on('ringerModeChange', (ringerMode: audio.AudioRingMode) => {
2385  console.info(`Updated ringermode: ${ringerMode}`);
2386});
2387```
2388
2389### on('deviceChange')<sup>(deprecated)</sup>
2390
2391on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void
2392
2393Subscribes to audio device connection change events. This API uses an asynchronous callback to return the result.
2394
2395> **NOTE**
2396>
2397> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [on('deviceChange')](#ondevicechange9) in **AudioRoutingManager**.
2398
2399**System capability**: SystemCapability.Multimedia.Audio.Device
2400
2401**Parameters**
2402
2403| Name  | Type                                                | Mandatory| Description                                      |
2404| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
2405| type     | string                                               | Yes  | Event type. The event **'deviceChange'** is triggered when the device connection status is changed.|
2406| callback | Callback<[DeviceChangeAction](#devicechangeaction)\> | Yes  | Callback used to return the device change details.|
2407
2408**Example**
2409
2410```ts
2411audioManager.on('deviceChange', (deviceChanged: audio.DeviceChangeAction) => {
2412  console.info(`device change type : ${deviceChanged.type} `);
2413  console.info(`device descriptor size : ${deviceChanged.deviceDescriptors.length} `);
2414  console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceRole} `);
2415  console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceType} `);
2416});
2417```
2418
2419### off('deviceChange')<sup>(deprecated)</sup>
2420
2421off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void
2422
2423Unsubscribes from audio device connection change events. This API uses an asynchronous callback to return the result.
2424
2425> **NOTE**
2426>
2427> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [off('deviceChange')](#offdevicechange9) in **AudioRoutingManager**.
2428
2429**System capability**: SystemCapability.Multimedia.Audio.Device
2430
2431**Parameters**
2432
2433| Name  | Type                                               | Mandatory| Description                                      |
2434| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
2435| type     | string                                              | Yes  | Event type. The event **'deviceChange'** is triggered when the device connection status is changed.|
2436| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | No  | Callback used to return the device change details.|
2437
2438**Example**
2439
2440```ts
2441audioManager.off('deviceChange');
2442```
2443
2444### on('interrupt')
2445
2446on(type: 'interrupt', interrupt: AudioInterrupt, callback: Callback\<InterruptAction>): void
2447
2448Subscribes to audio interruption events. When the application's audio is interrupted by another playback event, the application will receive the callback. This API uses an asynchronous callback to return the result.
2449
2450Same as [on('audioInterrupt')](#onaudiointerrupt9), this API is used to listen for focus changes. However, this API is used in scenarios without audio streams (no **AudioRenderer** instance is created), such as frequency modulation (FM) and voice wakeup.
2451
2452**System capability**: SystemCapability.Multimedia.Audio.Renderer
2453
2454**Parameters**
2455
2456| Name   | Type                                                     | Mandatory| Description                                                        |
2457| --------- |---------------------------------------------------------| ---- | ------------------------------------------------------------ |
2458| type      | string                                                  | Yes  | Event type. The event **'interrupt'** is triggered when the audio playback of the current application is interrupted by another application.|
2459| interrupt | [AudioInterrupt](#audiointerruptdeprecated)             | Yes  | Audio interruption event type.                                    |
2460| callback  | Callback<[InterruptAction](#interruptactiondeprecated)> | Yes  | Callback used to return the audio interruption event.|
2461
2462**Example**
2463
2464```ts
2465import audio from '@ohos.multimedia.audio';
2466
2467let interAudioInterrupt: audio.AudioInterrupt = {
2468  streamUsage:2,
2469  contentType:0,
2470  pauseWhenDucked:true
2471};
2472audioManager.on('interrupt', interAudioInterrupt, (InterruptAction: audio.InterruptAction) => {
2473  if (InterruptAction.actionType === 0) {
2474    console.info('An event to gain the audio focus starts.');
2475    console.info(`Focus gain event: ${InterruptAction} `);
2476  }
2477  if (InterruptAction.actionType === 1) {
2478    console.info('An audio interruption event starts.');
2479    console.info(`Audio interruption event: ${InterruptAction} `);
2480  }
2481});
2482```
2483
2484### off('interrupt')
2485
2486off(type: 'interrupt', interrupt: AudioInterrupt, callback?: Callback\<InterruptAction>): void
2487
2488Unsubscribes from audio interruption events. This API uses an asynchronous callback to return the result.
2489
2490**System capability**: SystemCapability.Multimedia.Audio.Renderer
2491
2492**Parameters**
2493
2494| Name   | Type                                                     | Mandatory| Description                                                        |
2495| --------- |---------------------------------------------------------| ---- | ------------------------------------------------------------ |
2496| type      | string                                                  | Yes  | Event type. The event **'interrupt'** is triggered when the audio playback of the current application is interrupted by another application.|
2497| interrupt | [AudioInterrupt](#audiointerruptdeprecated)                       | Yes  | Audio interruption event type.                                    |
2498| callback  | Callback<[InterruptAction](#interruptactiondeprecated)> | No  | Callback used to return the audio interruption event.|
2499
2500**Example**
2501
2502```ts
2503import audio from '@ohos.multimedia.audio';
2504
2505let interAudioInterrupt: audio.AudioInterrupt = {
2506  streamUsage:2,
2507  contentType:0,
2508  pauseWhenDucked:true
2509};
2510audioManager.off('interrupt', interAudioInterrupt, (InterruptAction: audio.InterruptAction) => {
2511  if (InterruptAction.actionType === 0) {
2512    console.info('An event to release the audio focus starts.');
2513    console.info(`Focus release event: ${InterruptAction} `);
2514  }
2515});
2516```
2517
2518## AudioVolumeManager<sup>9+</sup>
2519
2520Implements audio volume management. Before calling an API in **AudioVolumeManager**, you must use [getVolumeManager](#getvolumemanager9) to obtain an **AudioVolumeManager** instance.
2521
2522### getVolumeGroupInfos<sup>9+</sup>
2523
2524getVolumeGroupInfos(networkId: string, callback: AsyncCallback<VolumeGroupInfos\>\): void
2525
2526Obtains the volume groups. This API uses an asynchronous callback to return the result.
2527
2528**System API**: This is a system API.
2529
2530**System capability**: SystemCapability.Multimedia.Audio.Volume
2531
2532**Parameters**
2533
2534| Name    | Type                                                        | Mandatory| Description                |
2535| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
2536| networkId | string                                    | Yes  | Network ID of the device. The network ID of the local device is **audio.LOCAL_NETWORK_ID**.   |
2537| callback  | AsyncCallback&lt;[VolumeGroupInfos](#volumegroupinfos9)&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the volume groups obtained; otherwise, **err** is an error object.|
2538
2539**Example**
2540```ts
2541import { BusinessError } from '@ohos.base';
2542
2543audioVolumeManager.getVolumeGroupInfos(audio.LOCAL_NETWORK_ID, (err: BusinessError, value: audio.VolumeGroupInfos) => {
2544  if (err) {
2545    console.error(`Failed to obtain the volume group infos list. ${err}`);
2546    return;
2547  }
2548  console.info('Callback invoked to indicate that the volume group infos list is obtained.');
2549});
2550```
2551
2552### getVolumeGroupInfos<sup>9+</sup>
2553
2554getVolumeGroupInfos(networkId: string\): Promise<VolumeGroupInfos\>
2555
2556Obtains the volume groups. This API uses a promise to return the result.
2557
2558**System API**: This is a system API.
2559
2560**System capability**: SystemCapability.Multimedia.Audio.Volume
2561
2562**Parameters**
2563
2564| Name    | Type              | Mandatory| Description                |
2565| ---------- | ------------------| ---- | -------------------- |
2566| networkId | string             | Yes  | Network ID of the device. The network ID of the local device is **audio.LOCAL_NETWORK_ID**.  |
2567
2568**Return value**
2569
2570| Type               | Description                         |
2571| ------------------- | ----------------------------- |
2572| Promise&lt;[VolumeGroupInfos](#volumegroupinfos9)&gt; | Promise used to return the volume group information list.|
2573
2574**Example**
2575
2576```ts
2577async function getVolumeGroupInfos(){
2578  let volumegroupinfos: audio.VolumeGroupInfos = await audio.getAudioManager().getVolumeManager().getVolumeGroupInfos(audio.LOCAL_NETWORK_ID);
2579  console.info('Promise returned to indicate that the volumeGroup list is obtained.'+JSON.stringify(volumegroupinfos))
2580}
2581```
2582
2583### getVolumeGroupInfosSync<sup>10+</sup>
2584
2585getVolumeGroupInfosSync(networkId: string\): VolumeGroupInfos
2586
2587Obtains the volume groups. This API returns the result synchronously.
2588
2589**System API**: This is a system API.
2590
2591**System capability**: SystemCapability.Multimedia.Audio.Volume
2592
2593**Parameters**
2594
2595| Name    | Type              | Mandatory| Description                |
2596| ---------- | ------------------| ---- | -------------------- |
2597| networkId | string             | Yes  | Network ID of the device. The network ID of the local device is **audio.LOCAL_NETWORK_ID**.  |
2598
2599**Return value**
2600
2601| Type               | Description                         |
2602| ------------------- | ----------------------------- |
2603| [VolumeGroupInfos](#volumegroupinfos9) | Volume group information list.|
2604
2605**Error codes**
2606
2607For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
2608
2609| ID| Error Message|
2610| ------- | --------------------------------------------|
2611| 6800101 | invalid parameter error              |
2612
2613**Example**
2614
2615```ts
2616import { BusinessError } from '@ohos.base';
2617
2618try {
2619  let volumegroupinfos: audio.VolumeGroupInfos = audioVolumeManager.getVolumeGroupInfosSync(audio.LOCAL_NETWORK_ID);
2620  console.info(`Indicate that the volumeGroup list is obtained. ${JSON.stringify(volumegroupinfos)}`);
2621} catch (err) {
2622  let error = err as BusinessError;
2623  console.error(`Failed to obtain the volumeGroup list ${error}`);
2624}
2625```
2626
2627### getVolumeGroupManager<sup>9+</sup>
2628
2629getVolumeGroupManager(groupId: number, callback: AsyncCallback<AudioVolumeGroupManager\>\): void
2630
2631Obtains the volume group manager. This API uses an asynchronous callback to return the result.
2632
2633**System capability**: SystemCapability.Multimedia.Audio.Volume
2634
2635**Parameters**
2636
2637| Name    | Type                                                        | Mandatory| Description                                                       |
2638| ---------- | ------------------------------------------------------------ | ---- |-----------------------------------------------------------|
2639| groupId    | number                                    | Yes  | Volume group ID. The default value is **LOCAL_VOLUME_GROUP_ID**.                         |
2640| callback   | AsyncCallback&lt;[AudioVolumeGroupManager](#audiovolumegroupmanager9)&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the volume group manager obtained; otherwise, **err** is an error object.|
2641
2642**Example**
2643
2644```ts
2645import { BusinessError } from '@ohos.base';
2646
2647let groupId: number = audio.DEFAULT_VOLUME_GROUP_ID;
2648audioVolumeManager.getVolumeGroupManager(groupId, (err: BusinessError, value: audio.AudioVolumeGroupManager) => {
2649  if (err) {
2650    console.error(`Failed to obtain the volume group infos list. ${err}`);
2651    return;
2652  }
2653  console.info('Callback invoked to indicate that the volume group infos list is obtained.');
2654});
2655
2656```
2657
2658### getVolumeGroupManager<sup>9+</sup>
2659
2660getVolumeGroupManager(groupId: number\): Promise<AudioVolumeGroupManager\>
2661
2662Obtains the volume group manager. This API uses a promise to return the result.
2663
2664**System capability**: SystemCapability.Multimedia.Audio.Volume
2665
2666**Parameters**
2667
2668| Name    | Type                                     | Mandatory| Description                              |
2669| ---------- | ---------------------------------------- | ---- |----------------------------------|
2670| groupId    | number                                   | Yes  | Volume group ID. The default value is **LOCAL_VOLUME_GROUP_ID**.|
2671
2672**Return value**
2673
2674| Type               | Description                         |
2675| ------------------- | ----------------------------- |
2676| Promise&lt; [AudioVolumeGroupManager](#audiovolumegroupmanager9) &gt; | Promise used to return the volume group manager.|
2677
2678**Example**
2679
2680```ts
2681import audio from '@ohos.multimedia.audio';
2682
2683let groupId: number = audio.DEFAULT_VOLUME_GROUP_ID;
2684let audioVolumeGroupManager: audio.AudioVolumeGroupManager | undefined = undefined;
2685async function getVolumeGroupManager(){
2686  audioVolumeGroupManager = await audioVolumeManager.getVolumeGroupManager(groupId);
2687  console.info('Promise returned to indicate that the volume group infos list is obtained.');
2688}
2689```
2690
2691### getVolumeGroupManagerSync<sup>10+</sup>
2692
2693getVolumeGroupManagerSync(groupId: number\): AudioVolumeGroupManager
2694
2695Obtains the volume group manager. This API returns the result synchronously.
2696
2697**System capability**: SystemCapability.Multimedia.Audio.Volume
2698
2699**Parameters**
2700
2701| Name    | Type                                     | Mandatory| Description                              |
2702| ---------- | ---------------------------------------- | ---- |----------------------------------|
2703| groupId    | number                                   | Yes  | Volume group ID. The default value is **LOCAL_VOLUME_GROUP_ID**.|
2704
2705**Return value**
2706
2707| Type               | Description                         |
2708| ------------------- | ----------------------------- |
2709| [AudioVolumeGroupManager](#audiovolumegroupmanager9) | Volume group manager.|
2710
2711**Error codes**
2712
2713For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
2714
2715| ID| Error Message|
2716| ------- | --------------------------------------------|
2717| 6800101 | invalid parameter error              |
2718
2719**Example**
2720
2721```ts
2722import { BusinessError } from '@ohos.base';
2723
2724try {
2725  let audioVolumeGroupManager: audio.AudioVolumeGroupManager = audioVolumeManager.getVolumeGroupManagerSync(audio.DEFAULT_VOLUME_GROUP_ID);
2726  console.info(`Get audioVolumeGroupManager success.`);
2727} catch (err) {
2728  let error = err as BusinessError;
2729  console.error(`Failed to get audioVolumeGroupManager, error: ${error}`);
2730}
2731```
2732
2733### on('volumeChange')<sup>9+</sup>
2734
2735on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
2736
2737Subscribes to system volume change events. This API uses an asynchronous callback to return the result.
2738
2739**System capability**: SystemCapability.Multimedia.Audio.Volume
2740
2741**Parameters**
2742
2743| Name  | Type                                  | Mandatory| Description                                                        |
2744| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
2745| type     | string                                 | Yes  | Event type. The event **'volumeChange'** is triggered when the system volume is changed.|
2746| callback | Callback<[VolumeEvent](#volumeevent9)> | Yes  | Callback used to return the changed volume.|
2747
2748**Error codes**
2749
2750For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
2751
2752| ID| Error Message|
2753| ------- | --------------------------------------------|
2754| 6800101 | Invalid parameter error. |
2755
2756**Example**
2757
2758```ts
2759audioVolumeManager.on('volumeChange', (volumeEvent: audio.VolumeEvent) => {
2760  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
2761  console.info(`Volume level: ${volumeEvent.volume} `);
2762  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
2763});
2764```
2765
2766## AudioVolumeGroupManager<sup>9+</sup>
2767
2768Manages the volume of an audio group. Before calling any API in **AudioVolumeGroupManager**, you must use [getVolumeGroupManager](#getvolumegroupmanager9) to obtain an **AudioVolumeGroupManager** instance.
2769
2770### setVolume<sup>9+</sup>
2771
2772setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&lt;void&gt;): void
2773
2774Sets the volume for a stream. This API uses an asynchronous callback to return the result.
2775
2776**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
2777
2778This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
2779
2780**System API**: This is a system API.
2781
2782**System capability**: SystemCapability.Multimedia.Audio.Volume
2783
2784**Parameters**
2785
2786| Name    | Type                               | Mandatory| Description                                                    |
2787| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
2788| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
2789| volume     | number                              | Yes  | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
2790| callback   | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
2791
2792**Example**
2793
2794```ts
2795import { BusinessError } from '@ohos.base';
2796
2797audioVolumeGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err: BusinessError) => {
2798  if (err) {
2799    console.error(`Failed to set the volume. ${err}`);
2800    return;
2801  }
2802  console.info('Callback invoked to indicate a successful volume setting.');
2803});
2804```
2805
2806### setVolume<sup>9+</sup>
2807
2808setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
2809
2810Sets the volume for a stream. This API uses a promise to return the result.
2811
2812**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
2813
2814This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
2815
2816**System API**: This is a system API.
2817
2818**System capability**: SystemCapability.Multimedia.Audio.Volume
2819
2820**Parameters**
2821
2822| Name    | Type                               | Mandatory| Description                                                    |
2823| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
2824| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
2825| volume     | number                              | Yes  | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
2826
2827**Return value**
2828
2829| Type               | Description                         |
2830| ------------------- | ----------------------------- |
2831| Promise&lt;void&gt; | Promise that returns no value.|
2832
2833**Example**
2834
2835```ts
2836audioVolumeGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
2837  console.info('Promise returned to indicate a successful volume setting.');
2838});
2839```
2840
2841### getVolume<sup>9+</sup>
2842
2843getVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
2844
2845Obtains the volume of a stream. This API uses an asynchronous callback to return the result.
2846
2847**System capability**: SystemCapability.Multimedia.Audio.Volume
2848
2849**Parameters**
2850
2851| Name    | Type                               | Mandatory| Description              |
2852| ---------- | ----------------------------------- | ---- | ------------------ |
2853| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
2854| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the stream volume obtained; otherwise, **err** is an error object.|
2855
2856**Example**
2857
2858```ts
2859import { BusinessError } from '@ohos.base';
2860
2861audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
2862  if (err) {
2863    console.error(`Failed to obtain the volume. ${err}`);
2864    return;
2865  }
2866  console.info('Callback invoked to indicate that the volume is obtained.');
2867});
2868```
2869
2870### getVolume<sup>9+</sup>
2871
2872getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
2873
2874Obtains the volume of a stream. This API uses a promise to return the result.
2875
2876**System capability**: SystemCapability.Multimedia.Audio.Volume
2877
2878**Parameters**
2879
2880| Name    | Type                               | Mandatory| Description        |
2881| ---------- | ----------------------------------- | ---- | ------------ |
2882| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
2883
2884**Return value**
2885
2886| Type                 | Description                     |
2887| --------------------- | ------------------------- |
2888| Promise&lt;number&gt; | Promise used to return the volume.|
2889
2890**Example**
2891
2892```ts
2893audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA).then((value: number) => {
2894  console.info(`Promise returned to indicate that the volume is obtained ${value}.`);
2895});
2896```
2897
2898### getVolumeSync<sup>10+</sup>
2899
2900getVolumeSync(volumeType: AudioVolumeType): number;
2901
2902Obtains the volume of a stream. This API returns the result synchronously.
2903
2904**System capability**: SystemCapability.Multimedia.Audio.Volume
2905
2906**Parameters**
2907
2908| Name    | Type                               | Mandatory| Description        |
2909| ---------- | ----------------------------------- | ---- | ------------ |
2910| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
2911
2912**Return value**
2913
2914| Type                 | Description                     |
2915| --------------------- | ------------------------- |
2916| number | Volume of the stream.|
2917
2918**Error codes**
2919
2920For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
2921
2922| ID| Error Message|
2923| ------- | --------------------------------------------|
2924| 6800101 | invalid parameter error              |
2925
2926**Example**
2927
2928```ts
2929import { BusinessError } from '@ohos.base';
2930
2931try {
2932  let value: number = audioVolumeGroupManager.getVolumeSync(audio.AudioVolumeType.MEDIA);
2933  console.info(`Indicate that the volume is obtained ${value}.`);
2934} catch (err) {
2935  let error = err as BusinessError;
2936  console.error(`Failed to obtain the volume, error ${error}.`);
2937}
2938```
2939
2940### getMinVolume<sup>9+</sup>
2941
2942getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
2943
2944Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the result.
2945
2946**System capability**: SystemCapability.Multimedia.Audio.Volume
2947
2948**Parameters**
2949
2950| Name    | Type                               | Mandatory| Description              |
2951| ---------- | ----------------------------------- | ---- | ------------------ |
2952| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
2953| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the minimum stream volume obtained; otherwise, **err** is an error object.|
2954
2955**Example**
2956
2957```ts
2958import { BusinessError } from '@ohos.base';
2959
2960audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
2961  if (err) {
2962    console.error(`Failed to obtain the minimum volume. ${err}`);
2963    return;
2964  }
2965  console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
2966});
2967```
2968
2969### getMinVolume<sup>9+</sup>
2970
2971getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
2972
2973Obtains the minimum volume allowed for a stream. This API uses a promise to return the result.
2974
2975**System capability**: SystemCapability.Multimedia.Audio.Volume
2976
2977**Parameters**
2978
2979| Name    | Type                               | Mandatory| Description        |
2980| ---------- | ----------------------------------- | ---- | ------------ |
2981| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
2982
2983**Return value**
2984
2985| Type                 | Description                     |
2986| --------------------- | ------------------------- |
2987| Promise&lt;number&gt; | Promise used to return the minimum volume.|
2988
2989**Example**
2990
2991```ts
2992audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value: number) => {
2993  console.info(`Promised returned to indicate that the minimum volume is obtained ${value}.`);
2994});
2995```
2996
2997### getMinVolumeSync<sup>10+</sup>
2998
2999getMinVolumeSync(volumeType: AudioVolumeType): number;
3000
3001Obtains the minimum volume allowed for a stream. This API returns the result synchronously.
3002
3003**System capability**: SystemCapability.Multimedia.Audio.Volume
3004
3005**Parameters**
3006
3007| Name    | Type                               | Mandatory| Description        |
3008| ---------- | ----------------------------------- | ---- | ------------ |
3009| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
3010
3011**Return value**
3012
3013| Type                 | Description                     |
3014| --------------------- | ------------------------- |
3015| number | Minimum volume.|
3016
3017**Error codes**
3018
3019For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3020
3021| ID| Error Message|
3022| ------- | --------------------------------------------|
3023| 6800101 | invalid parameter error              |
3024
3025**Example**
3026
3027```ts
3028import { BusinessError } from '@ohos.base';
3029
3030try {
3031  let value: number = audioVolumeGroupManager.getMinVolumeSync(audio.AudioVolumeType.MEDIA);
3032  console.info(`Indicate that the minimum volume is obtained ${value}.`);
3033} catch (err) {
3034  let error = err as BusinessError;
3035  console.error(`Failed to obtain the minimum volume, error ${error}.`);
3036}
3037```
3038
3039### getMaxVolume<sup>9+</sup>
3040
3041getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
3042
3043Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the result.
3044
3045**System capability**: SystemCapability.Multimedia.Audio.Volume
3046
3047**Parameters**
3048
3049| Name    | Type                               | Mandatory| Description                  |
3050| ---------- | ----------------------------------- | ---- | ---------------------- |
3051| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.          |
3052| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the maximum stream volume obtained; otherwise, **err** is an error object.|
3053
3054**Example**
3055
3056```ts
3057import { BusinessError } from '@ohos.base';
3058
3059audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
3060  if (err) {
3061    console.error(`Failed to obtain the maximum volume. ${err}`);
3062    return;
3063  }
3064  console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`);
3065});
3066```
3067
3068### getMaxVolume<sup>9+</sup>
3069
3070getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
3071
3072Obtains the maximum volume allowed for a stream. This API uses a promise to return the result.
3073
3074**System capability**: SystemCapability.Multimedia.Audio.Volume
3075
3076**Parameters**
3077
3078| Name    | Type                               | Mandatory| Description        |
3079| ---------- | ----------------------------------- | ---- | ------------ |
3080| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
3081
3082**Return value**
3083
3084| Type                 | Description                         |
3085| --------------------- | ----------------------------- |
3086| Promise&lt;number&gt; | Promise used to return the maximum volume.|
3087
3088**Example**
3089
3090```ts
3091audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data: number) => {
3092  console.info('Promised returned to indicate that the maximum volume is obtained.');
3093});
3094```
3095
3096### getMaxVolumeSync<sup>10+</sup>
3097
3098getMaxVolumeSync(volumeType: AudioVolumeType): number;
3099
3100Obtains the maximum volume allowed for a stream. This API returns the result synchronously.
3101
3102**System capability**: SystemCapability.Multimedia.Audio.Volume
3103
3104**Parameters**
3105
3106| Name    | Type                               | Mandatory| Description        |
3107| ---------- | ----------------------------------- | ---- | ------------ |
3108| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
3109
3110**Return value**
3111
3112| Type                 | Description                         |
3113| --------------------- | ----------------------------- |
3114| number | Maximum volume.|
3115
3116**Error codes**
3117
3118For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3119
3120| ID| Error Message|
3121| ------- | --------------------------------------------|
3122| 6800101 | invalid parameter error              |
3123
3124**Example**
3125
3126```ts
3127import { BusinessError } from '@ohos.base';
3128
3129try {
3130  let value: number = audioVolumeGroupManager.getMaxVolumeSync(audio.AudioVolumeType.MEDIA);
3131  console.info(`Indicate that the maximum volume is obtained. ${value}`);
3132} catch (err) {
3133  let error = err as BusinessError;
3134  console.error(`Failed to obtain the maximum volume, error ${error}.`);
3135}
3136```
3137
3138### mute<sup>9+</sup>
3139
3140mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
3141
3142Mutes or unmutes a stream. This API uses an asynchronous callback to return the result.
3143
3144**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
3145
3146This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
3147
3148**System API**: This is a system API.
3149
3150**System capability**: SystemCapability.Multimedia.Audio.Volume
3151
3152**Parameters**
3153
3154| Name    | Type                               | Mandatory| Description                                 |
3155| ---------- | ----------------------------------- | ---- | ------------------------------------- |
3156| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                         |
3157| mute       | boolean                             | Yes  | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.|
3158| callback   | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
3159
3160**Example**
3161
3162```ts
3163import { BusinessError } from '@ohos.base';
3164
3165audioVolumeGroupManager.mute(audio.AudioVolumeType.MEDIA, true, (err: BusinessError) => {
3166  if (err) {
3167    console.error(`Failed to mute the stream. ${err}`);
3168    return;
3169  }
3170  console.info('Callback invoked to indicate that the stream is muted.');
3171});
3172```
3173
3174### mute<sup>9+</sup>
3175
3176mute(volumeType: AudioVolumeType, mute: boolean): Promise&lt;void&gt;
3177
3178Mutes or unmutes a stream. This API uses a promise to return the result.
3179
3180**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
3181
3182This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
3183
3184**System API**: This is a system API.
3185
3186**System capability**: SystemCapability.Multimedia.Audio.Volume
3187
3188**Parameters**
3189
3190| Name    | Type                               | Mandatory| Description                                 |
3191| ---------- | ----------------------------------- | ---- | ------------------------------------- |
3192| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                         |
3193| mute       | boolean                             | Yes  | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.|
3194
3195**Return value**
3196
3197| Type               | Description                         |
3198| ------------------- | ----------------------------- |
3199| Promise&lt;void&gt; | Promise that returns no value.|
3200
3201**Example**
3202
3203```ts
3204audioVolumeGroupManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
3205  console.info('Promise returned to indicate that the stream is muted.');
3206});
3207```
3208
3209### isMute<sup>9+</sup>
3210
3211isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
3212
3213Checks whether a stream is muted. This API uses an asynchronous callback to return the result.
3214
3215**System capability**: SystemCapability.Multimedia.Audio.Volume
3216
3217**Parameters**
3218
3219| Name    | Type                               | Mandatory| Description                                           |
3220| ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
3221| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                   |
3222| callback   | AsyncCallback&lt;boolean&gt;        | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true** if the stream is muted or **false** if not muted; otherwise, **err** is an error object.|
3223
3224**Example**
3225
3226```ts
3227import { BusinessError } from '@ohos.base';
3228
3229audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => {
3230  if (err) {
3231    console.error(`Failed to obtain the mute status. ${err}`);
3232    return;
3233  }
3234  console.info(`Callback invoked to indicate that the mute status of the stream is obtained ${value}.`);
3235});
3236```
3237
3238### isMute<sup>9+</sup>
3239
3240isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
3241
3242Checks whether a stream is muted. This API uses a promise to return the result.
3243
3244**System capability**: SystemCapability.Multimedia.Audio.Volume
3245
3246**Parameters**
3247
3248| Name    | Type                               | Mandatory| Description        |
3249| ---------- | ----------------------------------- | ---- | ------------ |
3250| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
3251
3252**Return value**
3253
3254| Type                  | Description                                                  |
3255| ---------------------- | ------------------------------------------------------ |
3256| Promise&lt;boolean&gt; | Promise used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite.|
3257
3258**Example**
3259
3260```ts
3261audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA).then((value: boolean) => {
3262  console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`);
3263});
3264```
3265
3266### isMuteSync<sup>10+</sup>
3267
3268isMuteSync(volumeType: AudioVolumeType): boolean
3269
3270Checks whether a stream is muted. This API returns the result synchronously.
3271
3272**System capability**: SystemCapability.Multimedia.Audio.Volume
3273
3274**Parameters**
3275
3276| Name    | Type                               | Mandatory| Description        |
3277| ---------- | ----------------------------------- | ---- | ------------ |
3278| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
3279
3280**Return value**
3281
3282| Type                  | Description                                                  |
3283| ---------------------- | ------------------------------------------------------ |
3284| boolean | Returns **true** if the stream is muted; returns **false** otherwise.|
3285
3286**Error codes**
3287
3288For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3289
3290| ID| Error Message|
3291| ------- | --------------------------------------------|
3292| 6800101 | invalid parameter error              |
3293
3294**Example**
3295
3296```ts
3297import { BusinessError } from '@ohos.base';
3298
3299try {
3300  let value: boolean = audioVolumeGroupManager.isMuteSync(audio.AudioVolumeType.MEDIA);
3301  console.info(`Indicate that the mute status of the stream is obtained ${value}.`);
3302} catch (err) {
3303  let error = err as BusinessError;
3304  console.error(`Failed to obtain the mute status of the stream, error ${error}.`);
3305}
3306```
3307
3308### setRingerMode<sup>9+</sup>
3309
3310setRingerMode(mode: AudioRingMode, callback: AsyncCallback&lt;void&gt;): void
3311
3312Sets the ringer mode. This API uses an asynchronous callback to return the result.
3313
3314**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
3315
3316This permission is required only for muting or unmuting the ringer.
3317
3318**System API**: This is a system API.
3319
3320**System capability**: SystemCapability.Multimedia.Audio.Volume
3321
3322**Parameters**
3323
3324| Name  | Type                           | Mandatory| Description                    |
3325| -------- | ------------------------------- | ---- | ------------------------ |
3326| mode     | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.          |
3327| callback | AsyncCallback&lt;void&gt;       | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
3328
3329**Example**
3330
3331```ts
3332import { BusinessError } from '@ohos.base';
3333
3334audioVolumeGroupManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err: BusinessError) => {
3335  if (err) {
3336    console.error(`Failed to set the ringer mode. ${err}`);
3337    return;
3338  }
3339  console.info('Callback invoked to indicate a successful setting of the ringer mode.');
3340});
3341```
3342
3343### setRingerMode<sup>9+</sup>
3344
3345setRingerMode(mode: AudioRingMode): Promise&lt;void&gt;
3346
3347Sets the ringer mode. This API uses a promise to return the result.
3348
3349**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
3350
3351This permission is required only for muting or unmuting the ringer.
3352
3353**System API**: This is a system API.
3354
3355**System capability**: SystemCapability.Multimedia.Audio.Volume
3356
3357**Parameters**
3358
3359| Name| Type                           | Mandatory| Description          |
3360| ------ | ------------------------------- | ---- | -------------- |
3361| mode   | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.|
3362
3363**Return value**
3364
3365| Type               | Description                           |
3366| ------------------- | ------------------------------- |
3367| Promise&lt;void&gt; | Promise that returns no value.|
3368
3369**Example**
3370
3371```ts
3372audioVolumeGroupManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
3373  console.info('Promise returned to indicate a successful setting of the ringer mode.');
3374});
3375```
3376
3377### getRingerMode<sup>9+</sup>
3378
3379getRingerMode(callback: AsyncCallback&lt;AudioRingMode&gt;): void
3380
3381Obtains the ringer mode. This API uses an asynchronous callback to return the result.
3382
3383**System capability**: SystemCapability.Multimedia.Audio.Volume
3384
3385**Parameters**
3386
3387| Name  | Type                                                | Mandatory| Description                    |
3388| -------- | ---------------------------------------------------- | ---- | ------------------------ |
3389| callback | AsyncCallback&lt;[AudioRingMode](#audioringmode)&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the ringer mode obtained; otherwise, **err** is an error object.|
3390
3391**Example**
3392
3393```ts
3394import { BusinessError } from '@ohos.base';
3395
3396audioVolumeGroupManager.getRingerMode((err: BusinessError, value: audio.AudioRingMode) => {
3397  if (err) {
3398    console.error(`Failed to obtain the ringer mode. ${err}`);
3399    return;
3400  }
3401  console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`);
3402});
3403```
3404
3405### getRingerMode<sup>9+</sup>
3406
3407getRingerMode(): Promise&lt;AudioRingMode&gt;
3408
3409Obtains the ringer mode. This API uses a promise to return the result.
3410
3411**System capability**: SystemCapability.Multimedia.Audio.Volume
3412
3413**Return value**
3414
3415| Type                                          | Description                           |
3416| ---------------------------------------------- | ------------------------------- |
3417| Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise used to return the ringer mode.|
3418
3419**Example**
3420
3421```ts
3422audioVolumeGroupManager.getRingerMode().then((value: audio.AudioRingMode) => {
3423  console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`);
3424});
3425```
3426
3427### getRingerModeSync<sup>10+</sup>
3428
3429getRingerModeSync(): AudioRingMode
3430
3431Obtains the ringer mode. This API returns the result synchronously.
3432
3433**System capability**: SystemCapability.Multimedia.Audio.Volume
3434
3435**Return value**
3436
3437| Type                                          | Description                           |
3438| ---------------------------------------------- | ------------------------------- |
3439| [AudioRingMode](#audioringmode) | Ringer mode.|
3440
3441**Example**
3442
3443```ts
3444import { BusinessError } from '@ohos.base';
3445
3446try {
3447  let value: audio.AudioRingMode = audioVolumeGroupManager.getRingerModeSync();
3448  console.info(`Indicate that the ringer mode is obtained ${value}.`);
3449} catch (err) {
3450  let error = err as BusinessError;
3451  console.error(`Failed to obtain the ringer mode, error ${error}.`);
3452}
3453```
3454
3455### on('ringerModeChange')<sup>9+</sup>
3456
3457on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void
3458
3459Subscribes to ringer mode change events. This API uses an asynchronous callback to return the result.
3460
3461**System capability**: SystemCapability.Multimedia.Audio.Volume
3462
3463**Parameters**
3464
3465| Name  | Type                                     | Mandatory| Description                                                        |
3466| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
3467| type     | string                                    | Yes  | Event type. The event **'ringerModeChange'** is triggered when the ringer mode is changed.|
3468| callback | Callback<[AudioRingMode](#audioringmode)> | Yes  | Callback used to return the changed ringer mode.|
3469
3470**Error codes**
3471
3472For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3473
3474| ID| Error Message|
3475| ------- | --------------------------------------------|
3476| 6800101 | Invalid parameter error. |
3477
3478**Example**
3479
3480```ts
3481audioVolumeGroupManager.on('ringerModeChange', (ringerMode: audio.AudioRingMode) => {
3482  console.info(`Updated ringermode: ${ringerMode}`);
3483});
3484```
3485### setMicrophoneMute<sup>9+</sup>
3486
3487setMicrophoneMute(mute: boolean, callback: AsyncCallback&lt;void&gt;): void
3488
3489Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result.
3490
3491**Required permissions**: ohos.permission.MANAGE_AUDIO_CONFIG
3492
3493**System capability**: SystemCapability.Multimedia.Audio.Volume
3494
3495**Parameters**
3496
3497| Name  | Type                     | Mandatory| Description                                         |
3498| -------- | ------------------------- | ---- | --------------------------------------------- |
3499| mute     | boolean                   | Yes  | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
3500| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
3501
3502**Example**
3503
3504```ts
3505import { BusinessError } from '@ohos.base';
3506
3507audioVolumeGroupManager.setMicrophoneMute(true, (err: BusinessError) => {
3508  if (err) {
3509    console.error(`Failed to mute the microphone. ${err}`);
3510    return;
3511  }
3512  console.info('Callback invoked to indicate that the microphone is muted.');
3513});
3514```
3515
3516### setMicrophoneMute<sup>9+</sup>
3517
3518setMicrophoneMute(mute: boolean): Promise&lt;void&gt;
3519
3520Mutes or unmutes the microphone. This API uses a promise to return the result.
3521
3522**Required permissions**: ohos.permission.MANAGE_AUDIO_CONFIG
3523
3524**System capability**: SystemCapability.Multimedia.Audio.Volume
3525
3526**Parameters**
3527
3528| Name| Type   | Mandatory| Description                                         |
3529| ------ | ------- | ---- | --------------------------------------------- |
3530| mute   | boolean | Yes  | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
3531
3532**Return value**
3533
3534| Type               | Description                           |
3535| ------------------- | ------------------------------- |
3536| Promise&lt;void&gt; | Promise that returns no value.|
3537
3538**Example**
3539
3540```ts
3541audioVolumeGroupManager.setMicrophoneMute(true).then(() => {
3542  console.info('Promise returned to indicate that the microphone is muted.');
3543});
3544```
3545
3546### isMicrophoneMute<sup>9+</sup>
3547
3548isMicrophoneMute(callback: AsyncCallback&lt;boolean&gt;): void
3549
3550Checks whether the microphone is muted. This API uses an asynchronous callback to return the result.
3551
3552**System capability**: SystemCapability.Multimedia.Audio.Volume
3553
3554**Parameters**
3555
3556| Name  | Type                        | Mandatory| Description                                                   |
3557| -------- | ---------------------------- | ---- | ------------------------------------------------------- |
3558| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true** if the microphone is muted or **false** if not muted; otherwise, **err** is an error object.|
3559
3560**Example**
3561
3562```ts
3563import { BusinessError } from '@ohos.base';
3564
3565audioVolumeGroupManager.isMicrophoneMute((err: BusinessError, value: boolean) => {
3566  if (err) {
3567    console.error(`Failed to obtain the mute status of the microphone. ${err}`);
3568    return;
3569  }
3570  console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`);
3571});
3572```
3573
3574### isMicrophoneMute<sup>9+</sup>
3575
3576isMicrophoneMute(): Promise&lt;boolean&gt;
3577
3578Checks whether the microphone is muted. This API uses a promise to return the result.
3579
3580**System capability**: SystemCapability.Multimedia.Audio.Volume
3581
3582**Return value**
3583
3584| Type                  | Description                                                        |
3585| ---------------------- | ------------------------------------------------------------ |
3586| Promise&lt;boolean&gt; | Promise used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.|
3587
3588**Example**
3589
3590```ts
3591audioVolumeGroupManager.isMicrophoneMute().then((value: boolean) => {
3592  console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`);
3593});
3594```
3595
3596### isMicrophoneMuteSync<sup>10+</sup>
3597
3598isMicrophoneMuteSync(): boolean
3599
3600Checks whether the microphone is muted. This API returns the result synchronously.
3601
3602**System capability**: SystemCapability.Multimedia.Audio.Volume
3603
3604**Return value**
3605
3606| Type                  | Description                                                        |
3607| ---------------------- | ------------------------------------------------------------ |
3608| boolean | Returns **true** if the microphone is muted; returns **false** otherwise.|
3609
3610**Example**
3611
3612```ts
3613import { BusinessError } from '@ohos.base';
3614
3615try {
3616  let value: boolean = audioVolumeGroupManager.isMicrophoneMuteSync();
3617  console.info(`Indicate that the mute status of the microphone is obtained ${value}.`);
3618} catch (err) {
3619  let error = err as BusinessError;
3620  console.error(`Failed to obtain the mute status of the microphone, error ${error}.`);
3621}
3622```
3623
3624### on('micStateChange')<sup>9+</sup>
3625
3626on(type: 'micStateChange', callback: Callback&lt;MicStateChangeEvent&gt;): void
3627
3628Subscribes to system microphone state change events. This API uses an asynchronous callback to return the result.
3629
3630Currently, when multiple **AudioManager** instances are used in a single process, only the subscription of the last instance takes effect, and the subscription of other instances is overwritten (even if the last instance does not initiate a subscription). Therefore, you are advised to use a single **AudioManager** instance.
3631
3632**System capability**: SystemCapability.Multimedia.Audio.Volume
3633
3634**Parameters**
3635
3636| Name  | Type                                  | Mandatory| Description                                                        |
3637| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
3638| type     | string                                 | Yes  | Event type. The event **'micStateChange'** is triggered when the system microphone state is changed.|
3639| callback | Callback<[MicStateChangeEvent](#micstatechangeevent9)> | Yes  | Callback used to return the changed microphone state.|
3640
3641**Error codes**
3642
3643For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3644
3645| ID| Error Message|
3646| ------- | --------------------------------------------|
3647| 6800101 | Invalid parameter error. |
3648
3649**Example**
3650
3651```ts
3652audioVolumeGroupManager.on('micStateChange', (micStateChange: audio.MicStateChangeEvent) => {
3653  console.info(`Current microphone status is: ${micStateChange.mute} `);
3654});
3655```
3656
3657### isVolumeUnadjustable<sup>10+</sup>
3658
3659isVolumeUnadjustable(): boolean
3660
3661Checks whether the fixed volume mode is enabled. When the fixed volume mode is enabled, the volume cannot be adjusted. This API returns the result synchronously.
3662
3663**System capability**: SystemCapability.Multimedia.Audio.Volume
3664
3665**Return value**
3666
3667| Type                  | Description                                                  |
3668| ---------------------- | ------------------------------------------------------ |
3669| boolean            | Returns the status of the fixed volume mode. The value **true** means that the fixed volume mode is enabled, and **false** means the opposite.|
3670
3671**Example**
3672
3673```ts
3674let volumeAdjustSwitch: boolean = audioVolumeGroupManager.isVolumeUnadjustable();
3675console.info(`Whether it is volume unadjustable: ${volumeAdjustSwitch}.`);
3676```
3677
3678### adjustVolumeByStep<sup>10+</sup>
3679
3680adjustVolumeByStep(adjustType: VolumeAdjustType, callback: AsyncCallback&lt;void&gt;): void
3681
3682Adjusts the volume of the stream with the highest priority by step. This API uses an asynchronous callback to return the result.
3683
3684**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
3685
3686This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
3687
3688**System API**: This is a system API.
3689
3690**System capability**: SystemCapability.Multimedia.Audio.Volume
3691
3692**Parameters**
3693
3694| Name    | Type                               | Mandatory| Description                                                    |
3695| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3696| adjustType | [VolumeAdjustType](#volumeadjusttype10) | Yes  | Volume adjustment type.                                            |
3697| callback   | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
3698
3699**Error codes**
3700
3701For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3702
3703| ID| Error Message|
3704| ------- | --------------------------------------------|
3705| 6800101 | Invalid parameter error. Return by callback.                     |
3706| 6800301 | System error. Return by callback.                                |
3707
3708**Example**
3709
3710```ts
3711import { BusinessError } from '@ohos.base';
3712
3713audioVolumeGroupManager.adjustVolumeByStep(audio.VolumeAdjustType.VOLUME_UP, (err: BusinessError) => {
3714  if (err) {
3715    console.error(`Failed to adjust the volume by step. ${err}`);
3716    return;
3717  } else {
3718    console.info('Success to adjust the volume by step.');
3719  }
3720});
3721```
3722### adjustVolumeByStep<sup>10+</sup>
3723
3724adjustVolumeByStep(adjustType: VolumeAdjustType): Promise&lt;void&gt;
3725
3726Adjusts the volume of the stream with the highest priority by step. This API uses a promise to return the result.
3727
3728**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
3729
3730This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
3731
3732**System API**: This is a system API.
3733
3734**System capability**: SystemCapability.Multimedia.Audio.Volume
3735
3736**Parameters**
3737
3738| Name    | Type                               | Mandatory| Description                                                    |
3739| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3740| adjustType | [VolumeAdjustType](#volumeadjusttype10) | Yes  | Volume adjustment type.                                            |
3741
3742**Return value**
3743
3744| Type               | Description                         |
3745| ------------------- | ----------------------------- |
3746| Promise&lt;void&gt; | Promise that returns no value.|
3747
3748**Error codes**
3749
3750For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3751
3752| ID| Error Message|
3753| ------- | --------------------------------------------|
3754| 6800101 | Invalid parameter error. Return by promise.                     |
3755| 6800301 | System error. Return by promise.                                |
3756
3757**Example**
3758
3759```ts
3760import { BusinessError } from '@ohos.base';
3761
3762audioVolumeGroupManager.adjustVolumeByStep(audio.VolumeAdjustType.VOLUME_UP).then(() => {
3763  console.info('Success to adjust the volume by step.');
3764}).catch((error: BusinessError) => {
3765  console.error('Fail to adjust the volume by step.');
3766});
3767```
3768
3769### adjustSystemVolumeByStep<sup>10+</sup>
3770
3771adjustSystemVolumeByStep(volumeType: AudioVolumeType, adjustType: VolumeAdjustType, callback: AsyncCallback&lt;void&gt;): void
3772
3773Adjusts the volume of a stream by step. This API uses an asynchronous callback to return the result.
3774
3775**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
3776
3777This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
3778
3779**System API**: This is a system API.
3780
3781**System capability**: SystemCapability.Multimedia.Audio.Volume
3782
3783**Parameters**
3784
3785| Name    | Type                               | Mandatory| Description                                                    |
3786| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3787| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
3788| adjustType | [VolumeAdjustType](#volumeadjusttype10) | Yes  | Volume adjustment type.                                      |
3789| callback   | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
3790
3791**Error codes**
3792
3793For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3794
3795| ID| Error Message|
3796| ------- | --------------------------------------------|
3797| 6800101 | Invalid parameter error. Return by callback.                     |
3798| 6800301 | System error. Return by callback.                                |
3799
3800**Example**
3801
3802```ts
3803import { BusinessError } from '@ohos.base';
3804
3805audioVolumeGroupManager.adjustSystemVolumeByStep(audio.AudioVolumeType.MEDIA, audio.VolumeAdjustType.VOLUME_UP, (err: BusinessError) => {
3806  if (err) {
3807    console.error(`Failed to adjust the system volume by step ${err}`);
3808  } else {
3809    console.info('Success to adjust the system volume by step.');
3810  }
3811});
3812```
3813### adjustSystemVolumeByStep<sup>10+</sup>
3814
3815adjustSystemVolumeByStep(volumeType: AudioVolumeType, adjustType: VolumeAdjustType): Promise&lt;void&gt;
3816
3817Adjusts the volume of a stream by step. This API uses a promise to return the result.
3818
3819**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
3820
3821This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
3822
3823**System API**: This is a system API.
3824
3825**System capability**: SystemCapability.Multimedia.Audio.Volume
3826
3827**Parameters**
3828
3829| Name    | Type                               | Mandatory| Description                                                    |
3830| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3831| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
3832| adjustType | [VolumeAdjustType](#volumeadjusttype10) | Yes  | Volume adjustment type.                                            |
3833
3834**Return value**
3835
3836| Type               | Description                         |
3837| ------------------- | ----------------------------- |
3838| Promise&lt;void&gt; | Promise that returns no value.|
3839
3840**Error codes**
3841
3842For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3843
3844| ID| Error Message|
3845| ------- | --------------------------------------------|
3846| 6800101 | Invalid parameter error. Return by promise.                     |
3847| 6800301 | System error. Return by promise.                                |
3848
3849**Example**
3850
3851```ts
3852import { BusinessError } from '@ohos.base';
3853
3854audioVolumeGroupManager.adjustSystemVolumeByStep(audio.AudioVolumeType.MEDIA, audio.VolumeAdjustType.VOLUME_UP).then(() => {
3855  console.info('Success to adjust the system volume by step.');
3856}).catch((error: BusinessError) => {
3857  console.error('Fail to adjust the system volume by step.');
3858});
3859```
3860
3861### getSystemVolumeInDb<sup>10+</sup>
3862
3863getSystemVolumeInDb(volumeType: AudioVolumeType, volumeLevel: number, device: DeviceType, callback: AsyncCallback&lt;number&gt;): void
3864
3865Obtains the volume gain. This API uses an asynchronous callback to return the result.
3866
3867**System capability**: SystemCapability.Multimedia.Audio.Volume
3868
3869**Parameters**
3870
3871| Name    | Type                               | Mandatory| Description                                                    |
3872| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3873| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
3874| volumeLevel | number                         | Yes  | Volume level.                                              |
3875| device     | [DeviceType](#devicetype)           | Yes  | Device type.                                              |
3876| callback   | AsyncCallback&lt;number&gt;           | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the volume gain obtained; otherwise, **err** is an error object.|
3877
3878**Error codes**
3879
3880For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3881
3882| ID| Error Message|
3883| ------- | --------------------------------------------|
3884| 6800101 | Invalid parameter error. Return by callback.                     |
3885| 6800301 | System error. Return by callback.                                |
3886
3887**Example**
3888
3889```ts
3890import { BusinessError } from '@ohos.base';
3891
3892audioVolumeGroupManager.getSystemVolumeInDb(audio.AudioVolumeType.MEDIA, 3, audio.DeviceType.SPEAKER, (err: BusinessError, dB: number) => {
3893  if (err) {
3894    console.error(`Failed to get the volume DB. ${err}`);
3895  } else {
3896    console.info(`Success to get the volume DB. ${dB}`);
3897  }
3898});
3899```
3900### getSystemVolumeInDb<sup>10+</sup>
3901
3902getSystemVolumeInDb(volumeType: AudioVolumeType, volumeLevel: number, device: DeviceType): Promise&lt;number&gt;
3903
3904Obtains the volume gain. This API uses a promise to return the result.
3905
3906**System capability**: SystemCapability.Multimedia.Audio.Volume
3907
3908**Parameters**
3909
3910| Name    | Type                               | Mandatory| Description                                                    |
3911| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3912| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
3913| volumeLevel | number                              | Yes  | Volume level.                                            |
3914| device     | [DeviceType](#devicetype)           | Yes  | Device type.                                              |
3915
3916**Return value**
3917
3918| Type                 | Description                              |
3919| --------------------- | ---------------------------------- |
3920| Promise&lt;number&gt; | Promise used to return the volume gain (in dB).|
3921
3922**Error codes**
3923
3924For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3925
3926| ID| Error Message|
3927| ------- | --------------------------------------------|
3928| 6800101 | Invalid parameter error. Return by promise.                     |
3929| 6800301 | System error. Return by promise.                                |
3930
3931**Example**
3932
3933```ts
3934import { BusinessError } from '@ohos.base';
3935
3936audioVolumeGroupManager.getSystemVolumeInDb(audio.AudioVolumeType.MEDIA, 3, audio.DeviceType.SPEAKER).then((value: number) => {
3937  console.info(`Success to get the volume DB. ${value}`);
3938}).catch((error: BusinessError) => {
3939  console.error(`Fail to adjust the system volume by step. ${error}`);
3940});
3941```
3942
3943### getSystemVolumeInDbSync<sup>10+</sup>
3944
3945getSystemVolumeInDbSync(volumeType: AudioVolumeType, volumeLevel: number, device: DeviceType): number
3946
3947Obtains the volume gain. This API returns the result synchronously.
3948
3949**System capability**: SystemCapability.Multimedia.Audio.Volume
3950
3951**Parameters**
3952
3953| Name    | Type                               | Mandatory| Description                                                    |
3954| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3955| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
3956| volumeLevel | number                              | Yes  | Volume level.                                            |
3957| device     | [DeviceType](#devicetype)           | Yes  | Device type.                                              |
3958
3959**Return value**
3960
3961| Type                 | Description                              |
3962| --------------------- | ---------------------------------- |
3963| number | Volume gain (in dB).|
3964
3965**Error codes**
3966
3967For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3968
3969| ID| Error Message|
3970| ------- | --------------------------------------------|
3971| 6800101 | invalid parameter error                     |
3972
3973**Example**
3974
3975```ts
3976import { BusinessError } from '@ohos.base';
3977
3978try {
3979  let value: number = audioVolumeGroupManager.getSystemVolumeInDbSync(audio.AudioVolumeType.MEDIA, 3, audio.DeviceType.SPEAKER);
3980  console.info(`Success to get the volume DB. ${value}`);
3981} catch (err) {
3982  let error = err as BusinessError;
3983  console.error(`Fail to adjust the system volume by step. ${error}`);
3984}
3985```
3986
3987## AudioStreamManager<sup>9+</sup>
3988
3989Implements audio stream management. Before calling any API in **AudioStreamManager**, you must use [getStreamManager](#getstreammanager9) to obtain an **AudioStreamManager** instance.
3990
3991### getCurrentAudioRendererInfoArray<sup>9+</sup>
3992
3993getCurrentAudioRendererInfoArray(callback: AsyncCallback&lt;AudioRendererChangeInfoArray&gt;): void
3994
3995Obtains the information about the current audio renderer. This API uses an asynchronous callback to return the result.
3996
3997**System capability**: SystemCapability.Multimedia.Audio.Renderer
3998
3999**Parameters**
4000
4001| Name     | Type                                                         | Mandatory | Description                                                  |
4002| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4003| callback | AsyncCallback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the information about the current audio renderer obtained; otherwise, **err** is an error object. |
4004
4005**Example**
4006
4007```ts
4008import { BusinessError } from '@ohos.base';
4009
4010audioStreamManager.getCurrentAudioRendererInfoArray(async (err: BusinessError, AudioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray) => {
4011  console.info('getCurrentAudioRendererInfoArray **** Get Callback Called ****');
4012  if (err) {
4013    console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`);
4014  } else {
4015    if (AudioRendererChangeInfoArray != null) {
4016      for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
4017        let AudioRendererChangeInfo: audio.AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
4018        console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
4019        console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
4020        console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
4021        console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
4022        for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
4023          console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
4024          console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
4025          console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
4026          console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
4027          console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
4028          console.info(`SampleRate: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
4029          console.info(`ChannelCount: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
4030          console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
4031        }
4032      }
4033    }
4034  }
4035});
4036```
4037
4038### getCurrentAudioRendererInfoArray<sup>9+</sup>
4039
4040getCurrentAudioRendererInfoArray(): Promise&lt;AudioRendererChangeInfoArray&gt;
4041
4042Obtains the information about the current audio renderer. This API uses a promise to return the result.
4043
4044**System capability**: SystemCapability.Multimedia.Audio.Renderer
4045
4046**Return value**
4047
4048| Type                                                         | Description                                      |
4049| ------------------------------------------------------------ | ------------------------------------------------ |
4050| Promise<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Promise used to return the renderer information. |
4051
4052**Example**
4053
4054```ts
4055import { BusinessError } from '@ohos.base';
4056
4057async function getCurrentAudioRendererInfoArray(){
4058  await audioStreamManager.getCurrentAudioRendererInfoArray().then((AudioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray) => {
4059    console.info(`getCurrentAudioRendererInfoArray ######### Get Promise is called ##########`);
4060    if (AudioRendererChangeInfoArray != null) {
4061      for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
4062        let AudioRendererChangeInfo: audio.AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
4063        console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
4064        console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
4065        console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
4066        console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
4067        for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
4068          console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
4069          console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
4070          console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
4071          console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
4072          console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
4073          console.info(`SampleRate: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
4074          console.info(`ChannelCount: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
4075          console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
4076        }
4077      }
4078    }
4079  }).catch((err: BusinessError) => {
4080    console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`);
4081  });
4082}
4083```
4084
4085### getCurrentAudioRendererInfoArraySync<sup>10+</sup>
4086
4087getCurrentAudioRendererInfoArraySync(): AudioRendererChangeInfoArray
4088
4089Obtains the information about the current audio renderer. This API returns the result synchronously.
4090
4091**System capability**: SystemCapability.Multimedia.Audio.Renderer
4092
4093**Return value**
4094
4095| Type                                                         | Description                 |
4096| ------------------------------------------------------------ | --------------------------- |
4097| [AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9) | Audio renderer information. |
4098
4099**Example**
4100
4101```ts
4102import { BusinessError } from '@ohos.base';
4103
4104try {
4105  let audioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray = audioStreamManager.getCurrentAudioRendererInfoArraySync();
4106  console.info(`getCurrentAudioRendererInfoArraySync success.`);
4107  if (audioRendererChangeInfoArray != null) {
4108    for (let i = 0; i < audioRendererChangeInfoArray.length; i++) {
4109      let AudioRendererChangeInfo: audio.AudioRendererChangeInfo = audioRendererChangeInfoArray[i];
4110      console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
4111      console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
4112      console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
4113      console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
4114      for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
4115        console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
4116        console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
4117        console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
4118        console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
4119        console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
4120        console.info(`SampleRate: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
4121        console.info(`ChannelCount: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
4122        console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
4123      }
4124    }
4125  }
4126} catch (err) {
4127  let error = err as BusinessError;
4128  console.error(`getCurrentAudioRendererInfoArraySync :ERROR: ${error}`);
4129}
4130```
4131
4132### getCurrentAudioCapturerInfoArray<sup>9+</sup>
4133
4134getCurrentAudioCapturerInfoArray(callback: AsyncCallback&lt;AudioCapturerChangeInfoArray&gt;): void
4135
4136Obtains the information about the current audio capturer. This API uses an asynchronous callback to return the result.
4137
4138**System capability**: SystemCapability.Multimedia.Audio.Renderer
4139
4140**Parameters**
4141
4142| Name     | Type                                                         | Mandatory | Description                                                  |
4143| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4144| callback | AsyncCallback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the information about the current audio capturer obtained; otherwise, **err** is an error object. |
4145
4146**Example**
4147
4148```ts
4149import { BusinessError } from '@ohos.base';
4150
4151audioStreamManager.getCurrentAudioCapturerInfoArray(async (err: BusinessError, AudioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray) => {
4152  console.info('getCurrentAudioCapturerInfoArray **** Get Callback Called ****');
4153  if (err) {
4154    console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
4155  } else {
4156    if (AudioCapturerChangeInfoArray != null) {
4157      for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
4158        console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
4159        console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
4160        console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
4161        for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
4162          console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
4163          console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
4164          console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
4165          console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
4166          console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
4167          console.info(`SampleRate: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
4168          console.info(`ChannelCount: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
4169          console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
4170        }
4171      }
4172    }
4173  }
4174});
4175```
4176
4177### getCurrentAudioCapturerInfoArray<sup>9+</sup>
4178
4179getCurrentAudioCapturerInfoArray(): Promise&lt;AudioCapturerChangeInfoArray&gt;
4180
4181Obtains the information about the current audio capturer. This API uses a promise to return the result.
4182
4183**System capability**: SystemCapability.Multimedia.Audio.Renderer
4184
4185**Return value**
4186
4187| Type                                                         | Description                                      |
4188| ------------------------------------------------------------ | ------------------------------------------------ |
4189| Promise<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Promise used to return the audio capturer information. |
4190
4191**Example**
4192
4193```ts
4194import { BusinessError } from '@ohos.base';
4195
4196async function getCurrentAudioCapturerInfoArray(){
4197  await audioStreamManager.getCurrentAudioCapturerInfoArray().then((AudioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray) => {
4198    console.info('getCurrentAudioCapturerInfoArray **** Get Promise Called ****');
4199    if (AudioCapturerChangeInfoArray != null) {
4200      for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
4201        console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
4202        console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
4203        console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
4204        for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
4205          console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
4206          console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
4207          console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
4208          console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
4209          console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
4210          console.info(`SampleRate: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
4211          console.info(`ChannelCount: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
4212          console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
4213        }
4214      }
4215    }
4216  }).catch((err: BusinessError) => {
4217    console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
4218  });
4219}
4220```
4221
4222### getCurrentAudioCapturerInfoArraySync<sup>10+</sup>
4223
4224getCurrentAudioCapturerInfoArraySync(): AudioCapturerChangeInfoArray
4225
4226Obtains the information about the current audio capturer. This API returns the result synchronously.
4227
4228**System capability**: SystemCapability.Multimedia.Audio.Capturer
4229
4230**Return value**
4231
4232| Type                                                         | Description                 |
4233| ------------------------------------------------------------ | --------------------------- |
4234| [AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9) | Audio capturer information. |
4235
4236**Example**
4237
4238```ts
4239import { BusinessError } from '@ohos.base';
4240
4241try {
4242  let audioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray = audioStreamManager.getCurrentAudioCapturerInfoArraySync();
4243  console.info('getCurrentAudioCapturerInfoArraySync success.');
4244  if (audioCapturerChangeInfoArray != null) {
4245    for (let i = 0; i < audioCapturerChangeInfoArray.length; i++) {
4246      console.info(`StreamId for ${i} is: ${audioCapturerChangeInfoArray[i].streamId}`);
4247      console.info(`Source for ${i} is: ${audioCapturerChangeInfoArray[i].capturerInfo.source}`);
4248      console.info(`Flag  ${i} is: ${audioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
4249      for (let j = 0; j < audioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
4250        console.info(`Id: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
4251        console.info(`Type: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
4252        console.info(`Role: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
4253        console.info(`Name: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
4254        console.info(`Address: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
4255        console.info(`SampleRate: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
4256        console.info(`ChannelCount: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
4257        console.info(`ChannelMask: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
4258      }
4259    }
4260  }
4261} catch (err) {
4262  let error = err as BusinessError;
4263  console.error(`getCurrentAudioCapturerInfoArraySync ERROR: ${error}`);
4264}
4265```
4266
4267### on('audioRendererChange')<sup>9+</sup>
4268
4269on(type: 'audioRendererChange', callback: Callback&lt;AudioRendererChangeInfoArray&gt;): void
4270
4271Subscribes to audio renderer change events. This API uses an asynchronous callback to return the result.
4272
4273**System capability**: SystemCapability.Multimedia.Audio.Renderer
4274
4275**Parameters**
4276
4277| Name     | Type                                                         | Mandatory | Description                                                  |
4278| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4279| type     | string                                                       | Yes       | Event type. The event `'audioRendererChange'` is triggered when the audio renderer is changed. |
4280| callback | Callback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Yes       | Callback used to return the audio renderer information.      |
4281
4282**Error codes**
4283
4284For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4285
4286| ID      | Error Message            |
4287| ------- | ------------------------ |
4288| 6800101 | Invalid parameter error. |
4289
4290**Example**
4291
4292```ts
4293audioStreamManager.on('audioRendererChange',  (AudioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray) => {
4294  for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
4295    let AudioRendererChangeInfo: audio.AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
4296    console.info(`## RendererChange on is called for ${i} ##`);
4297    console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
4298    console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
4299    console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
4300    console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
4301    for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
4302      console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
4303      console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
4304      console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
4305      console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
4306      console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
4307      console.info(`SampleRate: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
4308      console.info(`ChannelCount: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
4309      console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
4310    }
4311  }
4312});
4313```
4314
4315### off('audioRendererChange')<sup>9+</sup>
4316
4317off(type: 'audioRendererChange'): void
4318
4319Unsubscribes from audio renderer change events.
4320
4321**System capability**: SystemCapability.Multimedia.Audio.Renderer
4322
4323**Parameters**
4324
4325| Name | Type   | Mandatory | Description                                                  |
4326| ---- | ------ | --------- | ------------------------------------------------------------ |
4327| type | string | Yes       | Event type. The event `'audioRendererChange'` is triggered when the audio renderer is changed. |
4328
4329**Error codes**
4330
4331For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4332
4333| ID      | Error Message            |
4334| ------- | ------------------------ |
4335| 6800101 | Invalid parameter error. |
4336
4337**Example**
4338
4339```ts
4340audioStreamManager.off('audioRendererChange');
4341console.info('######### RendererChange Off is called #########');
4342```
4343
4344### on('audioCapturerChange')<sup>9+</sup>
4345
4346on(type: 'audioCapturerChange', callback: Callback&lt;AudioCapturerChangeInfoArray&gt;): void
4347
4348Subscribes to audio capturer change events. This API uses an asynchronous callback to return the result.
4349
4350**System capability**: SystemCapability.Multimedia.Audio.Capturer
4351
4352**Parameters**
4353
4354| Name     | Type                                                         | Mandatory | Description                                                  |
4355| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4356| type     | string                                                       | Yes       | Event type. The event `'audioCapturerChange'` is triggered when the audio capturer is changed. |
4357| callback | Callback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Yes       | Callback used to return the audio capturer information.      |
4358
4359**Error codes**
4360
4361For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4362
4363| ID      | Error Message            |
4364| ------- | ------------------------ |
4365| 6800101 | Invalid parameter error. |
4366
4367**Example**
4368
4369```ts
4370audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray) =>  {
4371  for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
4372    console.info(`## CapChange on is called for element ${i} ##`);
4373    console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
4374    console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
4375    console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
4376    for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
4377      console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
4378      console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
4379      console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
4380      console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
4381      console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
4382      console.info(`SampleRate: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
4383      console.info(`ChannelCount: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
4384      console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
4385    }
4386  }
4387});
4388
4389```
4390
4391### off('audioCapturerChange')<sup>9+</sup>
4392
4393off(type: 'audioCapturerChange'): void
4394
4395Unsubscribes from audio capturer change events.
4396
4397**System capability**: SystemCapability.Multimedia.Audio.Capturer
4398
4399**Parameters**
4400
4401| Name | Type   | Mandatory | Description                                                  |
4402| ---- | ------ | --------- | ------------------------------------------------------------ |
4403| type | string | Yes       | Event type. The event `'audioCapturerChange'` is triggered when the audio capturer is changed. |
4404
4405**Error codes**
4406
4407For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4408
4409| ID      | Error Message            |
4410| ------- | ------------------------ |
4411| 6800101 | Invalid parameter error. |
4412
4413**Example**
4414
4415```ts
4416audioStreamManager.off('audioCapturerChange');
4417console.info('######### CapturerChange Off is called #########');
4418
4419
4420```
4421
4422### isActive<sup>9+</sup>
4423
4424isActive(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
4425
4426Checks whether a stream is active. This API uses an asynchronous callback to return the result.
4427
4428**System capability**: SystemCapability.Multimedia.Audio.Renderer
4429
4430**Parameters**
4431
4432| Name       | Type                                | Mandatory | Description                                                  |
4433| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------ |
4434| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream types.                                          |
4435| callback   | AsyncCallback&lt;boolean&gt;        | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true** if the stream is active or **false** if not active; otherwise, **err** is an error object. |
4436
4437**Example**
4438
4439```ts
4440import { BusinessError } from '@ohos.base';
4441
4442audioStreamManager.isActive(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => {
4443if (err) {
4444  console.error(`Failed to obtain the active status of the stream. ${err}`);
4445  return;
4446}
4447  console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`);
4448});
4449
4450```
4451
4452### isActive<sup>9+</sup>
4453
4454isActive(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
4455
4456Checks whether a stream is active. This API uses a promise to return the result.
4457
4458**System capability**: SystemCapability.Multimedia.Audio.Renderer
4459
4460**Parameters**
4461
4462| Name       | Type                                | Mandatory | Description         |
4463| ---------- | ----------------------------------- | --------- | ------------------- |
4464| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream types. |
4465
4466**Return value**
4467
4468| Type                   | Description                                                  |
4469| ---------------------- | ------------------------------------------------------------ |
4470| Promise&lt;boolean&gt; | Promise used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite. |
4471
4472**Example**
4473
4474```ts
4475audioStreamManager.isActive(audio.AudioVolumeType.MEDIA).then((value: boolean) => {
4476  console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`);
4477});
4478
4479```
4480
4481### isActiveSync<sup>10+</sup>
4482
4483isActiveSync(volumeType: AudioVolumeType): boolean
4484
4485Checks whether a stream is active. This API returns the result synchronously.
4486
4487**System capability**: SystemCapability.Multimedia.Audio.Renderer
4488
4489**Parameters**
4490
4491| Name       | Type                                | Mandatory | Description         |
4492| ---------- | ----------------------------------- | --------- | ------------------- |
4493| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream types. |
4494
4495**Return value**
4496
4497| Type    | Description                                                  |
4498| ------- | ------------------------------------------------------------ |
4499| boolean | Returns **true** if the stream is active; returns **false** otherwise. |
4500
4501**Error codes**
4502
4503For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4504
4505| ID      | Error Message           |
4506| ------- | ----------------------- |
4507| 6800101 | invalid parameter error |
4508
4509**Example**
4510
4511```ts
4512import { BusinessError } from '@ohos.base';
4513
4514try {
4515  let value: boolean = audioStreamManager.isActiveSync(audio.AudioVolumeType.MEDIA);
4516  console.info(`Indicate that the active status of the stream is obtained ${value}.`);
4517} catch (err) {
4518  let error = err as BusinessError;
4519  console.error(`Failed to obtain the active status of the stream ${error}.`);
4520}
4521
4522```
4523
4524### getAudioEffectInfoArray<sup>10+</sup>
4525
4526getAudioEffectInfoArray(usage: StreamUsage, callback: AsyncCallback&lt;AudioEffectInfoArray&gt;): void
4527
4528Obtains information about the audio effect mode in use. This API uses an asynchronous callback to return the result.
4529
4530**System capability**: SystemCapability.Multimedia.Audio.Renderer
4531
4532**Parameters**
4533
4534| Name     | Type                                                         | Mandatory | Description                                                  |
4535| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4536| usage    | [StreamUsage](#streamusage)                                  | Yes       | Audio stream usage.                                          |
4537| callback | AsyncCallback<[AudioEffectInfoArray](#audioeffectinfoarray10)> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the information about the audio effect mode obtained; otherwise, **err** is an error object. |
4538
4539**Error codes**
4540
4541For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4542
4543| ID      | Error Message                                |
4544| ------- | -------------------------------------------- |
4545| 6800101 | Invalid parameter error. Return by callback. |
4546
4547**Example**
4548
4549```ts
4550import { BusinessError } from '@ohos.base';
4551
4552audioStreamManager.getAudioEffectInfoArray(audio.StreamUsage.STREAM_USAGE_MUSIC, async (err: BusinessError, audioEffectInfoArray: audio.AudioEffectInfoArray) => {
4553  console.info('getAudioEffectInfoArray **** Get Callback Called ****');
4554  if (err) {
4555    console.error(`getAudioEffectInfoArray :ERROR: ${err}`);
4556    return;
4557  } else {
4558    console.info(`The effect modes are: ${audioEffectInfoArray}`);
4559  }
4560});
4561
4562```
4563
4564### getAudioEffectInfoArray<sup>10+</sup>
4565
4566getAudioEffectInfoArray(usage: StreamUsage): Promise&lt;AudioEffectInfoArray&gt;
4567
4568Obtains information about the audio effect mode in use. This API uses a promise to return the result.
4569
4570**System capability**: SystemCapability.Multimedia.Audio.Renderer
4571
4572**Parameters**
4573
4574| Name  | Type                        | Mandatory | Description         |
4575| ----- | --------------------------- | --------- | ------------------- |
4576| usage | [StreamUsage](#streamusage) | Yes       | Audio stream usage. |
4577
4578**Return value**
4579
4580| Type                                                     | Description                                                  |
4581| -------------------------------------------------------- | ------------------------------------------------------------ |
4582| Promise<[AudioEffectInfoArray](#audioeffectinfoarray10)> | Promise used to return the information about the audio effect mode obtained. |
4583
4584**Error codes**
4585
4586For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4587
4588| ID      | Error Message                               |
4589| ------- | ------------------------------------------- |
4590| 6800101 | Invalid parameter error. Return by promise. |
4591
4592**Example**
4593
4594```ts
4595import { BusinessError } from '@ohos.base';
4596
4597audioStreamManager.getAudioEffectInfoArray(audio.StreamUsage.STREAM_USAGE_MUSIC).then((audioEffectInfoArray: audio.AudioEffectInfoArray) => {
4598  console.info('getAudioEffectInfoArray ######### Get Promise is called ##########');
4599  console.info(`The effect modes are: ${audioEffectInfoArray}`);
4600}).catch((err: BusinessError) => {
4601  console.error(`getAudioEffectInfoArray :ERROR: ${err}`);
4602});
4603
4604```
4605
4606### getAudioEffectInfoArraySync<sup>10+</sup>
4607
4608getAudioEffectInfoArraySync(usage: StreamUsage): AudioEffectInfoArray
4609
4610Obtains information about the audio effect mode in use. This API returns the result synchronously.
4611
4612**System capability**: SystemCapability.Multimedia.Audio.Renderer
4613
4614**Parameters**
4615
4616| Name  | Type                        | Mandatory | Description         |
4617| ----- | --------------------------- | --------- | ------------------- |
4618| usage | [StreamUsage](#streamusage) | Yes       | Audio stream usage. |
4619
4620**Return value**
4621
4622| Type                                            | Description                              |
4623| ----------------------------------------------- | ---------------------------------------- |
4624| [AudioEffectInfoArray](#audioeffectinfoarray10) | Information about the audio effect mode. |
4625
4626**Error codes**
4627
4628For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4629
4630| ID      | Error Message            |
4631| ------- | ------------------------ |
4632| 6800101 | Invalid parameter error. |
4633
4634**Example**
4635
4636```ts
4637import { BusinessError } from '@ohos.base';
4638
4639try {
4640  let audioEffectInfoArray: audio.AudioEffectInfoArray = audioStreamManager.getAudioEffectInfoArraySync(audio.StreamUsage.STREAM_USAGE_MUSIC);
4641  console.info(`The effect modes are: ${audioEffectInfoArray}`);
4642} catch (err) {
4643  let error = err as BusinessError;
4644  console.error(`getAudioEffectInfoArraySync ERROR: ${error}`);
4645}
4646
4647```
4648
4649## AudioRoutingManager<sup>9+</sup>
4650
4651Implements audio routing management. Before calling any API in **AudioRoutingManager**, you must use [getRoutingManager](#getroutingmanager9) to obtain an **AudioRoutingManager** instance.
4652
4653### getDevices<sup>9+</sup>
4654
4655getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
4656
4657Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the result.
4658
4659**System capability**: SystemCapability.Multimedia.Audio.Device
4660
4661**Parameters**
4662
4663| Name       | Type                                                         | Mandatory | Description                                                  |
4664| ---------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4665| deviceFlag | [DeviceFlag](#deviceflag)                                    | Yes       | Audio device flag.                                           |
4666| callback   | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the audio devices obtained; otherwise, **err** is an error object. |
4667
4668**Example**
4669
4670```ts
4671import { BusinessError } from '@ohos.base';
4672
4673audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err: BusinessError, value: audio.AudioDeviceDescriptors) => {
4674  if (err) {
4675    console.error(`Failed to obtain the device list. ${err}`);
4676    return;
4677  }
4678  console.info('Callback invoked to indicate that the device list is obtained.');
4679});
4680
4681```
4682
4683### getDevices<sup>9+</sup>
4684
4685getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
4686
4687Obtains the audio devices with a specific flag. This API uses a promise to return the result.
4688
4689**System capability**: SystemCapability.Multimedia.Audio.Device
4690
4691**Parameters**
4692
4693| Name       | Type                      | Mandatory | Description        |
4694| ---------- | ------------------------- | --------- | ------------------ |
4695| deviceFlag | [DeviceFlag](#deviceflag) | Yes       | Audio device flag. |
4696
4697**Return value**
4698
4699| Type                                                         | Description                             |
4700| ------------------------------------------------------------ | --------------------------------------- |
4701| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the device list. |
4702
4703**Example**
4704
4705```ts
4706audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data: audio.AudioDeviceDescriptors) => {
4707  console.info('Promise returned to indicate that the device list is obtained.');
4708});
4709
4710```
4711
4712### getDevicesSync<sup>10+</sup>
4713
4714getDevicesSync(deviceFlag: DeviceFlag): AudioDeviceDescriptors
4715
4716Obtains the audio devices with a specific flag. This API returns the result synchronously.
4717
4718**System capability**: SystemCapability.Multimedia.Audio.Device
4719
4720**Parameters**
4721
4722| Name       | Type                      | Mandatory | Description        |
4723| ---------- | ------------------------- | --------- | ------------------ |
4724| deviceFlag | [DeviceFlag](#deviceflag) | Yes       | Audio device flag. |
4725
4726**Return value**
4727
4728| Type                                              | Description  |
4729| ------------------------------------------------- | ------------ |
4730| [AudioDeviceDescriptors](#audiodevicedescriptors) | Device list. |
4731
4732**Error codes**
4733
4734For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4735
4736| ID      | Error Message           |
4737| ------- | ----------------------- |
4738| 6800101 | invalid parameter error |
4739
4740**Example**
4741
4742```ts
4743import { BusinessError } from '@ohos.base';
4744
4745try {
4746  let data: audio.AudioDeviceDescriptors = audioRoutingManager.getDevicesSync(audio.DeviceFlag.OUTPUT_DEVICES_FLAG);
4747  console.info(`Indicate that the device list is obtained ${data}`);
4748} catch (err) {
4749  let error = err as BusinessError;
4750  console.error(`Failed to obtain the device list. ${error}`);
4751}
4752
4753```
4754
4755### on('deviceChange')<sup>9+</sup>
4756
4757on(type: 'deviceChange', deviceFlag: DeviceFlag, callback: Callback<DeviceChangeAction\>): void
4758
4759Subscribes to audio device connection change events. This API uses an asynchronous callback to return the result.
4760
4761**System capability**: SystemCapability.Multimedia.Audio.Device
4762
4763**Parameters**
4764
4765| Name       | Type                                                 | Mandatory | Description                                                  |
4766| :--------- | :--------------------------------------------------- | :-------- | :----------------------------------------------------------- |
4767| type       | string                                               | Yes       | Event type. The event **'deviceChange'** is triggered when the device connection status is changed. |
4768| deviceFlag | [DeviceFlag](#deviceflag)                            | Yes       | Audio device flag.                                           |
4769| callback   | Callback<[DeviceChangeAction](#devicechangeaction)\> | Yes       | Callback used to return the device change details.           |
4770
4771**Error codes**
4772
4773For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4774
4775| ID      | Error Message            |
4776| ------- | ------------------------ |
4777| 6800101 | Invalid parameter error. |
4778
4779**Example**
4780
4781```ts
4782audioRoutingManager.on('deviceChange', audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (deviceChanged: audio.DeviceChangeAction) => {
4783  console.info('device change type : ' + deviceChanged.type);
4784  console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
4785  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole);
4786  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType);
4787});
4788
4789```
4790
4791### off('deviceChange')<sup>9+</sup>
4792
4793off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void
4794
4795Unsubscribes from audio device connection change events. This API uses an asynchronous callback to return the result.
4796
4797**System capability**: SystemCapability.Multimedia.Audio.Device
4798
4799**Parameters**
4800
4801| Name     | Type                                                | Mandatory | Description                                                  |
4802| -------- | --------------------------------------------------- | --------- | ------------------------------------------------------------ |
4803| type     | string                                              | Yes       | Event type. The event **'deviceChange'** is triggered when the device connection status is changed. |
4804| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | No        | Callback used to return the device change details.           |
4805
4806**Error codes**
4807
4808For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4809
4810| ID      | Error Message            |
4811| ------- | ------------------------ |
4812| 6800101 | Invalid parameter error. |
4813
4814**Example**
4815
4816```ts
4817audioRoutingManager.off('deviceChange');
4818
4819```
4820
4821### getAvailableDevices<sup>11+</sup>
4822
4823getAvailableDevices(deviceUsage: DeviceUsage): AudioDeviceDescriptors
4824
4825Obtains the available audio devices. This API returns the result synchronously.
4826
4827**System capability**: SystemCapability.Multimedia.Audio.Device
4828
4829**System API**: This is a system API.
4830
4831**Parameters**
4832
4833| Name        | Type                        | Mandatory | Description   |
4834| ----------- | --------------------------- | --------- | ------------- |
4835| deviceUsage | [DeviceUsage](#deviceusage) | Yes       | Device usage. |
4836
4837**Return value**
4838
4839| Type                                              | Description  |
4840| ------------------------------------------------- | ------------ |
4841| [AudioDeviceDescriptors](#audiodevicedescriptors) | Device list. |
4842
4843**Error codes**
4844
4845For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4846
4847| ID      | Error Message           |
4848| ------- | ----------------------- |
4849| 6800101 | invalid parameter error |
4850
4851**Example**
4852
4853```ts
4854import { BusinessError } from '@ohos.base';
4855
4856try {
4857  let data: audio.AudioDeviceDescriptors = audioRoutingManager.getAvailableDevices(audio.DeviceUsage.MEDIA_OUTPUT_DEVICES);
4858  console.info(`Indicate that the device list is obtained ${data}`);
4859} catch (err) {
4860  let error = err as BusinessError;
4861  console.error(`Failed to obtain the device list. ${error}`);
4862}
4863
4864```
4865
4866### on('availableDeviceChange')<sup>11+</sup>
4867
4868on(type: 'availableDeviceChange', deviceUsage: DeviceUsage, callback: Callback<DeviceChangeAction\>): void
4869
4870Subscribes to available audio device change events. This API uses an asynchronous callback to return the result.
4871
4872**System capability**: SystemCapability.Multimedia.Audio.Device
4873
4874**System API**: This is a system API.
4875
4876**Parameters**
4877
4878| Name        | Type                                                 | Mandatory | Description                                                  |
4879| :---------- | :--------------------------------------------------- | :-------- | :----------------------------------------------------------- |
4880| type        | string                                               | Yes       | Event type. The event **'availableDeviceChange'** is triggered when the available devices change. |
4881| deviceUsage | [DeviceUsage](#deviceusage)                          | Yes       | Device usage.                                                |
4882| callback    | Callback<[DeviceChangeAction](#devicechangeaction)\> | Yes       | Callback used to return the available device change details.           |
4883
4884**Error codes**
4885
4886For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4887
4888| ID      | Error Message            |
4889| ------- | ------------------------ |
4890| 6800101 | Invalid parameter error. |
4891
4892**Example**
4893
4894```ts
4895audioRoutingManager.on('availableDeviceChange', audio.DeviceUsage.MEDIA_OUTPUT_DEVICES, (deviceChanged: audio.DeviceChangeAction) => {
4896  console.info('device change type : ' + deviceChanged.type);
4897  console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
4898  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole);
4899  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType);
4900});
4901
4902```
4903
4904### off('availableDeviceChange')<sup>11+</sup>
4905
4906off(type: 'availableDeviceChange', callback?: Callback<DeviceChangeAction\>): void
4907
4908Unsubscribes from available audio device change events. This API uses an asynchronous callback to return the result.
4909
4910**System capability**: SystemCapability.Multimedia.Audio.Device
4911
4912**System API**: This is a system API.
4913
4914**Parameters**
4915
4916| Name     | Type                                                | Mandatory | Description                                                  |
4917| -------- | --------------------------------------------------- | --------- | ------------------------------------------------------------ |
4918| type     | string                                              | Yes       | Event type. The event **'availableDeviceChange'** is triggered when the available devices change. |
4919| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | No        | Callback used to return the available device change details. |
4920
4921**Error codes**
4922
4923For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4924
4925| ID      | Error Message            |
4926| ------- | ------------------------ |
4927| 6800101 | Invalid parameter error. |
4928
4929**Example**
4930
4931```ts
4932audioRoutingManager.off('availableDeviceChange');
4933
4934```
4935
4936### selectInputDevice<sup>9+</sup>
4937
4938selectInputDevice(inputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
4939
4940Selects an audio input device. Currently, only one input device can be selected. This API uses an asynchronous callback to return the result.
4941
4942**System API**: This is a system API.
4943
4944**System capability**: SystemCapability.Multimedia.Audio.Device
4945
4946**Parameters**
4947
4948| Name              | Type                                              | Mandatory | Description                                                  |
4949| ----------------- | ------------------------------------------------- | --------- | ------------------------------------------------------------ |
4950| inputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes       | Input device.                                                |
4951| callback          | AsyncCallback&lt;void&gt;                         | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
4952
4953**Example**
4954
4955```ts
4956import audio from '@ohos.multimedia.audio';
4957import { BusinessError } from '@ohos.base';
4958
4959let inputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{
4960  deviceRole : audio.DeviceRole.INPUT_DEVICE,
4961  deviceType : audio.DeviceType.MIC,
4962  id : 1,
4963  name : "",
4964  address : "",
4965  sampleRates : [44100],
4966  channelCounts : [2],
4967  channelMasks : [0],
4968  networkId : audio.LOCAL_NETWORK_ID,
4969  interruptGroupId : 1,
4970  volumeGroupId : 1,
4971  displayName : "",
4972}];
4973
4974async function selectInputDevice(){
4975  audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor, (err: BusinessError) => {
4976    if (err) {
4977      console.error(`Result ERROR: ${err}`);
4978    } else {
4979      console.info('Select input devices result callback: SUCCESS');
4980    }
4981  });
4982}
4983
4984```
4985
4986### selectInputDevice<sup>9+</sup>
4987
4988selectInputDevice(inputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
4989
4990**System API**: This is a system API.
4991
4992Selects an audio input device. Currently, only one input device can be selected. This API uses a promise to return the result.
4993
4994**System capability**: SystemCapability.Multimedia.Audio.Device
4995
4996**Parameters**
4997
4998| Name              | Type                                              | Mandatory | Description   |
4999| ----------------- | ------------------------------------------------- | --------- | ------------- |
5000| inputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes       | Input device. |
5001
5002**Return value**
5003
5004| Type                | Description                    |
5005| ------------------- | ------------------------------ |
5006| Promise&lt;void&gt; | Promise that returns no value. |
5007
5008**Example**
5009
5010```ts
5011import audio from '@ohos.multimedia.audio';
5012import { BusinessError } from '@ohos.base';
5013
5014let inputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{
5015  deviceRole : audio.DeviceRole.INPUT_DEVICE,
5016  deviceType : audio.DeviceType.MIC,
5017  id : 1,
5018  name : "",
5019  address : "",
5020  sampleRates : [44100],
5021  channelCounts : [2],
5022  channelMasks : [0],
5023  networkId : audio.LOCAL_NETWORK_ID,
5024  interruptGroupId : 1,
5025  volumeGroupId : 1,
5026  displayName : "",
5027}];
5028
5029async function getRoutingManager(){
5030  audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor).then(() => {
5031    console.info('Select input devices result promise: SUCCESS');
5032  }).catch((err: BusinessError) => {
5033    console.error(`Result ERROR: ${err}`);
5034  });
5035}
5036
5037```
5038
5039### setCommunicationDevice<sup>9+</sup>
5040
5041setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
5042
5043Sets a communication device to the active state. This API uses an asynchronous callback to return the result.
5044
5045This API will be deprecated in a later version due to function design changes. You are not advised to use it.
5046
5047**System capability**: SystemCapability.Multimedia.Audio.Communication
5048
5049**Parameters**
5050
5051| Name       | Type                                                 | Mandatory | Description                                                  |
5052| ---------- | ---------------------------------------------------- | --------- | ------------------------------------------------------------ |
5053| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes       | Communication device type.                                   |
5054| active     | boolean                                              | Yes       | Active status of the device. The value **true** means to set the device to the active state, and **false** means the opposite. |
5055| callback   | AsyncCallback&lt;void&gt;                            | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
5056
5057**Example**
5058
5059```ts
5060import { BusinessError } from '@ohos.base';
5061
5062audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true, (err: BusinessError) => {
5063  if (err) {
5064    console.error(`Failed to set the active status of the device. ${err}`);
5065    return;
5066  }
5067  console.info('Callback invoked to indicate that the device is set to the active status.');
5068});
5069
5070```
5071
5072### setCommunicationDevice<sup>9+</sup>
5073
5074setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean): Promise&lt;void&gt;
5075
5076Sets a communication device to the active state. This API uses a promise to return the result.
5077
5078This API will be deprecated in a later version due to function design changes. You are not advised to use it.
5079
5080**System capability**: SystemCapability.Multimedia.Audio.Communication
5081
5082**Parameters**
5083
5084| Name       | Type                                                 | Mandatory | Description                                                  |
5085| ---------- | ---------------------------------------------------- | --------- | ------------------------------------------------------------ |
5086| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes       | Communication device type.                                   |
5087| active     | boolean                                              | Yes       | Active status of the device. The value **true** means to set the device to the active state, and **false** means the opposite. |
5088
5089**Return value**
5090
5091| Type                | Description                    |
5092| ------------------- | ------------------------------ |
5093| Promise&lt;void&gt; | Promise that returns no value. |
5094
5095**Example**
5096
5097```ts
5098audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true).then(() => {
5099  console.info('Promise returned to indicate that the device is set to the active status.');
5100});
5101
5102```
5103
5104### isCommunicationDeviceActive<sup>9+</sup>
5105
5106isCommunicationDeviceActive(deviceType: CommunicationDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
5107
5108Checks whether a communication device is active. This API uses an asynchronous callback to return the result.
5109
5110**System capability**: SystemCapability.Multimedia.Audio.Communication
5111
5112**Parameters**
5113
5114| Name       | Type                                                 | Mandatory | Description                                                  |
5115| ---------- | ---------------------------------------------------- | --------- | ------------------------------------------------------------ |
5116| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes       | Communication device type.                                   |
5117| callback   | AsyncCallback&lt;boolean&gt;                         | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true** if the communication device is active or **false** if not active; otherwise, **err** is an error object. |
5118
5119**Example**
5120
5121```ts
5122import { BusinessError } from '@ohos.base';
5123
5124audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER, (err: BusinessError, value: boolean) => {
5125  if (err) {
5126    console.error(`Failed to obtain the active status of the device. ${err}`);
5127    return;
5128  }
5129  console.info('Callback invoked to indicate that the active status of the device is obtained.');
5130});
5131
5132```
5133
5134### isCommunicationDeviceActive<sup>9+</sup>
5135
5136isCommunicationDeviceActive(deviceType: CommunicationDeviceType): Promise&lt;boolean&gt;
5137
5138Checks whether a communication device is active. This API uses a promise to return the result.
5139
5140**System capability**: SystemCapability.Multimedia.Audio.Communication
5141
5142**Parameters**
5143
5144| Name       | Type                                                 | Mandatory | Description                |
5145| ---------- | ---------------------------------------------------- | --------- | -------------------------- |
5146| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes       | Communication device type. |
5147
5148**Return value**
5149
5150| Type                   | Description                                                  |
5151| ---------------------- | ------------------------------------------------------------ |
5152| Promise&lt;boolean&gt; | Promise used to return the active status of the device. The value **true** means that the device is active, and **false** means the opposite. |
5153
5154**Example**
5155
5156```ts
5157audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER).then((value: boolean) => {
5158  console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
5159});
5160
5161```
5162
5163### isCommunicationDeviceActiveSync<sup>10+</sup>
5164
5165isCommunicationDeviceActiveSync(deviceType: CommunicationDeviceType): boolean
5166
5167Checks whether a communication device is active. This API returns the result synchronously.
5168
5169**System capability**: SystemCapability.Multimedia.Audio.Communication
5170
5171**Parameters**
5172
5173| Name       | Type                                                 | Mandatory | Description                |
5174| ---------- | ---------------------------------------------------- | --------- | -------------------------- |
5175| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes       | Communication device type. |
5176
5177**Return value**
5178
5179| Type    | Description                                                  |
5180| ------- | ------------------------------------------------------------ |
5181| boolean | Returns **true** if the device is active; returns **false** otherwise. |
5182
5183**Error codes**
5184
5185For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5186
5187| ID      | Error Message           |
5188| ------- | ----------------------- |
5189| 6800101 | invalid parameter error |
5190
5191**Example**
5192
5193```ts
5194import { BusinessError } from '@ohos.base';
5195
5196try {
5197  let value: boolean = audioRoutingManager.isCommunicationDeviceActiveSync(audio.CommunicationDeviceType.SPEAKER);
5198  console.info(`Indicate that the active status of the device is obtained ${value}.`);
5199} catch (err) {
5200  let error = err as BusinessError;
5201  console.error(`Failed to obtain the active status of the device ${error}.`);
5202}
5203
5204```
5205
5206### selectOutputDevice<sup>9+</sup>
5207
5208selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
5209
5210Selects an audio output device. Currently, only one output device can be selected. This API uses an asynchronous callback to return the result.
5211
5212**System API**: This is a system API.
5213
5214**System capability**: SystemCapability.Multimedia.Audio.Device
5215
5216**Parameters**
5217
5218| Name               | Type                                              | Mandatory | Description                                                  |
5219| ------------------ | ------------------------------------------------- | --------- | ------------------------------------------------------------ |
5220| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes       | Output device.                                               |
5221| callback           | AsyncCallback&lt;void&gt;                         | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
5222
5223**Example**
5224
5225```ts
5226import audio from '@ohos.multimedia.audio';
5227import { BusinessError } from '@ohos.base';
5228
5229let outputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{
5230  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
5231  deviceType : audio.DeviceType.SPEAKER,
5232  id : 1,
5233  name : "",
5234  address : "",
5235  sampleRates : [44100],
5236  channelCounts : [2],
5237  channelMasks : [0],
5238  networkId : audio.LOCAL_NETWORK_ID,
5239  interruptGroupId : 1,
5240  volumeGroupId : 1,
5241  displayName : "",
5242}];
5243
5244async function selectOutputDevice(){
5245  audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor, (err: BusinessError) => {
5246    if (err) {
5247      console.error(`Result ERROR: ${err}`);
5248    } else {
5249      console.info('Select output devices result callback: SUCCESS'); }
5250  });
5251}
5252
5253```
5254
5255### selectOutputDevice<sup>9+</sup>
5256
5257selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
5258
5259**System API**: This is a system API.
5260
5261Selects an audio output device. Currently, only one output device can be selected. This API uses a promise to return the result.
5262
5263**System capability**: SystemCapability.Multimedia.Audio.Device
5264
5265**Parameters**
5266
5267| Name               | Type                                              | Mandatory | Description    |
5268| ------------------ | ------------------------------------------------- | --------- | -------------- |
5269| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes       | Output device. |
5270
5271**Return value**
5272
5273| Type                | Description                    |
5274| ------------------- | ------------------------------ |
5275| Promise&lt;void&gt; | Promise that returns no value. |
5276
5277**Example**
5278
5279```ts
5280import audio from '@ohos.multimedia.audio';
5281import { BusinessError } from '@ohos.base';
5282
5283let outputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{
5284  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
5285  deviceType : audio.DeviceType.SPEAKER,
5286  id : 1,
5287  name : "",
5288  address : "",
5289  sampleRates : [44100],
5290  channelCounts : [2],
5291  channelMasks : [0],
5292  networkId : audio.LOCAL_NETWORK_ID,
5293  interruptGroupId : 1,
5294  volumeGroupId : 1,
5295  displayName : "",
5296}];
5297
5298async function selectOutputDevice(){
5299  audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor).then(() => {
5300    console.info('Select output devices result promise: SUCCESS');
5301  }).catch((err: BusinessError) => {
5302    console.error(`Result ERROR: ${err}`);
5303  });
5304}
5305
5306```
5307
5308### selectOutputDeviceByFilter<sup>9+</sup>
5309
5310selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
5311
5312**System API**: This is a system API.
5313
5314Selects an audio output device based on the filter criteria. Currently, only one output device can be selected. This API uses an asynchronous callback to return the result.
5315
5316**System capability**: SystemCapability.Multimedia.Audio.Device
5317
5318**Parameters**
5319
5320| Name               | Type                                              | Mandatory | Description                                                  |
5321| ------------------ | ------------------------------------------------- | --------- | ------------------------------------------------------------ |
5322| filter             | [AudioRendererFilter](#audiorendererfilter9)      | Yes       | Filter criteria.                                             |
5323| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes       | Output device.                                               |
5324| callback           | AsyncCallback&lt;void&gt;                         | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
5325
5326**Example**
5327
5328```ts
5329import audio from '@ohos.multimedia.audio';
5330import { BusinessError } from '@ohos.base';
5331
5332let outputAudioRendererFilter: audio.AudioRendererFilter = {
5333  uid : 20010041,
5334  rendererInfo : {
5335    usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
5336    rendererFlags : 0
5337  },
5338  rendererId : 0
5339};
5340
5341let outputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{
5342  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
5343  deviceType : audio.DeviceType.SPEAKER,
5344  id : 1,
5345  name : "",
5346  address : "",
5347  sampleRates : [44100],
5348  channelCounts : [2],
5349  channelMasks : [0],
5350  networkId : audio.LOCAL_NETWORK_ID,
5351  interruptGroupId : 1,
5352  volumeGroupId : 1,
5353  displayName : "",
5354}];
5355
5356async function selectOutputDeviceByFilter(){
5357  audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor, (err: BusinessError) => {
5358    if (err) {
5359      console.error(`Result ERROR: ${err}`);
5360    } else {
5361      console.info('Select output devices by filter result callback: SUCCESS'); }
5362  });
5363}
5364
5365```
5366
5367### selectOutputDeviceByFilter<sup>9+</sup>
5368
5369selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
5370
5371**System API**: This is a system API.
5372
5373Selects an audio output device based on the filter criteria. Currently, only one output device can be selected. This API uses a promise to return the result.
5374
5375**System capability**: SystemCapability.Multimedia.Audio.Device
5376
5377**Parameters**
5378
5379| Name               | Type                                              | Mandatory | Description      |
5380| ------------------ | ------------------------------------------------- | --------- | ---------------- |
5381| filter             | [AudioRendererFilter](#audiorendererfilter9)      | Yes       | Filter criteria. |
5382| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes       | Output device.   |
5383
5384**Return value**
5385
5386| Type                | Description                    |
5387| ------------------- | ------------------------------ |
5388| Promise&lt;void&gt; | Promise that returns no value. |
5389
5390**Example**
5391
5392```ts
5393import audio from '@ohos.multimedia.audio';
5394import { BusinessError } from '@ohos.base';
5395
5396let outputAudioRendererFilter: audio.AudioRendererFilter = {
5397  uid : 20010041,
5398  rendererInfo : {
5399    usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
5400    rendererFlags : 0
5401  },
5402  rendererId : 0
5403};
5404
5405let outputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{
5406  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
5407  deviceType : audio.DeviceType.SPEAKER,
5408  id : 1,
5409  name : "",
5410  address : "",
5411  sampleRates : [44100],
5412  channelCounts : [2],
5413  channelMasks : [0],
5414  networkId : audio.LOCAL_NETWORK_ID,
5415  interruptGroupId : 1,
5416  volumeGroupId : 1,
5417  displayName : "",
5418}];
5419
5420async function selectOutputDeviceByFilter(){
5421  audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor).then(() => {
5422    console.info('Select output devices by filter result promise: SUCCESS');
5423  }).catch((err: BusinessError) => {
5424    console.error(`Result ERROR: ${err}`);
5425  })
5426}
5427
5428```
5429
5430### getPreferOutputDeviceForRendererInfo<sup>10+</sup>
5431
5432getPreferOutputDeviceForRendererInfo(rendererInfo: AudioRendererInfo, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
5433
5434Obtains the output device with the highest priority based on the audio renderer information. This API uses an asynchronous callback to return the result.
5435
5436**System capability**: SystemCapability.Multimedia.Audio.Device
5437
5438**Parameters**
5439
5440| Name         | Type                                                         | Mandatory | Description                                                  |
5441| ------------ | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
5442| rendererInfo | [AudioRendererInfo](#audiorendererinfo8)                     | Yes       | Audio renderer information.                                  |
5443| callback     | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the output device with the highest priority obtained; otherwise, **err** is an error object. |
5444
5445**Error codes**
5446
5447For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5448
5449| ID      | Error Message                                    |
5450| ------- | ------------------------------------------------ |
5451| 6800101 | Input parameter value error. Return by callback. |
5452| 6800301 | System error. Return by callback.                |
5453
5454**Example**
5455
5456```ts
5457import audio from '@ohos.multimedia.audio';
5458import { BusinessError } from '@ohos.base';
5459
5460let rendererInfo: audio.AudioRendererInfo = {
5461  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
5462  rendererFlags : 0
5463}
5464
5465async function getPreferOutputDevice() {
5466  audioRoutingManager.getPreferOutputDeviceForRendererInfo(rendererInfo, (err: BusinessError, desc: audio.AudioDeviceDescriptors) => {
5467    if (err) {
5468      console.error(`Result ERROR: ${err}`);
5469    } else {
5470      console.info(`device descriptor: ${desc}`);
5471    }
5472  });
5473}
5474
5475```
5476
5477### getPreferOutputDeviceForRendererInfo<sup>10+</sup>
5478
5479getPreferOutputDeviceForRendererInfo(rendererInfo: AudioRendererInfo): Promise&lt;AudioDeviceDescriptors&gt;
5480
5481Obtains the output device with the highest priority based on the audio renderer information. This API uses a promise to return the result.
5482
5483**System capability**: SystemCapability.Multimedia.Audio.Device
5484
5485**Parameters**
5486
5487| Name         | Type                                     | Mandatory | Description                 |
5488| ------------ | ---------------------------------------- | --------- | --------------------------- |
5489| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes       | Audio renderer information. |
5490
5491**Return value**
5492
5493| Type                                                         | Description                                                  |
5494| ------------------------------------------------------------ | ------------------------------------------------------------ |
5495| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the information about the output device with the highest priority. |
5496
5497**Error codes**
5498
5499For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5500
5501| ID      | Error Message                                   |
5502| ------- | ----------------------------------------------- |
5503| 6800101 | Input parameter value error. Return by promise. |
5504| 6800301 | System error. Return by promise.                |
5505
5506**Example**
5507
5508```ts
5509import audio from '@ohos.multimedia.audio';
5510import { BusinessError } from '@ohos.base';
5511
5512let rendererInfo: audio.AudioRendererInfo = {
5513  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
5514  rendererFlags : 0
5515}
5516
5517async function getPreferOutputDevice() {
5518  audioRoutingManager.getPreferOutputDeviceForRendererInfo(rendererInfo).then((desc: audio.AudioDeviceDescriptors) => {
5519    console.info(`device descriptor: ${desc}`);
5520  }).catch((err: BusinessError) => {
5521    console.error(`Result ERROR: ${err}`);
5522  })
5523}
5524
5525```
5526
5527### getPreferredOutputDeviceForRendererInfoSync<sup>10+</sup>
5528
5529getPreferredOutputDeviceForRendererInfoSync(rendererInfo: AudioRendererInfo): AudioDeviceDescriptors
5530
5531Obtains the output device with the highest priority based on the audio renderer information. This API returns the result synchronously.
5532
5533**System capability**: SystemCapability.Multimedia.Audio.Device
5534
5535**Parameters**
5536
5537| Name         | Type                                     | Mandatory | Description                 |
5538| ------------ | ---------------------------------------- | --------- | --------------------------- |
5539| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes       | Audio renderer information. |
5540
5541**Return value**
5542
5543| Type                                              | Description                                                  |
5544| ------------------------------------------------- | ------------------------------------------------------------ |
5545| [AudioDeviceDescriptors](#audiodevicedescriptors) | Information about the output device with the highest priority. |
5546
5547**Error codes**
5548
5549For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5550
5551| ID      | Error Message            |
5552| ------- | ------------------------ |
5553| 6800101 | Invalid parameter error. |
5554
5555**Example**
5556
5557```ts
5558import audio from '@ohos.multimedia.audio';
5559import { BusinessError } from '@ohos.base';
5560
5561let rendererInfo: audio.AudioRendererInfo = {
5562  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
5563  rendererFlags : 0
5564}
5565
5566try {
5567  let desc: audio.AudioDeviceDescriptors = audioRoutingManager.getPreferredOutputDeviceForRendererInfoSync(rendererInfo);
5568  console.info(`device descriptor: ${desc}`);
5569} catch (err) {
5570  let error = err as BusinessError;
5571  console.error(`Result ERROR: ${error}`);
5572}
5573
5574```
5575
5576### on('preferOutputDeviceChangeForRendererInfo')<sup>10+</sup>
5577
5578on(type: 'preferOutputDeviceChangeForRendererInfo', rendererInfo: AudioRendererInfo, callback: Callback<AudioDeviceDescriptors\>): void
5579
5580Subscribes to the change of the output device with the highest priority. This API uses an asynchronous callback to return the result.
5581
5582**System capability**: SystemCapability.Multimedia.Audio.Device
5583
5584**Parameters**
5585
5586| Name         | Type                                                         | Mandatory | Description                                                  |
5587| :----------- | :----------------------------------------------------------- | :-------- | :----------------------------------------------------------- |
5588| type         | string                                                       | Yes       | Event type. The event **'preferOutputDeviceChangeForRendererInfo'** is triggered when the output device with the highest priority is changed. |
5589| rendererInfo | [AudioRendererInfo](#audiorendererinfo8)                     | Yes       | Audio renderer information.                                  |
5590| callback     | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)\> | Yes       | Callback used to return the information about the output device with the highest priority. |
5591
5592**Error codes**
5593
5594For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5595
5596| ID      | Error Message                |
5597| ------- | ---------------------------- |
5598| 6800101 | Input parameter value error. |
5599
5600**Example**
5601
5602```ts
5603import audio from '@ohos.multimedia.audio';
5604
5605let rendererInfo: audio.AudioRendererInfo = {
5606  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
5607  rendererFlags : 0
5608}
5609
5610audioRoutingManager.on('preferOutputDeviceChangeForRendererInfo', rendererInfo, (desc: audio.AudioDeviceDescriptors) => {
5611  console.info(`device descriptor: ${desc}`);
5612});
5613
5614```
5615
5616### off('preferOutputDeviceChangeForRendererInfo')<sup>10+</sup>
5617
5618off(type: 'preferOutputDeviceChangeForRendererInfo', callback?: Callback<AudioDeviceDescriptors\>): void
5619
5620Unsubscribes from the change of the output device with the highest priority. This API uses an asynchronous callback to return the result.
5621
5622**System capability**: SystemCapability.Multimedia.Audio.Device
5623
5624**Parameters**
5625
5626| Name     | Type                                                        | Mandatory | Description                                                  |
5627| -------- | ----------------------------------------------------------- | --------- | ------------------------------------------------------------ |
5628| type     | string                                                      | Yes       | Event type. The event **'preferOutputDeviceChangeForRendererInfo'** is triggered when the output device with the highest priority is changed. |
5629| callback | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | No        | Callback used to return the information about the output device with the highest priority. |
5630
5631**Error codes**
5632
5633For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5634
5635| ID      | Error Message                |
5636| ------- | ---------------------------- |
5637| 6800101 | Input parameter value error. |
5638
5639**Example**
5640
5641```ts
5642audioRoutingManager.off('preferOutputDeviceChangeForRendererInfo');
5643
5644```
5645
5646### getPreferredInputDeviceForCapturerInfo<sup>10+</sup>
5647
5648getPreferredInputDeviceForCapturerInfo(capturerInfo: AudioCapturerInfo, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
5649
5650Obtains the input device with the highest priority based on the audio capturer information. This API uses an asynchronous callback to return the result.
5651
5652**System capability**: SystemCapability.Multimedia.Audio.Device
5653
5654**Parameters**
5655
5656| Name         | Type                                                         | Mandatory | Description                                                  |
5657| ------------ | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
5658| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8)                     | Yes       | Audio capturer information.                                  |
5659| callback     | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the input device with the highest priority obtained; otherwise, **err** is an error object. |
5660
5661**Error codes**
5662
5663For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5664
5665| ID      | Error Message                                |
5666| ------- | -------------------------------------------- |
5667| 6800101 | Invalid parameter error. Return by callback. |
5668| 6800301 | System error. Return by callback.            |
5669
5670**Example**
5671
5672```ts
5673import audio from '@ohos.multimedia.audio';
5674import { BusinessError } from '@ohos.base';
5675
5676let capturerInfo: audio.AudioCapturerInfo = {
5677  source: audio.SourceType.SOURCE_TYPE_MIC,
5678  capturerFlags: 0
5679}
5680
5681audioRoutingManager.getPreferredInputDeviceForCapturerInfo(capturerInfo, (err: BusinessError, desc: audio.AudioDeviceDescriptors) => {
5682  if (err) {
5683    console.error(`Result ERROR: ${err}`);
5684  } else {
5685    console.info(`device descriptor: ${desc}`);
5686  }
5687});
5688
5689```
5690
5691### getPreferredInputDeviceForCapturerInfo<sup>10+</sup>
5692
5693getPreferredInputDeviceForCapturerInfo(capturerInfo: AudioCapturerInfo): Promise&lt;AudioDeviceDescriptors&gt;
5694
5695Obtains the input device with the highest priority based on the audio capturer information. This API uses a promise to return the result.
5696
5697**System capability**: SystemCapability.Multimedia.Audio.Device
5698
5699**Parameters**
5700
5701| Name         | Type                                     | Mandatory | Description                 |
5702| ------------ | ---------------------------------------- | --------- | --------------------------- |
5703| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8) | Yes       | Audio capturer information. |
5704
5705**Return value**
5706
5707| Type                                                         | Description                                                  |
5708| ------------------------------------------------------------ | ------------------------------------------------------------ |
5709| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the information about the input device with the highest priority. |
5710
5711**Error codes**
5712
5713For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5714
5715| ID      | Error Message                               |
5716| ------- | ------------------------------------------- |
5717| 6800101 | Invalid parameter error. Return by promise. |
5718| 6800301 | System error. Return by promise.            |
5719
5720**Example**
5721
5722```ts
5723import audio from '@ohos.multimedia.audio';
5724import { BusinessError } from '@ohos.base';
5725
5726let capturerInfo: audio.AudioCapturerInfo = {
5727  source: audio.SourceType.SOURCE_TYPE_MIC,
5728  capturerFlags: 0
5729}
5730
5731audioRoutingManager.getPreferredInputDeviceForCapturerInfo(capturerInfo).then((desc: audio.AudioDeviceDescriptors) => {
5732  console.info(`device descriptor: ${desc}`);
5733}).catch((err: BusinessError) => {
5734  console.error(`Result ERROR: ${err}`);
5735});
5736
5737```
5738
5739### getPreferredInputDeviceForCapturerInfoSync<sup>10+</sup>
5740
5741getPreferredInputDeviceForCapturerInfoSync(capturerInfo: AudioCapturerInfo): AudioDeviceDescriptors
5742
5743Obtains the input device with the highest priority based on the audio capturer information. This API returns the result synchronously.
5744
5745**System capability**: SystemCapability.Multimedia.Audio.Device
5746
5747**Parameters**
5748
5749| Name         | Type                                     | Mandatory | Description                 |
5750| ------------ | ---------------------------------------- | --------- | --------------------------- |
5751| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8) | Yes       | Audio capturer information. |
5752
5753**Return value**
5754
5755| Type                                              | Description                                                  |
5756| ------------------------------------------------- | ------------------------------------------------------------ |
5757| [AudioDeviceDescriptors](#audiodevicedescriptors) | Information about the input device with the highest priority. |
5758
5759**Error codes**
5760
5761For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5762
5763| ID      | Error Message            |
5764| ------- | ------------------------ |
5765| 6800101 | Invalid parameter error. |
5766
5767**Example**
5768
5769```ts
5770import audio from '@ohos.multimedia.audio';
5771import { BusinessError } from '@ohos.base';
5772
5773let capturerInfo: audio.AudioCapturerInfo = {
5774  source: audio.SourceType.SOURCE_TYPE_MIC,
5775  capturerFlags: 0
5776}
5777
5778try {
5779  let desc: audio.AudioDeviceDescriptors = audioRoutingManager.getPreferredInputDeviceForCapturerInfoSync(capturerInfo);
5780  console.info(`device descriptor: ${desc}`);
5781} catch (err) {
5782  let error = err as BusinessError;
5783  console.error(`Result ERROR: ${error}`);
5784}
5785
5786```
5787
5788### on('preferredInputDeviceChangeForCapturerInfo')<sup>10+</sup>
5789
5790on(type: 'preferredInputDeviceChangeForCapturerInfo', capturerInfo: AudioCapturerInfo, callback: Callback<AudioDeviceDescriptors\>): void
5791
5792Subscribes to the change of the input device with the highest priority. This API uses an asynchronous callback to return the result.
5793
5794**System capability**: SystemCapability.Multimedia.Audio.Device
5795
5796**Parameters**
5797
5798| Name         | Type                                                         | Mandatory | Description                                                  |
5799| :----------- | :----------------------------------------------------------- | :-------- | :----------------------------------------------------------- |
5800| type         | string                                                       | Yes       | Event type. The event **'preferredInputDeviceChangeForCapturerInfo'** is triggered when the input device with the highest priority is changed. |
5801| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8)                     | Yes       | Audio capturer information.                                  |
5802| callback     | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)\> | Yes       | Callback used to return the information about the input device with the highest priority. |
5803
5804**Error codes**
5805
5806For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5807
5808| ID      | Error Message            |
5809| ------- | ------------------------ |
5810| 6800101 | Invalid parameter error. |
5811
5812**Example**
5813
5814```ts
5815import audio from '@ohos.multimedia.audio';
5816
5817let capturerInfo: audio.AudioCapturerInfo = {
5818  source: audio.SourceType.SOURCE_TYPE_MIC,
5819  capturerFlags: 0
5820}
5821
5822audioRoutingManager.on('preferredInputDeviceChangeForCapturerInfo', capturerInfo, (desc: audio.AudioDeviceDescriptors) => {
5823  console.info(`device descriptor: ${desc}`);
5824});
5825
5826```
5827
5828### off('preferredInputDeviceChangeForCapturerInfo')<sup>10+</sup>
5829
5830off(type: 'preferredInputDeviceChangeForCapturerInfo', callback?: Callback<AudioDeviceDescriptors\>): void
5831
5832Unsubscribes from the change of the input device with the highest priority. This API uses an asynchronous callback to return the result.
5833
5834**System capability**: SystemCapability.Multimedia.Audio.Device
5835
5836**Parameters**
5837
5838| Name     | Type                                                        | Mandatory | Description                                                  |
5839| -------- | ----------------------------------------------------------- | --------- | ------------------------------------------------------------ |
5840| type     | string                                                      | Yes       | Event type. The event **'preferredInputDeviceChangeForCapturerInfo'** is triggered when the input device with the highest priority is changed. |
5841| callback | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | No        | Callback used to return the information about the input device with the highest priority. |
5842
5843**Error codes**
5844
5845For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5846
5847| ID      | Error Message            |
5848| ------- | ------------------------ |
5849| 6800101 | Invalid parameter error. |
5850
5851**Example**
5852
5853```ts
5854audioRoutingManager.off('preferredInputDeviceChangeForCapturerInfo');
5855
5856```
5857
5858## AudioRendererChangeInfoArray<sup>9+</sup>
5859
5860Defines an **AudioRenderChangeInfo** array, which is read-only.
5861
5862**System capability**: SystemCapability.Multimedia.Audio.Renderer
5863
5864## AudioRendererChangeInfo<sup>9+</sup>
5865
5866Describes the audio renderer change event.
5867
5868**System capability**: SystemCapability.Multimedia.Audio.Renderer
5869
5870| Name              | Type                                              | Readable | Writable | Description                                                |
5871| ----------------- | ------------------------------------------------- | -------- | -------- | ---------------------------------------------------------- |
5872| streamId          | number                                            | Yes      | No       | Unique ID of an audio stream.                              |
5873| clientUid         | number                                            | Yes      | No       | UID of the audio renderer client.<br>This is a system API. |
5874| rendererInfo      | [AudioRendererInfo](#audiorendererinfo8)          | Yes      | No       | Audio renderer information.                                |
5875| rendererState     | [AudioState](#audiostate8)                        | Yes      | No       | Audio state.<br>This is a system API.                      |
5876| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes      | No       | Audio device description.                                  |
5877
5878**Example**
5879
5880```ts
5881import audio from '@ohos.multimedia.audio';
5882
5883const audioManager = audio.getAudioManager();
5884let audioStreamManager = audioManager.getStreamManager();
5885
5886audioStreamManager.on('audioRendererChange',  (AudioRendererChangeInfoArray) => {
5887  for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
5888    console.info(`## RendererChange on is called for ${i} ##`);
5889    console.info(`StreamId for ${i} is: ${AudioRendererChangeInfoArray[i].streamId}`);
5890    console.info(`Content for ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.content}`);
5891    console.info(`Stream for ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.usage}`);
5892    console.info(`Flag ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.rendererFlags}`);
5893    let devDescriptor = AudioRendererChangeInfoArray[i].deviceDescriptors;
5894    for (let j = 0; j < AudioRendererChangeInfoArray[i].deviceDescriptors.length; j++) {
5895      console.info(`Id: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].id}`);
5896      console.info(`Type: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
5897      console.info(`Role: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
5898      console.info(`Name: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].name}`);
5899      console.info(`Addr: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].address}`);
5900      console.info(`SR: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
5901      console.info(`C ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
5902      console.info(`CM: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
5903    }
5904  }
5905});
5906
5907```
5908
5909
5910## AudioCapturerChangeInfoArray<sup>9+</sup>
5911
5912Defines an **AudioCapturerChangeInfo** array, which is read-only.
5913
5914**System capability**: SystemCapability.Multimedia.Audio.Capturer
5915
5916## AudioCapturerChangeInfo<sup>9+</sup>
5917
5918Describes the audio capturer change event.
5919
5920**System capability**: SystemCapability.Multimedia.Audio.Capturer
5921
5922| Name                | Type                                              | Readable | Writable | Description                                                  |
5923| ------------------- | ------------------------------------------------- | -------- | -------- | ------------------------------------------------------------ |
5924| streamId            | number                                            | Yes      | No       | Unique ID of an audio stream.                                |
5925| clientUid           | number                                            | Yes      | No       | UID of the audio capturer client.<br>This is a system API.   |
5926| capturerInfo        | [AudioCapturerInfo](#audiocapturerinfo8)          | Yes      | No       | Audio capturer information.                                  |
5927| capturerState       | [AudioState](#audiostate8)                        | Yes      | No       | Audio state.<br>This is a system API.                        |
5928| deviceDescriptors   | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes      | No       | Audio device description.                                    |
5929| muted<sup>11+</sup> | boolean                                           | Yes      | No       | Whether the audio capturer is muted. The value **true** means that the audio capturer is muted, and **false** means the opposite. |
5930
5931**Example**
5932
5933```ts
5934import audio from '@ohos.multimedia.audio';
5935
5936const audioManager = audio.getAudioManager();
5937let audioStreamManager = audioManager.getStreamManager();
5938
5939audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) =>  {
5940  for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
5941    console.info(`## CapChange on is called for element ${i} ##`);
5942    console.info(`StrId for  ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
5943    console.info(`Src for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
5944    console.info(`Flag ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
5945    let devDescriptor = AudioCapturerChangeInfoArray[i].deviceDescriptors;
5946    for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
5947      console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
5948      console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
5949      console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
5950      console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
5951      console.info(`Addr: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
5952      console.info(`SR: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
5953      console.info(`C ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
5954      console.info(`CM ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
5955    }
5956  }
5957});
5958
5959```
5960
5961## AudioEffectInfoArray<sup>10+</sup>
5962
5963Defines an array that contains the audio effect mode corresponding to a specific audio content type (specified by **ContentType**) and audio stream usage (specified by **StreamUsage**). The [AudioEffectMode](#audioeffectmode10) array is read-only.
5964
5965## AudioDeviceDescriptors
5966
5967Defines an [AudioDeviceDescriptor](#audiodevicedescriptor) array, which is read-only.
5968
5969## AudioDeviceDescriptor
5970
5971Describes an audio device.
5972
5973| Name                          | Type                                                  | Readable | Writable | Description                                                  |
5974| ----------------------------- | ----------------------------------------------------- | -------- | -------- | ------------------------------------------------------------ |
5975| deviceRole                    | [DeviceRole](#devicerole)                             | Yes      | No       | Device role.<br>**System capability**: SystemCapability.Multimedia.Audio.Device |
5976| deviceType                    | [DeviceType](#devicetype)                             | Yes      | No       | Device type.<br>**System capability**: SystemCapability.Multimedia.Audio.Device |
5977| id<sup>9+</sup>               | number                                                | Yes      | No       | Device ID, which is unique.<br>**System capability**: SystemCapability.Multimedia.Audio.Device |
5978| name<sup>9+</sup>             | string                                                | Yes      | No       | Device name.<br>For a Bluetooth device, you must request the **ohos.permission.USE_BLUETOOTH** permission.<br>**System capability**: SystemCapability.Multimedia.Audio.Device |
5979| address<sup>9+</sup>          | string                                                | Yes      | No       | Device address.<br>For a Bluetooth device, you must request the **ohos.permission.USE_BLUETOOTH** permission.<br>**System capability**: SystemCapability.Multimedia.Audio.Device |
5980| sampleRates<sup>9+</sup>      | Array&lt;number&gt;                                   | Yes      | No       | Supported sampling rates.<br>**System capability**: SystemCapability.Multimedia.Audio.Device |
5981| channelCounts<sup>9+</sup>    | Array&lt;number&gt;                                   | Yes      | No       | Number of channels supported.<br>**System capability**: SystemCapability.Multimedia.Audio.Device |
5982| channelMasks<sup>9+</sup>     | Array&lt;number&gt;                                   | Yes      | No       | Supported channel masks.<br>**System capability**: SystemCapability.Multimedia.Audio.Device |
5983| displayName<sup>10+</sup>     | string                                                | Yes      | No       | Display name of the device.<br>**System capability**: SystemCapability.Multimedia.Audio.Device |
5984| networkId<sup>9+</sup>        | string                                                | Yes      | No       | ID of the device network.<br>This is a system API.<br>**System capability**: SystemCapability.Multimedia.Audio.Device |
5985| interruptGroupId<sup>9+</sup> | number                                                | Yes      | No       | ID of the interruption group to which the device belongs.<br>This is a system API.<br>**System capability**: SystemCapability.Multimedia.Audio.Device |
5986| volumeGroupId<sup>9+</sup>    | number                                                | Yes      | No       | ID of the volume group to which the device belongs.<br>This is a system API.<br>**System capability**: SystemCapability.Multimedia.Audio.Device |
5987| encodingTypes<sup>11+</sup>   | Array&lt;[AudioEncodingType](#audioencodingtype8)&gt; | Yes      | No       | Supported encoding types.<br>**System capability**: SystemCapability.Multimedia.Audio.Core |
5988
5989**Example**
5990
5991```ts
5992import audio from '@ohos.multimedia.audio';
5993
5994function displayDeviceProp(value: audio.AudioDeviceDescriptor) {
5995  deviceRoleValue = value.deviceRole;
5996  deviceTypeValue = value.deviceType;
5997}
5998
5999let deviceRoleValue: audio.DeviceRole | undefined = undefined;;
6000let deviceTypeValue: audio.DeviceType | undefined = undefined;;
6001audio.getAudioManager().getDevices(1).then((value: audio.AudioDeviceDescriptors) => {
6002  console.info('AudioFrameworkTest: Promise: getDevices OUTPUT_DEVICES_FLAG');
6003  value.forEach(displayDeviceProp);
6004  if (deviceTypeValue != undefined && deviceRoleValue != undefined){
6005    console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  PASS');
6006  } else {
6007    console.error('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  FAIL');
6008  }
6009});
6010
6011```
6012
6013## AudioRendererFilter<sup>9+</sup>
6014
6015Implements filter criteria. Before calling **selectOutputDeviceByFilter**, you must obtain an **AudioRendererFilter** instance.
6016
6017**System API**: This is a system API.
6018
6019| Name         | Type                                     | Mandatory | Description                                                  |
6020| ------------ | ---------------------------------------- | --------- | ------------------------------------------------------------ |
6021| uid          | number                                   | No        | Application ID.<br>**System capability**: SystemCapability.Multimedia.Audio.Core |
6022| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | No        | Audio renderer information.<br>**System capability**: SystemCapability.Multimedia.Audio.Renderer |
6023| rendererId   | number                                   | No        | Unique ID of an audio stream.<br>**System capability**: SystemCapability.Multimedia.Audio.Renderer |
6024
6025**Example**
6026
6027```ts
6028import audio from '@ohos.multimedia.audio';
6029
6030let outputAudioRendererFilter: audio.AudioRendererFilter = {
6031  uid : 20010041,
6032  rendererInfo : {
6033    usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
6034    rendererFlags : 0
6035  },
6036  rendererId : 0
6037};
6038
6039```
6040
6041## AudioSpatializationManager<sup>11+</sup>
6042
6043Implements spatial audio management. Before calling an API in **AudioSpatializationManager**, you must use [getSpatializationManager](#getspatializationmanager11) to obtain an **AudioSpatializationManager** instance.
6044
6045### isSpatializationSupported<sup>11+</sup>
6046
6047isSpatializationSupported(): boolean
6048
6049Checks whether the system supports spatial audio rendering. This API returns the result synchronously.
6050
6051**System API**: This is a system API.
6052
6053**System capability**: SystemCapability.Multimedia.Audio.Spatialization
6054
6055**Return value**
6056
6057| Type    | Description                                                  |
6058| ------- | ------------------------------------------------------------ |
6059| boolean | Returns **true** if the system supports spatial audio rendering, and returns **false** otherwise. |
6060
6061**Error codes**
6062
6063For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
6064
6065| ID   | Error Message   |
6066| ---- | --------------- |
6067| 202  | Not system App. |
6068
6069**Example**
6070
6071```ts
6072import audio from '@ohos.multimedia.audio';
6073import { BusinessError } from '@ohos.base';
6074try {
6075  let isSpatializationSupported: boolean = audioSpatializationManager.isSpatializationSupported();
6076  console.info(`AudioSpatializationManager isSpatializationSupported: ${isSpatializationSupported}`);
6077} catch (err) {
6078  let error = err as BusinessError;
6079  console.error(`ERROR: ${error}`);
6080}
6081
6082```
6083
6084### isSpatializationSupportedForDevice<sup>11+</sup>
6085
6086isSpatializationSupportedForDevice(deviceDescriptor: AudioDeviceDescriptor): boolean
6087
6088Checks whether a device supports spatial audio rendering. This API returns the result synchronously.
6089
6090**System API**: This is a system API.
6091
6092**System capability**: SystemCapability.Multimedia.Audio.Spatialization
6093
6094**Parameters**
6095
6096| Name             | Type                                            | Mandatory | Description               |
6097| ---------------- | ----------------------------------------------- | --------- | ------------------------- |
6098| deviceDescriptor | [AudioDeviceDescriptor](#audiodevicedescriptor) | Yes       | Descriptor of the device. |
6099
6100**Return value**
6101
6102| Type    | Description                                                  |
6103| ------- | ------------------------------------------------------------ |
6104| boolean | Returns **true** if the device supports spatial audio rendering, and returns **false** otherwise. |
6105
6106**Error codes**
6107
6108For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
6109
6110| ID      | Error Message                            |
6111| ------- | ---------------------------------------- |
6112| 202     | Not system App.                          |
6113| 401     | Input parameter type or number mismatch. |
6114| 6800101 | Invalid parameter error.                 |
6115
6116**Example**
6117
6118```ts
6119import audio from '@ohos.multimedia.audio';
6120import { BusinessError } from '@ohos.base';
6121let deviceDescriptor: audio.AudioDeviceDescriptor = {
6122  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
6123  deviceType : audio.DeviceType.BLUETOOTH_A2DP,
6124  id : 1,
6125  name : "",
6126  address : "123",
6127  sampleRates : [44100],
6128  channelCounts : [2],
6129  channelMasks : [0],
6130  networkId : audio.LOCAL_NETWORK_ID,
6131  interruptGroupId : 1,
6132  volumeGroupId : 1,
6133  displayName : ""
6134}
6135try {
6136  let isSpatializationSupportedForDevice: boolean = audioSpatializationManager.isSpatializationSupportedForDevice(deviceDescriptor);
6137  console.info(`AudioSpatializationManager isSpatializationSupportedForDevice: ${isSpatializationSupportedForDevice}`);
6138} catch (err) {
6139  let error = err as BusinessError;
6140  console.error(`ERROR: ${error}`);
6141}
6142
6143```
6144
6145### isHeadTrackingSupported<sup>11+</sup>
6146
6147isHeadTrackingSupported(): boolean
6148
6149Checks whether the system supports head tracking. This API returns the result synchronously.
6150
6151**System API**: This is a system API.
6152
6153**System capability**: SystemCapability.Multimedia.Audio.Spatialization
6154
6155**Return value**
6156
6157| Type    | Description                                                  |
6158| ------- | ------------------------------------------------------------ |
6159| boolean | Returns **true** if the system supports head tracking, and returns **false** otherwise. |
6160
6161**Error codes**
6162
6163For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
6164
6165| ID   | Error Message   |
6166| ---- | --------------- |
6167| 202  | Not system App. |
6168
6169**Example**
6170
6171```ts
6172import audio from '@ohos.multimedia.audio';
6173import { BusinessError } from '@ohos.base';
6174try {
6175  let isHeadTrackingSupported: boolean = audioSpatializationManager.isHeadTrackingSupported();
6176  console.info(`AudioSpatializationManager isHeadTrackingSupported: ${isHeadTrackingSupported}`);
6177} catch (err) {
6178  let error = err as BusinessError;
6179  console.error(`ERROR: ${error}`);
6180}
6181
6182```
6183
6184### isHeadTrackingSupportedForDevice<sup>11+</sup>
6185
6186isHeadTrackingSupportedForDevice(deviceDescriptor: AudioDeviceDescriptor): boolean
6187
6188Checks whether a device supports head tracking. This API returns the result synchronously.
6189
6190**System API**: This is a system API.
6191
6192**System capability**: SystemCapability.Multimedia.Audio.Spatialization
6193
6194**Parameters**
6195
6196| Name             | Type                                            | Mandatory | Description               |
6197| ---------------- | ----------------------------------------------- | --------- | ------------------------- |
6198| deviceDescriptor | [AudioDeviceDescriptor](#audiodevicedescriptor) | Yes       | Descriptor of the device. |
6199
6200**Return value**
6201
6202| Type    | Description                                                  |
6203| ------- | ------------------------------------------------------------ |
6204| boolean | Returns **true** if the device supports head tracking, and returns **false** otherwise. |
6205
6206**Error codes**
6207
6208For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
6209
6210| ID      | Error Message                            |
6211| ------- | ---------------------------------------- |
6212| 202     | Not system App.                          |
6213| 401     | Input parameter type or number mismatch. |
6214| 6800101 | Invalid parameter error.                 |
6215
6216**Example**
6217
6218```ts
6219import audio from '@ohos.multimedia.audio';
6220import { BusinessError } from '@ohos.base';
6221let deviceDescriptor: audio.AudioDeviceDescriptor = {
6222  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
6223  deviceType : audio.DeviceType.BLUETOOTH_A2DP,
6224  id : 1,
6225  name : "",
6226  address : "123",
6227  sampleRates : [44100],
6228  channelCounts : [2],
6229  channelMasks : [0],
6230  networkId : audio.LOCAL_NETWORK_ID,
6231  interruptGroupId : 1,
6232  volumeGroupId : 1,
6233  displayName : ""
6234}
6235try {
6236  let isHeadTrackingSupportedForDevice: boolean = audioSpatializationManager.isHeadTrackingSupportedForDevice(deviceDescriptor);
6237  console.info(`AudioSpatializationManager isHeadTrackingSupportedForDevice: ${isHeadTrackingSupportedForDevice}`);
6238} catch (err) {
6239  let error = err as BusinessError;
6240  console.error(`ERROR: ${error}`);
6241}
6242
6243```
6244
6245### setSpatializationEnabled<sup>11+</sup>
6246
6247setSpatializationEnabled(enable: boolean, callback: AsyncCallback&lt;void&gt;): void
6248
6249Enables or disables spatial audio rendering. This API uses an asynchronous callback to return the result.
6250
6251**Required permissions**: ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS
6252
6253**System API**: This is a system API.
6254
6255**System capability**: SystemCapability.Multimedia.Audio.Spatialization
6256
6257**Parameters**
6258
6259| Name     | Type                      | Mandatory | Description                                                  |
6260| -------- | ------------------------- | --------- | ------------------------------------------------------------ |
6261| enable   | boolean                   | Yes       | Whether to enable or disable spatial audio rendering. The value **true** means to enable spatial audio rendering, and **false** means the opposite. |
6262| callback | AsyncCallback&lt;void&gt; | Yes       | Callback that returns no value.                              |
6263
6264**Error codes**
6265
6266For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
6267
6268| ID      | Error Message                            |
6269| ------- | ---------------------------------------- |
6270| 201     | Permission denied. Return by callback.   |
6271| 202     | Not system App.                          |
6272| 401     | Input parameter type or number mismatch. |
6273| 6800101 | Invalid parameter error.                 |
6274
6275**Example**
6276
6277```ts
6278import audio from '@ohos.multimedia.audio';
6279import { BusinessError } from '@ohos.base';
6280
6281let enable: boolean = true
6282audioSpatializationManager.setSpatializationEnabled(enable, (err: BusinessError) => {
6283  if (err) {
6284    console.error(`Result ERROR: ${err}`);
6285  } else {
6286    console.info(`setSpatializationEnabled success`);
6287  }
6288});
6289
6290```
6291
6292### setSpatializationEnabled<sup>11+</sup>
6293
6294setSpatializationEnabled(enable: boolean): Promise&lt;void&gt;
6295
6296Enables or disables spatial audio rendering. This API uses a promise to return the result.
6297
6298**Required permissions**: ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS
6299
6300**System API**: This is a system API.
6301
6302**System capability**: SystemCapability.Multimedia.Audio.Spatialization
6303
6304**Parameters**
6305
6306| Name   | Type    | Mandatory | Description                                                  |
6307| ------ | ------- | --------- | ------------------------------------------------------------ |
6308| enable | boolean | Yes       | Whether to enable or disable spatial audio rendering. The value **true** means to enable spatial audio rendering, and **false** means the opposite. |
6309
6310**Return value**
6311
6312| Type                | Description                    |
6313| ------------------- | ------------------------------ |
6314| Promise&lt;void&gt; | Promise that returns no value. |
6315
6316**Error codes**
6317
6318For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
6319
6320| ID   | Error Message                            |
6321| ---- | ---------------------------------------- |
6322| 201  | Permission denied. Return by promise.    |
6323| 202  | Not system App.                          |
6324| 401  | Input parameter type or number mismatch. |
6325
6326**Example**
6327
6328```ts
6329import audio from '@ohos.multimedia.audio';
6330import { BusinessError } from '@ohos.base';
6331
6332let enable: boolean = true
6333audioSpatializationManager.setSpatializationEnabled(enable).then(() => {
6334  console.info(`setSpatializationEnabled success`);
6335}).catch((err: BusinessError) => {
6336  console.error(`Result ERROR: ${err}`);
6337});
6338
6339```
6340
6341### isSpatializationEnabled<sup>11+</sup>
6342
6343isSpatializationEnabled(): boolean
6344
6345Checks whether spatial audio rendering is enabled. This API returns the result synchronously.
6346
6347**System API**: This is a system API.
6348
6349**System capability**: SystemCapability.Multimedia.Audio.Spatialization
6350
6351**Return value**
6352
6353| Type    | Description                                                  |
6354| ------- | ------------------------------------------------------------ |
6355| boolean | Returns **true** if spatial audio rendering is enabled, and returns **false** otherwise. |
6356
6357**Error codes**
6358
6359For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
6360
6361| ID   | Error Message   |
6362| ---- | --------------- |
6363| 202  | Not system App. |
6364
6365**Example**
6366
6367```ts
6368import audio from '@ohos.multimedia.audio';
6369import { BusinessError } from '@ohos.base';
6370try {
6371  let isSpatializationEnabled: boolean = audioSpatializationManager.isSpatializationEnabled();
6372  console.info(`AudioSpatializationManager isSpatializationEnabled: ${isSpatializationEnabled}`);
6373} catch (err) {
6374  let error = err as BusinessError;
6375  console.error(`ERROR: ${error}`);
6376}
6377
6378```
6379
6380### on('spatializationEnabledChange')<sup>11+</sup>
6381
6382on(type: 'spatializationEnabledChange', callback: Callback<boolean\>): void
6383
6384Subscribes to spatial audio rendering status changes.
6385
6386**System API**: This is a system API.
6387
6388**System capability**: SystemCapability.Multimedia.Audio.Spatialization
6389
6390**Parameters**
6391
6392| Name     | Type               | Mandatory | Description                                                  |
6393| :------- | :----------------- | :-------- | :----------------------------------------------------------- |
6394| type     | string             | Yes       | Event type. The event **'spatializationEnabledChange'** is triggered when the status of spatial audio rendering changes. |
6395| callback | Callback<boolean\> | Yes       | Callback used to return the status of spatial audio rendering. |
6396
6397**Error codes**
6398
6399For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
6400
6401| ID      | Error Message                            |
6402| ------- | ---------------------------------------- |
6403| 202     | Not system App.                          |
6404| 401     | Input parameter type or number mismatch. |
6405| 6800101 | Invalid parameter error.                 |
6406
6407**Example**
6408
6409```ts
6410import audio from '@ohos.multimedia.audio';
6411
6412audioSpatializationManager.on('spatializationEnabledChange', (isSpatializationEnabled: boolean) => {
6413  console.info(`isSpatializationEnabled: ${isSpatializationEnabled}`);
6414});
6415
6416```
6417
6418### off('spatializationEnabledChange')<sup>11+</sup>
6419
6420off(type: 'spatializationEnabledChange', callback?: Callback<boolean\>): void
6421
6422Unsubscribes from spatial audio rendering status changes.
6423
6424**System API**: This is a system API.
6425
6426**System capability**: SystemCapability.Multimedia.Audio.Spatialization
6427
6428**Parameters**
6429
6430| Name     | Type               | Mandatory | Description                                                  |
6431| -------- | ------------------ | --------- | ------------------------------------------------------------ |
6432| type     | string             | Yes       | Event type. The event **'spatializationEnabledChange'** is triggered when the status of spatial audio rendering changes. |
6433| callback | Callback<boolean\> | No        | Callback used to return the status of spatial audio rendering. |
6434
6435**Error codes**
6436
6437For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
6438
6439| ID      | Error Message                            |
6440| ------- | ---------------------------------------- |
6441| 202     | Not system App.                          |
6442| 401     | Input parameter type or number mismatch. |
6443| 6800101 | Invalid parameter error.                 |
6444
6445**Example**
6446
6447```ts
6448import audio from '@ohos.multimedia.audio';
6449audioSpatializationManager.off('spatializationEnabledChange');
6450
6451```
6452
6453### setHeadTrackingEnabled<sup>11+</sup>
6454
6455setHeadTrackingEnabled(enable: boolean, callback: AsyncCallback&lt;void&gt;): void
6456
6457Enables or disables head tracking. This API uses an asynchronous callback to return the result.
6458
6459**Required permissions**: ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS
6460
6461**System API**: This is a system API.
6462
6463**System capability**: SystemCapability.Multimedia.Audio.Spatialization
6464
6465**Parameters**
6466
6467| Name     | Type                      | Mandatory | Description                                                  |
6468| -------- | ------------------------- | --------- | ------------------------------------------------------------ |
6469| enable   | boolean                   | Yes       | Whether to enable or disable head tracking. The value **true** means to enable head tracking, and **false** means the opposite. |
6470| callback | AsyncCallback&lt;void&gt; | Yes       | Callback that returns no value.                              |
6471
6472**Error codes**
6473
6474For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
6475
6476| ID      | Error Message                            |
6477| ------- | ---------------------------------------- |
6478| 201     | Permission denied. Return by callback.   |
6479| 202     | Not system App.                          |
6480| 401     | Input parameter type or number mismatch. |
6481| 6800101 | Invalid parameter error.                 |
6482
6483**Example**
6484
6485```ts
6486import audio from '@ohos.multimedia.audio';
6487import { BusinessError } from '@ohos.base';
6488
6489let enable: boolean = true
6490audioSpatializationManager.setHeadTrackingEnabled(enable, (err: BusinessError) => {
6491  if (err) {
6492    console.error(`Result ERROR: ${err}`);
6493  } else {
6494    console.info(`setHeadTrackingEnabled success`);
6495  }
6496});
6497
6498```
6499
6500### setHeadTrackingEnabled<sup>11+</sup>
6501
6502setHeadTrackingEnabled(enable: boolean): Promise&lt;void&gt;
6503
6504Enables or disables head tracking. This API uses a promise to return the result.
6505
6506**Required permissions**: ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS
6507
6508**System API**: This is a system API.
6509
6510**System capability**: SystemCapability.Multimedia.Audio.Spatialization
6511
6512**Parameters**
6513
6514| Name   | Type    | Mandatory | Description                                                  |
6515| ------ | ------- | --------- | ------------------------------------------------------------ |
6516| enable | boolean | Yes       | Whether to enable or disable head tracking. The value **true** means to enable head tracking, and **false** means the opposite. |
6517
6518**Return value**
6519
6520| Type                | Description                    |
6521| ------------------- | ------------------------------ |
6522| Promise&lt;void&gt; | Promise that returns no value. |
6523
6524**Error codes**
6525
6526For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
6527
6528| ID   | Error Message                            |
6529| ---- | ---------------------------------------- |
6530| 201  | Permission denied. Return by promise.    |
6531| 202  | Not system App.                          |
6532| 401  | Input parameter type or number mismatch. |
6533
6534**Example**
6535
6536```ts
6537import audio from '@ohos.multimedia.audio';
6538import { BusinessError } from '@ohos.base';
6539
6540let enable: boolean = true
6541audioSpatializationManager.setHeadTrackingEnabled(enable).then(() => {
6542  console.info(`setHeadTrackingEnabled success`);
6543}).catch((err: BusinessError) => {
6544  console.error(`Result ERROR: ${err}`);
6545});
6546
6547```
6548
6549### isHeadTrackingEnabled<sup>11+</sup>
6550
6551isHeadTrackingEnabled(): boolean
6552
6553Checks whether head tracking is enabled. This API returns the result synchronously.
6554
6555**System API**: This is a system API.
6556
6557**System capability**: SystemCapability.Multimedia.Audio.Spatialization
6558
6559**Return value**
6560
6561| Type    | Description                                                  |
6562| ------- | ------------------------------------------------------------ |
6563| boolean | Returns **true** if head tracking is enabled, and returns **false** otherwise. |
6564
6565**Error codes**
6566
6567For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
6568
6569| ID   | Error Message   |
6570| ---- | --------------- |
6571| 202  | Not system App. |
6572
6573**Example**
6574
6575```ts
6576import audio from '@ohos.multimedia.audio';
6577import { BusinessError } from '@ohos.base';
6578try {
6579  let isHeadTrackingEnabled: boolean = audioSpatializationManager.isHeadTrackingEnabled();
6580  console.info(`AudioSpatializationManager isHeadTrackingEnabled: ${isHeadTrackingEnabled}`);
6581} catch (err) {
6582  let error = err as BusinessError;
6583  console.error(`ERROR: ${error}`);
6584}
6585
6586```
6587
6588### on('headTrackingEnabledChange')<sup>11+</sup>
6589
6590on(type: 'headTrackingEnabledChange', callback: Callback<boolean\>): void
6591
6592Subscribes to head tracking status changes.
6593
6594**System API**: This is a system API.
6595
6596**System capability**: SystemCapability.Multimedia.Audio.Spatialization
6597
6598**Parameters**
6599
6600| Name     | Type               | Mandatory | Description                                                  |
6601| :------- | :----------------- | :-------- | :----------------------------------------------------------- |
6602| type     | string             | Yes       | Event type. The event **'headTrackingEnabledChange'** is triggered when the status of head tracking changes. |
6603| callback | Callback<boolean\> | Yes       | Callback used to return the status of head tracking.         |
6604
6605**Error codes**
6606
6607For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
6608
6609| ID      | Error Message                            |
6610| ------- | ---------------------------------------- |
6611| 202     | Not system App.                          |
6612| 401     | Input parameter type or number mismatch. |
6613| 6800101 | Invalid parameter error.                 |
6614
6615**Example**
6616
6617```ts
6618import audio from '@ohos.multimedia.audio';
6619
6620audioSpatializationManager.on('headTrackingEnabledChange', (isHeadTrackingEnabled: boolean) => {
6621  console.info(`isHeadTrackingEnabled: ${isHeadTrackingEnabled}`);
6622});
6623
6624```
6625
6626### off('headTrackingEnabledChange')<sup>11+</sup>
6627
6628off(type: 'headTrackingEnabledChange', callback?: Callback<boolean\>): void
6629
6630Unsubscribes from head tracking status changes.
6631
6632**System API**: This is a system API.
6633
6634**System capability**: SystemCapability.Multimedia.Audio.Spatialization
6635
6636**Parameters**
6637
6638| Name     | Type               | Mandatory | Description                                                  |
6639| -------- | ------------------ | --------- | ------------------------------------------------------------ |
6640| type     | string             | Yes       | Event type. The event **'headTrackingEnabledChange'** is triggered when the status of head tracking changes. |
6641| callback | Callback<boolean\> | No        | Callback used to return the status of head tracking.         |
6642
6643**Error codes**
6644
6645For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
6646
6647| ID      | Error Message                            |
6648| ------- | ---------------------------------------- |
6649| 202     | Not system App.                          |
6650| 401     | Input parameter type or number mismatch. |
6651| 6800101 | Invalid parameter error.                 |
6652
6653**Example**
6654
6655```ts
6656import audio from '@ohos.multimedia.audio';
6657audioSpatializationManager.off('headTrackingEnabledChange');
6658
6659```
6660
6661### updateSpatialDeviceState<sup>11+</sup>
6662
6663updateSpatialDeviceState(spatialDeviceState: AudioSpatialDeviceState): void
6664
6665Updates the state information of a spatial device. This API returns the result synchronously.
6666
6667**Required permissions**: ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS
6668
6669**System API**: This is a system API.
6670
6671**System capability**: SystemCapability.Multimedia.Audio.Spatialization
6672
6673**Parameters**
6674
6675| Name               | Type                                                  | Mandatory | Description                                  |
6676| ------------------ | ----------------------------------------------------- | --------- | -------------------------------------------- |
6677| spatialDeviceState | [AudioSpatialDeviceState](#audiospatialdevicestate11) | Yes       | New state information of the spatial device. |
6678
6679**Error codes**
6680
6681For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
6682
6683| ID      | Error Message                            |
6684| ------- | ---------------------------------------- |
6685| 201     | Permission denied.                       |
6686| 202     | Not system App.                          |
6687| 401     | Input parameter type or number mismatch. |
6688| 6800101 | Invalid parameter error.                 |
6689
6690**Example**
6691
6692```ts
6693import audio from '@ohos.multimedia.audio';
6694import { BusinessError } from '@ohos.base';
6695let spatialDeviceState: audio.AudioSpatialDeviceState = {
6696  address: "123",
6697  isSpatializationSupported: true,
6698  isHeadTrackingSupported: true,
6699  spatialDeviceType: audio.AudioSpatialDeviceType.SPATIAL_DEVICE_TYPE_IN_EAR_HEADPHONE
6700}
6701try {
6702  audioSpatializationManager.updateSpatialDeviceState(spatialDeviceState);
6703  console.info(`AudioSpatializationManager updateSpatialDeviceState success`);
6704} catch (err) {
6705  let error = err as BusinessError;
6706  console.error(`ERROR: ${error}`);
6707}
6708
6709```
6710
6711## AudioSpatialDeviceState<sup>11+</sup>
6712
6713Defines the state information of a spatial device.
6714
6715**System API**: This is a system API.
6716
6717**System capability**: SystemCapability.Multimedia.Audio.Spatialization
6718
6719| Name                                    | Type                                                | Readable | Writable | Description                                                  |
6720| --------------------------------------- | --------------------------------------------------- | -------- | -------- | ------------------------------------------------------------ |
6721| address<sup>11+</sup>                   | string                                              | Yes      | Yes      | Address of the spatial device.                               |
6722| isSpatializationSupported<sup>11+</sup> | boolean                                             | Yes      | Yes      | Whether the spatial device supports spatial audio rendering. |
6723| isHeadTrackingSupported<sup>11+</sup>   | boolean                                             | Yes      | Yes      | Whether the spatial device supports head tracking.           |
6724| spatialDeviceType<sup>11+</sup>         | [AudioSpatialDeviceType](#audiospatialdevicetype11) | Yes      | Yes      | Type of the spatial device.                                  |
6725
6726**Example**
6727
6728```ts
6729import audio from '@ohos.multimedia.audio';
6730
6731let spatialDeviceState: audio.AudioSpatialDeviceState = {
6732  address: "123",
6733  isSpatializationSupported: true,
6734  isHeadTrackingSupported: true,
6735  spatialDeviceType: audio.AudioSpatialDeviceType.SPATIAL_DEVICE_TYPE_IN_EAR_HEADPHONE
6736}
6737
6738```
6739
6740## AudioSpatialDeviceType<sup>11+</sup>
6741
6742Enumerates the types of spatial devices.
6743
6744**System API**: This is a system API.
6745
6746**System capability**: SystemCapability.Multimedia.Audio.Spatialization
6747
6748| Name                                      | Value | Description                       |
6749| ----------------------------------------- | ----- | --------------------------------- |
6750| SPATIAL_DEVICE_TYPE_NONE                  | 0     | No spatial device.                |
6751| SPATIAL_DEVICE_TYPE_IN_EAR_HEADPHONE      | 1     | In-ear headphones.                |
6752| SPATIAL_DEVICE_TYPE_HALF_IN_EAR_HEADPHONE | 2     | Half-in-ear headphones.           |
6753| SPATIAL_DEVICE_TYPE_OVER_EAR_HEADPHONE    | 3     | Over-ear headphones.              |
6754| SPATIAL_DEVICE_TYPE_GLASSES               | 4     | Glasses.                          |
6755| SPATIAL_DEVICE_TYPE_OTHERS                | 5     | Other type of the spatial device. |
6756
6757## AudioRenderer<sup>8+</sup>
6758
6759Provides APIs for audio rendering. Before calling any API in **AudioRenderer**, you must use [createAudioRenderer](#audiocreateaudiorenderer8) to create an **AudioRenderer** instance.
6760
6761### Attributes
6762
6763**System capability**: SystemCapability.Multimedia.Audio.Renderer
6764
6765| Name               | Type                       | Readable | Writable | Description           |
6766| ------------------ | -------------------------- | -------- | -------- | --------------------- |
6767| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes      | No       | Audio renderer state. |
6768
6769**Example**
6770
6771```ts
6772import audio from '@ohos.multimedia.audio';
6773
6774let state: audio.AudioState = audioRenderer.state;
6775
6776```
6777
6778### getRendererInfo<sup>8+</sup>
6779
6780getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void
6781
6782Obtains the renderer information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
6783
6784**System capability**: SystemCapability.Multimedia.Audio.Renderer
6785
6786**Parameters**
6787
6788| Name     | Type                                                     | Mandatory | Description                                                  |
6789| :------- | :------------------------------------------------------- | :-------- | :----------------------------------------------------------- |
6790| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the renderer information obtained; otherwise, **err** is an error object. |
6791
6792**Example**
6793
6794```ts
6795import { BusinessError } from '@ohos.base';
6796
6797audioRenderer.getRendererInfo((err: BusinessError, rendererInfo: audio.AudioRendererInfo) => {
6798  console.info('Renderer GetRendererInfo:');
6799  console.info(`Renderer content: ${rendererInfo.content}`);
6800  console.info(`Renderer usage: ${rendererInfo.usage}`);
6801  console.info(`Renderer flags: ${rendererInfo.rendererFlags}`);
6802});
6803
6804```
6805
6806### getRendererInfo<sup>8+</sup>
6807
6808getRendererInfo(): Promise<AudioRendererInfo\>
6809
6810Obtains the renderer information of this **AudioRenderer** instance. This API uses a promise to return the result.
6811
6812**System capability**: SystemCapability.Multimedia.Audio.Renderer
6813
6814**Return value**
6815
6816| Type                                               | Description                                      |
6817| -------------------------------------------------- | ------------------------------------------------ |
6818| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information. |
6819
6820**Example**
6821
6822```ts
6823import { BusinessError } from '@ohos.base';
6824
6825audioRenderer.getRendererInfo().then((rendererInfo: audio.AudioRendererInfo) => {
6826  console.info('Renderer GetRendererInfo:');
6827  console.info(`Renderer content: ${rendererInfo.content}`);
6828  console.info(`Renderer usage: ${rendererInfo.usage}`);
6829  console.info(`Renderer flags: ${rendererInfo.rendererFlags}`)
6830}).catch((err: BusinessError) => {
6831  console.error(`AudioFrameworkRenderLog: RendererInfo :ERROR: ${err}`);
6832});
6833
6834```
6835
6836### getRendererInfoSync<sup>10+</sup>
6837
6838getRendererInfoSync(): AudioRendererInfo
6839
6840Obtains the renderer information of this **AudioRenderer** instance. This API returns the result synchronously.
6841
6842**System capability**: SystemCapability.Multimedia.Audio.Renderer
6843
6844**Return value**
6845
6846| Type                                     | Description                 |
6847| ---------------------------------------- | --------------------------- |
6848| [AudioRendererInfo](#audiorendererinfo8) | Audio renderer information. |
6849
6850**Example**
6851
6852```ts
6853import { BusinessError } from '@ohos.base';
6854
6855try {
6856  let rendererInfo: audio.AudioRendererInfo = audioRenderer.getRendererInfoSync();
6857  console.info(`Renderer content: ${rendererInfo.content}`);
6858  console.info(`Renderer usage: ${rendererInfo.usage}`);
6859  console.info(`Renderer flags: ${rendererInfo.rendererFlags}`)
6860} catch (err) {
6861  let error = err as BusinessError;
6862  console.error(`AudioFrameworkRenderLog: RendererInfo :ERROR: ${error}`);
6863}
6864
6865```
6866
6867### getStreamInfo<sup>8+</sup>
6868
6869getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
6870
6871Obtains the stream information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
6872
6873**System capability**: SystemCapability.Multimedia.Audio.Renderer
6874
6875**Parameters**
6876
6877| Name     | Type                                                 | Mandatory | Description                                                  |
6878| :------- | :--------------------------------------------------- | :-------- | :----------------------------------------------------------- |
6879| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the stream information obtained; otherwise, **err** is an error object. |
6880
6881**Example**
6882
6883```ts
6884import { BusinessError } from '@ohos.base';
6885
6886audioRenderer.getStreamInfo((err: BusinessError, streamInfo: audio.AudioStreamInfo) => {
6887  console.info('Renderer GetStreamInfo:');
6888  console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
6889  console.info(`Renderer channel: ${streamInfo.channels}`);
6890  console.info(`Renderer format: ${streamInfo.sampleFormat}`);
6891  console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
6892});
6893
6894```
6895
6896### getStreamInfo<sup>8+</sup>
6897
6898getStreamInfo(): Promise<AudioStreamInfo\>
6899
6900Obtains the stream information of this **AudioRenderer** instance. This API uses a promise to return the result.
6901
6902**System capability**: SystemCapability.Multimedia.Audio.Renderer
6903
6904**Return value**
6905
6906| Type                                           | Description                                    |
6907| :--------------------------------------------- | :--------------------------------------------- |
6908| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
6909
6910**Example**
6911
6912```ts
6913import { BusinessError } from '@ohos.base';
6914
6915audioRenderer.getStreamInfo().then((streamInfo: audio.AudioStreamInfo) => {
6916  console.info('Renderer GetStreamInfo:');
6917  console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
6918  console.info(`Renderer channel: ${streamInfo.channels}`);
6919  console.info(`Renderer format: ${streamInfo.sampleFormat}`);
6920  console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
6921}).catch((err: BusinessError) => {
6922  console.error(`ERROR: ${err}`);
6923});
6924
6925```
6926
6927### getStreamInfoSync<sup>10+</sup>
6928
6929getStreamInfoSync(): AudioStreamInfo
6930
6931Obtains the stream information of this **AudioRenderer** instance. This API returns the result synchronously.
6932
6933**System capability**: SystemCapability.Multimedia.Audio.Renderer
6934
6935**Return value**
6936
6937| Type                                 | Description         |
6938| :----------------------------------- | :------------------ |
6939| [AudioStreamInfo](#audiostreaminfo8) | Stream information. |
6940
6941**Example**
6942
6943```ts
6944import { BusinessError } from '@ohos.base';
6945
6946try {
6947  let streamInfo: audio.AudioStreamInfo = audioRenderer.getStreamInfoSync();
6948  console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
6949  console.info(`Renderer channel: ${streamInfo.channels}`);
6950  console.info(`Renderer format: ${streamInfo.sampleFormat}`);
6951  console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
6952} catch (err) {
6953  let error = err as BusinessError;
6954  console.error(`ERROR: ${error}`);
6955}
6956
6957```
6958
6959### getAudioStreamId<sup>9+</sup>
6960
6961getAudioStreamId(callback: AsyncCallback<number\>): void
6962
6963Obtains the stream ID of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
6964
6965**System capability**: SystemCapability.Multimedia.Audio.Renderer
6966
6967**Parameters**
6968
6969| Name     | Type                   | Mandatory | Description                                                  |
6970| :------- | :--------------------- | :-------- | :----------------------------------------------------------- |
6971| callback | AsyncCallback<number\> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the stream ID obtained; otherwise, **err** is an error object. |
6972
6973**Example**
6974
6975```ts
6976import { BusinessError } from '@ohos.base';
6977
6978audioRenderer.getAudioStreamId((err: BusinessError, streamId: number) => {
6979  console.info(`Renderer GetStreamId: ${streamId}`);
6980});
6981
6982```
6983
6984### getAudioStreamId<sup>9+</sup>
6985
6986getAudioStreamId(): Promise<number\>
6987
6988Obtains the stream ID of this **AudioRenderer** instance. This API uses a promise to return the result.
6989
6990**System capability**: SystemCapability.Multimedia.Audio.Renderer
6991
6992**Return value**
6993
6994| Type             | Description                           |
6995| :--------------- | :------------------------------------ |
6996| Promise<number\> | Promise used to return the stream ID. |
6997
6998**Example**
6999
7000```ts
7001import { BusinessError } from '@ohos.base';
7002
7003audioRenderer.getAudioStreamId().then((streamId: number) => {
7004  console.info(`Renderer getAudioStreamId: ${streamId}`);
7005}).catch((err: BusinessError) => {
7006  console.error(`ERROR: ${err}`);
7007});
7008
7009```
7010
7011### getAudioStreamIdSync<sup>10+</sup>
7012
7013getAudioStreamIdSync(): number
7014
7015Obtains the stream ID of this **AudioRenderer** instance. This API returns the result synchronously.
7016
7017**System capability**: SystemCapability.Multimedia.Audio.Renderer
7018
7019**Return value**
7020
7021| Type   | Description |
7022| :----- | :---------- |
7023| number | Stream ID.  |
7024
7025**Example**
7026
7027```ts
7028import { BusinessError } from '@ohos.base';
7029
7030try {
7031  let streamId: number = audioRenderer.getAudioStreamIdSync();
7032  console.info(`Renderer getAudioStreamIdSync: ${streamId}`);
7033} catch (err) {
7034  let error = err as BusinessError;
7035  console.error(`ERROR: ${error}`);
7036}
7037
7038```
7039
7040### setAudioEffectMode<sup>10+</sup>
7041
7042setAudioEffectMode(mode: AudioEffectMode, callback: AsyncCallback\<void>): void
7043
7044Sets an audio effect mode. This API uses an asynchronous callback to return the result.
7045
7046**System capability**: SystemCapability.Multimedia.Audio.Renderer
7047
7048**Parameters**
7049
7050| Name     | Type                                  | Mandatory | Description                                                  |
7051| -------- | ------------------------------------- | --------- | ------------------------------------------------------------ |
7052| mode     | [AudioEffectMode](#audioeffectmode10) | Yes       | Audio effect mode to set.                                    |
7053| callback | AsyncCallback\<void>                  | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
7054
7055**Error codes**
7056
7057For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
7058
7059| ID      | Error Message                                |
7060| ------- | -------------------------------------------- |
7061| 6800101 | Invalid parameter error. Return by callback. |
7062
7063**Example**
7064
7065```ts
7066import { BusinessError } from '@ohos.base';
7067
7068audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_DEFAULT, (err: BusinessError) => {
7069  if (err) {
7070    console.error('Failed to set params');
7071  } else {
7072    console.info('Callback invoked to indicate a successful audio effect mode setting.');
7073  }
7074});
7075
7076```
7077
7078### setAudioEffectMode<sup>10+</sup>
7079
7080setAudioEffectMode(mode: AudioEffectMode): Promise\<void>
7081
7082Sets an audio effect mode. This API uses a promise to return the result.
7083
7084**System capability**: SystemCapability.Multimedia.Audio.Renderer
7085
7086**Parameters**
7087
7088| Name | Type                                  | Mandatory | Description               |
7089| ---- | ------------------------------------- | --------- | ------------------------- |
7090| mode | [AudioEffectMode](#audioeffectmode10) | Yes       | Audio effect mode to set. |
7091
7092**Return value**
7093
7094| Type           | Description                    |
7095| -------------- | ------------------------------ |
7096| Promise\<void> | Promise that returns no value. |
7097
7098**Error codes**
7099
7100For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
7101
7102| ID      | Error Message                               |
7103| ------- | ------------------------------------------- |
7104| 6800101 | Invalid parameter error. Return by promise. |
7105
7106**Example**
7107
7108```ts
7109import { BusinessError } from '@ohos.base';
7110
7111audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_DEFAULT).then(() => {
7112  console.info('setAudioEffectMode SUCCESS');
7113}).catch((err: BusinessError) => {
7114  console.error(`ERROR: ${err}`);
7115});
7116
7117```
7118
7119### getAudioEffectMode<sup>10+</sup>
7120
7121getAudioEffectMode(callback: AsyncCallback\<AudioEffectMode>): void
7122
7123Obtains the audio effect mode in use. This API uses an asynchronous callback to return the result.
7124
7125**System capability**: SystemCapability.Multimedia.Audio.Renderer
7126
7127**Parameters**
7128
7129| Name     | Type                                                 | Mandatory | Description                                                  |
7130| -------- | ---------------------------------------------------- | --------- | ------------------------------------------------------------ |
7131| callback | AsyncCallback<[AudioEffectMode](#audioeffectmode10)> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the audio effect mode obtained; otherwise, **err** is an error object. |
7132
7133**Example**
7134
7135```ts
7136import { BusinessError } from '@ohos.base';
7137
7138audioRenderer.getAudioEffectMode((err: BusinessError, effectMode: audio.AudioEffectMode) => {
7139  if (err) {
7140    console.error('Failed to get params');
7141  } else {
7142    console.info(`getAudioEffectMode: ${effectMode}`);
7143  }
7144});
7145
7146```
7147
7148### getAudioEffectMode<sup>10+</sup>
7149
7150getAudioEffectMode(): Promise\<AudioEffectMode>
7151
7152Obtains the audio effect mode in use. This API uses a promise to return the result.
7153
7154**System capability**: SystemCapability.Multimedia.Audio.Renderer
7155
7156**Return value**
7157
7158| Type                                           | Description                                   |
7159| ---------------------------------------------- | --------------------------------------------- |
7160| Promise<[AudioEffectMode](#audioeffectmode10)> | Promise used to return the audio effect mode. |
7161
7162**Example**
7163
7164```ts
7165import { BusinessError } from '@ohos.base';
7166
7167audioRenderer.getAudioEffectMode().then((effectMode: audio.AudioEffectMode) => {
7168  console.info(`getAudioEffectMode: ${effectMode}`);
7169}).catch((err: BusinessError) => {
7170  console.error(`ERROR: ${err}`);
7171});
7172
7173```
7174
7175### start<sup>8+</sup>
7176
7177start(callback: AsyncCallback<void\>): void
7178
7179Starts the renderer. This API uses an asynchronous callback to return the result.
7180
7181**System capability**: SystemCapability.Multimedia.Audio.Renderer
7182
7183**Parameters**
7184
7185| Name     | Type                 | Mandatory | Description                                                  |
7186| -------- | -------------------- | --------- | ------------------------------------------------------------ |
7187| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
7188
7189**Example**
7190
7191```ts
7192import { BusinessError } from '@ohos.base';
7193
7194audioRenderer.start((err: BusinessError) => {
7195  if (err) {
7196    console.error('Renderer start failed.');
7197  } else {
7198    console.info('Renderer start success.');
7199  }
7200});
7201
7202```
7203
7204### start<sup>8+</sup>
7205
7206start(): Promise<void\>
7207
7208Starts the renderer. This API uses a promise to return the result.
7209
7210**System capability**: SystemCapability.Multimedia.Audio.Renderer
7211
7212**Return value**
7213
7214| Type           | Description                    |
7215| -------------- | ------------------------------ |
7216| Promise\<void> | Promise that returns no value. |
7217
7218**Example**
7219
7220```ts
7221import { BusinessError } from '@ohos.base';
7222
7223audioRenderer.start().then(() => {
7224  console.info('Renderer started');
7225}).catch((err: BusinessError) => {
7226  console.error(`ERROR: ${err}`);
7227});
7228
7229```
7230
7231### pause<sup>8+</sup>
7232
7233pause(callback: AsyncCallback\<void>): void
7234
7235Pauses rendering. This API uses an asynchronous callback to return the result.
7236
7237**System capability**: SystemCapability.Multimedia.Audio.Renderer
7238
7239**Parameters**
7240
7241| Name     | Type                 | Mandatory | Description                                                  |
7242| -------- | -------------------- | --------- | ------------------------------------------------------------ |
7243| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
7244
7245**Example**
7246
7247```ts
7248import { BusinessError } from '@ohos.base';
7249
7250audioRenderer.pause((err: BusinessError) => {
7251  if (err) {
7252    console.error('Renderer pause failed');
7253  } else {
7254    console.info('Renderer paused.');
7255  }
7256});
7257
7258```
7259
7260### pause<sup>8+</sup>
7261
7262pause(): Promise\<void>
7263
7264Pauses rendering. This API uses a promise to return the result.
7265
7266**System capability**: SystemCapability.Multimedia.Audio.Renderer
7267
7268**Return value**
7269
7270| Type           | Description                    |
7271| -------------- | ------------------------------ |
7272| Promise\<void> | Promise that returns no value. |
7273
7274**Example**
7275
7276```ts
7277import { BusinessError } from '@ohos.base';
7278
7279audioRenderer.pause().then(() => {
7280  console.info('Renderer paused');
7281}).catch((err: BusinessError) => {
7282  console.error(`ERROR: ${err}`);
7283});
7284
7285```
7286
7287### drain<sup>8+</sup>
7288
7289drain(callback: AsyncCallback\<void>): void
7290
7291Drains the playback buffer. This API uses an asynchronous callback to return the result.
7292
7293**System capability**: SystemCapability.Multimedia.Audio.Renderer
7294
7295**Parameters**
7296
7297| Name     | Type                 | Mandatory | Description                                                  |
7298| -------- | -------------------- | --------- | ------------------------------------------------------------ |
7299| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
7300
7301**Example**
7302
7303```ts
7304import { BusinessError } from '@ohos.base';
7305
7306audioRenderer.drain((err: BusinessError) => {
7307  if (err) {
7308    console.error('Renderer drain failed');
7309  } else {
7310    console.info('Renderer drained.');
7311  }
7312});
7313
7314```
7315
7316### drain<sup>8+</sup>
7317
7318drain(): Promise\<void>
7319
7320Drains the playback buffer. This API uses a promise to return the result.
7321
7322**System capability**: SystemCapability.Multimedia.Audio.Renderer
7323
7324**Return value**
7325
7326| Type           | Description                    |
7327| -------------- | ------------------------------ |
7328| Promise\<void> | Promise that returns no value. |
7329
7330**Example**
7331
7332```ts
7333import { BusinessError } from '@ohos.base';
7334
7335audioRenderer.drain().then(() => {
7336  console.info('Renderer drained successfully');
7337}).catch((err: BusinessError) => {
7338  console.error(`ERROR: ${err}`);
7339});
7340
7341```
7342
7343### stop<sup>8+</sup>
7344
7345stop(callback: AsyncCallback\<void>): void
7346
7347Stops rendering. This API uses an asynchronous callback to return the result.
7348
7349**System capability**: SystemCapability.Multimedia.Audio.Renderer
7350
7351**Parameters**
7352
7353| Name     | Type                 | Mandatory | Description                                                  |
7354| -------- | -------------------- | --------- | ------------------------------------------------------------ |
7355| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
7356
7357**Example**
7358
7359```ts
7360import { BusinessError } from '@ohos.base';
7361
7362audioRenderer.stop((err: BusinessError) => {
7363  if (err) {
7364    console.error('Renderer stop failed');
7365  } else {
7366    console.info('Renderer stopped.');
7367  }
7368});
7369
7370```
7371
7372### stop<sup>8+</sup>
7373
7374stop(): Promise\<void>
7375
7376Stops rendering. This API uses a promise to return the result.
7377
7378**System capability**: SystemCapability.Multimedia.Audio.Renderer
7379
7380**Return value**
7381
7382| Type           | Description                    |
7383| -------------- | ------------------------------ |
7384| Promise\<void> | Promise that returns no value. |
7385
7386**Example**
7387
7388```ts
7389import { BusinessError } from '@ohos.base';
7390
7391audioRenderer.stop().then(() => {
7392  console.info('Renderer stopped successfully');
7393}).catch((err: BusinessError) => {
7394  console.error(`ERROR: ${err}`);
7395});
7396
7397```
7398
7399### release<sup>8+</sup>
7400
7401release(callback: AsyncCallback\<void>): void
7402
7403Releases the renderer. This API uses an asynchronous callback to return the result.
7404
7405**System capability**: SystemCapability.Multimedia.Audio.Renderer
7406
7407**Parameters**
7408
7409| Name     | Type                 | Mandatory | Description                                                  |
7410| -------- | -------------------- | --------- | ------------------------------------------------------------ |
7411| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
7412
7413**Example**
7414
7415```ts
7416import { BusinessError } from '@ohos.base';
7417
7418audioRenderer.release((err: BusinessError) => {
7419  if (err) {
7420    console.error('Renderer release failed');
7421  } else {
7422    console.info('Renderer released.');
7423  }
7424});
7425
7426```
7427
7428### release<sup>8+</sup>
7429
7430release(): Promise\<void>
7431
7432Releases the renderer. This API uses a promise to return the result.
7433
7434**System capability**: SystemCapability.Multimedia.Audio.Renderer
7435
7436**Return value**
7437
7438| Type           | Description                    |
7439| -------------- | ------------------------------ |
7440| Promise\<void> | Promise that returns no value. |
7441
7442**Example**
7443
7444```ts
7445import { BusinessError } from '@ohos.base';
7446
7447audioRenderer.release().then(() => {
7448  console.info('Renderer released successfully');
7449}).catch((err: BusinessError) => {
7450  console.error(`ERROR: ${err}`);
7451});
7452
7453```
7454
7455### write<sup>8+</sup>
7456
7457write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void
7458
7459Writes the buffer. This API uses an asynchronous callback to return the result.
7460
7461**System capability**: SystemCapability.Multimedia.Audio.Renderer
7462
7463**Parameters**
7464
7465| Name     | Type                   | Mandatory | Description                                                  |
7466| -------- | ---------------------- | --------- | ------------------------------------------------------------ |
7467| buffer   | ArrayBuffer            | Yes       | Buffer to be written.                                        |
7468| callback | AsyncCallback\<number> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the number of bytes written; otherwise, **err** is an error object. |
7469
7470**Example**
7471
7472```ts
7473import { BusinessError } from '@ohos.base';
7474import fs from '@ohos.file.fs';
7475
7476let bufferSize: number;
7477class Options {
7478  offset?: number;
7479  length?: number;
7480}
7481audioRenderer.getBufferSize().then((data: number)=> {
7482  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
7483  bufferSize = data;
7484  console.info(`Buffer size: ${bufferSize}`);
7485  let path = getContext().cacheDir;
7486  let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
7487  let file: fs.File = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
7488  fs.stat(filePath).then(async (stat: fs.Stat) => {
7489    let buf = new ArrayBuffer(bufferSize);
7490    let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1);
7491    for (let i = 0;i < len; i++) {
7492      let options: Options = {
7493        offset: i * bufferSize,
7494        length: bufferSize
7495      }
7496      let readsize: number = await fs.read(file.fd, buf, options)
7497      let writeSize: number = await new Promise((resolve,reject)=>{
7498        audioRenderer.write(buf,(err: BusinessError, writeSize: number)=>{
7499          if(err){
7500            reject(err)
7501          }else{
7502            resolve(writeSize)
7503          }
7504        })
7505      })
7506    }
7507  });
7508  }).catch((err: BusinessError) => {
7509    console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
7510});
7511
7512
7513
7514```
7515
7516### write<sup>8+</sup>
7517
7518write(buffer: ArrayBuffer): Promise\<number>
7519
7520Writes the buffer. This API uses a promise to return the result.
7521
7522**System capability**: SystemCapability.Multimedia.Audio.Renderer
7523
7524**Parameters**
7525
7526| Name   | Type        | Mandatory | Description           |
7527| ------ | ----------- | --------- | --------------------- |
7528| buffer | ArrayBuffer | Yes       | Buffer to be written. |
7529
7530**Return value**
7531
7532| Type             | Description                                         |
7533| ---------------- | --------------------------------------------------- |
7534| Promise\<number> | Promise used to return the number of written bytes. |
7535
7536**Example**
7537
7538```ts
7539import { BusinessError } from '@ohos.base';
7540import fs from '@ohos.file.fs';
7541
7542let bufferSize: number;
7543class Options {
7544  offset?: number;
7545  length?: number;
7546}
7547audioRenderer.getBufferSize().then((data: number) => {
7548  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
7549  bufferSize = data;
7550  console.info(`BufferSize: ${bufferSize}`);
7551  let path = getContext().cacheDir;
7552  let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
7553  let file: fs.File = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
7554  fs.stat(filePath).then(async (stat: fs.Stat) => {
7555    let buf = new ArrayBuffer(bufferSize);
7556    let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1);
7557    for (let i = 0;i < len; i++) {
7558      let options: Options = {
7559        offset: i * bufferSize,
7560        length: bufferSize
7561      }
7562      let readsize: number = await fs.read(file.fd, buf, options)
7563      try{
7564        let writeSize: number = await audioRenderer.write(buf);
7565      } catch(err) {
7566        let error = err as BusinessError;
7567        console.error(`audioRenderer.write err: ${error}`);
7568      }
7569    }
7570  });
7571}).catch((err: BusinessError) => {
7572  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
7573});
7574
7575```
7576
7577### getAudioTime<sup>8+</sup>
7578
7579getAudioTime(callback: AsyncCallback\<number>): void
7580
7581Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result.
7582
7583**System capability**: SystemCapability.Multimedia.Audio.Renderer
7584
7585**Parameters**
7586
7587| Name     | Type                   | Mandatory | Description                                                  |
7588| -------- | ---------------------- | --------- | ------------------------------------------------------------ |
7589| callback | AsyncCallback\<number> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the number of nanoseconds obtained; otherwise, **err** is an error object. |
7590
7591**Example**
7592
7593```ts
7594import { BusinessError } from '@ohos.base';
7595
7596audioRenderer.getAudioTime((err: BusinessError, timestamp: number) => {
7597  console.info(`Current timestamp: ${timestamp}`);
7598});
7599
7600```
7601
7602### getAudioTime<sup>8+</sup>
7603
7604getAudioTime(): Promise\<number>
7605
7606Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
7607
7608**System capability**: SystemCapability.Multimedia.Audio.Renderer
7609
7610**Return value**
7611
7612| Type             | Description                           |
7613| ---------------- | ------------------------------------- |
7614| Promise\<number> | Promise used to return the timestamp. |
7615
7616**Example**
7617
7618```ts
7619import { BusinessError } from '@ohos.base';
7620
7621audioRenderer.getAudioTime().then((timestamp: number) => {
7622  console.info(`Current timestamp: ${timestamp}`);
7623}).catch((err: BusinessError) => {
7624  console.error(`ERROR: ${err}`);
7625});
7626
7627```
7628
7629### getAudioTimeSync<sup>10+</sup>
7630
7631getAudioTimeSync(): number
7632
7633Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API returns the result synchronously.
7634
7635**System capability**: SystemCapability.Multimedia.Audio.Renderer
7636
7637**Return value**
7638
7639| Type   | Description |
7640| ------ | ----------- |
7641| number | Timestamp.  |
7642
7643**Example**
7644
7645```ts
7646import { BusinessError } from '@ohos.base';
7647
7648try {
7649  let timestamp: number = audioRenderer.getAudioTimeSync();
7650  console.info(`Current timestamp: ${timestamp}`);
7651} catch (err) {
7652  let error = err as BusinessError;
7653  console.error(`ERROR: ${error}`);
7654}
7655
7656```
7657
7658### getBufferSize<sup>8+</sup>
7659
7660getBufferSize(callback: AsyncCallback\<number>): void
7661
7662Obtains a reasonable minimum buffer size in bytes for rendering. This API uses an asynchronous callback to return the result.
7663
7664**System capability**: SystemCapability.Multimedia.Audio.Renderer
7665
7666**Parameters**
7667
7668| Name     | Type                   | Mandatory | Description                                                  |
7669| -------- | ---------------------- | --------- | ------------------------------------------------------------ |
7670| callback | AsyncCallback\<number> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the minimum buffer size obtained; otherwise, **err** is an error object. |
7671
7672**Example**
7673
7674```ts
7675import { BusinessError } from '@ohos.base';
7676
7677let bufferSize: number;
7678audioRenderer.getBufferSize((err: BusinessError, data: number) => {
7679  if (err) {
7680    console.error('getBufferSize error');
7681  } else {
7682    console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
7683    bufferSize = data;
7684  }
7685});
7686
7687```
7688
7689### getBufferSize<sup>8+</sup>
7690
7691getBufferSize(): Promise\<number>
7692
7693Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a promise to return the result.
7694
7695**System capability**: SystemCapability.Multimedia.Audio.Renderer
7696
7697**Return value**
7698
7699| Type             | Description                             |
7700| ---------------- | --------------------------------------- |
7701| Promise\<number> | Promise used to return the buffer size. |
7702
7703**Example**
7704
7705```ts
7706import { BusinessError } from '@ohos.base';
7707
7708let bufferSize: number;
7709audioRenderer.getBufferSize().then((data: number) => {
7710  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
7711  bufferSize = data;
7712}).catch((err: BusinessError) => {
7713  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
7714});
7715
7716```
7717
7718### getBufferSizeSync<sup>10+</sup>
7719
7720getBufferSizeSync(): number
7721
7722Obtains a reasonable minimum buffer size in bytes for rendering. This API returns the result synchronously.
7723
7724**System capability**: SystemCapability.Multimedia.Audio.Renderer
7725
7726**Return value**
7727
7728| Type   | Description  |
7729| ------ | ------------ |
7730| number | Buffer size. |
7731
7732**Example**
7733
7734```ts
7735import { BusinessError } from '@ohos.base';
7736
7737let bufferSize: number = 0;
7738try {
7739  bufferSize = audioRenderer.getBufferSizeSync();
7740  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${bufferSize}`);
7741} catch (err) {
7742  let error = err as BusinessError;
7743  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${error}`);
7744}
7745
7746```
7747
7748### setRenderRate<sup>8+</sup>
7749
7750setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\<void>): void
7751
7752Sets the render rate. This API uses an asynchronous callback to return the result.
7753
7754**System capability**: SystemCapability.Multimedia.Audio.Renderer
7755
7756**Parameters**
7757
7758| Name     | Type                                     | Mandatory | Description                                                  |
7759| -------- | ---------------------------------------- | --------- | ------------------------------------------------------------ |
7760| rate     | [AudioRendererRate](#audiorendererrate8) | Yes       | Audio render rate.                                           |
7761| callback | AsyncCallback\<void>                     | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
7762
7763**Example**
7764
7765```ts
7766import { BusinessError } from '@ohos.base';
7767
7768audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err: BusinessError) => {
7769  if (err) {
7770    console.error('Failed to set params');
7771  } else {
7772    console.info('Callback invoked to indicate a successful render rate setting.');
7773  }
7774});
7775
7776```
7777
7778### setRenderRate<sup>8+</sup>
7779
7780setRenderRate(rate: AudioRendererRate): Promise\<void>
7781
7782Sets the render rate. This API uses a promise to return the result.
7783
7784**System capability**: SystemCapability.Multimedia.Audio.Renderer
7785
7786**Parameters**
7787
7788| Name | Type                                     | Mandatory | Description        |
7789| ---- | ---------------------------------------- | --------- | ------------------ |
7790| rate | [AudioRendererRate](#audiorendererrate8) | Yes       | Audio render rate. |
7791
7792**Return value**
7793
7794| Type           | Description                    |
7795| -------------- | ------------------------------ |
7796| Promise\<void> | Promise that returns no value. |
7797
7798**Example**
7799
7800```ts
7801import { BusinessError } from '@ohos.base';
7802
7803audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
7804  console.info('setRenderRate SUCCESS');
7805}).catch((err: BusinessError) => {
7806  console.error(`ERROR: ${err}`);
7807});
7808
7809```
7810
7811### getRenderRate<sup>8+</sup>
7812
7813getRenderRate(callback: AsyncCallback\<AudioRendererRate>): void
7814
7815Obtains the current render rate. This API uses an asynchronous callback to return the result.
7816
7817**System capability**: SystemCapability.Multimedia.Audio.Renderer
7818
7819**Parameters**
7820
7821| Name     | Type                                                    | Mandatory | Description                                                  |
7822| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
7823| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the render rate obtained; otherwise, **err** is an error object. |
7824
7825**Example**
7826
7827```ts
7828import { BusinessError } from '@ohos.base';
7829
7830audioRenderer.getRenderRate((err: BusinessError, renderRate: audio.AudioRendererRate) => {
7831  console.info(`getRenderRate: ${renderRate}`);
7832});
7833
7834```
7835
7836### getRenderRate<sup>8+</sup>
7837
7838getRenderRate(): Promise\<AudioRendererRate>
7839
7840Obtains the current render rate. This API uses a promise to return the result.
7841
7842**System capability**: SystemCapability.Multimedia.Audio.Renderer
7843
7844**Return value**
7845
7846| Type                                              | Description                             |
7847| ------------------------------------------------- | --------------------------------------- |
7848| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the render rate. |
7849
7850**Example**
7851
7852```ts
7853import { BusinessError } from '@ohos.base';
7854
7855audioRenderer.getRenderRate().then((renderRate: audio.AudioRendererRate) => {
7856  console.info(`getRenderRate: ${renderRate}`);
7857}).catch((err: BusinessError) => {
7858  console.error(`ERROR: ${err}`);
7859});
7860
7861```
7862
7863### getRenderRateSync<sup>10+</sup>
7864
7865getRenderRateSync(): AudioRendererRate
7866
7867Obtains the current render rate. This API returns the result synchronously.
7868
7869**System capability**: SystemCapability.Multimedia.Audio.Renderer
7870
7871**Return value**
7872
7873| Type                                     | Description        |
7874| ---------------------------------------- | ------------------ |
7875| [AudioRendererRate](#audiorendererrate8) | Audio render rate. |
7876
7877**Example**
7878
7879```ts
7880import { BusinessError } from '@ohos.base';
7881
7882try {
7883  let renderRate: audio.AudioRendererRate = audioRenderer.getRenderRateSync();
7884  console.info(`getRenderRate: ${renderRate}`);
7885} catch (err) {
7886  let error = err as BusinessError;
7887  console.error(`ERROR: ${error}`);
7888}
7889
7890```
7891
7892### setInterruptMode<sup>9+</sup>
7893
7894setInterruptMode(mode: InterruptMode): Promise&lt;void&gt;
7895
7896Sets the audio interruption mode for the application. This API uses a promise to return the result.
7897
7898**System capability**: SystemCapability.Multimedia.Audio.Interrupt
7899
7900**Parameters**
7901
7902| Name | Type                             | Mandatory | Description              |
7903| ---- | -------------------------------- | --------- | ------------------------ |
7904| mode | [InterruptMode](#interruptmode9) | Yes       | Audio interruption mode. |
7905
7906**Return value**
7907
7908| Type                | Description                    |
7909| ------------------- | ------------------------------ |
7910| Promise&lt;void&gt; | Promise that returns no value. |
7911
7912**Example**
7913
7914```ts
7915import { BusinessError } from '@ohos.base';
7916
7917let mode = 0;
7918audioRenderer.setInterruptMode(mode).then(() => {
7919  console.info('setInterruptMode Success!');
7920}).catch((err: BusinessError) => {
7921  console.error(`setInterruptMode Fail: ${err}`);
7922});
7923
7924```
7925
7926### setInterruptMode<sup>9+</sup>
7927
7928setInterruptMode(mode: InterruptMode, callback: AsyncCallback\<void>): void
7929
7930Sets the audio interruption mode for the application. This API uses an asynchronous callback to return the result.
7931
7932**System capability**: SystemCapability.Multimedia.Audio.Interrupt
7933
7934**Parameters**
7935
7936| Name     | Type                             | Mandatory | Description                                                  |
7937| -------- | -------------------------------- | --------- | ------------------------------------------------------------ |
7938| mode     | [InterruptMode](#interruptmode9) | Yes       | Audio interruption mode.                                     |
7939| callback | AsyncCallback\<void>             | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
7940
7941**Example**
7942
7943```ts
7944import { BusinessError } from '@ohos.base';
7945
7946let mode = 1;
7947audioRenderer.setInterruptMode(mode, (err: BusinessError) => {
7948  if(err){
7949    console.error(`setInterruptMode Fail: ${err}`);
7950  }
7951  console.info('setInterruptMode Success!');
7952});
7953
7954```
7955
7956### setInterruptModeSync<sup>10+</sup>
7957
7958setInterruptModeSync(mode: InterruptMode): void
7959
7960Sets the audio interruption mode for the application. This API returns the result synchronously.
7961
7962**System capability**: SystemCapability.Multimedia.Audio.Interrupt
7963
7964**Parameters**
7965
7966| Name | Type                             | Mandatory | Description              |
7967| ---- | -------------------------------- | --------- | ------------------------ |
7968| mode | [InterruptMode](#interruptmode9) | Yes       | Audio interruption mode. |
7969
7970**Error codes**
7971
7972For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
7973
7974| ID      | Error Message           |
7975| ------- | ----------------------- |
7976| 6800101 | invalid parameter error |
7977
7978**Example**
7979
7980```ts
7981import { BusinessError } from '@ohos.base';
7982
7983try {
7984  audioRenderer.setInterruptModeSync(0);
7985  console.info('setInterruptMode Success!');
7986} catch (err) {
7987  let error = err as BusinessError;
7988  console.error(`setInterruptMode Fail: ${error}`);
7989}
7990
7991```
7992
7993### setVolume<sup>9+</sup>
7994
7995setVolume(volume: number): Promise&lt;void&gt;
7996
7997Sets the volume for the application. This API uses a promise to return the result.
7998
7999**System capability**: SystemCapability.Multimedia.Audio.Renderer
8000
8001**Parameters**
8002
8003| Name   | Type   | Mandatory | Description                                                  |
8004| ------ | ------ | --------- | ------------------------------------------------------------ |
8005| volume | number | Yes       | Volume to set, which can be within the range from 0.0 to 1.0. |
8006
8007**Return value**
8008
8009| Type                | Description                    |
8010| ------------------- | ------------------------------ |
8011| Promise&lt;void&gt; | Promise that returns no value. |
8012
8013**Example**
8014
8015```ts
8016import { BusinessError } from '@ohos.base';
8017
8018audioRenderer.setVolume(0.5).then(() => {
8019  console.info('setVolume Success!');
8020}).catch((err: BusinessError) => {
8021  console.error(`setVolume Fail: ${err}`);
8022});
8023
8024```
8025
8026### setVolume<sup>9+</sup>
8027
8028setVolume(volume: number, callback: AsyncCallback\<void>): void
8029
8030Sets the volume for the application. This API uses an asynchronous callback to return the result.
8031
8032**System capability**: SystemCapability.Multimedia.Audio.Renderer
8033
8034**Parameters**
8035
8036| Name     | Type                 | Mandatory | Description                                                  |
8037| -------- | -------------------- | --------- | ------------------------------------------------------------ |
8038| volume   | number               | Yes       | Volume to set, which can be within the range from 0.0 to 1.0. |
8039| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
8040
8041**Example**
8042
8043```ts
8044import { BusinessError } from '@ohos.base';
8045
8046audioRenderer.setVolume(0.5, (err: BusinessError) => {
8047  if(err){
8048    console.error(`setVolume Fail: ${err}`);
8049    return;
8050  }
8051  console.info('setVolume Success!');
8052});
8053
8054```
8055
8056### getMinStreamVolume<sup>10+</sup>
8057
8058getMinStreamVolume(callback: AsyncCallback&lt;number&gt;): void
8059
8060Obtains the minimum volume of the application from the perspective of an audio stream. This API uses an asynchronous callback to return the result.
8061
8062**System capability**: SystemCapability.Multimedia.Audio.Renderer
8063
8064**Parameters**
8065
8066| Name     | Type                        | Mandatory | Description                                                  |
8067| -------- | --------------------------- | --------- | ------------------------------------------------------------ |
8068| callback | AsyncCallback&lt;number&gt; | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the minimum volume (range: 0-1) obtained; otherwise, **err** is an error object. |
8069
8070**Example**
8071
8072```ts
8073import { BusinessError } from '@ohos.base';
8074
8075audioRenderer.getMinStreamVolume((err: BusinessError, minVolume: number) => {
8076  if (err) {
8077    console.error(`getMinStreamVolume error: ${err}`);
8078  } else {
8079    console.info(`getMinStreamVolume Success! ${minVolume}`);
8080  }
8081});
8082
8083```
8084
8085### getMinStreamVolume<sup>10+</sup>
8086
8087getMinStreamVolume(): Promise&lt;number&gt;
8088
8089Obtains the minimum volume of the application from the perspective of an audio stream. This API uses a promise to return the result.
8090
8091**System capability**: SystemCapability.Multimedia.Audio.Renderer
8092
8093**Return value**
8094
8095| Type                  | Description                                                  |
8096| --------------------- | ------------------------------------------------------------ |
8097| Promise&lt;number&gt; | Promise used to return the minimum volume, ranging from 0 to 1. |
8098
8099**Example**
8100
8101```ts
8102import { BusinessError } from '@ohos.base';
8103
8104audioRenderer.getMinStreamVolume().then((value: number) => {
8105  console.info(`Get min stream volume Success! ${value}`);
8106}).catch((err: BusinessError) => {
8107  console.error(`Get min stream volume Fail: ${err}`);
8108});
8109
8110```
8111
8112### getMinStreamVolumeSync<sup>10+</sup>
8113
8114getMinStreamVolumeSync(): number
8115
8116Obtains the minimum volume of the application from the perspective of an audio stream. This API returns the result synchronously.
8117
8118**System capability**: SystemCapability.Multimedia.Audio.Renderer
8119
8120**Return value**
8121
8122| Type   | Description                          |
8123| ------ | ------------------------------------ |
8124| number | Minimum volume, ranging from 0 to 1. |
8125
8126**Example**
8127
8128```ts
8129import { BusinessError } from '@ohos.base';
8130
8131try {
8132  let value: number = audioRenderer.getMinStreamVolumeSync();
8133  console.info(`Get min stream volume Success! ${value}`);
8134} catch (err) {
8135  let error = err as BusinessError;
8136  console.error(`Get min stream volume Fail: ${error}`);
8137}
8138
8139```
8140
8141### getMaxStreamVolume<sup>10+</sup>
8142
8143getMaxStreamVolume(callback: AsyncCallback&lt;number&gt;): void
8144
8145Obtains the maximum volume of the application from the perspective of an audio stream. This API uses an asynchronous callback to return the result.
8146
8147**System capability**: SystemCapability.Multimedia.Audio.Renderer
8148
8149**Parameters**
8150
8151| Name     | Type                        | Mandatory | Description                                                  |
8152| -------- | --------------------------- | --------- | ------------------------------------------------------------ |
8153| callback | AsyncCallback&lt;number&gt; | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the maximum volume (range: 0-1) obtained; otherwise, **err** is an error object. |
8154
8155**Example**
8156
8157```ts
8158import { BusinessError } from '@ohos.base';
8159
8160audioRenderer.getMaxStreamVolume((err: BusinessError, maxVolume: number) => {
8161  if (err) {
8162    console.error(`getMaxStreamVolume Fail: ${err}`);
8163  } else {
8164    console.info(`getMaxStreamVolume Success! ${maxVolume}`);
8165  }
8166});
8167
8168```
8169
8170### getMaxStreamVolume<sup>10+</sup>
8171
8172getMaxStreamVolume(): Promise&lt;number&gt;
8173
8174Obtains the maximum volume of the application from the perspective of an audio stream. This API uses a promise to return the result.
8175
8176**System capability**: SystemCapability.Multimedia.Audio.Renderer
8177
8178**Return value**
8179
8180| Type                  | Description                                                  |
8181| --------------------- | ------------------------------------------------------------ |
8182| Promise&lt;number&gt; | Promise used to return the maximum volume, ranging from 0 to 1. |
8183
8184**Example**
8185
8186```ts
8187import { BusinessError } from '@ohos.base';
8188
8189audioRenderer.getMaxStreamVolume().then((value: number) => {
8190  console.info(`Get max stream volume Success! ${value}`);
8191}).catch((err: BusinessError) => {
8192  console.error(`Get max stream volume Fail: ${err}`);
8193});
8194
8195```
8196
8197### getMaxStreamVolumeSync<sup>10+</sup>
8198
8199getMaxStreamVolumeSync(): number
8200
8201Obtains the maximum volume of the application from the perspective of an audio stream. This API returns the result synchronously.
8202
8203**System capability**: SystemCapability.Multimedia.Audio.Renderer
8204
8205**Return value**
8206
8207| Type   | Description                          |
8208| ------ | ------------------------------------ |
8209| number | Maximum volume, ranging from 0 to 1. |
8210
8211**Example**
8212
8213```ts
8214import { BusinessError } from '@ohos.base';
8215
8216try {
8217  let value: number = audioRenderer.getMaxStreamVolumeSync();
8218  console.info(`Get max stream volume Success! ${value}`);
8219} catch (err) {
8220  let error = err as BusinessError;
8221  console.error(`Get max stream volume Fail: ${error}`);
8222}
8223
8224```
8225
8226### getUnderflowCount<sup>10+</sup>
8227
8228getUnderflowCount(callback: AsyncCallback&lt;number&gt;): void
8229
8230Obtains the number of underflow audio frames in the audio stream that is being played. This API uses an asynchronous callback to return the result.
8231
8232**System capability**: SystemCapability.Multimedia.Audio.Renderer
8233
8234**Parameters**
8235
8236| Name     | Type                        | Mandatory | Description                                                  |
8237| -------- | --------------------------- | --------- | ------------------------------------------------------------ |
8238| callback | AsyncCallback&lt;number&gt; | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the number of underloaded audio frames obtained; otherwise, **err** is an error object. |
8239
8240**Example**
8241
8242```ts
8243import { BusinessError } from '@ohos.base';
8244
8245audioRenderer.getUnderflowCount((err: BusinessError, underflowCount: number) => {
8246  if (err) {
8247    console.error(`getUnderflowCount Fail: ${err}`);
8248  } else {
8249    console.info(`getUnderflowCount Success! ${underflowCount}`);
8250  }
8251});
8252
8253```
8254
8255### getUnderflowCount<sup>10+</sup>
8256
8257getUnderflowCount(): Promise&lt;number&gt;
8258
8259Obtains the number of underflow audio frames in the audio stream that is being played. This API uses a promise to return the result.
8260
8261**System capability**: SystemCapability.Multimedia.Audio.Renderer
8262
8263**Return value**
8264
8265| Type                  | Description                                                  |
8266| --------------------- | ------------------------------------------------------------ |
8267| Promise&lt;number&gt; | Promise used to return the number of underflow audio frames. |
8268
8269**Example**
8270
8271```ts
8272import { BusinessError } from '@ohos.base';
8273
8274audioRenderer.getUnderflowCount().then((value: number) => {
8275  console.info(`Get underflow count Success! ${value}`);
8276}).catch((err: BusinessError) => {
8277  console.error(`Get underflow count Fail: ${err}`);
8278});
8279
8280```
8281
8282### getUnderflowCountSync<sup>10+</sup>
8283
8284getUnderflowCountSync(): number
8285
8286Obtains the number of underflow audio frames in the audio stream that is being played. This API returns the result synchronously.
8287
8288**System capability**: SystemCapability.Multimedia.Audio.Renderer
8289
8290**Return value**
8291
8292| Type   | Description                       |
8293| ------ | --------------------------------- |
8294| number | Number of underflow audio frames. |
8295
8296**Example**
8297
8298```ts
8299import { BusinessError } from '@ohos.base';
8300
8301try {
8302  let value: number = audioRenderer.getUnderflowCountSync();
8303  console.info(`Get underflow count Success! ${value}`);
8304} catch (err) {
8305  let error = err as BusinessError;
8306  console.error(`Get underflow count Fail: ${error}`);
8307}
8308
8309```
8310
8311### getCurrentOutputDevices<sup>10+</sup>
8312
8313getCurrentOutputDevices(callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
8314
8315Obtains the output device descriptors of the audio streams. This API uses an asynchronous callback to return the result.
8316
8317**System capability**: SystemCapability.Multimedia.Audio.Device
8318
8319**Parameters**
8320
8321| Name     | Type                                                         | Mandatory | Description                                                  |
8322| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
8323| callback | AsyncCallback\<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the output device descriptors obtained; otherwise, **err** is an error object. |
8324
8325**Example**
8326
8327```ts
8328import { BusinessError } from '@ohos.base';
8329
8330audioRenderer.getCurrentOutputDevices((err: BusinessError, deviceInfo: audio.AudioDeviceDescriptors) => {
8331  if (err) {
8332    console.error(`getCurrentOutputDevices Fail: ${err}`);
8333  } else {
8334    for (let i = 0; i < deviceInfo.length; i++) {
8335      console.info(`DeviceInfo id: ${deviceInfo[i].id}`);
8336      console.info(`DeviceInfo type: ${deviceInfo[i].deviceType}`);
8337      console.info(`DeviceInfo role: ${deviceInfo[i].deviceRole}`);
8338      console.info(`DeviceInfo name: ${deviceInfo[i].name}`);
8339      console.info(`DeviceInfo address: ${deviceInfo[i].address}`);
8340      console.info(`DeviceInfo samplerate: ${deviceInfo[i].sampleRates[0]}`);
8341      console.info(`DeviceInfo channelcount: ${deviceInfo[i].channelCounts[0]}`);
8342      console.info(`DeviceInfo channelmask: ${deviceInfo[i].channelMasks[0]}`);
8343    }
8344  }
8345});
8346
8347```
8348
8349### getCurrentOutputDevices<sup>10+</sup>
8350
8351getCurrentOutputDevices(): Promise&lt;AudioDeviceDescriptors&gt;
8352
8353Obtains the output device descriptors of the audio streams. This API uses a promise to return the result.
8354
8355**System capability**: SystemCapability.Multimedia.Audio.Device
8356
8357**Return value**
8358
8359| Type                                                         | Description                                           |
8360| ------------------------------------------------------------ | ----------------------------------------------------- |
8361| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the output device descriptors. |
8362
8363**Example**
8364
8365```ts
8366import { BusinessError } from '@ohos.base';
8367
8368audioRenderer.getCurrentOutputDevices().then((deviceInfo: audio.AudioDeviceDescriptors) => {
8369  for (let i = 0; i < deviceInfo.length; i++) {
8370    console.info(`DeviceInfo id: ${deviceInfo[i].id}`);
8371    console.info(`DeviceInfo type: ${deviceInfo[i].deviceType}`);
8372    console.info(`DeviceInfo role: ${deviceInfo[i].deviceRole}`);
8373    console.info(`DeviceInfo name: ${deviceInfo[i].name}`);
8374    console.info(`DeviceInfo address: ${deviceInfo[i].address}`);
8375    console.info(`DeviceInfo samplerate: ${deviceInfo[i].sampleRates[0]}`);
8376    console.info(`DeviceInfo channelcount: ${deviceInfo[i].channelCounts[0]}`);
8377    console.info(`DeviceInfo channelmask: ${deviceInfo[i].channelMasks[0]}`);
8378  }
8379}).catch((err: BusinessError) => {
8380  console.error(`Get current output devices Fail: ${err}`);
8381});
8382
8383```
8384
8385### getCurrentOutputDevicesSync<sup>10+</sup>
8386
8387getCurrentOutputDevicesSync(): AudioDeviceDescriptors
8388
8389Obtains the output device descriptors of the audio streams. This API returns the result synchronously.
8390
8391**System capability**: SystemCapability.Multimedia.Audio.Device
8392
8393**Return value**
8394
8395| Type                                              | Description                |
8396| ------------------------------------------------- | -------------------------- |
8397| [AudioDeviceDescriptors](#audiodevicedescriptors) | Output device descriptors. |
8398
8399**Example**
8400
8401```ts
8402import { BusinessError } from '@ohos.base';
8403
8404try {
8405  let deviceInfo: audio.AudioDeviceDescriptors = audioRenderer.getCurrentOutputDevicesSync();
8406  for (let i = 0; i < deviceInfo.length; i++) {
8407    console.info(`DeviceInfo id: ${deviceInfo[i].id}`);
8408    console.info(`DeviceInfo type: ${deviceInfo[i].deviceType}`);
8409    console.info(`DeviceInfo role: ${deviceInfo[i].deviceRole}`);
8410    console.info(`DeviceInfo name: ${deviceInfo[i].name}`);
8411    console.info(`DeviceInfo address: ${deviceInfo[i].address}`);
8412    console.info(`DeviceInfo samplerate: ${deviceInfo[i].sampleRates[0]}`);
8413    console.info(`DeviceInfo channelcount: ${deviceInfo[i].channelCounts[0]}`);
8414    console.info(`DeviceInfo channelmask: ${deviceInfo[i].channelMasks[0]}`);
8415  }
8416} catch (err) {
8417  let error = err as BusinessError;
8418  console.error(`Get current output devices Fail: ${error}`);
8419}
8420
8421```
8422
8423### setChannelBlendMode<sup>11+</sup>
8424
8425setChannelBlendMode(mode: ChannelBlendMode): void
8426
8427Sets the audio channel blending mode. This API returns the result synchronously.
8428
8429**System capability**: SystemCapability.Multimedia.Audio.Renderer
8430
8431**Parameters**
8432
8433| Name | Type                                    | Mandatory | Description                  |
8434| ---- | --------------------------------------- | --------- | ---------------------------- |
8435| mode | [ChannelBlendMode](#channelblendmode11) | Yes       | Audio channel blending mode. |
8436
8437**Error codes**
8438
8439For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
8440
8441| ID      | Error Message                          |
8442| ------- | -------------------------------------- |
8443| 6800101 | Input parameter value error.           |
8444| 6800103 | Operation not permit at current state. |
8445
8446**Example**
8447
8448```ts
8449let mode = audio.ChannelBlendMode.MODE_DEFAULT;
8450
8451audioRenderer.setChannelBlendMode(mode);
8452console.info(`BlendMode: ${mode}`);
8453
8454```
8455
8456### setVolumeWithRamp<sup>11+</sup>
8457
8458setVolumeWithRamp(volume: number, duration: number): void
8459
8460Sets a volume ramp. This API returns the result synchronously.
8461
8462**System capability**: SystemCapability.Multimedia.Audio.Renderer
8463
8464**Parameters**
8465
8466| Name     | Type   | Mandatory | Description                                      |
8467| -------- | ------ | --------- | ------------------------------------------------ |
8468| volume   | number | Yes       | Target volume, within the range [0.0, 1.0].      |
8469| duration | number | Yes       | Time range during which the ramp applies, in ms. |
8470
8471**Error codes**
8472
8473For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
8474
8475| ID      | Error Message                            |
8476| ------- | ---------------------------------------- |
8477| 6800101 | Input parameter value error.             |
8478| 401     | Input parameter type or number mismatch. |
8479
8480**Example**
8481
8482```ts
8483let volume = 0.5;
8484let duration = 1000;
8485
8486audioRenderer.setVolumeWithRamp(volume, duration);
8487console.info(`setVolumeWithRamp: ${volume}`);
8488
8489```
8490
8491### on('audioInterrupt')<sup>9+</sup>
8492
8493on(type: 'audioInterrupt', callback: Callback\<InterruptEvent>): void
8494
8495Subscribes to audio interruption events. This API uses an asynchronous callback to return the result.
8496
8497Same as [on('interrupt')](#oninterrupt), this API is used to listen for focus changes. The **AudioRenderer** instance proactively gains the focus when the **start** event occurs and releases the focus when the **pause** or **stop** event occurs. Therefore, you do not need to request to gain or release the focus.
8498
8499**System capability**: SystemCapability.Multimedia.Audio.Interrupt
8500
8501**Parameters**
8502
8503| Name     | Type                                           | Mandatory | Description                                                  |
8504| -------- | ---------------------------------------------- | --------- | ------------------------------------------------------------ |
8505| type     | string                                         | Yes       | Event type. The event **'audioInterrupt'** is triggered when audio rendering is interrupted. |
8506| callback | Callback\<[InterruptEvent](#interruptevent9)\> | Yes       | Callback used to return the audio interruption event received by the application when playback is interrupted. |
8507
8508**Error codes**
8509
8510For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
8511
8512| ID      | Error Message            |
8513| ------- | ------------------------ |
8514| 6800101 | Invalid parameter error. |
8515
8516**Example**
8517
8518```ts
8519import audio from '@ohos.multimedia.audio';
8520
8521let isPlaying: boolean; // An identifier specifying whether rendering is in progress.
8522let isDucked: boolean; // An identifier specifying whether the audio volume is reduced.
8523onAudioInterrupt();
8524
8525async function onAudioInterrupt(){
8526  audioRenderer.on('audioInterrupt', (interruptEvent: audio.InterruptEvent) => {
8527    if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
8528      // The system forcibly interrupts audio rendering. The application must update the status and displayed content accordingly.
8529      switch (interruptEvent.hintType) {
8530        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
8531          // The audio stream has been paused and temporarily loses the focus. It will receive the interruptEvent corresponding to resume when it is able to regain the focus.
8532          console.info('Force paused. Update playing status and stop writing');
8533          isPlaying = false; // A simplified processing indicating several operations for switching the application to the paused state.
8534          break;
8535        case audio.InterruptHint.INTERRUPT_HINT_STOP:
8536          // The audio stream has been stopped and permanently loses the focus. The user must manually trigger the operation to resume rendering.
8537          console.info('Force stopped. Update playing status and stop writing');
8538          isPlaying = false; // A simplified processing indicating several operations for switching the application to the paused state.
8539          break;
8540        case audio.InterruptHint.INTERRUPT_HINT_DUCK:
8541          // The audio stream is rendered at a reduced volume.
8542          console.info('Force ducked. Update volume status');
8543          isDucked = true; // A simplified processing indicating several operations for updating the volume status.
8544          break;
8545        case audio.InterruptHint.INTERRUPT_HINT_UNDUCK:
8546          // The audio stream is rendered at the normal volume.
8547          console.info('Force ducked. Update volume status');
8548          isDucked = false; // A simplified processing indicating several operations for updating the volume status.
8549          break;
8550        default:
8551          console.info('Invalid interruptEvent');
8552          break;
8553      }
8554    } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
8555      // The application can choose to take action or ignore.
8556      switch (interruptEvent.hintType) {
8557        case audio.InterruptHint.INTERRUPT_HINT_RESUME:
8558          // It is recommended that the application continue rendering. (The audio stream has been forcibly paused and temporarily lost the focus. It can resume rendering now.)
8559          console.info('Resume force paused renderer or ignore');
8560          // To continue rendering, the application must perform the required operations.
8561          break;
8562        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
8563          // It is recommended that the application pause rendering.
8564          console.info('Choose to pause or ignore');
8565          // To pause rendering, the application must perform the required operations.
8566          break;
8567        case audio.InterruptHint.INTERRUPT_HINT_STOP:
8568          // It is recommended that the application stop rendering.
8569          console.info('Choose to stop or ignore');
8570          // To stop rendering, the application must perform the required operations.
8571          break;
8572        case audio.InterruptHint.INTERRUPT_HINT_DUCK:
8573          // It is recommended that the application reduce the volume for rendering.
8574          console.info('Choose to duck or ignore');
8575          // To decrease the volume for rendering, the application must perform the required operations.
8576          break;
8577        case audio.InterruptHint.INTERRUPT_HINT_UNDUCK:
8578          // It is recommended that the application resume rendering at the normal volume.
8579          console.info('Choose to unduck or ignore');
8580          // To resume rendering at the normal volume, the application must perform the required operations.
8581          break;
8582        default:
8583          break;
8584      }
8585    }
8586  });
8587}
8588
8589```
8590
8591### on('markReach')<sup>8+</sup>
8592
8593on(type: 'markReach', frame: number, callback: Callback&lt;number&gt;): void
8594
8595Subscribes to mark reached events. When the number of frames rendered reaches the value of the **frame** parameter, a callback is invoked. This API uses an asynchronous callback to return the result.
8596
8597**System capability**: SystemCapability.Multimedia.Audio.Renderer
8598
8599**Parameters**
8600
8601| Name     | Type              | Mandatory | Description                                                  |
8602| :------- | :---------------- | :-------- | :----------------------------------------------------------- |
8603| type     | string            | Yes       | Event type. The value is fixed at **'markReach'**.           |
8604| frame    | number            | Yes       | Number of frames to trigger the event. The value must be greater than **0**. |
8605| callback | Callback\<number> | Yes       | Callback used to return the value of the **frame** parameter. |
8606
8607**Example**
8608
8609```ts
8610audioRenderer.on('markReach', 1000, (position: number) => {
8611  if (position == 1000) {
8612    console.info('ON Triggered successfully');
8613  }
8614});
8615
8616```
8617
8618
8619### off('markReach') <sup>8+</sup>
8620
8621off(type: 'markReach'): void
8622
8623Unsubscribes from mark reached events.
8624
8625**System capability**: SystemCapability.Multimedia.Audio.Renderer
8626
8627**Parameters**
8628
8629| Name | Type   | Mandatory | Description                                        |
8630| :--- | :----- | :-------- | :------------------------------------------------- |
8631| type | string | Yes       | Event type. The value is fixed at **'markReach'**. |
8632
8633**Example**
8634
8635```ts
8636audioRenderer.off('markReach');
8637
8638```
8639
8640### on('periodReach') <sup>8+</sup>
8641
8642on(type: 'periodReach', frame: number, callback: Callback&lt;number&gt;): void
8643
8644Subscribes to period reached events. When the number of frames rendered reaches the value of the **frame** parameter, a callback is triggered and the specified value is returned. This API uses an asynchronous callback to return the result.
8645
8646**System capability**: SystemCapability.Multimedia.Audio.Renderer
8647
8648**Parameters**
8649
8650| Name     | Type              | Mandatory | Description                                                  |
8651| :------- | :---------------- | :-------- | :----------------------------------------------------------- |
8652| type     | string            | Yes       | Event type. The value is fixed at **'periodReach'**.         |
8653| frame    | number            | Yes       | Number of frames to trigger the event. The value must be greater than **0**. |
8654| callback | Callback\<number> | Yes       | Callback used to return the value of the **frame** parameter. |
8655
8656**Example**
8657
8658```ts
8659audioRenderer.on('periodReach', 1000, (position: number) => {
8660  if (position == 1000) {
8661    console.info('ON Triggered successfully');
8662  }
8663});
8664
8665```
8666
8667### off('periodReach') <sup>8+</sup>
8668
8669off(type: 'periodReach'): void
8670
8671Unsubscribes from period reached events.
8672
8673**System capability**: SystemCapability.Multimedia.Audio.Renderer
8674
8675**Parameters**
8676
8677| Name | Type   | Mandatory | Description                                          |
8678| :--- | :----- | :-------- | :--------------------------------------------------- |
8679| type | string | Yes       | Event type. The value is fixed at **'periodReach'**. |
8680
8681**Example**
8682
8683```ts
8684audioRenderer.off('periodReach');
8685
8686```
8687
8688### on('stateChange')<sup>8+</sup>
8689
8690on(type: 'stateChange', callback: Callback<AudioState\>): void
8691
8692Subscribes to state change events. This API uses an asynchronous callback to return the result.
8693
8694**System capability**: SystemCapability.Multimedia.Audio.Renderer
8695
8696**Parameters**
8697
8698| Name     | Type                                  | Mandatory | Description                                                  |
8699| :------- | :------------------------------------ | :-------- | :----------------------------------------------------------- |
8700| type     | string                                | Yes       | Event type. The value **stateChange** means the state change event. |
8701| callback | Callback\<[AudioState](#audiostate8)> | Yes       | Callback used to return the audio status.                    |
8702
8703**Example**
8704
8705```ts
8706audioRenderer.on('stateChange', (state: audio.AudioState) => {
8707  if (state == 1) {
8708    console.info('audio renderer state is: STATE_PREPARED');
8709  }
8710  if (state == 2) {
8711    console.info('audio renderer state is: STATE_RUNNING');
8712  }
8713});
8714
8715```
8716
8717### on('outputDeviceChange') <sup>10+</sup>
8718
8719on(type: 'outputDeviceChange', callback: Callback\<AudioDeviceDescriptors>): void
8720
8721Subscribes to audio output device change events. This API uses an asynchronous callback to return the result.
8722
8723**System capability**: SystemCapability.Multimedia.Audio.Device
8724
8725**Parameters**
8726
8727| Name     | Type                                                         | Mandatory | Description                                                  |
8728| :------- | :----------------------------------------------------------- | :-------- | :----------------------------------------------------------- |
8729| type     | string                                                       | Yes       | Event type. The event **'outputDeviceChange'** is triggered when the audio output device is changed. |
8730| callback | Callback\<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Yes       | Callback used to return the output device descriptor of the current audio stream. |
8731
8732**Error codes**
8733
8734For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
8735
8736| ID      | Error Message            |
8737| ------- | ------------------------ |
8738| 6800101 | Invalid parameter error. |
8739
8740**Example**
8741
8742```ts
8743audioRenderer.on('outputDeviceChange', (deviceInfo: audio.AudioDeviceDescriptors) => {
8744  console.info(`DeviceInfo id: ${deviceInfo[0].id}`);
8745  console.info(`DeviceInfo name: ${deviceInfo[0].name}`);
8746  console.info(`DeviceInfo address: ${deviceInfo[0].address}`);
8747});
8748
8749```
8750
8751### off('outputDeviceChange') <sup>10+</sup>
8752
8753off(type: 'outputDeviceChange', callback?: Callback\<AudioDeviceDescriptors>): void
8754
8755Unsubscribes from audio output device change events. This API uses an asynchronous callback to return the result.
8756
8757**System capability**: SystemCapability.Multimedia.Audio.Device
8758
8759**Parameters**
8760
8761| Name     | Type                                                         | Mandatory | Description                                                  |
8762| :------- | :----------------------------------------------------------- | :-------- | :----------------------------------------------------------- |
8763| type     | string                                                       | Yes       | Event type. The event **'outputDeviceChange'** is triggered when the audio output device is changed. |
8764| callback | Callback\<[AudioDeviceDescriptors](#audiodevicedescriptors)> | No        | Callback used to return the output device descriptor of the current audio stream. |
8765
8766**Error codes**
8767
8768For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
8769
8770| ID      | Error Message            |
8771| ------- | ------------------------ |
8772| 6800101 | Invalid parameter error. |
8773
8774**Example**
8775
8776```ts
8777audioRenderer.off('outputDeviceChange', (deviceInfo: audio.AudioDeviceDescriptors) => {
8778  console.info(`DeviceInfo id: ${deviceInfo[0].id}`);
8779  console.info(`DeviceInfo name: ${deviceInfo[0].name}`);
8780  console.info(`DeviceInfo address: ${deviceInfo[0].address}`);
8781});
8782
8783```
8784
8785### on('outputDeviceChangeWithInfo') <sup>11+</sup>
8786
8787on(type: 'outputDeviceChangeWithInfo', callback: Callback\<AudioStreamDeviceChangeInfo>): void
8788
8789Subscribes to audio stream output device changes and reasons. This API uses an asynchronous callback to return the result.
8790
8791**System capability**: SystemCapability.Multimedia.Audio.Device
8792
8793**Parameters**
8794
8795| Name     | Type                                                         | Mandatory | Description                                                  |
8796| :------- | :----------------------------------------------------------- | :-------- | :----------------------------------------------------------- |
8797| type     | string                                                       | Yes       | Event type. The event **'outputDeviceChangeWithInfo'** is triggered when the output device is changed. |
8798| callback | Callback\<[AudioStreamDeviceChangeInfo](#audiostreamdevicechangeinfo11)> | Yes       | Callback used to return the output device descriptor of the current audio stream and the change reason. |
8799
8800**Error codes**
8801
8802For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
8803
8804| ID      | Error Message                   |
8805| ------- | ------------------------------- |
8806| 6800101 | if input parameter value error. |
8807
8808**Example**
8809
8810```ts
8811audioRenderer.on('outputDeviceChangeWithInfo', (deviceChangeInfo: audio.AudioStreamDeviceChangeInfo) => {
8812  console.info(`DeviceInfo id: ${deviceChangeInfo.devices[0].id}`);
8813  console.info(`DeviceInfo name: ${deviceChangeInfo.devices[0].name}`);
8814  console.info(`DeviceInfo address: ${deviceChangeInfo.devices[0].address}`);
8815  console.info(`Device change reason: ${deviceChangeInfo.changeReason}`);
8816});
8817
8818```
8819
8820### off('outputDeviceChangeWithInfo') <sup>11+</sup>
8821
8822off(type: 'outputDeviceChangeWithInfo', callback?: Callback\<AudioStreamDeviceChangeInfo>): void
8823
8824Unsubscribes from audio stream output device changes and reasons. This API uses an asynchronous callback to return the result.
8825
8826**System capability**: SystemCapability.Multimedia.Audio.Device
8827
8828**Parameters**
8829
8830| Name     | Type                                                         | Mandatory | Description                                                  |
8831| :------- | :----------------------------------------------------------- | :-------- | :----------------------------------------------------------- |
8832| type     | string                                                       | Yes       | Event type. The event **'outputDeviceChangeWithInfo'** is triggered when the output device is changed. |
8833| callback | Callback\<[AudioStreamDeviceChangeInfo](#audiostreamdevicechangeinfo11)> | No        | Callback used to return the output device descriptor of the current audio stream and the change reason. |
8834
8835**Error codes**
8836
8837For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
8838
8839| ID      | Error Message                   |
8840| ------- | ------------------------------- |
8841| 6800101 | if input parameter value error. |
8842
8843**Example**
8844
8845```ts
8846audioRenderer.off('outputDeviceChangeWithInfo', (deviceChangeInfo: audio.AudioStreamDeviceChangeInfo) => {
8847  console.info(`DeviceInfo id: ${deviceChangeInfo.devices[0].id}`);
8848  console.info(`DeviceInfo name: ${deviceChangeInfo.devices[0].name}`);
8849  console.info(`DeviceInfo address: ${deviceChangeInfo.devices[0].address}`);
8850  console.info(`Device change reason: ${deviceChangeInfo.changeReason}`);
8851});
8852
8853```
8854
8855## AudioCapturer<sup>8+</sup>
8856
8857Provides APIs for audio capture. Before calling any API in **AudioCapturer**, you must use [createAudioCapturer](#audiocreateaudiocapturer8) to create an **AudioCapturer** instance.
8858
8859### Attributes
8860
8861**System capability**: SystemCapability.Multimedia.Audio.Capturer
8862
8863| Name               | Type                       | Readable | Writable | Description           |
8864| :----------------- | :------------------------- | :------- | :------- | :-------------------- |
8865| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes      | No       | Audio capturer state. |
8866
8867**Example**
8868
8869```ts
8870import audio from '@ohos.multimedia.audio';
8871
8872let state: audio.AudioState = audioCapturer.state;
8873
8874```
8875
8876### getCapturerInfo<sup>8+</sup>
8877
8878getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void
8879
8880Obtains the capturer information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
8881
8882**System capability**: SystemCapability.Multimedia.Audio.Capturer
8883
8884**Parameters**
8885
8886| Name     | Type                                                    | Mandatory | Description                                                  |
8887| :------- | :------------------------------------------------------ | :-------- | :----------------------------------------------------------- |
8888| callback | AsyncCallback<[AudioCapturerInfo](#audiocapturerinfo)\> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the capturer information obtained; otherwise, **err** is an error object. |
8889
8890**Example**
8891
8892```ts
8893import { BusinessError } from '@ohos.base';
8894
8895audioCapturer.getCapturerInfo((err: BusinessError, capturerInfo: audio.AudioCapturerInfo) => {
8896  if (err) {
8897    console.error('Failed to get capture info');
8898  } else {
8899    console.info('Capturer getCapturerInfo:');
8900    console.info(`Capturer source: ${capturerInfo.source}`);
8901    console.info(`Capturer flags: ${capturerInfo.capturerFlags}`);
8902  }
8903});
8904
8905```
8906
8907
8908### getCapturerInfo<sup>8+</sup>
8909
8910getCapturerInfo(): Promise<AudioCapturerInfo\>
8911
8912Obtains the capturer information of this **AudioCapturer** instance. This API uses a promise to return the result.
8913
8914**System capability**: SystemCapability.Multimedia.Audio.Capturer
8915
8916**Return value**
8917
8918| Type                                              | Description                                  |
8919| :------------------------------------------------ | :------------------------------------------- |
8920| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return capturer information. |
8921
8922**Example**
8923
8924```ts
8925import { BusinessError } from '@ohos.base';
8926
8927audioCapturer.getCapturerInfo().then((audioParamsGet: audio.AudioCapturerInfo) => {
8928  if (audioParamsGet != undefined) {
8929    console.info('AudioFrameworkRecLog: Capturer CapturerInfo:');
8930    console.info(`AudioFrameworkRecLog: Capturer SourceType: ${audioParamsGet.source}`);
8931    console.info(`AudioFrameworkRecLog: Capturer capturerFlags: ${audioParamsGet.capturerFlags}`);
8932  } else {
8933    console.info(`AudioFrameworkRecLog: audioParamsGet is : ${audioParamsGet}`);
8934    console.info('AudioFrameworkRecLog: audioParams getCapturerInfo are incorrect');
8935  }
8936}).catch((err: BusinessError) => {
8937  console.error(`AudioFrameworkRecLog: CapturerInfo :ERROR: ${err}`);
8938})
8939
8940```
8941
8942### getCapturerInfoSync<sup>10+</sup>
8943
8944getCapturerInfoSync(): AudioCapturerInfo
8945
8946Obtains the capturer information of this **AudioCapturer** instance. This API returns the result synchronously.
8947
8948**System capability**: SystemCapability.Multimedia.Audio.Capturer
8949
8950**Return value**
8951
8952| Type                                    | Description           |
8953| :-------------------------------------- | :-------------------- |
8954| [AudioCapturerInfo](#audiocapturerinfo) | Capturer information. |
8955
8956**Example**
8957
8958```ts
8959import { BusinessError } from '@ohos.base';
8960
8961try {
8962  let audioParamsGet: audio.AudioCapturerInfo = audioCapturer.getCapturerInfoSync();
8963  console.info(`AudioFrameworkRecLog: Capturer SourceType: ${audioParamsGet.source}`);
8964  console.info(`AudioFrameworkRecLog: Capturer capturerFlags: ${audioParamsGet.capturerFlags}`);
8965} catch (err) {
8966  let error = err as BusinessError;
8967  console.error(`AudioFrameworkRecLog: CapturerInfo :ERROR: ${error}`);
8968}
8969
8970```
8971
8972### getStreamInfo<sup>8+</sup>
8973
8974getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
8975
8976Obtains the stream information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
8977
8978**System capability**: SystemCapability.Multimedia.Audio.Capturer
8979
8980**Parameters**
8981
8982| Name     | Type                                                 | Mandatory | Description                                                  |
8983| :------- | :--------------------------------------------------- | :-------- | :----------------------------------------------------------- |
8984| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the stream information obtained; otherwise, **err** is an error object. |
8985
8986**Example**
8987
8988```ts
8989import { BusinessError } from '@ohos.base';
8990
8991audioCapturer.getStreamInfo((err: BusinessError, streamInfo: audio.AudioStreamInfo) => {
8992  if (err) {
8993    console.error('Failed to get stream info');
8994  } else {
8995    console.info('Capturer GetStreamInfo:');
8996    console.info(`Capturer sampling rate: ${streamInfo.samplingRate}`);
8997    console.info(`Capturer channel: ${streamInfo.channels}`);
8998    console.info(`Capturer format: ${streamInfo.sampleFormat}`);
8999    console.info(`Capturer encoding type: ${streamInfo.encodingType}`);
9000  }
9001});
9002
9003```
9004
9005### getStreamInfo<sup>8+</sup>
9006
9007getStreamInfo(): Promise<AudioStreamInfo\>
9008
9009Obtains the stream information of this **AudioCapturer** instance. This API uses a promise to return the result.
9010
9011**System capability**: SystemCapability.Multimedia.Audio.Capturer
9012
9013**Return value**
9014
9015| Type                                           | Description                                    |
9016| :--------------------------------------------- | :--------------------------------------------- |
9017| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
9018
9019**Example**
9020
9021```ts
9022import { BusinessError } from '@ohos.base';
9023
9024audioCapturer.getStreamInfo().then((audioParamsGet: audio.AudioStreamInfo) => {
9025  console.info('getStreamInfo:');
9026  console.info(`sampleFormat: ${audioParamsGet.sampleFormat}`);
9027  console.info(`samplingRate: ${audioParamsGet.samplingRate}`);
9028  console.info(`channels: ${audioParamsGet.channels}`);
9029  console.info(`encodingType: ${audioParamsGet.encodingType}`);
9030}).catch((err: BusinessError) => {
9031  console.error(`getStreamInfo :ERROR: ${err}`);
9032});
9033
9034```
9035
9036### getStreamInfoSync<sup>10+</sup>
9037
9038getStreamInfoSync(): AudioStreamInfo
9039
9040Obtains the stream information of this **AudioCapturer** instance. This API returns the result synchronously.
9041
9042**System capability**: SystemCapability.Multimedia.Audio.Capturer
9043
9044**Return value**
9045
9046| Type                                 | Description         |
9047| :----------------------------------- | :------------------ |
9048| [AudioStreamInfo](#audiostreaminfo8) | Stream information. |
9049
9050**Example**
9051
9052```ts
9053import { BusinessError } from '@ohos.base';
9054
9055try {
9056  let audioParamsGet: audio.AudioStreamInfo = audioCapturer.getStreamInfoSync();
9057  console.info(`sampleFormat: ${audioParamsGet.sampleFormat}`);
9058  console.info(`samplingRate: ${audioParamsGet.samplingRate}`);
9059  console.info(`channels: ${audioParamsGet.channels}`);
9060  console.info(`encodingType: ${audioParamsGet.encodingType}`);
9061} catch (err) {
9062  let error = err as BusinessError;
9063  console.error(`getStreamInfo :ERROR: ${error}`);
9064}
9065
9066```
9067
9068### getAudioStreamId<sup>9+</sup>
9069
9070getAudioStreamId(callback: AsyncCallback<number\>): void
9071
9072Obtains the stream ID of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
9073
9074**System capability**: SystemCapability.Multimedia.Audio.Capturer
9075
9076**Parameters**
9077
9078| Name     | Type                   | Mandatory | Description                                                  |
9079| :------- | :--------------------- | :-------- | :----------------------------------------------------------- |
9080| callback | AsyncCallback<number\> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the stream ID obtained; otherwise, **err** is an error object. |
9081
9082**Example**
9083
9084```ts
9085import { BusinessError } from '@ohos.base';
9086
9087audioCapturer.getAudioStreamId((err: BusinessError, streamId: number) => {
9088  console.info(`audioCapturer GetStreamId: ${streamId}`);
9089});
9090
9091```
9092
9093### getAudioStreamId<sup>9+</sup>
9094
9095getAudioStreamId(): Promise<number\>
9096
9097Obtains the stream ID of this **AudioCapturer** instance. This API uses a promise to return the result.
9098
9099**System capability**: SystemCapability.Multimedia.Audio.Capturer
9100
9101**Return value**
9102
9103| Type             | Description                           |
9104| :--------------- | :------------------------------------ |
9105| Promise<number\> | Promise used to return the stream ID. |
9106
9107**Example**
9108
9109```ts
9110import { BusinessError } from '@ohos.base';
9111
9112audioCapturer.getAudioStreamId().then((streamId: number) => {
9113  console.info(`audioCapturer getAudioStreamId: ${streamId}`);
9114}).catch((err: BusinessError) => {
9115  console.error(`ERROR: ${err}`);
9116});
9117
9118```
9119
9120### getAudioStreamIdSync<sup>10+</sup>
9121
9122getAudioStreamIdSync(): number
9123
9124Obtains the stream ID of this **AudioCapturer** instance. This API returns the result synchronously.
9125
9126**System capability**: SystemCapability.Multimedia.Audio.Capturer
9127
9128**Return value**
9129
9130| Type   | Description |
9131| :----- | :---------- |
9132| number | Stream ID.  |
9133
9134**Example**
9135
9136```ts
9137import { BusinessError } from '@ohos.base';
9138
9139try {
9140  let streamId: number = audioCapturer.getAudioStreamIdSync();
9141  console.info(`audioCapturer getAudioStreamIdSync: ${streamId}`);
9142} catch (err) {
9143  let error = err as BusinessError;
9144  console.error(`ERROR: ${error}`);
9145}
9146
9147```
9148
9149### start<sup>8+</sup>
9150
9151start(callback: AsyncCallback<void\>): void
9152
9153Starts capturing. This API uses an asynchronous callback to return the result.
9154
9155**System capability**: SystemCapability.Multimedia.Audio.Capturer
9156
9157**Parameters**
9158
9159| Name     | Type                 | Mandatory | Description                                                  |
9160| :------- | :------------------- | :-------- | :----------------------------------------------------------- |
9161| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
9162
9163**Example**
9164
9165```ts
9166import { BusinessError } from '@ohos.base';
9167
9168audioCapturer.start((err: BusinessError) => {
9169  if (err) {
9170    console.error('Capturer start failed.');
9171  } else {
9172    console.info('Capturer start success.');
9173  }
9174});
9175
9176```
9177
9178
9179### start<sup>8+</sup>
9180
9181start(): Promise<void\>
9182
9183Starts capturing. This API uses a promise to return the result.
9184
9185**System capability**: SystemCapability.Multimedia.Audio.Capturer
9186
9187**Return value**
9188
9189| Type           | Description                    |
9190| :------------- | :----------------------------- |
9191| Promise<void\> | Promise that returns no value. |
9192
9193**Example**
9194
9195```ts
9196import { BusinessError } from '@ohos.base';
9197
9198audioCapturer.start().then(() => {
9199  console.info('AudioFrameworkRecLog: ---------START---------');
9200  console.info('AudioFrameworkRecLog: Capturer started: SUCCESS');
9201  console.info(`AudioFrameworkRecLog: AudioCapturer: STATE: ${audioCapturer.state}`);
9202  console.info('AudioFrameworkRecLog: Capturer started: SUCCESS');
9203  if ((audioCapturer.state == audio.AudioState.STATE_RUNNING)) {
9204    console.info('AudioFrameworkRecLog: AudioCapturer is in Running State');
9205  }
9206}).catch((err: BusinessError) => {
9207  console.error(`AudioFrameworkRecLog: Capturer start :ERROR : ${err}`);
9208});
9209
9210```
9211
9212### stop<sup>8+</sup>
9213
9214stop(callback: AsyncCallback<void\>): void
9215
9216Stops capturing. This API uses an asynchronous callback to return the result.
9217
9218**System capability**: SystemCapability.Multimedia.Audio.Capturer
9219
9220**Parameters**
9221
9222| Name     | Type                 | Mandatory | Description                                                  |
9223| :------- | :------------------- | :-------- | :----------------------------------------------------------- |
9224| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. If the vibration stops, **err** is **undefined**; otherwise, **err** is an error object. |
9225
9226**Example**
9227
9228```ts
9229import { BusinessError } from '@ohos.base';
9230
9231audioCapturer.stop((err: BusinessError) => {
9232  if (err) {
9233    console.error('Capturer stop failed');
9234  } else {
9235    console.info('Capturer stopped.');
9236  }
9237});
9238
9239```
9240
9241
9242### stop<sup>8+</sup>
9243
9244stop(): Promise<void\>
9245
9246Stops capturing. This API uses a promise to return the result.
9247
9248**System capability**: SystemCapability.Multimedia.Audio.Capturer
9249
9250**Return value**
9251
9252| Type           | Description                    |
9253| :------------- | :----------------------------- |
9254| Promise<void\> | Promise that returns no value. |
9255
9256**Example**
9257
9258```ts
9259import { BusinessError } from '@ohos.base';
9260
9261audioCapturer.stop().then(() => {
9262  console.info('AudioFrameworkRecLog: ---------STOP RECORD---------');
9263  console.info('AudioFrameworkRecLog: Capturer stopped: SUCCESS');
9264  if ((audioCapturer.state == audio.AudioState.STATE_STOPPED)){
9265    console.info('AudioFrameworkRecLog: State is Stopped:');
9266  }
9267}).catch((err: BusinessError) => {
9268  console.error(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
9269});
9270
9271```
9272
9273### release<sup>8+</sup>
9274
9275release(callback: AsyncCallback<void\>): void
9276
9277Releases this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
9278
9279**System capability**: SystemCapability.Multimedia.Audio.Capturer
9280
9281**Parameters**
9282
9283| Name     | Type                 | Mandatory | Description                                                  |
9284| :------- | :------------------- | :-------- | :----------------------------------------------------------- |
9285| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
9286
9287**Example**
9288
9289```ts
9290import { BusinessError } from '@ohos.base';
9291
9292audioCapturer.release((err: BusinessError) => {
9293  if (err) {
9294    console.error('capturer release failed');
9295  } else {
9296    console.info('capturer released.');
9297  }
9298});
9299
9300```
9301
9302
9303### release<sup>8+</sup>
9304
9305release(): Promise<void\>
9306
9307Releases this **AudioCapturer** instance. This API uses a promise to return the result.
9308
9309**System capability**: SystemCapability.Multimedia.Audio.Capturer
9310
9311**Return value**
9312
9313| Type           | Description                    |
9314| :------------- | :----------------------------- |
9315| Promise<void\> | Promise that returns no value. |
9316
9317**Example**
9318
9319```ts
9320import { BusinessError } from '@ohos.base';
9321
9322audioCapturer.release().then(() => {
9323  console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
9324  console.info('AudioFrameworkRecLog: Capturer release : SUCCESS');
9325  console.info(`AudioFrameworkRecLog: AudioCapturer : STATE : ${audioCapturer.state}`);
9326}).catch((err: BusinessError) => {
9327  console.error(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
9328});
9329
9330```
9331
9332### read<sup>8+</sup>
9333
9334read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void
9335
9336Reads the buffer. This API uses an asynchronous callback to return the result.
9337
9338**System capability**: SystemCapability.Multimedia.Audio.Capturer
9339
9340**Parameters**
9341
9342| Name           | Type                        | Mandatory | Description                                                  |
9343| :------------- | :-------------------------- | :-------- | :----------------------------------------------------------- |
9344| size           | number                      | Yes       | Number of bytes to read.                                     |
9345| isBlockingRead | boolean                     | Yes       | Whether to block the read operation. The value **true** means to block the read operation, and **false** means the opposite. |
9346| callback       | AsyncCallback<ArrayBuffer\> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the buffer read; otherwise, **err** is an error object. |
9347
9348**Example**
9349
9350```ts
9351import { BusinessError } from '@ohos.base';
9352
9353let bufferSize: number = 0;
9354audioCapturer.getBufferSize().then((data: number) => {
9355  console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ${data}`);
9356  bufferSize = data;
9357}).catch((err: BusinessError) => {
9358  console.error(`AudioFrameworkRecLog: getBufferSize: ERROR: ${err}`);
9359});
9360audioCapturer.read(bufferSize, true, (err: BusinessError, buffer: ArrayBuffer) => {
9361  if (!err) {
9362    console.info('Success in reading the buffer data');
9363  }
9364});
9365
9366```
9367
9368### read<sup>8+</sup>
9369
9370read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
9371
9372Reads the buffer. This API uses a promise to return the result.
9373
9374**System capability**: SystemCapability.Multimedia.Audio.Capturer
9375
9376**Parameters**
9377
9378| Name           | Type    | Mandatory | Description                                                  |
9379| :------------- | :------ | :-------- | :----------------------------------------------------------- |
9380| size           | number  | Yes       | Number of bytes to read.                                     |
9381| isBlockingRead | boolean | Yes       | Whether to block the read operation. The value **true** means to block the read operation, and **false** means the opposite. |
9382
9383**Return value**
9384
9385| Type                  | Description                                           |
9386| :-------------------- | :---------------------------------------------------- |
9387| Promise<ArrayBuffer\> | Promise used to return the data read from the buffer. |
9388
9389**Example**
9390
9391```ts
9392import { BusinessError } from '@ohos.base';
9393
9394let bufferSize: number = 0;
9395audioCapturer.getBufferSize().then((data: number) => {
9396  console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ${data}`);
9397  bufferSize = data;
9398}).catch((err: BusinessError) => {
9399  console.error(`AudioFrameworkRecLog: getBufferSize: ERROR ${err}`);
9400});
9401console.info(`Buffer size: ${bufferSize}`);
9402audioCapturer.read(bufferSize, true).then((buffer: ArrayBuffer) => {
9403  console.info('buffer read successfully');
9404}).catch((err: BusinessError) => {
9405  console.error(`ERROR : ${err}`);
9406});
9407
9408```
9409
9410### getAudioTime<sup>8+</sup>
9411
9412getAudioTime(callback: AsyncCallback<number\>): void
9413
9414Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result.
9415
9416**System capability**: SystemCapability.Multimedia.Audio.Capturer
9417
9418**Parameters**
9419
9420| Name     | Type                   | Mandatory | Description                                                  |
9421| :------- | :--------------------- | :-------- | :----------------------------------------------------------- |
9422| callback | AsyncCallback<number\> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the number of nanoseconds obtained; otherwise, **err** is an error object. |
9423
9424**Example**
9425
9426```ts
9427import { BusinessError } from '@ohos.base';
9428
9429audioCapturer.getAudioTime((err: BusinessError, timestamp: number) => {
9430  console.info(`Current timestamp: ${timestamp}`);
9431});
9432
9433```
9434
9435### getAudioTime<sup>8+</sup>
9436
9437getAudioTime(): Promise<number\>
9438
9439Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
9440
9441**System capability**: SystemCapability.Multimedia.Audio.Capturer
9442
9443**Return value**
9444
9445| Type             | Description                                                  |
9446| :--------------- | :----------------------------------------------------------- |
9447| Promise<number\> | Promise used to return the number of nanoseconds elapsed from the Unix epoch. |
9448
9449**Example**
9450
9451```ts
9452import { BusinessError } from '@ohos.base';
9453
9454audioCapturer.getAudioTime().then((audioTime: number) => {
9455  console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTime : Success ${audioTime}`);
9456}).catch((err: BusinessError) => {
9457  console.error(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
9458});
9459
9460```
9461
9462### getAudioTimeSync<sup>10+</sup>
9463
9464getAudioTimeSync(): number
9465
9466Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API returns the result synchronously.
9467
9468**System capability**: SystemCapability.Multimedia.Audio.Capturer
9469
9470**Return value**
9471
9472| Type   | Description |
9473| :----- | :---------- |
9474| number | Timestamp.  |
9475
9476**Example**
9477
9478```ts
9479import { BusinessError } from '@ohos.base';
9480
9481try {
9482  let audioTime: number = audioCapturer.getAudioTimeSync();
9483  console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTimeSync : Success ${audioTime}`);
9484} catch (err) {
9485  let error = err as BusinessError;
9486  console.error(`AudioFrameworkRecLog: AudioCapturer getAudioTimeSync : ERROR : ${error}`);
9487}
9488
9489```
9490
9491### getBufferSize<sup>8+</sup>
9492
9493getBufferSize(callback: AsyncCallback<number\>): void
9494
9495Obtains a reasonable minimum buffer size in bytes for capturing. This API uses an asynchronous callback to return the result.
9496
9497**System capability**: SystemCapability.Multimedia.Audio.Capturer
9498
9499**Parameters**
9500
9501| Name     | Type                   | Mandatory | Description                                                  |
9502| :------- | :--------------------- | :-------- | :----------------------------------------------------------- |
9503| callback | AsyncCallback<number\> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the minimum buffer size obtained; otherwise, **err** is an error object. |
9504
9505**Example**
9506
9507```ts
9508import { BusinessError } from '@ohos.base';
9509
9510audioCapturer.getBufferSize((err: BusinessError, bufferSize: number) => {
9511  if (!err) {
9512    console.info(`BufferSize : ${bufferSize}`);
9513    audioCapturer.read(bufferSize, true).then((buffer: ArrayBuffer) => {
9514      console.info(`Buffer read is ${buffer.byteLength}`);
9515    }).catch((err: BusinessError) => {
9516      console.error(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
9517    });
9518  }
9519});
9520
9521```
9522
9523### getBufferSize<sup>8+</sup>
9524
9525getBufferSize(): Promise<number\>
9526
9527Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a promise to return the result.
9528
9529**System capability**: SystemCapability.Multimedia.Audio.Capturer
9530
9531**Return value**
9532
9533| Type             | Description                             |
9534| :--------------- | :-------------------------------------- |
9535| Promise<number\> | Promise used to return the buffer size. |
9536
9537**Example**
9538
9539```ts
9540import { BusinessError } from '@ohos.base';
9541
9542let bufferSize: number = 0;
9543audioCapturer.getBufferSize().then((data: number) => {
9544  console.info(`AudioFrameworkRecLog: getBufferSize :SUCCESS ${data}`);
9545  bufferSize = data;
9546}).catch((err: BusinessError) => {
9547  console.error(`AudioFrameworkRecLog: getBufferSize :ERROR : ${err}`);
9548});
9549
9550```
9551
9552### getBufferSizeSync<sup>10+</sup>
9553
9554getBufferSizeSync(): number
9555
9556Obtains a reasonable minimum buffer size in bytes for capturing. This API returns the result synchronously.
9557
9558**System capability**: SystemCapability.Multimedia.Audio.Capturer
9559
9560**Return value**
9561
9562| Type   | Description  |
9563| :----- | :----------- |
9564| number | Buffer size. |
9565
9566**Example**
9567
9568```ts
9569import { BusinessError } from '@ohos.base';
9570
9571let bufferSize: number = 0;
9572try {
9573  bufferSize = audioCapturer.getBufferSizeSync();
9574  console.info(`AudioFrameworkRecLog: getBufferSizeSync :SUCCESS ${bufferSize}`);
9575} catch (err) {
9576  let error = err as BusinessError;
9577  console.error(`AudioFrameworkRecLog: getBufferSizeSync :ERROR : ${error}`);
9578}
9579
9580```
9581
9582### getCurrentInputDevices<sup>11+</sup>
9583
9584getCurrentInputDevices(): AudioDeviceDescriptors
9585
9586Obtains the descriptors of the current input devices. This API returns the result synchronously.
9587
9588**System capability**: SystemCapability.Multimedia.Audio.Device
9589
9590**Return value**
9591
9592| Type                                              | Description                               |
9593| ------------------------------------------------- | ----------------------------------------- |
9594| [AudioDeviceDescriptors](#audiodevicedescriptors) | An array of the audio device descriptors. |
9595
9596**Example**
9597
9598```ts
9599let deviceDescriptors: audio.AudioDeviceDescriptors = audioCapturer.getCurrentInputDevices();
9600console.info(`Device id: ${deviceDescriptors[0].id}`);
9601console.info(`Device type: ${deviceDescriptors[0].deviceType}`);
9602console.info(`Device role: ${deviceDescriptors[0].deviceRole}`);
9603console.info(`Device name: ${deviceDescriptors[0].name}`);
9604console.info(`Device address: ${deviceDescriptors[0].address}`);
9605console.info(`Device samplerates: ${deviceDescriptors[0].sampleRates[0]}`);
9606console.info(`Device channelcounts: ${deviceDescriptors[0].channelCounts[0]}`);
9607console.info(`Device channelmask: ${deviceDescriptors[0].channelMasks[0]}`);
9608if (deviceDescriptors[0].encodingTypes) {
9609  console.info(`Device encodingTypes: ${deviceDescriptors[0].encodingTypes[0]}`);
9610}
9611
9612```
9613
9614### getCurrentAudioCapturerChangeInfo<sup>11+</sup>
9615
9616getCurrentAudioCapturerChangeInfo(): AudioCapturerChangeInfo
9617
9618Obtains the configuration changes of the current audio capturer. This API returns the result synchronously.
9619
9620**System capability**: SystemCapability.Multimedia.Audio.Device
9621
9622**Return value**
9623
9624| Type                                                 | Description                                  |
9625| :--------------------------------------------------- | :------------------------------------------- |
9626| [AudioCapturerChangeInfo](#audiocapturerchangeinfo9) | Configuration changes of the audio capturer. |
9627
9628**Example**
9629
9630```ts
9631let info: audio.AudioCapturerChangeInfo = audioCapturer.getCurrentAudioCapturerChangeInfo();
9632console.info(`Info streamId: ${info.streamId}`);
9633console.info(`Info source: ${info.capturerInfo.source}`);
9634console.info(`Info capturerFlags: ${info.capturerInfo.capturerFlags}`);
9635console.info(`Info muted: ${info.muted}`);
9636console.info(`Info type: ${info.deviceDescriptors[0].deviceType}`);
9637console.info(`Info role: ${info.deviceDescriptors[0].deviceRole}`);
9638console.info(`Info name: ${info.deviceDescriptors[0].name}`);
9639console.info(`Info address: ${info.deviceDescriptors[0].address}`);
9640console.info(`Info samplerates: ${info.deviceDescriptors[0].sampleRates[0]}`);
9641console.info(`Info channelcounts: ${info.deviceDescriptors[0].channelCounts[0]}`);
9642console.info(`Info channelmask: ${info.deviceDescriptors[0].channelMasks[0]}`);
9643if (deviceDescriptors[0].encodingTypes) {
9644  console.info(`Device encodingTypes: ${deviceDescriptors[0].encodingTypes[0]}`);
9645}
9646
9647```
9648
9649### on('audioInterrupt')<sup>10+</sup>
9650
9651on(type: 'audioInterrupt', callback: Callback\<InterruptEvent>): void
9652
9653Subscribes to audio interruption events. This API uses an asynchronous callback to return the result.
9654
9655Same as [on('interrupt')](#oninterrupt), this API is used to listen for focus changes. The **AudioCapturer** instance proactively gains the focus when the **start** event occurs and releases the focus when the **pause** or **stop** event occurs. Therefore, you do not need to request to gain or release the focus.
9656
9657**System capability**: SystemCapability.Multimedia.Audio.Interrupt
9658
9659**Parameters**
9660
9661| Name     | Type                                           | Mandatory | Description                                                  |
9662| -------- | ---------------------------------------------- | --------- | ------------------------------------------------------------ |
9663| type     | string                                         | Yes       | Event type. The event **'audioInterrupt'** is triggered when audio capture is interrupted. |
9664| callback | Callback\<[InterruptEvent](#interruptevent9)\> | Yes       | Callback used to return the audio interruption event received by the application when playback is interrupted. |
9665
9666**Error codes**
9667
9668For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
9669
9670| ID      | Error Message            |
9671| ------- | ------------------------ |
9672| 6800101 | Invalid parameter error. |
9673
9674**Example**
9675
9676```ts
9677import audio from '@ohos.multimedia.audio';
9678
9679let isCapturing: boolean; // An identifier specifying whether capturing is in progress.
9680onAudioInterrupt();
9681
9682async function onAudioInterrupt(){
9683  audioCapturer.on('audioInterrupt', (interruptEvent: audio.InterruptEvent) => {
9684    if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
9685      // The system forcibly interrupts audio capture. The application must update the status and displayed content accordingly.
9686      switch (interruptEvent.hintType) {
9687        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
9688          // The audio stream has been paused and temporarily loses the focus. It will receive the interruptEvent corresponding to resume when it is able to regain the focus.
9689          console.info('Force paused. Update capturing status and stop reading');
9690          isCapturing = false; // A simplified processing indicating several operations for switching the application to the paused state.
9691          break;
9692        case audio.InterruptHint.INTERRUPT_HINT_STOP:
9693          // The audio stream has been stopped and permanently loses the focus. The user must manually trigger the operation to resume capturing.
9694          console.info('Force stopped. Update capturing status and stop reading');
9695          isCapturing = false; // A simplified processing indicating several operations for switching the application to the paused state.
9696          break;
9697        default:
9698          console.info('Invalid interruptEvent');
9699          break;
9700      }
9701    } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
9702      // The application can choose to take action or ignore.
9703      switch (interruptEvent.hintType) {
9704        case audio.InterruptHint.INTERRUPT_HINT_RESUME:
9705          // It is recommended that the application continue capturing. (The audio stream has been forcibly paused and temporarily lost the focus. It can resume capturing now.)
9706          console.info('Resume force paused renderer or ignore');
9707          // To continue capturing, the application must perform the required operations.
9708          break;
9709        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
9710          // It is recommended that the application pause capturing.
9711          console.info('Choose to pause or ignore');
9712          // To pause capturing, the application must perform the required operations.
9713          break;
9714        case audio.InterruptHint.INTERRUPT_HINT_STOP:
9715          // It is recommended that the application stop capturing.
9716          console.info('Choose to stop or ignore');
9717          // To stop capturing, the application must perform the required operations.
9718          break;
9719        default:
9720          break;
9721      }
9722    }
9723  });
9724}
9725
9726```
9727
9728### off('audioInterrupt')<sup>10+</sup>
9729
9730off(type: 'audioInterrupt'): void
9731
9732Unsubscribes from audio interruption events.
9733
9734**System capability**: SystemCapability.Multimedia.Audio.Interrupt
9735
9736**Parameters**
9737
9738| Name | Type   | Mandatory | Description                                                  |
9739| ---- | ------ | --------- | ------------------------------------------------------------ |
9740| type | string | Yes       | Event type. The event **'audioInterrupt'** is triggered when audio capture is interrupted. |
9741
9742**Error codes**
9743
9744For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
9745
9746| ID      | Error Message            |
9747| ------- | ------------------------ |
9748| 6800101 | Invalid parameter error. |
9749
9750**Example**
9751
9752```ts
9753audioCapturer.off('audioInterrupt');
9754
9755```
9756
9757### on('inputDeviceChange')<sup>11+</sup>
9758
9759on(type: 'inputDeviceChange', callback: Callback\<AudioDeviceDescriptors>): void
9760
9761Subscribes to audio input device change events. This API uses an asynchronous callback to return the result.
9762
9763**System capability**: SystemCapability.Multimedia.Audio.Device
9764
9765**Parameters**
9766
9767| Name     | Type                                                         | Mandatory | Description                                                  |
9768| :------- | :----------------------------------------------------------- | :-------- | :----------------------------------------------------------- |
9769| type     | string                                                       | Yes       | Event type. The event **'inputDeviceChange'** is triggered when the audio input device is changed. |
9770| callback | Callback\<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Yes       | Callback used to return the information about the new audio input device. |
9771
9772**Error codes**
9773
9774For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
9775
9776| ID      | Error Message                |
9777| ------- | ---------------------------- |
9778| 6800101 | Input parameter value error. |
9779
9780**Example**
9781
9782```ts
9783audioCapturer.on('inputDeviceChange', (deviceChangeInfo: audio.AudioDeviceDescriptors) => {
9784  console.info(`inputDevice id: ${deviceChangeInfo[0].id}`);
9785  console.info(`inputDevice deviceRole: ${deviceChangeInfo[0].deviceRole}`);
9786  console.info(`inputDevice deviceType: ${deviceChangeInfo[0].deviceType}`);
9787});
9788
9789```
9790
9791### off('inputDeviceChange')<sup>11+</sup>
9792
9793off(type: 'inputDeviceChange', callback?: Callback\<AudioDeviceDescriptors>): void
9794
9795Unsubscribes from audio input device change events. This API uses an asynchronous callback to return the result.
9796
9797**System capability**: SystemCapability.Multimedia.Audio.Device
9798
9799**Parameters**
9800
9801| Name     | Type                                                         | Mandatory | Description                                                  |
9802| :------- | :----------------------------------------------------------- | :-------- | :----------------------------------------------------------- |
9803| type     | string                                                       | Yes       | Event type. The event **'inputDeviceChange'** is triggered when the audio input device is changed. |
9804| callback | Callback\<[AudioDeviceDescriptors](#audiodevicedescriptors)> | No        | Callback used to return the information about the audio input device. |
9805
9806**Error codes**
9807
9808For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
9809
9810| ID      | Error Message                |
9811| ------- | ---------------------------- |
9812| 6800101 | Input parameter value error. |
9813
9814**Example**
9815
9816```ts
9817audioCapturer.off('inputDeviceChange');
9818
9819```
9820
9821### on('audioCapturerChange')<sup>11+</sup>
9822
9823on(type: 'audioCapturerChange', callback: Callback\<AudioCapturerChangeInfo>): void
9824
9825Subscribes to audio capturer change events. This API uses an asynchronous callback to return the result.
9826
9827**System capability**: SystemCapability.Multimedia.Audio.Capturer
9828
9829**Parameters**
9830
9831| Name     | Type                                                         | Mandatory | Description                                                  |
9832| :------- | :----------------------------------------------------------- | :-------- | :----------------------------------------------------------- |
9833| type     | string                                                       | Yes       | Event type. The event **'audioCapturerChange'** is triggered when the audio capturer is changed. |
9834| callback | Callback\<[AudioCapturerChangeInfo](#audiocapturerchangeinfo9)> | Yes       | Callback used to return the audio capturer changes.          |
9835
9836**Error codes**
9837
9838For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
9839
9840| ID      | Error Message                |
9841| ------- | ---------------------------- |
9842| 6800101 | Input parameter value error. |
9843
9844**Example**
9845
9846```ts
9847audioCapturer.on('audioCapturerChange', (capturerChangeInfo: audio.AudioCapturerChangeInfo) => {
9848  console.info(`audioCapturerChange id: ${capturerChangeInfo[0].id}`);
9849  console.info(`audioCapturerChange deviceRole: ${capturerChangeInfo[0].deviceRole}`);
9850  console.info(`audioCapturerChange deviceType: ${capturerChangeInfo[0].deviceType}`);
9851});
9852
9853```
9854
9855### off('audioCapturerChange')<sup>11+</sup>
9856
9857off(type: 'audioCapturerChange', callback?: Callback\<AudioCapturerChangeInfo>): void
9858
9859Unsubscribes from audio capturer change events. This API uses an asynchronous callback to return the result.
9860
9861**System capability**: SystemCapability.Multimedia.Audio.Capturer
9862
9863**Parameters**
9864
9865| Name     | Type                                                         | Mandatory | Description                                                  |
9866| :------- | :----------------------------------------------------------- | :-------- | :----------------------------------------------------------- |
9867| type     | string                                                       | Yes       | Event type. The event **'audioCapturerChange'** is triggered when the audio capturer is changed. |
9868| callback | Callback\<[AudioCapturerChangeInfo](#audiocapturerchangeinfo9)> | No        | Callback used to return the audio capturer changes.          |
9869
9870**Error codes**
9871
9872For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
9873
9874| ID      | Error Message                |
9875| ------- | ---------------------------- |
9876| 6800101 | Input parameter value error. |
9877
9878**Example**
9879
9880```ts
9881audioCapturer.off('audioCapturerChange');
9882
9883```
9884
9885### on('markReach')<sup>8+</sup>
9886
9887on(type: 'markReach', frame: number, callback: Callback&lt;number&gt;): void
9888
9889Subscribes to mark reached events. When the number of frames captured reaches the value of the **frame** parameter, a callback is invoked. This API uses an asynchronous callback to return the result.
9890
9891**System capability**: SystemCapability.Multimedia.Audio.Capturer
9892
9893**Parameters**
9894
9895| Name     | Type              | Mandatory | Description                                                  |
9896| :------- | :---------------- | :-------- | :----------------------------------------------------------- |
9897| type     | string            | Yes       | Event type. The value is fixed at **'markReach'**.           |
9898| frame    | number            | Yes       | Number of frames to trigger the event. The value must be greater than **0**. |
9899| callback | Callback\<number> | Yes       | Callback used to return the value of the **frame** parameter. |
9900
9901**Example**
9902
9903```ts
9904audioCapturer.on('markReach', 1000, (position: number) => {
9905  if (position == 1000) {
9906    console.info('ON Triggered successfully');
9907  }
9908});
9909
9910```
9911
9912### off('markReach')<sup>8+</sup>
9913
9914off(type: 'markReach'): void
9915
9916Unsubscribes from mark reached events.
9917
9918**System capability**: SystemCapability.Multimedia.Audio.Capturer
9919
9920**Parameters**
9921
9922| Name | Type   | Mandatory | Description                                        |
9923| :--- | :----- | :-------- | :------------------------------------------------- |
9924| type | string | Yes       | Event type. The value is fixed at **'markReach'**. |
9925
9926**Example**
9927
9928```ts
9929audioCapturer.off('markReach');
9930
9931```
9932
9933### on('periodReach')<sup>8+</sup>
9934
9935on(type: 'periodReach', frame: number, callback: Callback&lt;number&gt;): void
9936
9937Subscribes to period reached events. When the number of frames captured reaches the value of the **frame** parameter, a callback is triggered and the specified value is returned. This API uses an asynchronous callback to return the result.
9938
9939**System capability**: SystemCapability.Multimedia.Audio.Capturer
9940
9941**Parameters**
9942
9943| Name     | Type              | Mandatory | Description                                                  |
9944| :------- | :---------------- | :-------- | :----------------------------------------------------------- |
9945| type     | string            | Yes       | Event type. The value is fixed at **'periodReach'**.         |
9946| frame    | number            | Yes       | Number of frames to trigger the event. The value must be greater than **0**. |
9947| callback | Callback\<number> | Yes       | Callback used to return the value of the **frame** parameter. |
9948
9949**Example**
9950
9951```ts
9952audioCapturer.on('periodReach', 1000, (position: number) => {
9953  if (position == 1000) {
9954    console.info('ON Triggered successfully');
9955  }
9956});
9957
9958```
9959
9960### off('periodReach')<sup>8+</sup>
9961
9962off(type: 'periodReach'): void
9963
9964Unsubscribes from period reached events.
9965
9966**System capability**: SystemCapability.Multimedia.Audio.Capturer
9967
9968**Parameters**
9969
9970| Name | Type   | Mandatory | Description                                          |
9971| :--- | :----- | :-------- | :--------------------------------------------------- |
9972| type | string | Yes       | Event type. The value is fixed at **'periodReach'**. |
9973
9974**Example**
9975
9976```ts
9977audioCapturer.off('periodReach');
9978
9979```
9980
9981### on('stateChange')<sup>8+</sup>
9982
9983on(type: 'stateChange', callback: Callback<AudioState\>): void
9984
9985Subscribes to state change events. This API uses an asynchronous callback to return the result.
9986
9987**System capability**: SystemCapability.Multimedia.Audio.Capturer
9988
9989**Parameters**
9990
9991| Name     | Type                                  | Mandatory | Description                                                  |
9992| :------- | :------------------------------------ | :-------- | :----------------------------------------------------------- |
9993| type     | string                                | Yes       | Event type. The value **stateChange** means the state change event. |
9994| callback | Callback\<[AudioState](#audiostate8)> | Yes       | Callback used to return the audio status.                    |
9995
9996**Example**
9997
9998```ts
9999audioCapturer.on('stateChange', (state: audio.AudioState) => {
10000  if (state == 1) {
10001    console.info('audio capturer state is: STATE_PREPARED');
10002  }
10003  if (state == 2) {
10004    console.info('audio capturer state is: STATE_RUNNING');
10005  }
10006});
10007
10008```
10009
10010## ToneType<sup>9+</sup>
10011
10012Enumerates the tone types of the player.
10013
10014**System API**: This is a system API.
10015
10016**System capability**: SystemCapability.Multimedia.Audio.Tone
10017
10018| Name                                             | Value | Description                                   |
10019| :----------------------------------------------- | :---- | :-------------------------------------------- |
10020| TONE_TYPE_DIAL_0                                 | 0     | DTMF tone of key 0.                           |
10021| TONE_TYPE_DIAL_1                                 | 1     | DTMF tone of key 1.                           |
10022| TONE_TYPE_DIAL_2                                 | 2     | DTMF tone of key 2.                           |
10023| TONE_TYPE_DIAL_3                                 | 3     | DTMF tone of key 3.                           |
10024| TONE_TYPE_DIAL_4                                 | 4     | DTMF tone of key 4.                           |
10025| TONE_TYPE_DIAL_5                                 | 5     | DTMF tone of key 5.                           |
10026| TONE_TYPE_DIAL_6                                 | 6     | DTMF tone of key 6.                           |
10027| TONE_TYPE_DIAL_7                                 | 7     | DTMF tone of key 7.                           |
10028| TONE_TYPE_DIAL_8                                 | 8     | DTMF tone of key 8.                           |
10029| TONE_TYPE_DIAL_9                                 | 9     | DTMF tone of key 9.                           |
10030| TONE_TYPE_DIAL_S                                 | 10    | DTMF tone of the star key (*).                |
10031| TONE_TYPE_DIAL_P                                 | 11    | DTMF tone of the pound key (#).               |
10032| TONE_TYPE_DIAL_A                                 | 12    | DTMF tone of key A.                           |
10033| TONE_TYPE_DIAL_B                                 | 13    | DTMF tone of key B.                           |
10034| TONE_TYPE_DIAL_C                                 | 14    | DTMF tone of key C.                           |
10035| TONE_TYPE_DIAL_D                                 | 15    | DTMF tone of key D.                           |
10036| TONE_TYPE_COMMON_SUPERVISORY_DIAL                | 100   | Supervisory tone - dial tone.                 |
10037| TONE_TYPE_COMMON_SUPERVISORY_BUSY                | 101   | Supervisory tone - busy.                      |
10038| TONE_TYPE_COMMON_SUPERVISORY_CONGESTION          | 102   | Supervisory tone - congestion.                |
10039| TONE_TYPE_COMMON_SUPERVISORY_RADIO_ACK           | 103   | Supervisory tone - radio path acknowledgment. |
10040| TONE_TYPE_COMMON_SUPERVISORY_RADIO_NOT_AVAILABLE | 104   | Supervisory tone - radio path not available.  |
10041| TONE_TYPE_COMMON_SUPERVISORY_CALL_WAITING        | 106   | Supervisory tone - call waiting tone.         |
10042| TONE_TYPE_COMMON_SUPERVISORY_RINGTONE            | 107   | Supervisory tone - ringing tone.              |
10043| TONE_TYPE_COMMON_PROPRIETARY_BEEP                | 200   | Proprietary tone - beep tone.                 |
10044| TONE_TYPE_COMMON_PROPRIETARY_ACK                 | 201   | Proprietary tone - ACK.                       |
10045| TONE_TYPE_COMMON_PROPRIETARY_PROMPT              | 203   | Proprietary tone - PROMPT.                    |
10046| TONE_TYPE_COMMON_PROPRIETARY_DOUBLE_BEEP         | 204   | Proprietary tone - double beep tone.          |
10047
10048## TonePlayer<sup>9+</sup>
10049
10050Provides APIs for playing and managing DTMF tones, such as dial tones, ringback tones, supervisory tones, and proprietary tones.
10051Before calling any API in **TonePlayer**, you must use [createTonePlayer](#audiocreatetoneplayer9) to create a **TonePlayer** instance.
10052
10053**System API**: This is a system API.
10054
10055### load<sup>9+</sup>
10056
10057load(type: ToneType, callback: AsyncCallback&lt;void&gt;): void
10058
10059Loads the DTMF tone configuration. This API uses an asynchronous callback to return the result.
10060
10061**System API**: This is a system API.
10062
10063**System capability**: SystemCapability.Multimedia.Audio.Tone
10064
10065**Parameters**
10066
10067| Name     | Type                   | Mandatory | Description                                                  |
10068| :------- | :--------------------- | :-------- | :----------------------------------------------------------- |
10069| type     | [ToneType](#tonetype9) | Yes       | Tone type.                                                   |
10070| callback | AsyncCallback<void\>   | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
10071
10072**Example**
10073
10074```ts
10075import { BusinessError } from '@ohos.base';
10076
10077tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_5, (err: BusinessError) => {
10078  if (err) {
10079    console.error(`callback call load failed error: ${err.message}`);
10080    return;
10081  } else {
10082    console.info('callback call load success');
10083  }
10084});
10085
10086```
10087
10088### load<sup>9+</sup>
10089
10090load(type: ToneType): Promise&lt;void&gt;
10091
10092Loads the DTMF tone configuration. This API uses a promise to return the result.
10093
10094**System API**: This is a system API.
10095
10096**System capability**: SystemCapability.Multimedia.Audio.Tone
10097
10098**Parameters**
10099
10100| Name | Type                   | Mandatory | Description |
10101| :--- | :--------------------- | :-------- | ----------- |
10102| type | [ToneType](#tonetype9) | Yes       | Tone type.  |
10103
10104**Return value**
10105
10106| Type           | Description                    |
10107| :------------- | :----------------------------- |
10108| Promise<void\> | Promise that returns no value. |
10109
10110**Example**
10111
10112```ts
10113tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_1).then(() => {
10114  console.info('promise call load ');
10115}).catch(() => {
10116  console.error('promise call load fail');
10117});
10118
10119```
10120
10121### start<sup>9+</sup>
10122
10123start(callback: AsyncCallback&lt;void&gt;): void
10124
10125Starts DTMF tone playing. This API uses an asynchronous callback to return the result.
10126
10127**System API**: This is a system API.
10128
10129**System capability**: SystemCapability.Multimedia.Audio.Tone
10130
10131**Parameters**
10132
10133| Name     | Type                 | Mandatory | Description                                                  |
10134| :------- | :------------------- | :-------- | :----------------------------------------------------------- |
10135| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
10136
10137**Example**
10138
10139```ts
10140import { BusinessError } from '@ohos.base';
10141
10142tonePlayer.start((err: BusinessError) => {
10143  if (err) {
10144    console.error(`callback call start failed error: ${err.message}`);
10145    return;
10146  } else {
10147    console.info('callback call start success');
10148  }
10149});
10150
10151```
10152
10153### start<sup>9+</sup>
10154
10155start(): Promise&lt;void&gt;
10156
10157Starts DTMF tone playing. This API uses a promise to return the result.
10158
10159**System API**: This is a system API.
10160
10161**System capability**: SystemCapability.Multimedia.Audio.Tone
10162
10163**Return value**
10164
10165| Type           | Description                    |
10166| :------------- | :----------------------------- |
10167| Promise<void\> | Promise that returns no value. |
10168
10169**Example**
10170
10171```ts
10172tonePlayer.start().then(() => {
10173  console.info('promise call start');
10174}).catch(() => {
10175  console.error('promise call start fail');
10176});
10177
10178```
10179
10180### stop<sup>9+</sup>
10181
10182stop(callback: AsyncCallback&lt;void&gt;): void
10183
10184Stops the tone that is being played. This API uses an asynchronous callback to return the result.
10185
10186**System API**: This is a system API.
10187
10188**System capability**: SystemCapability.Multimedia.Audio.Tone
10189
10190**Parameters**
10191
10192| Name     | Type                 | Mandatory | Description                                                  |
10193| :------- | :------------------- | :-------- | :----------------------------------------------------------- |
10194| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
10195
10196**Example**
10197
10198```ts
10199import { BusinessError } from '@ohos.base';
10200
10201tonePlayer.stop((err: BusinessError) => {
10202  if (err) {
10203    console.error(`callback call stop error: ${err.message}`);
10204    return;
10205  } else {
10206    console.error('callback call stop success ');
10207  }
10208});
10209
10210```
10211
10212### stop<sup>9+</sup>
10213
10214stop(): Promise&lt;void&gt;
10215
10216Stops the tone that is being played. This API uses a promise to return the result.
10217
10218**System API**: This is a system API.
10219
10220**System capability**: SystemCapability.Multimedia.Audio.Tone
10221
10222**Return value**
10223
10224| Type           | Description                    |
10225| :------------- | :----------------------------- |
10226| Promise<void\> | Promise that returns no value. |
10227
10228**Example**
10229
10230```ts
10231tonePlayer.stop().then(() => {
10232  console.info('promise call stop finish');
10233}).catch(() => {
10234  console.error('promise call stop fail');
10235});
10236
10237```
10238
10239### release<sup>9+</sup>
10240
10241release(callback: AsyncCallback&lt;void&gt;): void
10242
10243Releases the resources associated with the **TonePlayer** instance. This API uses an asynchronous callback to return the result.
10244
10245**System API**: This is a system API.
10246
10247**System capability**: SystemCapability.Multimedia.Audio.Tone
10248
10249**Parameters**
10250
10251| Name     | Type                 | Mandatory | Description                                                  |
10252| :------- | :------------------- | :-------- | :----------------------------------------------------------- |
10253| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
10254
10255**Example**
10256
10257```ts
10258import { BusinessError } from '@ohos.base';
10259
10260tonePlayer.release((err: BusinessError) => {
10261  if (err) {
10262    console.error(`callback call release failed error: ${err.message}`);
10263    return;
10264  } else {
10265    console.info('callback call release success ');
10266  }
10267});
10268
10269```
10270
10271### release<sup>9+</sup>
10272
10273release(): Promise&lt;void&gt;
10274
10275Releases the resources associated with the **TonePlayer** instance. This API uses a promise to return the result.
10276
10277**System API**: This is a system API.
10278
10279**System capability**: SystemCapability.Multimedia.Audio.Tone
10280
10281**Return value**
10282
10283| Type           | Description                    |
10284| :------------- | :----------------------------- |
10285| Promise<void\> | Promise that returns no value. |
10286
10287**Example**
10288
10289```ts
10290tonePlayer.release().then(() => {
10291  console.info('promise call release');
10292}).catch(() => {
10293  console.error('promise call release fail');
10294});
10295
10296```
10297
10298## ActiveDeviceType<sup>(deprecated)</sup>
10299
10300Enumerates the active device types.
10301
10302> **NOTE**
10303>
10304> This API is deprecated since API version 9. You are advised to use [CommunicationDeviceType](#communicationdevicetype9) instead.
10305
10306**System capability**: SystemCapability.Multimedia.Audio.Device
10307
10308| Name          | Value | Description                                                  |
10309| ------------- | ----- | ------------------------------------------------------------ |
10310| SPEAKER       | 2     | Speaker.                                                     |
10311| BLUETOOTH_SCO | 7     | Bluetooth device using Synchronous Connection Oriented (SCO) links. |
10312
10313## InterruptActionType<sup>(deprecated)</sup>
10314
10315Enumerates the returned event types for audio interruption events.
10316
10317> **NOTE**
10318>
10319> This API is supported since API version 7 and deprecated since API version 9. No substitute enum is provided. It is used together with the audio interruption events.
10320
10321**System capability**: SystemCapability.Multimedia.Audio.Renderer
10322
10323| Name           | Value | Description               |
10324| -------------- | ----- | ------------------------- |
10325| TYPE_ACTIVATED | 0     | Focus gain event.         |
10326| TYPE_INTERRUPT | 1     | Audio interruption event. |
10327
10328## AudioInterrupt<sup>(deprecated)</sup>
10329
10330Describes input parameters of audio interruption events.
10331
10332> **NOTE**
10333>
10334> This API is supported since API version 7 and deprecated since API version 9. No substitute enum is provided. It is used together with the audio interruption events.
10335
10336**System capability**: SystemCapability.Multimedia.Audio.Renderer
10337
10338| Name            | Type                                  | Mandatory | Description                                                  |
10339| --------------- | ------------------------------------- | --------- | ------------------------------------------------------------ |
10340| streamUsage     | [StreamUsage](#streamusage)           | Yes       | Audio stream usage.                                          |
10341| contentType     | [ContentType](#contenttypedeprecated) | Yes       | Audio content type.                                          |
10342| pauseWhenDucked | boolean                               | Yes       | Whether audio playback can be paused during audio interruption. The value **true** means that audio playback can be paused during audio interruption, and **false** means the opposite. |
10343
10344## InterruptAction<sup>(deprecated)</sup>
10345
10346Describes the callback invoked for audio interruption or focus gain events.
10347
10348> **NOTE**
10349>
10350> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [InterruptEvent](#interruptevent9).
10351
10352**System capability**: SystemCapability.Multimedia.Audio.Renderer
10353
10354| Name       | Type                                                  | Mandatory | Description                                                  |
10355| ---------- | ----------------------------------------------------- | --------- | ------------------------------------------------------------ |
10356| actionType | [InterruptActionType](#interruptactiontypedeprecated) | Yes       | Returned event type. The value **TYPE_ACTIVATED** means the focus gain event, and **TYPE_INTERRUPT** means the audio interruption event. |
10357| type       | [InterruptType](#interrupttype)                       | No        | Type of the audio interruption event.                        |
10358| hint       | [InterruptHint](#interrupthint)                       | No        | Hint provided along with the audio interruption event.       |
10359| activated  | boolean                                               | No        | Whether the focus is gained or released. The value **true** means that the focus is gained or released, and **false** means that the focus fails to be gained or released. |