• 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 localNetworkId = audio.LOCAL_NETWORK_ID;
36const defaultVolumeGroupId = audio.DEFAULT_VOLUME_GROUP_ID;
37const defaultInterruptGroupId = audio.DEFAULT_INTERRUPT_GROUP_ID;
38```
39
40## audio.getAudioManager
41
42getAudioManager(): AudioManager
43
44Obtains an **AudioManager** instance.
45
46**System capability**: SystemCapability.Multimedia.Audio.Core
47
48**Return value**
49
50| Type                         | Description        |
51| ----------------------------- | ------------ |
52| [AudioManager](#audiomanager) | **AudioManager** instance.|
53
54**Example**
55```ts
56import audio from '@ohos.multimedia.audio';
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 **AudioRenderer** instance.|
74
75**Example**
76
77```ts
78import fs from '@ohos.file.fs';
79import audio from '@ohos.multimedia.audio';
80
81let audioStreamInfo: audio.AudioStreamInfo = {
82  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
83  channels: audio.AudioChannel.CHANNEL_1,
84  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
85  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
86}
87
88let audioRendererInfo: audio.AudioRendererInfo = {
89  content: audio.ContentType.CONTENT_TYPE_SPEECH,
90  usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
91  rendererFlags: 0
92}
93
94let audioRendererOptions: audio.AudioRendererOptions = {
95  streamInfo: audioStreamInfo,
96  rendererInfo: audioRendererInfo
97}
98
99audio.createAudioRenderer(audioRendererOptions,(err, data) => {
100  if (err) {
101    console.error(`AudioRenderer Created: Error: ${err}`);
102  } else {
103    console.info('AudioRenderer Created: Success: SUCCESS');
104    let audioRenderer = data;
105  }
106});
107```
108
109## audio.createAudioRenderer<sup>8+</sup>
110
111createAudioRenderer(options: AudioRendererOptions): Promise<AudioRenderer\>
112
113Creates an **AudioRenderer** instance. This API uses a promise to return the result.
114
115**System capability**: SystemCapability.Multimedia.Audio.Renderer
116
117**Parameters**
118
119| Name | Type                                          | Mandatory| Description        |
120| :------ | :--------------------------------------------- | :--- | :----------- |
121| options | [AudioRendererOptions](#audiorendereroptions8) | Yes  | Renderer configurations.|
122
123**Return value**
124
125| Type                                     | Description            |
126| ----------------------------------------- | ---------------- |
127| Promise<[AudioRenderer](#audiorenderer8)> | Promise used to return the **AudioRenderer** instance.|
128
129**Example**
130
131```ts
132import fs from '@ohos.file.fs';
133import audio from '@ohos.multimedia.audio';
134import { BusinessError } from '@ohos.base';
135
136let audioStreamInfo: audio.AudioStreamInfo = {
137  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
138  channels: audio.AudioChannel.CHANNEL_1,
139  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
140  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
141}
142
143let audioRendererInfo: audio.AudioRendererInfo = {
144  content: audio.ContentType.CONTENT_TYPE_SPEECH,
145  usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
146  rendererFlags: 0
147}
148
149let audioRendererOptions: audio.AudioRendererOptions = {
150  streamInfo: audioStreamInfo,
151  rendererInfo: audioRendererInfo
152}
153
154let audioRenderer: audio.AudioRenderer;
155audio.createAudioRenderer(audioRendererOptions).then((data) => {
156  audioRenderer = data;
157  console.info('AudioFrameworkRenderLog: AudioRenderer Created : Success : Stream Type: SUCCESS');
158}).catch((err: BusinessError) => {
159  console.error(`AudioFrameworkRenderLog: AudioRenderer Created : ERROR : ${err}`);
160});
161```
162
163## audio.createAudioCapturer<sup>8+</sup>
164
165createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback<AudioCapturer\>): void
166
167Creates an **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
168
169**System capability**: SystemCapability.Multimedia.Audio.Capturer
170
171**Required permissions**: ohos.permission.MICROPHONE
172
173**Parameters**
174
175| Name  | Type                                           | Mandatory| Description            |
176| :------- | :---------------------------------------------- | :--- | :--------------- |
177| options  | [AudioCapturerOptions](#audiocaptureroptions8)  | Yes  | Capturer configurations.|
178| callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | Yes  | Callback used to return the **AudioCapturer** instance.|
179
180**Example**
181
182```ts
183import audio from '@ohos.multimedia.audio';
184let audioStreamInfo: audio.AudioStreamInfo = {
185  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
186  channels: audio.AudioChannel.CHANNEL_2,
187  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
188  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
189}
190
191let audioCapturerInfo: audio.AudioCapturerInfo = {
192  source: audio.SourceType.SOURCE_TYPE_MIC,
193  capturerFlags: 0
194}
195
196let audioCapturerOptions: audio.AudioCapturerOptions = {
197  streamInfo: audioStreamInfo,
198  capturerInfo: audioCapturerInfo
199}
200
201audio.createAudioCapturer(audioCapturerOptions, (err, data) => {
202  if (err) {
203    console.error(`AudioCapturer Created : Error: ${err}`);
204  } else {
205    console.info('AudioCapturer Created : Success : SUCCESS');
206    let audioCapturer = data;
207  }
208});
209```
210
211## audio.createAudioCapturer<sup>8+</sup>
212
213createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\>
214
215Creates an **AudioCapturer** instance. This API uses a promise to return the result.
216
217**System capability**: SystemCapability.Multimedia.Audio.Capturer
218
219**Required permissions**: ohos.permission.MICROPHONE
220
221**Parameters**
222
223| Name | Type                                          | Mandatory| Description            |
224| :------ | :--------------------------------------------- | :--- | :--------------- |
225| options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes  | Capturer configurations.|
226
227**Return value**
228
229| Type                                     | Description          |
230| ----------------------------------------- | -------------- |
231| Promise<[AudioCapturer](#audiocapturer8)> | Promise used to return the **AudioCapturer** instance.|
232
233**Example**
234
235```ts
236import audio from '@ohos.multimedia.audio';
237import { BusinessError } from '@ohos.base';
238
239let audioStreamInfo: audio.AudioStreamInfo = {
240  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
241  channels: audio.AudioChannel.CHANNEL_2,
242  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
243  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
244}
245
246let audioCapturerInfo: audio.AudioCapturerInfo = {
247  source: audio.SourceType.SOURCE_TYPE_MIC,
248  capturerFlags: 0
249}
250
251let audioCapturerOptions:audio.AudioCapturerOptions = {
252  streamInfo: audioStreamInfo,
253  capturerInfo: audioCapturerInfo
254}
255
256let audioCapturer: audio.AudioCapturer;
257audio.createAudioCapturer(audioCapturerOptions).then((data) => {
258  audioCapturer = data;
259  console.info('AudioCapturer Created : Success : Stream Type: SUCCESS');
260}).catch((err: BusinessError) => {
261  console.error(`AudioCapturer Created : ERROR : ${err}`);
262});
263```
264
265## audio.createTonePlayer<sup>9+</sup>
266
267createTonePlayer(options: AudioRendererInfo, callback: AsyncCallback&lt;TonePlayer&gt;): void
268
269Creates a **TonePlayer** instance. This API uses an asynchronous callback to return the result.
270
271**System capability**: SystemCapability.Multimedia.Audio.Tone
272
273**System API**: This is a system API.
274
275**Parameters**
276
277| Name  | Type                                            | Mandatory| Description           |
278| -------- | ----------------------------------------------- | ---- | -------------- |
279| options  | [AudioRendererInfo](#audiorendererinfo8)        | Yes  | Audio renderer information.|
280| callback | AsyncCallback<[TonePlayer](#toneplayer9)>       | Yes  | Callback used to return the **TonePlayer** instance.|
281
282**Example**
283
284```ts
285import audio from '@ohos.multimedia.audio';
286
287let audioRendererInfo: audio.AudioRendererInfo = {
288  usage : audio.StreamUsage.STREAM_USAGE_DTMF,
289  rendererFlags : 0
290}
291let tonePlayer: audio.TonePlayer;
292
293audio.createTonePlayer(audioRendererInfo, (err, data) => {
294  console.info(`callback call createTonePlayer: audioRendererInfo: ${audioRendererInfo}`);
295  if (err) {
296    console.error(`callback call createTonePlayer return error: ${err.message}`);
297  } else {
298    console.info(`callback call createTonePlayer return data: ${data}`);
299    tonePlayer = data;
300  }
301});
302```
303
304## audio.createTonePlayer<sup>9+</sup>
305
306createTonePlayer(options: AudioRendererInfo): Promise&lt;TonePlayer&gt;
307
308Creates a **TonePlayer** instance. This API uses a promise to return the result.
309
310**System capability**: SystemCapability.Multimedia.Audio.Tone
311
312**System API**: This is a system API.
313
314**Parameters**
315
316| Name | Type                                          | Mandatory| Description        |
317| :------ | :---------------------------------------------| :--- | :----------- |
318| options | [AudioRendererInfo](#audiorendererinfo8)      | Yes  | Audio renderer information.|
319
320**Return value**
321
322| Type                                     | Description                            |
323| ----------------------------------------- | -------------------------------- |
324| Promise<[TonePlayer](#toneplayer9)>       | Promise used to return the **TonePlayer** instance.  |
325
326**Example**
327
328```ts
329import audio from '@ohos.multimedia.audio';
330let tonePlayer: audio.TonePlayer;
331async function createTonePlayerBefore(){
332  let audioRendererInfo: audio.AudioRendererInfo = {
333    usage : audio.StreamUsage.STREAM_USAGE_DTMF,
334    rendererFlags : 0
335  }
336  tonePlayer = await audio.createTonePlayer(audioRendererInfo);
337}
338```
339
340## AudioVolumeType
341
342Enumerates the audio stream types.
343
344**System capability**: SystemCapability.Multimedia.Audio.Volume
345
346| Name                        | Value     | Description      |
347| ---------------------------- | ------ | ---------- |
348| VOICE_CALL<sup>8+</sup>      | 0      | Audio stream for voice calls.|
349| RINGTONE                     | 2      | Audio stream for ringtones.    |
350| MEDIA                        | 3      | Audio stream for media purpose.    |
351| ALARM<sup>10+</sup>          | 4      | Audio stream for alarming.    |
352| ACCESSIBILITY<sup>10+</sup>  | 5      | Audio stream for accessibility.  |
353| VOICE_ASSISTANT<sup>8+</sup> | 9      | Audio stream for voice assistant.|
354| ULTRASONIC<sup>10+</sup>     | 10     | Audio stream for ultrasonic.<br>This is a system API.|
355| ALL<sup>9+</sup>             | 100    | All public audio streams.<br>This is a system API.|
356
357## InterruptRequestResultType<sup>9+</sup>
358
359Enumerates the result types of audio interruption requests.
360
361**System capability**: SystemCapability.Multimedia.Audio.Interrupt
362
363**System API**: This is a system API.
364
365| Name                        | Value     | Description      |
366| ---------------------------- | ------ | ---------- |
367| INTERRUPT_REQUEST_GRANT      | 0      | The audio interruption request is accepted.|
368| INTERRUPT_REQUEST_REJECT     | 1      | The audio interruption request is denied. There may be a stream with a higher priority.|
369
370## InterruptMode<sup>9+</sup>
371
372Enumerates the audio interruption modes.
373
374**System capability**: SystemCapability.Multimedia.Audio.Interrupt
375
376| Name                        | Value     | Description      |
377| ---------------------------- | ------ | ---------- |
378| SHARE_MODE                   | 0      | Shared mode.|
379| INDEPENDENT_MODE             | 1      | Independent mode.|
380
381## DeviceFlag
382
383Enumerates the audio device flags.
384
385**System capability**: SystemCapability.Multimedia.Audio.Device
386
387| Name                           |  Value    | Description                                             |
388| ------------------------------- | ------ | ------------------------------------------------- |
389| NONE_DEVICES_FLAG<sup>9+</sup>  | 0      | No device.<br>This is a system API.       |
390| OUTPUT_DEVICES_FLAG             | 1      | Output device.|
391| INPUT_DEVICES_FLAG              | 2      | Input device.|
392| ALL_DEVICES_FLAG                | 3      | All devices.|
393| DISTRIBUTED_OUTPUT_DEVICES_FLAG<sup>9+</sup> | 4   | Distributed output device.<br>This is a system API. |
394| DISTRIBUTED_INPUT_DEVICES_FLAG<sup>9+</sup>  | 8   | Distributed input device.<br>This is a system API. |
395| ALL_DISTRIBUTED_DEVICES_FLAG<sup>9+</sup>    | 12  | Distributed input and output device.<br>This is a system API. |
396
397## DeviceRole
398
399Enumerates the audio device roles.
400
401**System capability**: SystemCapability.Multimedia.Audio.Device
402
403| Name         |  Value   | Description          |
404| ------------- | ------ | -------------- |
405| INPUT_DEVICE  | 1      | Input role.|
406| OUTPUT_DEVICE | 2      | Output role.|
407
408## DeviceType
409
410Enumerates the audio device types.
411
412**System capability**: SystemCapability.Multimedia.Audio.Device
413
414| Name                | Value    | Description                                                     |
415| ---------------------| ------ | --------------------------------------------------------- |
416| INVALID              | 0      | Invalid device.                                               |
417| EARPIECE             | 1      | Earpiece.                                                   |
418| SPEAKER              | 2      | Speaker.                                                 |
419| WIRED_HEADSET        | 3      | Wired headset with a microphone.                                     |
420| WIRED_HEADPHONES     | 4      | Wired headset without microphone.                                     |
421| BLUETOOTH_SCO        | 7      | Bluetooth device using Synchronous Connection Oriented (SCO) links.     |
422| BLUETOOTH_A2DP       | 8      | Bluetooth device using Advanced Audio Distribution Profile (A2DP) links.|
423| MIC                  | 15     | Microphone.                                                 |
424| USB_HEADSET          | 22     | USB Type-C headset.                                      |
425| DEFAULT<sup>9+</sup> | 1000   | Default device type.                                           |
426
427## CommunicationDeviceType<sup>9+</sup>
428
429Enumerates the device types used for communication.
430
431**System capability**: SystemCapability.Multimedia.Audio.Communication
432
433| Name         | Value    | Description         |
434| ------------- | ------ | -------------|
435| SPEAKER       | 2      | Speaker.     |
436
437## AudioRingMode
438
439Enumerates the ringer modes.
440
441**System capability**: SystemCapability.Multimedia.Audio.Communication
442
443| Name               |  Value   | Description      |
444| ------------------- | ------ | ---------- |
445| RINGER_MODE_SILENT  | 0      | Silent mode.|
446| RINGER_MODE_VIBRATE | 1      | Vibration mode.|
447| RINGER_MODE_NORMAL  | 2      | Normal mode.|
448
449## AudioSampleFormat<sup>8+</sup>
450
451Enumerates the audio sample formats.
452
453**System capability**: SystemCapability.Multimedia.Audio.Core
454
455| Name                               |  Value   | Description                      |
456| ---------------------------------- | ------ | -------------------------- |
457| SAMPLE_FORMAT_INVALID              | -1     | Invalid format.                |
458| SAMPLE_FORMAT_U8                   | 0      | Unsigned 8-bit integer.           |
459| SAMPLE_FORMAT_S16LE                | 1      | Signed 16-bit integer, little endian.|
460| SAMPLE_FORMAT_S24LE                | 2      | Signed 24-bit integer, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
461| SAMPLE_FORMAT_S32LE                | 3      | Signed 32-bit integer, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
462| 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.|
463
464## AudioErrors<sup>9+</sup>
465
466Enumerates the audio error codes.
467
468**System capability**: SystemCapability.Multimedia.Audio.Core
469
470| Name                | Value     | Description        |
471| ---------------------| --------| ----------------- |
472| ERROR_INVALID_PARAM  | 6800101 | Invalid parameter.        |
473| ERROR_NO_MEMORY      | 6800102 | Memory allocation failure.    |
474| ERROR_ILLEGAL_STATE  | 6800103 | Unsupported state.      |
475| ERROR_UNSUPPORTED    | 6800104 | Unsupported parameter value.   |
476| ERROR_TIMEOUT        | 6800105 | Processing timeout.        |
477| ERROR_STREAM_LIMIT   | 6800201 | Too many audio streams.|
478| ERROR_SYSTEM         | 6800301 | System error.    |
479
480## AudioChannel<sup>8+</sup>
481
482Enumerates the audio channels.
483
484**System capability**: SystemCapability.Multimedia.Audio.Core
485
486| Name     |  Value      | Description    |
487| --------- | -------- | -------- |
488| CHANNEL_1 | 0x1 << 0 | Channel 1.|
489| CHANNEL_2 | 0x1 << 1 | Channel 2.|
490
491## AudioSamplingRate<sup>8+</sup>
492
493Enumerates the audio sampling rates. The sampling rates supported vary according to the device in use.
494
495**System capability**: SystemCapability.Multimedia.Audio.Core
496
497| Name             |  Value   | Description           |
498| ----------------- | ------ | --------------- |
499| SAMPLE_RATE_8000  | 8000   | The sampling rate is 8000. |
500| SAMPLE_RATE_11025 | 11025  | The sampling rate is 11025.|
501| SAMPLE_RATE_12000 | 12000  | The sampling rate is 12000.|
502| SAMPLE_RATE_16000 | 16000  | The sampling rate is 16000.|
503| SAMPLE_RATE_22050 | 22050  | The sampling rate is 22050.|
504| SAMPLE_RATE_24000 | 24000  | The sampling rate is 24000.|
505| SAMPLE_RATE_32000 | 32000  | The sampling rate is 32000.|
506| SAMPLE_RATE_44100 | 44100  | The sampling rate is 44100.|
507| SAMPLE_RATE_48000 | 48000  | The sampling rate is 48000.|
508| SAMPLE_RATE_64000 | 64000  | The sampling rate is 64000.|
509| SAMPLE_RATE_96000 | 96000  | The sampling rate is 96000.|
510
511## AudioEncodingType<sup>8+</sup>
512
513Enumerates the audio encoding types.
514
515**System capability**: SystemCapability.Multimedia.Audio.Core
516
517| Name                 |  Value   | Description     |
518| --------------------- | ------ | --------- |
519| ENCODING_TYPE_INVALID | -1     | Invalid.   |
520| ENCODING_TYPE_RAW     | 0      | PCM encoding.|
521
522## ContentType
523
524Enumerates the audio content types.
525
526**System capability**: SystemCapability.Multimedia.Audio.Core
527
528| Name                              |  Value   | Description      |
529| ---------------------------------- | ------ | ---------- |
530| CONTENT_TYPE_UNKNOWN               | 0      | Unknown content.|
531| CONTENT_TYPE_SPEECH                | 1      | Speech.    |
532| CONTENT_TYPE_MUSIC                 | 2      | Music.    |
533| CONTENT_TYPE_MOVIE                 | 3      | Movie.    |
534| CONTENT_TYPE_SONIFICATION          | 4      | Notification tone.  |
535| CONTENT_TYPE_RINGTONE<sup>8+</sup> | 5      | Ringtone.    |
536## StreamUsage
537
538Enumerates the audio stream usage.
539
540**System capability**: SystemCapability.Multimedia.Audio.Core
541
542| Name                                     |  Value   | Description      |
543| ------------------------------------------| ------ | ---------- |
544| STREAM_USAGE_UNKNOWN                      | 0      | Unknown usage.|
545| STREAM_USAGE_MEDIA                        | 1      | Media.    |
546| STREAM_USAGE_MUSIC<sup>10+</sup>          | 1      | Music.    |
547| STREAM_USAGE_VOICE_COMMUNICATION          | 2      | Voice communication.|
548| STREAM_USAGE_VOICE_ASSISTANT<sup>9+</sup> | 3      | Voice assistant.|
549| STREAM_USAGE_ALARM<sup>10+</sup>          | 4      | Alarming.    |
550| STREAM_USAGE_VOICE_MESSAGE<sup>10+</sup>  | 5      | Voice message.|
551| STREAM_USAGE_NOTIFICATION_RINGTONE        | 6      | Notification tone.|
552| STREAM_USAGE_RINGTONE<sup>10+</sup>       | 6      | Ringtone.    |
553| STREAM_USAGE_NOTIFICATION<sup>10+</sup>   | 7      | Notification.    |
554| STREAM_USAGE_ACCESSIBILITY<sup>10+</sup>  | 8      | Accessibility.  |
555| STREAM_USAGE_SYSTEM<sup>10+</sup>         | 9      | System tone (such as screen lock sound effect or key tone).<br>This is a system API.|
556| STREAM_USAGE_MOVIE<sup>10+</sup>          | 10     | Movie or video.|
557| STREAM_USAGE_GAME<sup>10+</sup>           | 11     | Game sound effect. |
558| STREAM_USAGE_AUDIOBOOK<sup>10+</sup>      | 12     | Audiobook. |
559| STREAM_USAGE_NAVIGATION<sup>10+</sup>     | 13     | Navigation.    |
560| STREAM_USAGE_DTMF<sup>10+</sup>           | 14     | Dial tone.<br>This is a system API.|
561| STREAM_USAGE_ENFORCED_TONE<sup>10+</sup>  | 15     | Forcible tone (such as camera shutter sound effect).<br>This is a system API.|
562| STREAM_USAGE_ULTRASONIC<sup>10+</sup>     | 16     | Ultrasonic.<br>This is a system API.|
563
564
565## InterruptRequestType<sup>9+</sup>
566
567Enumerates the audio interruption request types.
568
569**System API**: This is a system API.
570
571**System capability**: SystemCapability.Multimedia.Audio.Interrupt
572
573| Name                              |  Value    | Description                      |
574| ---------------------------------- | ------ | ------------------------- |
575| INTERRUPT_REQUEST_TYPE_DEFAULT     | 0      |  Default type, which can be used to interrupt audio requests. |
576
577## AudioState<sup>8+</sup>
578
579Enumerates the audio states.
580
581**System capability**: SystemCapability.Multimedia.Audio.Core
582
583| Name          | Value    | Description            |
584| -------------- | ------ | ---------------- |
585| STATE_INVALID  | -1     | Invalid state.      |
586| STATE_NEW      | 0      | Creating instance state.|
587| STATE_PREPARED | 1      | Prepared.      |
588| STATE_RUNNING  | 2      | Running.    |
589| STATE_STOPPED  | 3      | Stopped.      |
590| STATE_RELEASED | 4      | Released.      |
591| STATE_PAUSED   | 5      | Paused.      |
592
593## AudioEffectMode<sup>10+</sup>
594
595Enumerates the audio effect modes.
596
597**System capability**: SystemCapability.Multimedia.Audio.Renderer
598
599| Name              | Value    | Description      |
600| ------------------ | ------ | ---------- |
601| EFFECT_NONE        | 0      | The audio effect is disabled.|
602| EFFECT_DEFAULT     | 1      | The default audio effect is used.|
603
604## AudioRendererRate<sup>8+</sup>
605
606Enumerates the audio renderer rates.
607
608**System capability**: SystemCapability.Multimedia.Audio.Renderer
609
610| Name              | Value    | Description      |
611| ------------------ | ------ | ---------- |
612| RENDER_RATE_NORMAL | 0      | Normal rate.|
613| RENDER_RATE_DOUBLE | 1      | Double rate.   |
614| RENDER_RATE_HALF   | 2      | Half rate. |
615
616## InterruptType
617
618Enumerates the audio interruption types.
619
620**System capability**: SystemCapability.Multimedia.Audio.Renderer
621
622| Name                |  Value    | Description                  |
623| -------------------- | ------ | ---------------------- |
624| INTERRUPT_TYPE_BEGIN | 1      | Audio interruption started.|
625| INTERRUPT_TYPE_END   | 2      | Audio interruption ended.|
626
627## InterruptForceType<sup>9+</sup>
628
629Enumerates the types of force that causes audio interruption.
630
631**System capability**: SystemCapability.Multimedia.Audio.Renderer
632
633| Name           |  Value   | Description                                |
634| --------------- | ------ | ------------------------------------ |
635| INTERRUPT_FORCE | 0      | Forced action taken by the system.  |
636| INTERRUPT_SHARE | 1      | The application can choose to take action or ignore.|
637
638## InterruptHint
639
640Enumerates the hints provided along with audio interruption.
641
642**System capability**: SystemCapability.Multimedia.Audio.Renderer
643
644| Name                              |  Value    | Description                                        |
645| ---------------------------------- | ------ | -------------------------------------------- |
646| INTERRUPT_HINT_NONE<sup>8+</sup>   | 0      | None.                                    |
647| INTERRUPT_HINT_RESUME              | 1      | Resume the playback.                              |
648| INTERRUPT_HINT_PAUSE               | 2      | Paused/Pause the playback.                              |
649| INTERRUPT_HINT_STOP                | 3      | Stopped/Stop the playback.                              |
650| INTERRUPT_HINT_DUCK                | 4      | Ducked the playback. (In ducking, the audio volume is reduced, but not silenced.)|
651| INTERRUPT_HINT_UNDUCK<sup>8+</sup> | 5      | Unducked the playback.                              |
652
653## AudioStreamInfo<sup>8+</sup>
654
655Describes audio stream information.
656
657**System capability**: SystemCapability.Multimedia.Audio.Core
658
659| Name        | Type                                              | Mandatory| Description              |
660| ------------ | ------------------------------------------------- | ---- | ------------------ |
661| samplingRate | [AudioSamplingRate](#audiosamplingrate8)          | Yes  | Audio sampling rate.|
662| channels     | [AudioChannel](#audiochannel8)                    | Yes  | Number of audio channels.|
663| sampleFormat | [AudioSampleFormat](#audiosampleformat8)          | Yes  | Audio sample format.    |
664| encodingType | [AudioEncodingType](#audioencodingtype8)          | Yes  | Audio encoding type.    |
665
666## AudioRendererInfo<sup>8+</sup>
667
668Describes audio renderer information.
669
670**System capability**: SystemCapability.Multimedia.Audio.Core
671
672| Name         | Type                       | Mandatory | Description            |
673| ------------- | --------------------------- | ---- | ---------------- |
674| content       | [ContentType](#contenttype) | No  | Audio content type.<br>This parameter is mandatory in API versions 8 and 9 and optional since API version 10.|
675| usage         | [StreamUsage](#streamusage) | Yes  | Audio stream usage.|
676| 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 JS APIs do not support the low-latency audio renderer.|
677
678## InterruptResult<sup>9+</sup>
679
680Describes the audio interruption result.
681
682**System capability**: SystemCapability.Multimedia.Audio.Interrupt
683
684**System API**: This is a system API.
685
686| Name         | Type                                                           | Mandatory| Description            |
687| --------------| -------------------------------------------------------------- | ---- | ---------------- |
688| requestResult | [InterruptRequestResultType](#interruptrequestresulttype9)     | Yes  | Audio interruption request type.|
689| interruptNode | number                                                         | Yes  | Node to interrupt.|
690
691## AudioRendererOptions<sup>8+</sup>
692
693Describes audio renderer configurations.
694
695| Name        | Type                                    | Mandatory | Description            |
696| ------------ | ---------------------------------------- | ---- | ---------------- |
697| streamInfo   | [AudioStreamInfo](#audiostreaminfo8)     | Yes  | Audio stream information.<br>**System capability**: SystemCapability.Multimedia.Audio.Renderer|
698| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes  | Audio renderer information.<br>**System capability**: SystemCapability.Multimedia.Audio.Renderer|
699| 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|
700
701## AudioPrivacyType<sup>10+</sup><a name="audioprivacytype"></a>
702
703Enumerates whether an audio stream can be recorded by other applications.
704
705**System capability**: SystemCapability.Multimedia.Audio.PlaybackCapture
706
707| Name                | Value  | Description                            |
708| -------------------- | ---- | -------------------------------- |
709| PRIVACY_TYPE_PUBLIC  | 0    | The audio stream can be recorded by other applications.  |
710| PRIVACY_TYPE_PRIVATE | 1    | The audio stream cannot be recorded by other applications.|
711
712## InterruptEvent<sup>9+</sup>
713
714Describes the interruption event received by the application when playback is interrupted.
715
716**System capability**: SystemCapability.Multimedia.Audio.Renderer
717
718| Name     | Type                                      |Mandatory  | Description                                |
719| --------- | ------------------------------------------ | ---- | ------------------------------------ |
720| eventType | [InterruptType](#interrupttype)            | Yes  | Whether the interruption has started or ended.        |
721| forceType | [InterruptForceType](#interruptforcetype9) | Yes  | Whether the interruption is taken by the system or to be taken by the application.|
722| hintType  | [InterruptHint](#interrupthint)            | Yes  | Hint provided along the interruption.                          |
723
724## VolumeEvent<sup>9+</sup>
725
726Describes the event received by the application when the volume is changed.
727
728**System capability**: SystemCapability.Multimedia.Audio.Volume
729
730| Name      | Type                               | Mandatory  | Description                                                    |
731| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
732| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                              |
733| volume     | number                              | Yes  | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.    |
734| updateUi   | boolean                             | Yes  | Whether to show the volume change in UI.                                       |
735| volumeGroupId | number                           | Yes  | Volume group ID. It can be used as an input parameter of **getGroupManager**.<br>This is a system API. |
736| networkId  | string                              | Yes  | Network ID.<br>This is a system API.                            |
737
738## MicStateChangeEvent<sup>9+</sup>
739
740Describes the event received by the application when the microphone mute status changes.
741
742**System capability**: SystemCapability.Multimedia.Audio.Device
743
744| Name      | Type                               | Mandatory| Description                                                    |
745| ---------- | ----------------------------------- | ---- |-------------------------------------------------------- |
746| mute | boolean | Yes  | Mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.         |
747
748## ConnectType<sup>9+</sup>
749
750Enumerates the types of connected devices.
751
752**System API**: This is a system API.
753
754**System capability**: SystemCapability.Multimedia.Audio.Volume
755
756| Name                           |  Value    | Description                  |
757| :------------------------------ | :----- | :--------------------- |
758| CONNECT_TYPE_LOCAL              | 1      | Local device.        |
759| CONNECT_TYPE_DISTRIBUTED        | 2      | Distributed device.           |
760
761## VolumeGroupInfos<sup>9+</sup>
762
763Describes the volume group information. The value is an array of [VolumeGroupInfo](#volumegroupinfo9) and is read-only.
764
765**System API**: This is a system API.
766
767**System capability**: SystemCapability.Multimedia.Audio.Volume
768
769## VolumeGroupInfo<sup>9+</sup>
770
771Describes the volume group information.
772
773**System API**: This is a system API.
774
775**System capability**: SystemCapability.Multimedia.Audio.Volume
776
777| Name                       | Type                      | Readable| Writable| Description      |
778| -------------------------- | -------------------------- | ---- | ---- | ---------- |
779| networkId<sup>9+</sup>     | string                     | Yes  | No  | Network ID of the device. |
780| groupId<sup>9+</sup>       | number                     | Yes  | No  | Group ID of the device.|
781| mappingId<sup>9+</sup>     | number                     | Yes  | No  | Group mapping ID.|
782| groupName<sup>9+</sup>     | string                     | Yes  | No  | Group name.|
783| type<sup>9+</sup>          | [ConnectType](#connecttype9)| Yes  | No  | Type of the connected device.|
784
785## DeviceChangeAction
786
787Describes the device connection status and device information.
788
789**System capability**: SystemCapability.Multimedia.Audio.Device
790
791| Name             | Type                                             | Mandatory| Description              |
792| :---------------- | :------------------------------------------------ | :--- | :----------------- |
793| type              | [DeviceChangeType](#devicechangetype)             | Yes  | Device connection status.|
794| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes  | Device information.        |
795
796## DeviceChangeType
797
798Enumerates the device connection statuses.
799
800**System capability**: SystemCapability.Multimedia.Audio.Device
801
802| Name      | Value  | Description          |
803| :--------- | :--- | :------------- |
804| CONNECT    | 0    | Connected.    |
805| DISCONNECT | 1    | Disconnected.|
806
807## AudioCapturerOptions<sup>8+</sup>
808
809Describes audio capturer configurations.
810
811| Name                               | Type                                                     | Mandatory| Description                                                        |
812| ----------------------------------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ |
813| streamInfo                          | [AudioStreamInfo](#audiostreaminfo8)                      | Yes  | Audio stream information.<br>**System capability**: SystemCapability.Multimedia.Audio.Capturer  |
814| capturerInfo                        | [AudioCapturerInfo](#audiocapturerinfo)                   | Yes  | Audio capturer information.<br>**System capability**: SystemCapability.Multimedia.Audio.Capturer       |
815| playbackCaptureConfig<sup>10+</sup> | [AudioPlaybackCaptureConfig](#audioplaybackcaptureconfig) | No  | Configuration of internal audio recording.<br>**System capability**: SystemCapability.Multimedia.Audio.PlaybackCapture|
816
817## AudioCapturerInfo<sup>8+</sup><a name="audiocapturerinfo"></a>
818
819Describes audio capturer information.
820
821**System capability**: SystemCapability.Multimedia.Audio.Core
822
823| Name         | Type                     | Mandatory| Description            |
824| :------------ | :------------------------ | :--- | :--------------- |
825| source        | [SourceType](#sourcetype) | Yes  | Audio source type.      |
826| capturerFlags | number                    | Yes  | Audio capturer flags.|
827
828## SourceType<sup>8+</sup><a name="sourcetype"></a>
829
830Enumerates the audio source types.
831
832| Name                                        |  Value    | Description                  |
833| :------------------------------------------- | :----- | :--------------------- |
834| SOURCE_TYPE_INVALID                          | -1     | Invalid audio source.<br>**System capability**: SystemCapability.Multimedia.Audio.Core |
835| SOURCE_TYPE_MIC                              | 0      | Mic source.<br>**System capability**: SystemCapability.Multimedia.Audio.Core|
836| SOURCE_TYPE_VOICE_RECOGNITION<sup>9+</sup>   | 1      | Voice recognition source.<br>**System capability**: SystemCapability.Multimedia.Audio.Core |
837| SOURCE_TYPE_PLAYBACK_CAPTURE<sup>10+</sup>   | 2 | Internal audio recording source.<br>**System capability**: SystemCapability.Multimedia.Audio.PlaybackCapture|
838| 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.|
839| SOURCE_TYPE_VOICE_COMMUNICATION              | 7      | Voice communication source.<br>**System capability**: SystemCapability.Multimedia.Audio.Core|
840
841## AudioPlaybackCaptureConfig<sup>10+</sup><a name="audioplaybackcaptureconfig"></a>
842
843Defines the configuration of internal audio recording.
844
845**System capability**: SystemCapability.Multimedia.Audio.PlaybackCapture
846
847| Name         | Type                                         | Mandatory| Description                            |
848| ------------- | --------------------------------------------- | ---- | -------------------------------- |
849| filterOptions | [CaptureFilterOptions](#capturefilteroptions) | Yes  | Options for filtering the played audio streams to be recorded.|
850
851## CaptureFilterOptions<sup>10+</sup><a name="capturefilteroptions"></a>
852
853Defines the options for filtering the played audio streams to be recorded.
854
855**Required permissions**: ohos.permission.CAPTURE_VOICE_DOWNLINK_AUDIO
856
857This permission is required when an application wants to record a played audio stream for which **StreamUsage** is set to **SOURCE_TYPE_VOICE_COMMUNICATION**.
858
859**System capability**: SystemCapability.Multimedia.Audio.PlaybackCapture
860
861| Name  | Type                              | Mandatory| Description                                                        |
862| ------ | ---------------------------------- | ---- | ------------------------------------------------------------ |
863| 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.|
864
865## AudioScene<sup>8+</sup><a name="audioscene"></a>
866
867Enumerates the audio scenes.
868
869**System capability**: SystemCapability.Multimedia.Audio.Communication
870
871| Name                  |  Value    | Description                                         |
872| :--------------------- | :----- | :-------------------------------------------- |
873| AUDIO_SCENE_DEFAULT    | 0      | Default audio scene.                               |
874| AUDIO_SCENE_RINGING    | 1      | Ringing audio scene.<br>This is a system API.|
875| AUDIO_SCENE_PHONE_CALL | 2      | Phone call audio scene.<br>This is a system API.|
876| AUDIO_SCENE_VOICE_CHAT | 3      | Voice chat audio scene.                               |
877
878## VolumeAdjustType<sup>10+</sup>
879
880Enumerates the volume adjustment types.
881
882**System capability**: SystemCapability.Multimedia.Audio.Volume
883
884| Name                  |  Value    | Description                                         |
885| :--------------------- | :----- | :-------------------------------------------- |
886| VOLUME_UP              | 0      | Adjusts the volume upwards.<br>This is a system API.  |
887| VOLUME_DOWN            | 1      | Adjusts the volume downwards.<br>This is a system API.  |
888
889## AudioManager
890
891Implements audio volume and audio device management. Before calling any API in **AudioManager**, you must use [getAudioManager](#audiogetaudiomanager) to create an **AudioManager** instance.
892
893### setAudioParameter
894
895setAudioParameter(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
896
897Sets an audio parameter. This API uses an asynchronous callback to return the result.
898
899This 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.
900
901**Required permissions**: ohos.permission.MODIFY_AUDIO_SETTINGS
902
903**System capability**: SystemCapability.Multimedia.Audio.Core
904
905**Parameters**
906
907| Name  | Type                     | Mandatory| Description                    |
908| -------- | ------------------------- | ---- | ------------------------ |
909| key      | string                    | Yes  | Key of the audio parameter to set.  |
910| value    | string                    | Yes  | Value of the audio parameter to set.  |
911| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.|
912
913**Example**
914
915```ts
916import { BusinessError } from '@ohos.base';
917audioManager.setAudioParameter('key_example', 'value_example', (err: BusinessError) => {
918  if (err) {
919    console.error(`Failed to set the audio parameter. ${err}`);
920    return;
921  }
922  console.info('Callback invoked to indicate a successful setting of the audio parameter.');
923});
924```
925
926### setAudioParameter
927
928setAudioParameter(key: string, value: string): Promise&lt;void&gt;
929
930Sets an audio parameter. This API uses a promise to return the result.
931
932This 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.
933
934**Required permissions**: ohos.permission.MODIFY_AUDIO_SETTINGS
935
936**System capability**: SystemCapability.Multimedia.Audio.Core
937
938**Parameters**
939
940| Name| Type  | Mandatory| Description                  |
941| ------ | ------ | ---- | ---------------------- |
942| key    | string | Yes  | Key of the audio parameter to set.|
943| value  | string | Yes  | Value of the audio parameter to set.|
944
945**Return value**
946
947| Type               | Description                           |
948| ------------------- | ------------------------------- |
949| Promise&lt;void&gt; | Promise used to return the result.|
950
951**Example**
952
953```ts
954audioManager.setAudioParameter('key_example', 'value_example').then(() => {
955  console.info('Promise returned to indicate a successful setting of the audio parameter.');
956});
957```
958
959### getAudioParameter
960
961getAudioParameter(key: string, callback: AsyncCallback&lt;string&gt;): void
962
963Obtains the value of an audio parameter. This API uses an asynchronous callback to return the result.
964
965This 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.
966
967**System capability**: SystemCapability.Multimedia.Audio.Core
968
969**Parameters**
970
971| Name  | Type                       | Mandatory| Description                        |
972| -------- | --------------------------- | ---- | ---------------------------- |
973| key      | string                      | Yes  | Key of the audio parameter whose value is to be obtained.      |
974| callback | AsyncCallback&lt;string&gt; | Yes  | Callback used to return the value of the audio parameter.|
975
976**Example**
977
978```ts
979import { BusinessError } from '@ohos.base';
980audioManager.getAudioParameter('key_example', (err: BusinessError, value: string) => {
981  if (err) {
982    console.error(`Failed to obtain the value of the audio parameter. ${err}`);
983    return;
984  }
985  console.info(`Callback invoked to indicate that the value of the audio parameter is obtained ${value}.`);
986});
987```
988
989### getAudioParameter
990
991getAudioParameter(key: string): Promise&lt;string&gt;
992
993Obtains the value of an audio parameter. This API uses a promise to return the result.
994
995This 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.
996
997**System capability**: SystemCapability.Multimedia.Audio.Core
998
999**Parameters**
1000
1001| Name| Type  | Mandatory| Description                  |
1002| ------ | ------ | ---- | ---------------------- |
1003| key    | string | Yes  | Key of the audio parameter whose value is to be obtained.|
1004
1005**Return value**
1006
1007| Type                 | Description                               |
1008| --------------------- | ----------------------------------- |
1009| Promise&lt;string&gt; | Promise used to return the value of the audio parameter.|
1010
1011**Example**
1012
1013```ts
1014audioManager.getAudioParameter('key_example').then((value: string) => {
1015  console.info(`Promise returned to indicate that the value of the audio parameter is obtained ${value}.`);
1016});
1017```
1018
1019### setAudioScene<sup>8+</sup>
1020
1021setAudioScene\(scene: AudioScene, callback: AsyncCallback<void\>\): void
1022
1023Sets an audio scene. This API uses an asynchronous callback to return the result.
1024
1025**System API**: This is a system API.
1026
1027**System capability**: SystemCapability.Multimedia.Audio.Communication
1028
1029**Parameters**
1030
1031| Name  | Type                                | Mandatory| Description                |
1032| :------- | :----------------------------------- | :--- | :------------------- |
1033| scene    | <a href="#audioscene">AudioScene</a> | Yes  | Audio scene to set.      |
1034| callback | AsyncCallback<void\>                 | Yes  | Callback used to return the result.|
1035
1036**Example**
1037
1038```ts
1039import { BusinessError } from '@ohos.base';
1040audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err: BusinessError) => {
1041  if (err) {
1042    console.error(`Failed to set the audio scene mode.​ ${err}`);
1043    return;
1044  }
1045  console.info('Callback invoked to indicate a successful setting of the audio scene mode.');
1046});
1047```
1048
1049### setAudioScene<sup>8+</sup>
1050
1051setAudioScene\(scene: AudioScene\): Promise<void\>
1052
1053Sets an audio scene. This API uses a promise to return the result.
1054
1055**System API**: This is a system API.
1056
1057**System capability**: SystemCapability.Multimedia.Audio.Communication
1058
1059**Parameters**
1060
1061| Name| Type                                | Mandatory| Description          |
1062| :----- | :----------------------------------- | :--- | :------------- |
1063| scene  | <a href="#audioscene">AudioScene</a> | Yes  | Audio scene to set.|
1064
1065**Return value**
1066
1067| Type          | Description                |
1068| :------------- | :------------------- |
1069| Promise<void\> | Promise used to return the result.|
1070
1071**Example**
1072
1073```ts
1074import { BusinessError } from '@ohos.base';
1075audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => {
1076  console.info('Promise returned to indicate a successful setting of the audio scene mode.');
1077}).catch ((err: BusinessError) => {
1078  console.error(`Failed to set the audio scene mode ${err}`);
1079});
1080```
1081
1082### getAudioScene<sup>8+</sup>
1083
1084getAudioScene\(callback: AsyncCallback<AudioScene\>\): void
1085
1086Obtains the audio scene. This API uses an asynchronous callback to return the result.
1087
1088**System capability**: SystemCapability.Multimedia.Audio.Communication
1089
1090**Parameters**
1091
1092| Name  | Type                                               | Mandatory| Description                        |
1093| :------- | :-------------------------------------------------- | :--- | :--------------------------- |
1094| callback | AsyncCallback<<a href="#audioscene">AudioScene</a>> | Yes  | Callback used to return the audio scene.|
1095
1096**Example**
1097
1098```ts
1099import { BusinessError } from '@ohos.base';
1100audioManager.getAudioScene((err: BusinessError, value: audio.AudioScene) => {
1101  if (err) {
1102    console.error(`Failed to obtain the audio scene mode.​ ${err}`);
1103    return;
1104  }
1105  console.info(`Callback invoked to indicate that the audio scene mode is obtained ${value}.`);
1106});
1107```
1108
1109### getAudioScene<sup>8+</sup>
1110
1111getAudioScene\(\): Promise<AudioScene\>
1112
1113Obtains the audio scene. This API uses a promise to return the result.
1114
1115**System capability**: SystemCapability.Multimedia.Audio.Communication
1116
1117**Return value**
1118
1119| Type                                         | Description                        |
1120| :-------------------------------------------- | :--------------------------- |
1121| Promise<<a href="#audioscene">AudioScene</a>> | Promise used to return the audio scene.|
1122
1123**Example**
1124
1125```ts
1126import { BusinessError } from '@ohos.base';
1127audioManager.getAudioScene().then((value: audio.AudioScene) => {
1128  console.info(`Promise returned to indicate that the audio scene mode is obtained ${value}.`);
1129}).catch ((err: BusinessError) => {
1130  console.error(`Failed to obtain the audio scene mode ${err}`);
1131});
1132```
1133
1134### getAudioSceneSync<sup>10+</sup>
1135
1136getAudioSceneSync\(\): AudioScene
1137
1138Obtains the audio scene. This API returns the result synchronously.
1139
1140**System capability**: SystemCapability.Multimedia.Audio.Communication
1141
1142**Return value**
1143
1144| Type                                         | Description                        |
1145| :-------------------------------------------- | :--------------------------- |
1146| <a href="#audioscene">AudioScene</a> | Audio scene.|
1147
1148**Example**
1149
1150```ts
1151import { BusinessError } from '@ohos.base';
1152
1153try {
1154  let value: audio.AudioScene = audioManager.getAudioSceneSync();
1155  console.info(`indicate that the audio scene mode is obtained ${value}.`);
1156} catch (err) {
1157  let error = err as BusinessError;
1158  console.error(`Failed to obtain the audio scene mode ${error}`);
1159}
1160```
1161
1162### getVolumeManager<sup>9+</sup>
1163
1164getVolumeManager(): AudioVolumeManager
1165
1166Obtains an **AudioVolumeManager** instance.
1167
1168**System capability**: SystemCapability.Multimedia.Audio.Volume
1169
1170**Example**
1171
1172```ts
1173import audio from '@ohos.multimedia.audio';
1174let audioVolumeManager: audio.AudioVolumeManager = audioManager.getVolumeManager();
1175```
1176
1177### getStreamManager<sup>9+</sup>
1178
1179getStreamManager(): AudioStreamManager
1180
1181Obtains an **AudioStreamManager** instance.
1182
1183**System capability**: SystemCapability.Multimedia.Audio.Core
1184
1185**Example**
1186
1187```ts
1188import audio from '@ohos.multimedia.audio';
1189let audioStreamManager: audio.AudioStreamManager = audioManager.getStreamManager();
1190```
1191
1192### getRoutingManager<sup>9+</sup>
1193
1194getRoutingManager(): AudioRoutingManager
1195
1196Obtains an **AudioRoutingManager** instance.
1197
1198**System capability**: SystemCapability.Multimedia.Audio.Device
1199
1200**Example**
1201
1202```ts
1203import audio from '@ohos.multimedia.audio';
1204let audioRoutingManager: audio.AudioRoutingManager = audioManager.getRoutingManager();
1205```
1206
1207### setVolume<sup>(deprecated)</sup>
1208
1209setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&lt;void&gt;): void
1210
1211Sets the volume for a stream. This API uses an asynchronous callback to return the result.
1212
1213> **NOTE**
1214>
1215> 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.
1216
1217**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
1218
1219This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
1220
1221**System capability**: SystemCapability.Multimedia.Audio.Volume
1222
1223**Parameters**
1224
1225| Name    | Type                               | Mandatory| Description                                                    |
1226| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
1227| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
1228| volume     | number                              | Yes  | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
1229| callback   | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result.                                  |
1230
1231**Example**
1232
1233```ts
1234import { BusinessError } from '@ohos.base';
1235audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err: BusinessError) => {
1236  if (err) {
1237    console.error(`Failed to set the volume. ${err}`);
1238    return;
1239  }
1240  console.info('Callback invoked to indicate a successful volume setting.');
1241});
1242```
1243
1244### setVolume<sup>(deprecated)</sup>
1245
1246setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
1247
1248Sets the volume for a stream. This API uses a promise to return the result.
1249
1250> **NOTE**
1251>
1252> 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.
1253
1254**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
1255
1256This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
1257
1258**System capability**: SystemCapability.Multimedia.Audio.Volume
1259
1260**Parameters**
1261
1262| Name    | Type                               | Mandatory| Description                                                    |
1263| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
1264| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
1265| volume     | number                              | Yes  | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
1266
1267**Return value**
1268
1269| Type               | Description                         |
1270| ------------------- | ----------------------------- |
1271| Promise&lt;void&gt; | Promise used to return the result.|
1272
1273**Example**
1274
1275```ts
1276audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
1277  console.info('Promise returned to indicate a successful volume setting.');
1278});
1279```
1280
1281### getVolume<sup>(deprecated)</sup>
1282
1283getVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
1284
1285Obtains the volume of a stream. This API uses an asynchronous callback to return the result.
1286
1287> **NOTE**
1288>
1289> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getVolume](#getvolume9) in **AudioVolumeGroupManager**.
1290
1291**System capability**: SystemCapability.Multimedia.Audio.Volume
1292
1293**Parameters**
1294
1295| Name    | Type                               | Mandatory| Description              |
1296| ---------- | ----------------------------------- | ---- | ------------------ |
1297| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
1298| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the volume.|
1299
1300**Example**
1301
1302```ts
1303import { BusinessError } from '@ohos.base';
1304audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
1305  if (err) {
1306    console.error(`Failed to obtain the volume. ${err}`);
1307    return;
1308  }
1309  console.info('Callback invoked to indicate that the volume is obtained.');
1310});
1311```
1312
1313### getVolume<sup>(deprecated)</sup>
1314
1315getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
1316
1317Obtains the volume of a stream. This API uses a promise to return the result.
1318
1319> **NOTE**
1320>
1321> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getVolume](#getvolume9) in **AudioVolumeGroupManager**.
1322
1323**System capability**: SystemCapability.Multimedia.Audio.Volume
1324
1325**Parameters**
1326
1327| Name    | Type                               | Mandatory| Description        |
1328| ---------- | ----------------------------------- | ---- | ------------ |
1329| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
1330
1331**Return value**
1332
1333| Type                 | Description                     |
1334| --------------------- | ------------------------- |
1335| Promise&lt;number&gt; | Promise used to return the volume.|
1336
1337**Example**
1338
1339```ts
1340audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value: number) => {
1341  console.info(`Promise returned to indicate that the volume is obtained ${value} .`);
1342});
1343```
1344
1345### getMinVolume<sup>(deprecated)</sup>
1346
1347getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
1348
1349Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the result.
1350
1351> **NOTE**
1352>
1353> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMinVolume](#getminvolume9) in **AudioVolumeGroupManager**.
1354
1355**System capability**: SystemCapability.Multimedia.Audio.Volume
1356
1357**Parameters**
1358
1359| Name    | Type                               | Mandatory| Description              |
1360| ---------- | ----------------------------------- | ---- | ------------------ |
1361| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
1362| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the minimum volume.|
1363
1364**Example**
1365
1366```ts
1367import { BusinessError } from '@ohos.base';
1368audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
1369  if (err) {
1370    console.error(`Failed to obtain the minimum volume. ${err}`);
1371    return;
1372  }
1373  console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
1374});
1375```
1376
1377### getMinVolume<sup>(deprecated)</sup>
1378
1379getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
1380
1381Obtains the minimum volume allowed for a stream. This API uses a promise to return the result.
1382
1383> **NOTE**
1384>
1385> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMinVolume](#getminvolume9) in **AudioVolumeGroupManager**.
1386
1387**System capability**: SystemCapability.Multimedia.Audio.Volume
1388
1389**Parameters**
1390
1391| Name    | Type                               | Mandatory| Description        |
1392| ---------- | ----------------------------------- | ---- | ------------ |
1393| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
1394
1395**Return value**
1396
1397| Type                 | Description                     |
1398| --------------------- | ------------------------- |
1399| Promise&lt;number&gt; | Promise used to return the minimum volume.|
1400
1401**Example**
1402
1403```ts
1404audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value: number) => {
1405  console.info(`Promised returned to indicate that the minimum volume is obtained. ${value}`);
1406});
1407```
1408
1409### getMaxVolume<sup>(deprecated)</sup>
1410
1411getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
1412
1413Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the result.
1414
1415> **NOTE**
1416>
1417> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMaxVolume](#getmaxvolume9) in **AudioVolumeGroupManager**.
1418
1419**System capability**: SystemCapability.Multimedia.Audio.Volume
1420
1421**Parameters**
1422
1423| Name    | Type                               | Mandatory| Description                  |
1424| ---------- | ----------------------------------- | ---- | ---------------------- |
1425| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.          |
1426| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the maximum volume.|
1427
1428**Example**
1429
1430```ts
1431import { BusinessError } from '@ohos.base';
1432audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
1433  if (err) {
1434    console.error(`Failed to obtain the maximum volume. ${err}`);
1435    return;
1436  }
1437  console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`);
1438});
1439```
1440
1441### getMaxVolume<sup>(deprecated)</sup>
1442
1443getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
1444
1445Obtains the maximum volume allowed for a stream. This API uses a promise to return the result.
1446
1447> **NOTE**
1448>
1449> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMaxVolume](#getmaxvolume9) in **AudioVolumeGroupManager**.
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
1459**Return value**
1460
1461| Type                 | Description                         |
1462| --------------------- | ----------------------------- |
1463| Promise&lt;number&gt; | Promise used to return the maximum volume.|
1464
1465**Example**
1466
1467```ts
1468audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data: number) => {
1469  console.info('Promised returned to indicate that the maximum volume is obtained.');
1470});
1471```
1472
1473### mute<sup>(deprecated)</sup>
1474
1475mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
1476
1477Mutes or unmutes a stream. This API uses an asynchronous callback to return the result.
1478
1479> **NOTE**
1480>
1481> 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.
1482
1483**System capability**: SystemCapability.Multimedia.Audio.Volume
1484
1485**Parameters**
1486
1487| Name    | Type                               | Mandatory| Description                                 |
1488| ---------- | ----------------------------------- | ---- | ------------------------------------- |
1489| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                         |
1490| mute       | boolean                             | Yes  | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.|
1491| callback   | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result.               |
1492
1493**Example**
1494
1495```ts
1496import { BusinessError } from '@ohos.base';
1497audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err: BusinessError) => {
1498  if (err) {
1499    console.error(`Failed to mute the stream. ${err}`);
1500    return;
1501  }
1502  console.info('Callback invoked to indicate that the stream is muted.');
1503});
1504```
1505
1506### mute<sup>(deprecated)</sup>
1507
1508mute(volumeType: AudioVolumeType, mute: boolean): Promise&lt;void&gt;
1509
1510Mutes or unmutes a stream. This API uses a promise to return the result.
1511
1512> **NOTE**
1513>
1514> 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.
1515
1516**System capability**: SystemCapability.Multimedia.Audio.Volume
1517
1518**Parameters**
1519
1520| Name    | Type                               | Mandatory| Description                                 |
1521| ---------- | ----------------------------------- | ---- | ------------------------------------- |
1522| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                         |
1523| mute       | boolean                             | Yes  | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.|
1524
1525**Return value**
1526
1527| Type               | Description                         |
1528| ------------------- | ----------------------------- |
1529| Promise&lt;void&gt; | Promise used to return the result.|
1530
1531**Example**
1532
1533
1534```ts
1535audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
1536  console.info('Promise returned to indicate that the stream is muted.');
1537});
1538```
1539
1540### isMute<sup>(deprecated)</sup>
1541
1542isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
1543
1544Checks whether a stream is muted. This API uses an asynchronous callback to return the result.
1545
1546> **NOTE**
1547>
1548> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMute](#ismute9) in **AudioVolumeGroupManager**.
1549
1550**System capability**: SystemCapability.Multimedia.Audio.Volume
1551
1552**Parameters**
1553
1554| Name    | Type                               | Mandatory| Description                                           |
1555| ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
1556| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                   |
1557| callback   | AsyncCallback&lt;boolean&gt;        | Yes  | Callback used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite.|
1558
1559**Example**
1560
1561```ts
1562import { BusinessError } from '@ohos.base';
1563audioManager.isMute(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => {
1564  if (err) {
1565    console.error(`Failed to obtain the mute status. ${err}`);
1566    return;
1567  }
1568  console.info(`Callback invoked to indicate that the mute status of the stream is obtained. ${value}`);
1569});
1570```
1571
1572### isMute<sup>(deprecated)</sup>
1573
1574isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
1575
1576Checks whether a stream is muted. 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 [isMute](#ismute9) 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;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.|
1595
1596**Example**
1597
1598```ts
1599audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value: boolean) => {
1600  console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`);
1601});
1602```
1603
1604### isActive<sup>(deprecated)</sup>
1605
1606isActive(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
1607
1608Checks whether a stream is active. 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 [isActive](#isactive9) in **AudioStreamManager**.
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;boolean&gt;        | Yes  | Callback used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite.|
1622
1623**Example**
1624
1625```ts
1626import { BusinessError } from '@ohos.base';
1627audioManager.isActive(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => {
1628  if (err) {
1629    console.error(`Failed to obtain the active status of the stream. ${err}`);
1630    return;
1631  }
1632  console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`);
1633});
1634```
1635
1636### isActive<sup>(deprecated)</sup>
1637
1638isActive(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
1639
1640Checks whether a stream is active. This API uses a promise to return the result.
1641
1642> **NOTE**
1643>
1644> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isActive](#isactive9) in **AudioStreamManager**.
1645
1646**System capability**: SystemCapability.Multimedia.Audio.Volume
1647
1648**Parameters**
1649
1650| Name    | Type                               | Mandatory| Description        |
1651| ---------- | ----------------------------------- | ---- | ------------ |
1652| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
1653
1654**Return value**
1655
1656| Type                  | Description                                                    |
1657| ---------------------- | -------------------------------------------------------- |
1658| 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.|
1659
1660**Example**
1661
1662```ts
1663audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value: boolean) => {
1664  console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`);
1665});
1666```
1667
1668### setRingerMode<sup>(deprecated)</sup>
1669
1670setRingerMode(mode: AudioRingMode, callback: AsyncCallback&lt;void&gt;): void
1671
1672Sets the ringer mode. This API uses an asynchronous callback to return the result.
1673
1674> **NOTE**
1675>
1676> 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.
1677
1678**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
1679
1680This permission is required only for muting or unmuting the ringer.
1681
1682**System capability**: SystemCapability.Multimedia.Audio.Communication
1683
1684**Parameters**
1685
1686| Name  | Type                           | Mandatory| Description                    |
1687| -------- | ------------------------------- | ---- | ------------------------ |
1688| mode     | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.          |
1689| callback | AsyncCallback&lt;void&gt;       | Yes  | Callback used to return the result.|
1690
1691**Example**
1692
1693```ts
1694import { BusinessError } from '@ohos.base';
1695audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err: BusinessError) => {
1696  if (err) {
1697    console.error(`Failed to set the ringer mode.​ ${err}`);
1698    return;
1699  }
1700  console.info('Callback invoked to indicate a successful setting of the ringer mode.');
1701});
1702```
1703
1704### setRingerMode<sup>(deprecated)</sup>
1705
1706setRingerMode(mode: AudioRingMode): Promise&lt;void&gt;
1707
1708Sets the ringer mode. This API uses a promise to return the result.
1709
1710> **NOTE**
1711>
1712> 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.
1713
1714
1715**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
1716
1717This permission is required only for muting or unmuting the ringer.
1718
1719**System capability**: SystemCapability.Multimedia.Audio.Communication
1720
1721**Parameters**
1722
1723| Name| Type                           | Mandatory| Description          |
1724| ------ | ------------------------------- | ---- | -------------- |
1725| mode   | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.|
1726
1727**Return value**
1728
1729| Type               | Description                           |
1730| ------------------- | ------------------------------- |
1731| Promise&lt;void&gt; | Promise used to return the result.|
1732
1733**Example**
1734
1735```ts
1736audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
1737  console.info('Promise returned to indicate a successful setting of the ringer mode.');
1738});
1739```
1740
1741### getRingerMode<sup>(deprecated)</sup>
1742
1743getRingerMode(callback: AsyncCallback&lt;AudioRingMode&gt;): void
1744
1745Obtains the ringer mode. This API uses an asynchronous callback to return the result.
1746
1747> **NOTE**
1748>
1749> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getRingerMode](#getringermode9) in **AudioVolumeGroupManager**.
1750
1751**System capability**: SystemCapability.Multimedia.Audio.Communication
1752
1753**Parameters**
1754
1755| Name  | Type                                                | Mandatory| Description                    |
1756| -------- | ---------------------------------------------------- | ---- | ------------------------ |
1757| callback | AsyncCallback&lt;[AudioRingMode](#audioringmode)&gt; | Yes  | Callback used to return the ringer mode.|
1758
1759**Example**
1760
1761```ts
1762import { BusinessError } from '@ohos.base';
1763audioManager.getRingerMode((err: BusinessError, value: audio.AudioRingMode) => {
1764  if (err) {
1765    console.error(`Failed to obtain the ringer mode.​ ${err}`);
1766    return;
1767  }
1768  console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`);
1769});
1770```
1771
1772### getRingerMode<sup>(deprecated)</sup>
1773
1774getRingerMode(): Promise&lt;AudioRingMode&gt;
1775
1776Obtains the ringer mode. This API uses a promise to return the result.
1777
1778> **NOTE**
1779>
1780> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getRingerMode](#getringermode9) in **AudioVolumeGroupManager**.
1781
1782**System capability**: SystemCapability.Multimedia.Audio.Communication
1783
1784**Return value**
1785
1786| Type                                          | Description                           |
1787| ---------------------------------------------- | ------------------------------- |
1788| Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise used to return the ringer mode.|
1789
1790**Example**
1791
1792```ts
1793audioManager.getRingerMode().then((value: audio.AudioRingMode) => {
1794  console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`);
1795});
1796```
1797
1798### getDevices<sup>(deprecated)</sup>
1799
1800getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
1801
1802Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the result.
1803
1804> **NOTE**
1805>
1806> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getDevices](#getdevices9) in **AudioRoutingManager**.
1807
1808**System capability**: SystemCapability.Multimedia.Audio.Device
1809
1810**Parameters**
1811
1812| Name    | Type                                                        | Mandatory| Description                |
1813| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
1814| deviceFlag | [DeviceFlag](#deviceflag)                                    | Yes  | Audio device flag.    |
1815| callback   | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Yes  | Callback used to return the device list.|
1816
1817**Example**
1818```ts
1819import { BusinessError } from '@ohos.base';
1820audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err: BusinessError, value: audio.AudioDeviceDescriptors) => {
1821  if (err) {
1822    console.error(`Failed to obtain the device list. ${err}`);
1823    return;
1824  }
1825  console.info('Callback invoked to indicate that the device list is obtained.');
1826});
1827```
1828
1829### getDevices<sup>(deprecated)</sup>
1830
1831getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
1832
1833Obtains the audio devices with a specific flag. This API uses a promise to return the result.
1834
1835> **NOTE**
1836>
1837> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getDevices](#getdevices9) in **AudioRoutingManager**.
1838
1839**System capability**: SystemCapability.Multimedia.Audio.Device
1840
1841**Parameters**
1842
1843| Name    | Type                     | Mandatory| Description            |
1844| ---------- | ------------------------- | ---- | ---------------- |
1845| deviceFlag | [DeviceFlag](#deviceflag) | Yes  | Audio device flag.|
1846
1847**Return value**
1848
1849| Type                                                        | Description                     |
1850| ------------------------------------------------------------ | ------------------------- |
1851| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the device list.|
1852
1853**Example**
1854
1855```ts
1856audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data: audio.AudioDeviceDescriptors) => {
1857  console.info('Promise returned to indicate that the device list is obtained.');
1858});
1859```
1860
1861### setDeviceActive<sup>(deprecated)</sup>
1862
1863setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
1864
1865Sets a device to the active state. This API uses an asynchronous callback to return the result.
1866
1867> **NOTE**
1868>
1869> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCommunicationDevice](#setcommunicationdevice9) in **AudioRoutingManager**.
1870
1871**System capability**: SystemCapability.Multimedia.Audio.Device
1872
1873**Parameters**
1874
1875| Name    | Type                                 | Mandatory| Description                    |
1876| ---------- | ------------------------------------- | ---- | ------------------------ |
1877| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes  | Active audio device type.      |
1878| active     | boolean                               | Yes  | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite.          |
1879| callback   | AsyncCallback&lt;void&gt;             | Yes  | Callback used to return the result.|
1880
1881**Example**
1882
1883```ts
1884import { BusinessError } from '@ohos.base';
1885audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err: BusinessError) => {
1886  if (err) {
1887    console.error(`Failed to set the active status of the device. ${err}`);
1888    return;
1889  }
1890  console.info('Callback invoked to indicate that the device is set to the active status.');
1891});
1892```
1893
1894### setDeviceActive<sup>(deprecated)</sup>
1895
1896setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise&lt;void&gt;
1897
1898Sets a device to the active state. This API uses a promise to return the result.
1899
1900> **NOTE**
1901>
1902> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCommunicationDevice](#setcommunicationdevice9) in **AudioRoutingManager**.
1903
1904**System capability**: SystemCapability.Multimedia.Audio.Device
1905
1906**Parameters**
1907
1908| Name    | Type                                 | Mandatory| Description              |
1909| ---------- | ------------------------------------- | ---- | ------------------ |
1910| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes  | Active audio device type.|
1911| active     | boolean                               | Yes  | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite.    |
1912
1913**Return value**
1914
1915| Type               | Description                           |
1916| ------------------- | ------------------------------- |
1917| Promise&lt;void&gt; | Promise used to return the result.|
1918
1919**Example**
1920
1921
1922```ts
1923audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => {
1924  console.info('Promise returned to indicate that the device is set to the active status.');
1925});
1926```
1927
1928### isDeviceActive<sup>(deprecated)</sup>
1929
1930isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
1931
1932Checks whether a device is active. This API uses an asynchronous callback to return the result.
1933
1934> **NOTE**
1935>
1936> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isCommunicationDeviceActive](#iscommunicationdeviceactive9) in **AudioRoutingManager**.
1937
1938**System capability**: SystemCapability.Multimedia.Audio.Device
1939
1940**Parameters**
1941
1942| Name    | Type                                 | Mandatory| Description                    |
1943| ---------- | ------------------------------------- | ---- | ------------------------ |
1944| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes  | Active audio device type.      |
1945| callback   | AsyncCallback&lt;boolean&gt;          | Yes  | Callback used to return the active state of the device.|
1946
1947**Example**
1948
1949```ts
1950import { BusinessError } from '@ohos.base';
1951audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err: BusinessError, value: boolean) => {
1952  if (err) {
1953    console.error(`Failed to obtain the active status of the device. ${err}`);
1954    return;
1955  }
1956  console.info('Callback invoked to indicate that the active status of the device is obtained.');
1957});
1958```
1959
1960### isDeviceActive<sup>(deprecated)</sup>
1961
1962isDeviceActive(deviceType: ActiveDeviceType): Promise&lt;boolean&gt;
1963
1964Checks whether a device is active. This API uses a promise to return the result.
1965
1966> **NOTE**
1967>
1968> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isCommunicationDeviceActive](#iscommunicationdeviceactive9) in **AudioRoutingManager**.
1969
1970**System capability**: SystemCapability.Multimedia.Audio.Device
1971
1972**Parameters**
1973
1974| Name    | Type                                 | Mandatory| Description              |
1975| ---------- | ------------------------------------- | ---- | ------------------ |
1976| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes  | Active audio device type.|
1977
1978**Return value**
1979
1980| Type                   | Description                     |
1981| ---------------------- | ------------------------------- |
1982| Promise&lt;boolean&gt; | Promise used to return the active state of the device.|
1983
1984**Example**
1985
1986```ts
1987audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value: boolean) => {
1988  console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
1989});
1990```
1991
1992### setMicrophoneMute<sup>(deprecated)</sup>
1993
1994setMicrophoneMute(mute: boolean, callback: AsyncCallback&lt;void&gt;): void
1995
1996Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result.
1997
1998> **NOTE**
1999>
2000> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setMicrophoneMute](#setmicrophonemute9) in **AudioVolumeGroupManager**.
2001
2002**Required permissions**: ohos.permission.MICROPHONE
2003
2004**System capability**: SystemCapability.Multimedia.Audio.Device
2005
2006**Parameters**
2007
2008| Name  | Type                     | Mandatory| Description                                         |
2009| -------- | ------------------------- | ---- | --------------------------------------------- |
2010| mute     | boolean                   | Yes  | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
2011| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.                     |
2012
2013**Example**
2014
2015```ts
2016import { BusinessError } from '@ohos.base';
2017audioManager.setMicrophoneMute(true, (err: BusinessError) => {
2018  if (err) {
2019    console.error(`Failed to mute the microphone. ${err}`);
2020    return;
2021  }
2022  console.info('Callback invoked to indicate that the microphone is muted.');
2023});
2024```
2025
2026### setMicrophoneMute<sup>(deprecated)</sup>
2027
2028setMicrophoneMute(mute: boolean): Promise&lt;void&gt;
2029
2030Mutes or unmutes the microphone. This API uses a promise to return the result.
2031
2032> **NOTE**
2033>
2034> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setMicrophoneMute](#setmicrophonemute9) in **AudioVolumeGroupManager**.
2035
2036**Required permissions**: ohos.permission.MICROPHONE
2037
2038**System capability**: SystemCapability.Multimedia.Audio.Device
2039
2040**Parameters**
2041
2042| Name| Type   | Mandatory| Description                                         |
2043| ------ | ------- | ---- | --------------------------------------------- |
2044| mute   | boolean | Yes  | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
2045
2046**Return value**
2047
2048| Type               | Description                           |
2049| ------------------- | ------------------------------- |
2050| Promise&lt;void&gt; | Promise used to return the result.|
2051
2052**Example**
2053
2054```ts
2055audioManager.setMicrophoneMute(true).then(() => {
2056  console.info('Promise returned to indicate that the microphone is muted.');
2057});
2058```
2059
2060### isMicrophoneMute<sup>(deprecated)</sup>
2061
2062isMicrophoneMute(callback: AsyncCallback&lt;boolean&gt;): void
2063
2064Checks whether the microphone is muted. This API uses an asynchronous callback to return the result.
2065
2066> **NOTE**
2067>
2068> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMicrophoneMute](#ismicrophonemute9) in **AudioVolumeGroupManager**.
2069
2070**Required permissions**: ohos.permission.MICROPHONE
2071
2072**System capability**: SystemCapability.Multimedia.Audio.Device
2073
2074**Parameters**
2075
2076| Name  | Type                        | Mandatory| Description                                                   |
2077| -------- | ---------------------------- | ---- | ------------------------------------------------------- |
2078| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.|
2079
2080**Example**
2081
2082```ts
2083import { BusinessError } from '@ohos.base';
2084audioManager.isMicrophoneMute((err: BusinessError, value: boolean) => {
2085  if (err) {
2086    console.error(`Failed to obtain the mute status of the microphone. ${err}`);
2087    return;
2088  }
2089  console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`);
2090});
2091```
2092
2093### isMicrophoneMute<sup>(deprecated)</sup>
2094
2095isMicrophoneMute(): Promise&lt;boolean&gt;
2096
2097Checks whether the microphone is muted. This API uses a promise to return the result.
2098
2099> **NOTE**
2100>
2101> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMicrophoneMute](#ismicrophonemute9) in **AudioVolumeGroupManager**.
2102
2103**Required permissions**: ohos.permission.MICROPHONE
2104
2105**System capability**: SystemCapability.Multimedia.Audio.Device
2106
2107**Return value**
2108
2109| Type                  | Description                                                        |
2110| ---------------------- | ------------------------------------------------------------ |
2111| 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.|
2112
2113**Example**
2114
2115```ts
2116audioManager.isMicrophoneMute().then((value: boolean) => {
2117  console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`);
2118});
2119```
2120
2121### on('volumeChange')<sup>(deprecated)</sup>
2122
2123on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
2124
2125> **NOTE**
2126>
2127> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [on('volumeChange')](#onvolumechange9) in **AudioVolumeManager**.
2128
2129Subscribes to system volume change events.
2130
2131**System API**: This is a system API.
2132
2133Currently, 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.
2134
2135**System capability**: SystemCapability.Multimedia.Audio.Volume
2136
2137**Parameters**
2138
2139| Name  | Type                                  | Mandatory| Description                                                        |
2140| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
2141| type     | string                                 | Yes  | Event type. The event **'volumeChange'** is triggered when the system volume is changed.|
2142| callback | Callback<[VolumeEvent](#volumeevent9)> | Yes  | Callback used to return the result.                                                  |
2143
2144**Example**
2145
2146```ts
2147audioManager.on('volumeChange', (volumeEvent: audio.VolumeEvent) => {
2148  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
2149  console.info(`Volume level: ${volumeEvent.volume} `);
2150  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
2151});
2152```
2153
2154### on('ringerModeChange')<sup>(deprecated)</sup>
2155
2156on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void
2157
2158Subscribes to ringer mode change events.
2159
2160> **NOTE**
2161>
2162> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [on('ringerModeChange')](#onringermodechange9) in **AudioVolumeGroupManager**.
2163
2164**System API**: This is a system API.
2165
2166**System capability**: SystemCapability.Multimedia.Audio.Communication
2167
2168**Parameters**
2169
2170| Name  | Type                                     | Mandatory| Description                                                        |
2171| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
2172| type     | string                                    | Yes  | Event type. The event **'ringerModeChange'** is triggered when the ringer mode is changed.|
2173| callback | Callback<[AudioRingMode](#audioringmode)> | Yes  | Callback used to return the result.                                                  |
2174
2175**Example**
2176
2177```ts
2178audioManager.on('ringerModeChange', (ringerMode: audio.AudioRingMode) => {
2179  console.info(`Updated ringermode: ${ringerMode}`);
2180});
2181```
2182
2183### on('deviceChange')<sup>(deprecated)</sup>
2184
2185on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void
2186
2187Subscribes to device change events. When a device is connected or disconnected, registered clients will receive the callback.
2188
2189> **NOTE**
2190>
2191> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [on('deviceChange')](#ondevicechange9) in **AudioRoutingManager**.
2192
2193**System capability**: SystemCapability.Multimedia.Audio.Device
2194
2195**Parameters**
2196
2197| Name  | Type                                                | Mandatory| Description                                      |
2198| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
2199| type     | string                                               | Yes  | Event type. The event **'deviceChange'** is triggered when the device connection status is changed.|
2200| callback | Callback<[DeviceChangeAction](#devicechangeaction)\> | Yes  | Callback used to return the device update details.                        |
2201
2202**Example**
2203
2204```ts
2205audioManager.on('deviceChange', (deviceChanged: audio.DeviceChangeAction) => {
2206  console.info(`device change type : ${deviceChanged.type} `);
2207  console.info(`device descriptor size : ${deviceChanged.deviceDescriptors.length} `);
2208  console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceRole} `);
2209  console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceType} `);
2210});
2211```
2212
2213### off('deviceChange')<sup>(deprecated)</sup>
2214
2215off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void
2216
2217Unsubscribes from device change events.
2218
2219> **NOTE**
2220>
2221> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [off('deviceChange')](#offdevicechange9) in **AudioRoutingManager**.
2222
2223**System capability**: SystemCapability.Multimedia.Audio.Device
2224
2225**Parameters**
2226
2227| Name  | Type                                               | Mandatory| Description                                      |
2228| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
2229| type     | string                                              | Yes  | Event type. The event **'deviceChange'** is triggered when the device connection status is changed.|
2230| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | No  | Callback used to return the device update details.                        |
2231
2232**Example**
2233
2234```ts
2235audioManager.off('deviceChange');
2236```
2237
2238### on('interrupt')
2239
2240on(type: 'interrupt', interrupt: AudioInterrupt, callback: Callback\<InterruptAction>): void
2241
2242Subscribes to audio interruption events. When the application's audio is interrupted by another playback event, the application will receive the callback.
2243
2244Same 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.
2245
2246**System capability**: SystemCapability.Multimedia.Audio.Renderer
2247
2248**Parameters**
2249
2250| Name   | Type                                         | Mandatory| Description                                                        |
2251| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
2252| type      | string                                        | Yes  | Event type. The event **'interrupt'** is triggered when the audio playback of the current application is interrupted by another application.|
2253| interrupt | AudioInterrupt                                | Yes  | Audio interruption event type.                                    |
2254| callback  | Callback<[InterruptAction](#interruptactiondeprecated)> | Yes  | Callback invoked for the audio interruption event.                                      |
2255
2256**Example**
2257
2258```ts
2259import audio from '@ohos.multimedia.audio';
2260let interAudioInterrupt: audio.AudioInterrupt = {
2261  streamUsage:2,
2262  contentType:0,
2263  pauseWhenDucked:true
2264};
2265audioManager.on('interrupt', interAudioInterrupt, (InterruptAction: audio.InterruptAction) => {
2266  if (InterruptAction.actionType === 0) {
2267    console.info('An event to gain the audio focus starts.');
2268    console.info(`Focus gain event: ${InterruptAction} `);
2269  }
2270  if (InterruptAction.actionType === 1) {
2271    console.info('An audio interruption event starts.');
2272    console.info(`Audio interruption event: ${InterruptAction} `);
2273  }
2274});
2275```
2276
2277### off('interrupt')
2278
2279off(type: 'interrupt', interrupt: AudioInterrupt, callback?: Callback\<InterruptAction>): void
2280
2281Unsubscribes from audio interruption events.
2282
2283**System capability**: SystemCapability.Multimedia.Audio.Renderer
2284
2285**Parameters**
2286
2287| Name   | Type                                         | Mandatory| Description                                                        |
2288| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
2289| type      | string                                        | Yes  | Event type. The event **'interrupt'** is triggered when the audio playback of the current application is interrupted by another application.|
2290| interrupt | AudioInterrupt                                | Yes  | Audio interruption event type.                                    |
2291| callback  | Callback<[InterruptAction](#interruptactiondeprecated)> | No  | Callback invoked for the audio interruption event.                                      |
2292
2293**Example**
2294
2295```ts
2296import audio from '@ohos.multimedia.audio';
2297let interAudioInterrupt: audio.AudioInterrupt = {
2298  streamUsage:2,
2299  contentType:0,
2300  pauseWhenDucked:true
2301};
2302audioManager.off('interrupt', interAudioInterrupt, (InterruptAction: audio.InterruptAction) => {
2303  if (InterruptAction.actionType === 0) {
2304    console.info('An event to release the audio focus starts.');
2305    console.info(`Focus release event: ${InterruptAction} `);
2306  }
2307});
2308```
2309
2310## AudioVolumeManager<sup>9+</sup>
2311
2312Implements audio volume management. Before calling an API in **AudioVolumeManager**, you must use [getVolumeManager](#getvolumemanager9) to obtain an **AudioVolumeManager** instance.
2313
2314### getVolumeGroupInfos<sup>9+</sup>
2315
2316getVolumeGroupInfos(networkId: string, callback: AsyncCallback<VolumeGroupInfos\>\): void
2317
2318Obtains the volume groups. This API uses an asynchronous callback to return the result.
2319
2320**System API**: This is a system API.
2321
2322**System capability**: SystemCapability.Multimedia.Audio.Volume
2323
2324**Parameters**
2325
2326| Name    | Type                                                        | Mandatory| Description                |
2327| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
2328| networkId | string                                    | Yes  | Network ID of the device. The network ID of the local device is **audio.LOCAL_NETWORK_ID**.   |
2329| callback  | AsyncCallback&lt;[VolumeGroupInfos](#volumegroupinfos9)&gt; | Yes  | Callback used to return the volume group information array.|
2330
2331**Example**
2332```ts
2333import { BusinessError } from '@ohos.base';
2334audioVolumeManager.getVolumeGroupInfos(audio.LOCAL_NETWORK_ID, (err: BusinessError, value: audio.VolumeGroupInfos) => {
2335  if (err) {
2336    console.error(`Failed to obtain the volume group infos list. ${err}`);
2337    return;
2338  }
2339  console.info('Callback invoked to indicate that the volume group infos list is obtained.');
2340});
2341```
2342
2343### getVolumeGroupInfos<sup>9+</sup>
2344
2345getVolumeGroupInfos(networkId: string\): Promise<VolumeGroupInfos\>
2346
2347Obtains the volume groups. This API uses a promise to return the result.
2348
2349**System API**: This is a system API.
2350
2351**System capability**: SystemCapability.Multimedia.Audio.Volume
2352
2353**Parameters**
2354
2355| Name    | Type              | Mandatory| Description                |
2356| ---------- | ------------------| ---- | -------------------- |
2357| networkId | string             | Yes  | Network ID of the device. The network ID of the local device is **audio.LOCAL_NETWORK_ID**.  |
2358
2359**Return value**
2360
2361| Type               | Description                         |
2362| ------------------- | ----------------------------- |
2363| Promise&lt;[VolumeGroupInfos](#volumegroupinfos9)&gt; | Volume group information array.|
2364
2365**Example**
2366
2367```ts
2368async function getVolumeGroupInfos(){
2369  let volumegroupinfos: audio.VolumeGroupInfos = await audio.getAudioManager().getVolumeManager().getVolumeGroupInfos(audio.LOCAL_NETWORK_ID);
2370  console.info('Promise returned to indicate that the volumeGroup list is obtained.'+JSON.stringify(volumegroupinfos))
2371}
2372```
2373
2374### getVolumeGroupInfosSync<sup>10+</sup>
2375
2376getVolumeGroupInfosSync(networkId: string\): VolumeGroupInfos
2377
2378Obtains the volume groups. This API returns the result synchronously.
2379
2380**System API**: This is a system API.
2381
2382**System capability**: SystemCapability.Multimedia.Audio.Volume
2383
2384**Parameters**
2385
2386| Name    | Type              | Mandatory| Description                |
2387| ---------- | ------------------| ---- | -------------------- |
2388| networkId | string             | Yes  | Network ID of the device. The network ID of the local device is **audio.LOCAL_NETWORK_ID**.  |
2389
2390**Return value**
2391
2392| Type               | Description                         |
2393| ------------------- | ----------------------------- |
2394| [VolumeGroupInfos](#volumegroupinfos9) | Volume group information array.|
2395
2396**Error codes**
2397
2398For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
2399
2400| ID| Error Message|
2401| ------- | --------------------------------------------|
2402| 6800101 | invalid parameter error              |
2403
2404**Example**
2405
2406```ts
2407import { BusinessError } from '@ohos.base';
2408
2409try {
2410  let volumegroupinfos: audio.VolumeGroupInfos = audioVolumeManager.getVolumeGroupInfosSync(audio.LOCAL_NETWORK_ID);
2411  console.info(`Indicate that the volumeGroup list is obtained. ${JSON.stringify(volumegroupinfos)}`);
2412} catch (err) {
2413  let error = err as BusinessError;
2414  console.error(`Failed to obtain the volumeGroup list ${error}`);
2415}
2416```
2417
2418### getVolumeGroupManager<sup>9+</sup>
2419
2420getVolumeGroupManager(groupId: number, callback: AsyncCallback<AudioVolumeGroupManager\>\): void
2421
2422Obtains the volume group manager. This API uses an asynchronous callback to return the result.
2423
2424**System capability**: SystemCapability.Multimedia.Audio.Volume
2425
2426**Parameters**
2427
2428| Name    | Type                                                        | Mandatory| Description                |
2429| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
2430| groupId    | number                                    | Yes  | Volume group ID.    |
2431| callback   | AsyncCallback&lt;[AudioVolumeGroupManager](#audiovolumegroupmanager9)&gt; | Yes  | Callback used to return the volume group manager.|
2432
2433**Example**
2434
2435```ts
2436import { BusinessError } from '@ohos.base';
2437let groupid: number = audio.DEFAULT_VOLUME_GROUP_ID;
2438audioVolumeManager.getVolumeGroupManager(groupid, (err: BusinessError, value: audio.AudioVolumeGroupManager) => {
2439  if (err) {
2440    console.error(`Failed to obtain the volume group infos list. ${err}`);
2441    return;
2442  }
2443  console.info('Callback invoked to indicate that the volume group infos list is obtained.');
2444});
2445
2446```
2447
2448### getVolumeGroupManager<sup>9+</sup>
2449
2450getVolumeGroupManager(groupId: number\): Promise<AudioVolumeGroupManager\>
2451
2452Obtains the volume group manager. This API uses a promise to return the result.
2453
2454**System capability**: SystemCapability.Multimedia.Audio.Volume
2455
2456**Parameters**
2457
2458| Name    | Type                                     | Mandatory| Description             |
2459| ---------- | ---------------------------------------- | ---- | ---------------- |
2460| groupId    | number                                   | Yes  | Volume group ID.    |
2461
2462**Return value**
2463
2464| Type               | Description                         |
2465| ------------------- | ----------------------------- |
2466| Promise&lt; [AudioVolumeGroupManager](#audiovolumegroupmanager9) &gt; | Promise used to return the volume group manager.|
2467
2468**Example**
2469
2470```ts
2471import audio from '@ohos.multimedia.audio';
2472let groupid: number = audio.DEFAULT_VOLUME_GROUP_ID;
2473let audioVolumeGroupManager: audio.AudioVolumeGroupManager | undefined = undefined;
2474async function getVolumeGroupManager(){
2475  audioVolumeGroupManager = await audioVolumeManager.getVolumeGroupManager(groupid);
2476  console.info('Callback invoked to indicate that the volume group infos list is obtained.');
2477}
2478```
2479
2480### getVolumeGroupManagerSync<sup>10+</sup>
2481
2482getVolumeGroupManagerSync(groupId: number\): AudioVolumeGroupManager
2483
2484Obtains the volume group manager. This API returns the result synchronously.
2485
2486**System capability**: SystemCapability.Multimedia.Audio.Volume
2487
2488**Parameters**
2489
2490| Name    | Type                                     | Mandatory| Description             |
2491| ---------- | ---------------------------------------- | ---- | ---------------- |
2492| groupId    | number                                   | Yes  | Volume group ID.    |
2493
2494**Return value**
2495
2496| Type               | Description                         |
2497| ------------------- | ----------------------------- |
2498| [AudioVolumeGroupManager](#audiovolumegroupmanager9) | Volume group manager.|
2499
2500**Error codes**
2501
2502For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
2503
2504| ID| Error Message|
2505| ------- | --------------------------------------------|
2506| 6800101 | invalid parameter error              |
2507
2508**Example**
2509
2510```ts
2511import { BusinessError } from '@ohos.base';
2512
2513try {
2514  let audioVolumeGroupManager: audio.AudioVolumeGroupManager = audioVolumeManager.getVolumeGroupManagerSync(audio.DEFAULT_VOLUME_GROUP_ID);
2515  console.info(`Get audioVolumeGroupManager success.`);
2516} catch (err) {
2517  let error = err as BusinessError;
2518  console.error(`Failed to get audioVolumeGroupManager, error: ${error}`);
2519}
2520```
2521
2522### on('volumeChange')<sup>9+</sup>
2523
2524on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
2525
2526Subscribes to system volume change events. This API uses an asynchronous callback to return the result.
2527
2528**System capability**: SystemCapability.Multimedia.Audio.Volume
2529
2530**Parameters**
2531
2532| Name  | Type                                  | Mandatory| Description                                                        |
2533| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
2534| type     | string                                 | Yes  | Event type. The event **'volumeChange'** is triggered when the system volume is changed.|
2535| callback | Callback<[VolumeEvent](#volumeevent9)> | Yes  | Callback used to return the result.                                                  |
2536
2537**Error codes**
2538
2539For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
2540
2541| ID| Error Message|
2542| ------- | --------------------------------------------|
2543| 6800101 | if input parameter value error              |
2544
2545**Example**
2546
2547```ts
2548audioVolumeManager.on('volumeChange', (volumeEvent: audio.VolumeEvent) => {
2549  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
2550  console.info(`Volume level: ${volumeEvent.volume} `);
2551  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
2552});
2553```
2554
2555## AudioVolumeGroupManager<sup>9+</sup>
2556
2557Manages the volume of an audio group. Before calling any API in **AudioVolumeGroupManager**, you must use [getVolumeGroupManager](#getvolumegroupmanager9) to obtain an **AudioVolumeGroupManager** instance.
2558
2559### setVolume<sup>9+</sup>
2560
2561setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&lt;void&gt;): void
2562
2563Sets the volume for a stream. This API uses an asynchronous callback to return the result.
2564
2565**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
2566
2567This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
2568
2569**System API**: This is a system API.
2570
2571**System capability**: SystemCapability.Multimedia.Audio.Volume
2572
2573**Parameters**
2574
2575| Name    | Type                               | Mandatory| Description                                                    |
2576| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
2577| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
2578| volume     | number                              | Yes  | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
2579| callback   | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result.                                  |
2580
2581**Example**
2582
2583```ts
2584import { BusinessError } from '@ohos.base';
2585audioVolumeGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err: BusinessError) => {
2586  if (err) {
2587    console.error(`Failed to set the volume. ${err}`);
2588    return;
2589  }
2590  console.info('Callback invoked to indicate a successful volume setting.');
2591});
2592```
2593
2594### setVolume<sup>9+</sup>
2595
2596setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
2597
2598Sets the volume for a stream. This API uses a promise to return the result.
2599
2600**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
2601
2602This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
2603
2604**System API**: This is a system API.
2605
2606**System capability**: SystemCapability.Multimedia.Audio.Volume
2607
2608**Parameters**
2609
2610| Name    | Type                               | Mandatory| Description                                                    |
2611| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
2612| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
2613| volume     | number                              | Yes  | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
2614
2615**Return value**
2616
2617| Type               | Description                         |
2618| ------------------- | ----------------------------- |
2619| Promise&lt;void&gt; | Promise used to return the result.|
2620
2621**Example**
2622
2623```ts
2624audioVolumeGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
2625  console.info('Promise returned to indicate a successful volume setting.');
2626});
2627```
2628
2629### getVolume<sup>9+</sup>
2630
2631getVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
2632
2633Obtains the volume of a stream. This API uses an asynchronous callback to return the result.
2634
2635**System capability**: SystemCapability.Multimedia.Audio.Volume
2636
2637**Parameters**
2638
2639| Name    | Type                               | Mandatory| Description              |
2640| ---------- | ----------------------------------- | ---- | ------------------ |
2641| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
2642| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the volume.|
2643
2644**Example**
2645
2646```ts
2647import { BusinessError } from '@ohos.base';
2648audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
2649  if (err) {
2650    console.error(`Failed to obtain the volume. ${err}`);
2651    return;
2652  }
2653  console.info('Callback invoked to indicate that the volume is obtained.');
2654});
2655```
2656
2657### getVolume<sup>9+</sup>
2658
2659getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
2660
2661Obtains the volume of a stream. This API uses a promise to return the result.
2662
2663**System capability**: SystemCapability.Multimedia.Audio.Volume
2664
2665**Parameters**
2666
2667| Name    | Type                               | Mandatory| Description        |
2668| ---------- | ----------------------------------- | ---- | ------------ |
2669| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
2670
2671**Return value**
2672
2673| Type                 | Description                     |
2674| --------------------- | ------------------------- |
2675| Promise&lt;number&gt; | Promise used to return the volume.|
2676
2677**Example**
2678
2679```ts
2680audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA).then((value: number) => {
2681  console.info(`Promise returned to indicate that the volume is obtained ${value}.`);
2682});
2683```
2684
2685### getVolumeSync<sup>10+</sup>
2686
2687getVolumeSync(volumeType: AudioVolumeType): number;
2688
2689Obtains the volume of a stream. This API returns the result synchronously.
2690
2691**System capability**: SystemCapability.Multimedia.Audio.Volume
2692
2693**Parameters**
2694
2695| Name    | Type                               | Mandatory| Description        |
2696| ---------- | ----------------------------------- | ---- | ------------ |
2697| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
2698
2699**Return value**
2700
2701| Type                 | Description                     |
2702| --------------------- | ------------------------- |
2703| number | Volume of the stream.|
2704
2705**Error codes**
2706
2707For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
2708
2709| ID| Error Message|
2710| ------- | --------------------------------------------|
2711| 6800101 | invalid parameter error              |
2712
2713**Example**
2714
2715```ts
2716import { BusinessError } from '@ohos.base';
2717
2718try {
2719  let value: number = audioVolumeGroupManager.getVolumeSync(audio.AudioVolumeType.MEDIA);
2720  console.info(`Indicate that the volume is obtained ${value}.`);
2721} catch (err) {
2722  let error = err as BusinessError;
2723  console.info(`Failed to obtain the volume, error ${error}.`);
2724}
2725```
2726
2727### getMinVolume<sup>9+</sup>
2728
2729getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
2730
2731Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the result.
2732
2733**System capability**: SystemCapability.Multimedia.Audio.Volume
2734
2735**Parameters**
2736
2737| Name    | Type                               | Mandatory| Description              |
2738| ---------- | ----------------------------------- | ---- | ------------------ |
2739| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
2740| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the minimum volume.|
2741
2742**Example**
2743
2744```ts
2745import { BusinessError } from '@ohos.base';
2746audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
2747  if (err) {
2748    console.error(`Failed to obtain the minimum volume. ${err}`);
2749    return;
2750  }
2751  console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
2752});
2753```
2754
2755### getMinVolume<sup>9+</sup>
2756
2757getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
2758
2759Obtains the minimum volume allowed for a stream. This API uses a promise to return the result.
2760
2761**System capability**: SystemCapability.Multimedia.Audio.Volume
2762
2763**Parameters**
2764
2765| Name    | Type                               | Mandatory| Description        |
2766| ---------- | ----------------------------------- | ---- | ------------ |
2767| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
2768
2769**Return value**
2770
2771| Type                 | Description                     |
2772| --------------------- | ------------------------- |
2773| Promise&lt;number&gt; | Promise used to return the minimum volume.|
2774
2775**Example**
2776
2777```ts
2778audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value: number) => {
2779  console.info(`Promised returned to indicate that the minimum volume is obtained ${value}.`);
2780});
2781```
2782
2783### getMinVolumeSync<sup>10+</sup>
2784
2785getMinVolumeSync(volumeType: AudioVolumeType): number;
2786
2787Obtains the minimum volume allowed for a stream. This API returns the result synchronously.
2788
2789**System capability**: SystemCapability.Multimedia.Audio.Volume
2790
2791**Parameters**
2792
2793| Name    | Type                               | Mandatory| Description        |
2794| ---------- | ----------------------------------- | ---- | ------------ |
2795| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
2796
2797**Return value**
2798
2799| Type                 | Description                     |
2800| --------------------- | ------------------------- |
2801| number | Minimum volume.|
2802
2803**Error codes**
2804
2805For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
2806
2807| ID| Error Message|
2808| ------- | --------------------------------------------|
2809| 6800101 | invalid parameter error              |
2810
2811**Example**
2812
2813```ts
2814import { BusinessError } from '@ohos.base';
2815
2816try {
2817  let value: number = audioVolumeGroupManager.getMinVolumeSync(audio.AudioVolumeType.MEDIA);
2818  console.info(`Indicate that the minimum volume is obtained ${value}.`);
2819} catch (err) {
2820  let error = err as BusinessError;
2821  console.error(`Failed to obtain the minimum volume, error ${error}.`);
2822}
2823```
2824
2825### getMaxVolume<sup>9+</sup>
2826
2827getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
2828
2829Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the result.
2830
2831**System capability**: SystemCapability.Multimedia.Audio.Volume
2832
2833**Parameters**
2834
2835| Name    | Type                               | Mandatory| Description                  |
2836| ---------- | ----------------------------------- | ---- | ---------------------- |
2837| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.          |
2838| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the maximum volume.|
2839
2840**Example**
2841
2842```ts
2843import { BusinessError } from '@ohos.base';
2844audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
2845  if (err) {
2846    console.error(`Failed to obtain the maximum volume. ${err}`);
2847    return;
2848  }
2849  console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`);
2850});
2851```
2852
2853### getMaxVolume<sup>9+</sup>
2854
2855getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
2856
2857Obtains the maximum volume allowed for a stream. This API uses a promise to return the result.
2858
2859**System capability**: SystemCapability.Multimedia.Audio.Volume
2860
2861**Parameters**
2862
2863| Name    | Type                               | Mandatory| Description        |
2864| ---------- | ----------------------------------- | ---- | ------------ |
2865| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
2866
2867**Return value**
2868
2869| Type                 | Description                         |
2870| --------------------- | ----------------------------- |
2871| Promise&lt;number&gt; | Promise used to return the maximum volume.|
2872
2873**Example**
2874
2875```ts
2876audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data: number) => {
2877  console.info('Promised returned to indicate that the maximum volume is obtained.');
2878});
2879```
2880
2881### getMaxVolumeSync<sup>10+</sup>
2882
2883getMaxVolumeSync(volumeType: AudioVolumeType): number;
2884
2885Obtains the maximum volume allowed for a stream. This API returns the result synchronously.
2886
2887**System capability**: SystemCapability.Multimedia.Audio.Volume
2888
2889**Parameters**
2890
2891| Name    | Type                               | Mandatory| Description        |
2892| ---------- | ----------------------------------- | ---- | ------------ |
2893| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
2894
2895**Return value**
2896
2897| Type                 | Description                         |
2898| --------------------- | ----------------------------- |
2899| number | Maximum volume.|
2900
2901**Error codes**
2902
2903For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
2904
2905| ID| Error Message|
2906| ------- | --------------------------------------------|
2907| 6800101 | invalid parameter error              |
2908
2909**Example**
2910
2911```ts
2912import { BusinessError } from '@ohos.base';
2913
2914try {
2915  let value: number = audioVolumeGroupManager.getMaxVolumeSync(audio.AudioVolumeType.MEDIA);
2916  console.info(`Indicate that the maximum volume is obtained. ${value}`);
2917} catch (err) {
2918  let error = err as BusinessError;
2919  console.error(`Failed to obtain the maximum volume, error ${error}.`);
2920}
2921```
2922
2923### mute<sup>9+</sup>
2924
2925mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
2926
2927Mutes or unmutes a stream. This API uses an asynchronous callback to return the result.
2928
2929**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
2930
2931This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
2932
2933**System API**: This is a system API.
2934
2935**System capability**: SystemCapability.Multimedia.Audio.Volume
2936
2937**Parameters**
2938
2939| Name    | Type                               | Mandatory| Description                                 |
2940| ---------- | ----------------------------------- | ---- | ------------------------------------- |
2941| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                         |
2942| mute       | boolean                             | Yes  | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.|
2943| callback   | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result.               |
2944
2945**Example**
2946
2947```ts
2948import { BusinessError } from '@ohos.base';
2949audioVolumeGroupManager.mute(audio.AudioVolumeType.MEDIA, true, (err: BusinessError) => {
2950  if (err) {
2951    console.error(`Failed to mute the stream. ${err}`);
2952    return;
2953  }
2954  console.info('Callback invoked to indicate that the stream is muted.');
2955});
2956```
2957
2958### mute<sup>9+</sup>
2959
2960mute(volumeType: AudioVolumeType, mute: boolean): Promise&lt;void&gt;
2961
2962Mutes or unmutes a stream. This API uses a promise to return the result.
2963
2964**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
2965
2966This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
2967
2968**System API**: This is a system API.
2969
2970**System capability**: SystemCapability.Multimedia.Audio.Volume
2971
2972**Parameters**
2973
2974| Name    | Type                               | Mandatory| Description                                 |
2975| ---------- | ----------------------------------- | ---- | ------------------------------------- |
2976| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                         |
2977| mute       | boolean                             | Yes  | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.|
2978
2979**Return value**
2980
2981| Type               | Description                         |
2982| ------------------- | ----------------------------- |
2983| Promise&lt;void&gt; | Promise used to return the result.|
2984
2985**Example**
2986
2987```ts
2988audioVolumeGroupManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
2989  console.info('Promise returned to indicate that the stream is muted.');
2990});
2991```
2992
2993### isMute<sup>9+</sup>
2994
2995isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
2996
2997Checks whether a stream is muted. This API uses an asynchronous callback to return the result.
2998
2999**System capability**: SystemCapability.Multimedia.Audio.Volume
3000
3001**Parameters**
3002
3003| Name    | Type                               | Mandatory| Description                                           |
3004| ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
3005| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                   |
3006| callback   | AsyncCallback&lt;boolean&gt;        | Yes  | Callback used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite.|
3007
3008**Example**
3009
3010```ts
3011import { BusinessError } from '@ohos.base';
3012audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => {
3013  if (err) {
3014    console.error(`Failed to obtain the mute status. ${err}`);
3015    return;
3016  }
3017  console.info(`Callback invoked to indicate that the mute status of the stream is obtained ${value}.`);
3018});
3019```
3020
3021### isMute<sup>9+</sup>
3022
3023isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
3024
3025Checks whether a stream is muted. This API uses a promise to return the result.
3026
3027**System capability**: SystemCapability.Multimedia.Audio.Volume
3028
3029**Parameters**
3030
3031| Name    | Type                               | Mandatory| Description        |
3032| ---------- | ----------------------------------- | ---- | ------------ |
3033| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
3034
3035**Return value**
3036
3037| Type                  | Description                                                  |
3038| ---------------------- | ------------------------------------------------------ |
3039| 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.|
3040
3041**Example**
3042
3043```ts
3044audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA).then((value: boolean) => {
3045  console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`);
3046});
3047```
3048
3049### isMuteSync<sup>10+</sup>
3050
3051isMuteSync(volumeType: AudioVolumeType): boolean
3052
3053Checks whether a stream is muted. This API returns the result synchronously.
3054
3055**System capability**: SystemCapability.Multimedia.Audio.Volume
3056
3057**Parameters**
3058
3059| Name    | Type                               | Mandatory| Description        |
3060| ---------- | ----------------------------------- | ---- | ------------ |
3061| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
3062
3063**Return value**
3064
3065| Type                  | Description                                                  |
3066| ---------------------- | ------------------------------------------------------ |
3067| boolean | Returns **true** if the stream is muted; returns **false** otherwise.|
3068
3069**Error codes**
3070
3071For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3072
3073| ID| Error Message|
3074| ------- | --------------------------------------------|
3075| 6800101 | invalid parameter error              |
3076
3077**Example**
3078
3079```ts
3080import { BusinessError } from '@ohos.base';
3081
3082try {
3083  let value: boolean = audioVolumeGroupManager.isMuteSync(audio.AudioVolumeType.MEDIA);
3084  console.info(`Indicate that the mute status of the stream is obtained ${value}.`);
3085} catch (err) {
3086  let error = err as BusinessError;
3087  console.error(`Failed to obtain the mute status of the stream, error ${error}.`);
3088}
3089```
3090
3091### setRingerMode<sup>9+</sup>
3092
3093setRingerMode(mode: AudioRingMode, callback: AsyncCallback&lt;void&gt;): void
3094
3095Sets the ringer mode. This API uses an asynchronous callback to return the result.
3096
3097**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
3098
3099This permission is required only for muting or unmuting the ringer.
3100
3101**System API**: This is a system API.
3102
3103**System capability**: SystemCapability.Multimedia.Audio.Volume
3104
3105**Parameters**
3106
3107| Name  | Type                           | Mandatory| Description                    |
3108| -------- | ------------------------------- | ---- | ------------------------ |
3109| mode     | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.          |
3110| callback | AsyncCallback&lt;void&gt;       | Yes  | Callback used to return the result.|
3111
3112**Example**
3113
3114```ts
3115import { BusinessError } from '@ohos.base';
3116audioVolumeGroupManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err: BusinessError) => {
3117  if (err) {
3118    console.error(`Failed to set the ringer mode.​ ${err}`);
3119    return;
3120  }
3121  console.info('Callback invoked to indicate a successful setting of the ringer mode.');
3122});
3123```
3124
3125### setRingerMode<sup>9+</sup>
3126
3127setRingerMode(mode: AudioRingMode): Promise&lt;void&gt;
3128
3129Sets the ringer mode. This API uses a promise to return the result.
3130
3131**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
3132
3133This permission is required only for muting or unmuting the ringer.
3134
3135**System API**: This is a system API.
3136
3137**System capability**: SystemCapability.Multimedia.Audio.Volume
3138
3139**Parameters**
3140
3141| Name| Type                           | Mandatory| Description          |
3142| ------ | ------------------------------- | ---- | -------------- |
3143| mode   | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.|
3144
3145**Return value**
3146
3147| Type               | Description                           |
3148| ------------------- | ------------------------------- |
3149| Promise&lt;void&gt; | Promise used to return the result.|
3150
3151**Example**
3152
3153```ts
3154audioVolumeGroupManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
3155  console.info('Promise returned to indicate a successful setting of the ringer mode.');
3156});
3157```
3158
3159### getRingerMode<sup>9+</sup>
3160
3161getRingerMode(callback: AsyncCallback&lt;AudioRingMode&gt;): void
3162
3163Obtains the ringer mode. This API uses an asynchronous callback to return the result.
3164
3165**System capability**: SystemCapability.Multimedia.Audio.Volume
3166
3167**Parameters**
3168
3169| Name  | Type                                                | Mandatory| Description                    |
3170| -------- | ---------------------------------------------------- | ---- | ------------------------ |
3171| callback | AsyncCallback&lt;[AudioRingMode](#audioringmode)&gt; | Yes  | Callback used to return the ringer mode.|
3172
3173**Example**
3174
3175```ts
3176import { BusinessError } from '@ohos.base';
3177audioVolumeGroupManager.getRingerMode((err: BusinessError, value: audio.AudioRingMode) => {
3178  if (err) {
3179    console.error(`Failed to obtain the ringer mode.​ ${err}`);
3180    return;
3181  }
3182  console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`);
3183});
3184```
3185
3186### getRingerMode<sup>9+</sup>
3187
3188getRingerMode(): Promise&lt;AudioRingMode&gt;
3189
3190Obtains the ringer mode. This API uses a promise to return the result.
3191
3192**System capability**: SystemCapability.Multimedia.Audio.Volume
3193
3194**Return value**
3195
3196| Type                                          | Description                           |
3197| ---------------------------------------------- | ------------------------------- |
3198| Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise used to return the ringer mode.|
3199
3200**Example**
3201
3202```ts
3203audioVolumeGroupManager.getRingerMode().then((value: audio.AudioRingMode) => {
3204  console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`);
3205});
3206```
3207
3208### getRingerModeSync<sup>10+</sup>
3209
3210getRingerModeSync(): AudioRingMode
3211
3212Obtains the ringer mode. This API returns the result synchronously.
3213
3214**System capability**: SystemCapability.Multimedia.Audio.Volume
3215
3216**Return value**
3217
3218| Type                                          | Description                           |
3219| ---------------------------------------------- | ------------------------------- |
3220| [AudioRingMode](#audioringmode) | Ringer mode.|
3221
3222**Example**
3223
3224```ts
3225import { BusinessError } from '@ohos.base';
3226
3227try {
3228  let value: audio.AudioRingMode = audioVolumeGroupManager.getRingerModeSync();
3229  console.info(`Indicate that the ringer mode is obtained ${value}.`);
3230} catch (err) {
3231  let error = err as BusinessError;
3232  console.error(`Failed to obtain the ringer mode, error ${error}.`);
3233}
3234```
3235
3236### on('ringerModeChange')<sup>9+</sup>
3237
3238on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void
3239
3240Subscribes to ringer mode change events.
3241
3242**System capability**: SystemCapability.Multimedia.Audio.Volume
3243
3244**Parameters**
3245
3246| Name  | Type                                     | Mandatory| Description                                                        |
3247| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
3248| type     | string                                    | Yes  | Event type. The event **'ringerModeChange'** is triggered when the ringer mode is changed.|
3249| callback | Callback<[AudioRingMode](#audioringmode)> | Yes  | Callback used to return the result.                                                  |
3250
3251**Error codes**
3252
3253For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3254
3255| ID| Error Message|
3256| ------- | --------------------------------------------|
3257| 6800101 | if input parameter value error              |
3258
3259**Example**
3260
3261```ts
3262audioVolumeGroupManager.on('ringerModeChange', (ringerMode: audio.AudioRingMode) => {
3263  console.info(`Updated ringermode: ${ringerMode}`);
3264});
3265```
3266### setMicrophoneMute<sup>9+</sup>
3267
3268setMicrophoneMute(mute: boolean, callback: AsyncCallback&lt;void&gt;): void
3269
3270Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result.
3271
3272**Required permissions**: ohos.permission.MANAGE_AUDIO_CONFIG
3273
3274**System capability**: SystemCapability.Multimedia.Audio.Volume
3275
3276**Parameters**
3277
3278| Name  | Type                     | Mandatory| Description                                         |
3279| -------- | ------------------------- | ---- | --------------------------------------------- |
3280| mute     | boolean                   | Yes  | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
3281| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.                     |
3282
3283**Example**
3284
3285```ts
3286import { BusinessError } from '@ohos.base';
3287audioVolumeGroupManager.setMicrophoneMute(true, (err: BusinessError) => {
3288  if (err) {
3289    console.error(`Failed to mute the microphone. ${err}`);
3290    return;
3291  }
3292  console.info('Callback invoked to indicate that the microphone is muted.');
3293});
3294```
3295
3296### setMicrophoneMute<sup>9+</sup>
3297
3298setMicrophoneMute(mute: boolean): Promise&lt;void&gt;
3299
3300Mutes or unmutes the microphone. This API uses a promise to return the result.
3301
3302**Required permissions**: ohos.permission.MANAGE_AUDIO_CONFIG
3303
3304**System capability**: SystemCapability.Multimedia.Audio.Volume
3305
3306**Parameters**
3307
3308| Name| Type   | Mandatory| Description                                         |
3309| ------ | ------- | ---- | --------------------------------------------- |
3310| mute   | boolean | Yes  | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
3311
3312**Return value**
3313
3314| Type               | Description                           |
3315| ------------------- | ------------------------------- |
3316| Promise&lt;void&gt; | Promise used to return the result.|
3317
3318**Example**
3319
3320```ts
3321audioVolumeGroupManager.setMicrophoneMute(true).then(() => {
3322  console.info('Promise returned to indicate that the microphone is muted.');
3323});
3324```
3325
3326### isMicrophoneMute<sup>9+</sup>
3327
3328isMicrophoneMute(callback: AsyncCallback&lt;boolean&gt;): void
3329
3330Checks whether the microphone is muted. This API uses an asynchronous callback to return the result.
3331
3332**System capability**: SystemCapability.Multimedia.Audio.Volume
3333
3334**Parameters**
3335
3336| Name  | Type                        | Mandatory| Description                                                   |
3337| -------- | ---------------------------- | ---- | ------------------------------------------------------- |
3338| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.|
3339
3340**Example**
3341
3342```ts
3343import { BusinessError } from '@ohos.base';
3344audioVolumeGroupManager.isMicrophoneMute((err: BusinessError, value: boolean) => {
3345  if (err) {
3346    console.error(`Failed to obtain the mute status of the microphone. ${err}`);
3347    return;
3348  }
3349  console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`);
3350});
3351```
3352
3353### isMicrophoneMute<sup>9+</sup>
3354
3355isMicrophoneMute(): Promise&lt;boolean&gt;
3356
3357Checks whether the microphone is muted. This API uses a promise to return the result.
3358
3359**System capability**: SystemCapability.Multimedia.Audio.Volume
3360
3361**Return value**
3362
3363| Type                  | Description                                                        |
3364| ---------------------- | ------------------------------------------------------------ |
3365| 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.|
3366
3367**Example**
3368
3369```ts
3370audioVolumeGroupManager.isMicrophoneMute().then((value: boolean) => {
3371  console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`);
3372});
3373```
3374
3375### isMicrophoneMuteSync<sup>10+</sup>
3376
3377isMicrophoneMuteSync(): boolean
3378
3379Checks whether the microphone is muted. This API returns the result synchronously.
3380
3381**System capability**: SystemCapability.Multimedia.Audio.Volume
3382
3383**Return value**
3384
3385| Type                  | Description                                                        |
3386| ---------------------- | ------------------------------------------------------------ |
3387| boolean | Returns **true** if the microphone is muted; returns **false** otherwise.|
3388
3389**Example**
3390
3391```ts
3392import { BusinessError } from '@ohos.base';
3393
3394try {
3395  let value: boolean = audioVolumeGroupManager.isMicrophoneMuteSync();
3396  console.info(`Indicate that the mute status of the microphone is obtained ${value}.`);
3397} catch (err) {
3398  let error = err as BusinessError;
3399  console.error(`Failed to obtain the mute status of the microphone, error ${error}.`);
3400}
3401```
3402
3403### on('micStateChange')<sup>9+</sup>
3404
3405on(type: 'micStateChange', callback: Callback&lt;MicStateChangeEvent&gt;): void
3406
3407Subscribes to system microphone state change events.
3408
3409Currently, 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.
3410
3411**System capability**: SystemCapability.Multimedia.Audio.Volume
3412
3413**Parameters**
3414
3415| Name  | Type                                  | Mandatory| Description                                                        |
3416| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
3417| type     | string                                 | Yes  | Event type. The event **'micStateChange'** is triggered when the system microphone state is changed.|
3418| callback | Callback<[MicStateChangeEvent](#micstatechangeevent9)> | Yes  | Callback used to return the changed microphone state.                                                  |
3419
3420**Error codes**
3421
3422For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3423
3424| ID| Error Message|
3425| ------- | --------------------------------------------|
3426| 6800101 | if input parameter value error              |
3427
3428**Example**
3429
3430```ts
3431audioVolumeGroupManager.on('micStateChange', (micStateChange: audio.MicStateChangeEvent) => {
3432  console.info(`Current microphone status is: ${micStateChange.mute} `);
3433});
3434```
3435
3436### isVolumeUnadjustable<sup>10+</sup>
3437
3438isVolumeUnadjustable(): boolean
3439
3440Checks 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.
3441
3442**System capability**: SystemCapability.Multimedia.Audio.Volume
3443
3444**Return value**
3445
3446| Type                  | Description                                                  |
3447| ---------------------- | ------------------------------------------------------ |
3448| 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.|
3449
3450**Example**
3451
3452```ts
3453let volumeAdjustSwitch: boolean = audioVolumeGroupManager.isVolumeUnadjustable();
3454console.info(`Whether it is volume unadjustable: ${volumeAdjustSwitch}.`);
3455```
3456
3457### adjustVolumeByStep<sup>10+</sup>
3458
3459adjustVolumeByStep(adjustType: VolumeAdjustType, callback: AsyncCallback&lt;void&gt;): void
3460
3461Adjusts the volume of the stream with the highest priority by step. This API uses an asynchronous callback to return the result.
3462
3463**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
3464
3465This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
3466
3467**System API**: This is a system API.
3468
3469**System capability**: SystemCapability.Multimedia.Audio.Volume
3470
3471**Parameters**
3472
3473| Name    | Type                               | Mandatory| Description                                                    |
3474| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3475| adjustType | [VolumeAdjustType](#volumeadjusttype10) | Yes  | Volume adjustment type.                                            |
3476| callback   | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result.                                  |
3477
3478**Error codes**
3479
3480For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3481
3482| ID| Error Message|
3483| ------- | --------------------------------------------|
3484| 6800101 | Invalid parameter error. Return by callback.                     |
3485| 6800301 | System error. Return by callback.                                |
3486
3487**Example**
3488
3489```ts
3490import { BusinessError } from '@ohos.base';
3491audioVolumeGroupManager.adjustVolumeByStep(audio.VolumeAdjustType.VOLUME_UP, (err: BusinessError) => {
3492  if (err) {
3493    console.error(`Failed to adjust the volume by step. ${err}`);
3494    return;
3495  } else {
3496    console.info('Success to adjust the volume by step.');
3497  }
3498});
3499```
3500### adjustVolumeByStep<sup>10+</sup>
3501
3502adjustVolumeByStep(adjustType: VolumeAdjustType): Promise&lt;void&gt;
3503
3504Adjusts the volume of the stream with the highest priority by step. This API uses a promise to return the result.
3505
3506**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
3507
3508This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
3509
3510**System API**: This is a system API.
3511
3512**System capability**: SystemCapability.Multimedia.Audio.Volume
3513
3514**Parameters**
3515
3516| Name    | Type                               | Mandatory| Description                                                    |
3517| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3518| adjustType | [VolumeAdjustType](#volumeadjusttype10) | Yes  | Volume adjustment type.                                            |
3519
3520**Return value**
3521
3522| Type               | Description                         |
3523| ------------------- | ----------------------------- |
3524| Promise&lt;void&gt; | Promise used to return the result.|
3525
3526**Error codes**
3527
3528For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3529
3530| ID| Error Message|
3531| ------- | --------------------------------------------|
3532| 6800101 | Invalid parameter error. Return by promise.                     |
3533| 6800301 | System error. Return by promise.                                |
3534
3535**Example**
3536
3537```ts
3538import { BusinessError } from '@ohos.base';
3539audioVolumeGroupManager.adjustVolumeByStep(audio.VolumeAdjustType.VOLUME_UP).then(() => {
3540  console.info('Success to adjust the volume by step.');
3541}).catch((error: BusinessError) => {
3542  console.error('Fail to adjust the volume by step.');
3543});
3544```
3545
3546### adjustSystemVolumeByStep<sup>10+</sup>
3547
3548adjustSystemVolumeByStep(volumeType: AudioVolumeType, adjustType: VolumeAdjustType, callback: AsyncCallback&lt;void&gt;): void
3549
3550Adjusts the volume of a stream by step. This API uses an asynchronous callback to return the result.
3551
3552**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
3553
3554This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
3555
3556**System API**: This is a system API.
3557
3558**System capability**: SystemCapability.Multimedia.Audio.Volume
3559
3560**Parameters**
3561
3562| Name    | Type                               | Mandatory| Description                                                    |
3563| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3564| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
3565| adjustType | [VolumeAdjustType](#volumeadjusttype10) | Yes  | Volume adjustment type.                                      |
3566| callback   | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result.                                  |
3567
3568**Error codes**
3569
3570For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3571
3572| ID| Error Message|
3573| ------- | --------------------------------------------|
3574| 6800101 | Invalid parameter error. Return by callback.                     |
3575| 6800301 | System error. Return by callback.                                |
3576
3577**Example**
3578
3579```ts
3580import { BusinessError } from '@ohos.base';
3581audioVolumeGroupManager.adjustSystemVolumeByStep(audio.AudioVolumeType.MEDIA, audio.VolumeAdjustType.VOLUME_UP, (err: BusinessError) => {
3582  if (err) {
3583    console.error(`Failed to adjust the system volume by step ${err}`);
3584  } else {
3585    console.info('Success to adjust the system volume by step.');
3586  }
3587});
3588```
3589### adjustSystemVolumeByStep<sup>10+</sup>
3590
3591adjustSystemVolumeByStep(volumeType: AudioVolumeType, adjustType: VolumeAdjustType): Promise&lt;void&gt;
3592
3593Adjusts the volume of a stream by step. This API uses a promise to return the result.
3594
3595**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
3596
3597This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
3598
3599**System API**: This is a system API.
3600
3601**System capability**: SystemCapability.Multimedia.Audio.Volume
3602
3603**Parameters**
3604
3605| Name    | Type                               | Mandatory| Description                                                    |
3606| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3607| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
3608| adjustType | [VolumeAdjustType](#volumeadjusttype10) | Yes  | Volume adjustment type.                                            |
3609
3610**Return value**
3611
3612| Type               | Description                         |
3613| ------------------- | ----------------------------- |
3614| Promise&lt;void&gt; | Promise used to return the result.|
3615
3616**Error codes**
3617
3618For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3619
3620| ID| Error Message|
3621| ------- | --------------------------------------------|
3622| 6800101 | Invalid parameter error. Return by promise.                     |
3623| 6800301 | System error. Return by promise.                                |
3624
3625**Example**
3626
3627```ts
3628import { BusinessError } from '@ohos.base';
3629audioVolumeGroupManager.adjustSystemVolumeByStep(audio.AudioVolumeType.MEDIA, audio.VolumeAdjustType.VOLUME_UP).then(() => {
3630  console.info('Success to adjust the system volume by step.');
3631}).catch((error: BusinessError) => {
3632  console.error('Fail to adjust the system volume by step.');
3633});
3634```
3635
3636### getSystemVolumeInDb<sup>10+</sup>
3637
3638getSystemVolumeInDb(volumeType: AudioVolumeType, volumeLevel: number, device: DeviceType, callback: AsyncCallback&lt;number&gt;): void
3639
3640Obtains the volume gain. This API uses an asynchronous callback to return the result.
3641
3642**System capability**: SystemCapability.Multimedia.Audio.Volume
3643
3644**Parameters**
3645
3646| Name    | Type                               | Mandatory| Description                                                    |
3647| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3648| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
3649| volumeLevel | number                         | Yes  | Volume level.                                              |
3650| device     | [DeviceType](#devicetype)           | Yes  | Device type.                                              |
3651| callback   | AsyncCallback&lt;number&gt;           | Yes  | Callback used to return the volume gain (in dB).                             |
3652
3653**Error codes**
3654
3655For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3656
3657| ID| Error Message|
3658| ------- | --------------------------------------------|
3659| 6800101 | Invalid parameter error. Return by callback.                     |
3660| 6800301 | System error. Return by callback.                                |
3661
3662**Example**
3663
3664```ts
3665import { BusinessError } from '@ohos.base';
3666audioVolumeGroupManager.getSystemVolumeInDb(audio.AudioVolumeType.MEDIA, 3, audio.DeviceType.SPEAKER, (err: BusinessError, dB: number) => {
3667  if (err) {
3668    console.error(`Failed to get the volume DB. ${err}`);
3669  } else {
3670    console.info(`Success to get the volume DB. ${dB}`);
3671  }
3672});
3673```
3674### getSystemVolumeInDb<sup>10+</sup>
3675
3676getSystemVolumeInDb(volumeType: AudioVolumeType, volumeLevel: number, device: DeviceType): Promise&lt;number&gt;
3677
3678Obtains the volume gain. This API uses a promise to return the result.
3679
3680**System capability**: SystemCapability.Multimedia.Audio.Volume
3681
3682**Parameters**
3683
3684| Name    | Type                               | Mandatory| Description                                                    |
3685| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3686| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
3687| volumeLevel | number                              | Yes  | Volume level.                                            |
3688| device     | [DeviceType](#devicetype)           | Yes  | Device type.                                              |
3689
3690**Return value**
3691
3692| Type                 | Description                              |
3693| --------------------- | ---------------------------------- |
3694| Promise&lt;number&gt; | Promise used to return the volume gain (in dB).|
3695
3696**Error codes**
3697
3698For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3699
3700| ID| Error Message|
3701| ------- | --------------------------------------------|
3702| 6800101 | Invalid parameter error. Return by promise.                     |
3703| 6800301 | System error. Return by promise.                                |
3704
3705**Example**
3706
3707```ts
3708import { BusinessError } from '@ohos.base';
3709audioVolumeGroupManager.getSystemVolumeInDb(audio.AudioVolumeType.MEDIA, 3, audio.DeviceType.SPEAKER).then((value: number) => {
3710  console.info(`Success to get the volume DB. ${value}`);
3711}).catch((error: BusinessError) => {
3712  console.error(`Fail to adjust the system volume by step. ${error}`);
3713});
3714```
3715
3716### getSystemVolumeInDbSync<sup>10+</sup>
3717
3718getSystemVolumeInDbSync(volumeType: AudioVolumeType, volumeLevel: number, device: DeviceType): number
3719
3720Obtains the volume gain. This API returns the result synchronously.
3721
3722**System capability**: SystemCapability.Multimedia.Audio.Volume
3723
3724**Parameters**
3725
3726| Name    | Type                               | Mandatory| Description                                                    |
3727| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3728| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
3729| volumeLevel | number                              | Yes  | Volume level.                                            |
3730| device     | [DeviceType](#devicetype)           | Yes  | Device type.                                              |
3731
3732**Return value**
3733
3734| Type                 | Description                              |
3735| --------------------- | ---------------------------------- |
3736| number | Volume gain (in dB).|
3737
3738**Error codes**
3739
3740For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
3741
3742| ID| Error Message|
3743| ------- | --------------------------------------------|
3744| 6800101 | invalid parameter error                     |
3745
3746**Example**
3747
3748```ts
3749import { BusinessError } from '@ohos.base';
3750
3751try {
3752  let value: number = audioVolumeGroupManager.getSystemVolumeInDbSync(audio.AudioVolumeType.MEDIA, 3, audio.DeviceType.SPEAKER);
3753  console.info(`Success to get the volume DB. ${value}`);
3754} catch (err) {
3755  let error = err as BusinessError;
3756  console.error(`Fail to adjust the system volume by step. ${error}`);
3757}
3758```
3759
3760## AudioStreamManager<sup>9+</sup>
3761
3762Implements audio stream management. Before calling any API in **AudioStreamManager**, you must use [getStreamManager](#getstreammanager9) to obtain an **AudioStreamManager** instance.
3763
3764### getCurrentAudioRendererInfoArray<sup>9+</sup>
3765
3766getCurrentAudioRendererInfoArray(callback: AsyncCallback&lt;AudioRendererChangeInfoArray&gt;): void
3767
3768Obtains the information about the current audio renderer. This API uses an asynchronous callback to return the result.
3769
3770**System capability**: SystemCapability.Multimedia.Audio.Renderer
3771
3772**Parameters**
3773
3774| Name     | Type                                                         | Mandatory | Description                                             |
3775| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------- |
3776| callback | AsyncCallback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Yes       | Callback used to return the audio renderer information. |
3777
3778**Example**
3779
3780```ts
3781import { BusinessError } from '@ohos.base';
3782audioStreamManager.getCurrentAudioRendererInfoArray(async (err: BusinessError, AudioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray) => {
3783  console.info('getCurrentAudioRendererInfoArray **** Get Callback Called ****');
3784  if (err) {
3785    console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`);
3786  } else {
3787    if (AudioRendererChangeInfoArray != null) {
3788      for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
3789        let AudioRendererChangeInfo: audio.AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
3790        console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
3791        console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`);
3792        console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
3793        console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
3794        console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
3795        console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`);
3796        for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
3797          console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
3798          console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
3799          console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
3800          console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
3801          console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
3802          console.info(`SampleRate: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
3803          console.info(`ChannelCount: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
3804          console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
3805        }
3806      }
3807    }
3808  }
3809});
3810```
3811
3812### getCurrentAudioRendererInfoArray<sup>9+</sup>
3813
3814getCurrentAudioRendererInfoArray(): Promise&lt;AudioRendererChangeInfoArray&gt;
3815
3816Obtains the information about the current audio renderer. This API uses a promise to return the result.
3817
3818**System capability**: SystemCapability.Multimedia.Audio.Renderer
3819
3820**Return value**
3821
3822| Type                                                         | Description                                            |
3823| ------------------------------------------------------------ | ------------------------------------------------------ |
3824| Promise<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Promise used to return the audio renderer information. |
3825
3826**Example**
3827
3828```ts
3829import { BusinessError } from '@ohos.base';
3830async function getCurrentAudioRendererInfoArray(){
3831  await audioStreamManager.getCurrentAudioRendererInfoArray().then((AudioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray) => {
3832    console.info(`getCurrentAudioRendererInfoArray ######### Get Promise is called ##########`);
3833    if (AudioRendererChangeInfoArray != null) {
3834      for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
3835        let AudioRendererChangeInfo: audio.AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
3836        console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
3837        console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`);
3838        console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
3839        console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
3840        console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
3841        console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`);
3842        for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
3843          console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
3844          console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
3845          console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
3846          console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
3847          console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
3848          console.info(`SampleRate: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
3849          console.info(`ChannelCount: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
3850          console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
3851        }
3852      }
3853    }
3854  }).catch((err: BusinessError) => {
3855    console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`);
3856  });
3857}
3858```
3859
3860### getCurrentAudioRendererInfoArraySync<sup>10+</sup>
3861
3862getCurrentAudioRendererInfoArraySync(): AudioRendererChangeInfoArray
3863
3864Obtains the information about the current audio renderer. This API returns the result synchronously.
3865
3866**System capability**: SystemCapability.Multimedia.Audio.Renderer
3867
3868**Return value**
3869
3870| Type                                                         | Description                 |
3871| ------------------------------------------------------------ | --------------------------- |
3872| [AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9) | Audio renderer information. |
3873
3874**Example**
3875
3876```ts
3877import { BusinessError } from '@ohos.base';
3878
3879try {
3880  let audioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray = audioStreamManager.getCurrentAudioRendererInfoArraySync();
3881  console.info(`getCurrentAudioRendererInfoArraySync success.`);
3882  if (audioRendererChangeInfoArray != null) {
3883    for (let i = 0; i < audioRendererChangeInfoArray.length; i++) {
3884      let AudioRendererChangeInfo: audio.AudioRendererChangeInfo = audioRendererChangeInfoArray[i];
3885      console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
3886      console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`);
3887      console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
3888      console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
3889      console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
3890      console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`);
3891      for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
3892        console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
3893        console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
3894        console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
3895        console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
3896        console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
3897        console.info(`SampleRate: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
3898        console.info(`ChannelCount: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
3899        console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
3900      }
3901    }
3902  }
3903} catch (err) {
3904  let error = err as BusinessError;
3905  console.error(`getCurrentAudioRendererInfoArraySync :ERROR: ${error}`);
3906}
3907```
3908
3909### getCurrentAudioCapturerInfoArray<sup>9+</sup>
3910
3911getCurrentAudioCapturerInfoArray(callback: AsyncCallback&lt;AudioCapturerChangeInfoArray&gt;): void
3912
3913Obtains the information about the current audio capturer. This API uses an asynchronous callback to return the result.
3914
3915**System capability**: SystemCapability.Multimedia.Audio.Renderer
3916
3917**Parameters**
3918
3919| Name     | Type                                                         | Mandatory | Description                                             |
3920| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------- |
3921| callback | AsyncCallback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Yes       | Callback used to return the audio capturer information. |
3922
3923**Example**
3924
3925```ts
3926import { BusinessError } from '@ohos.base';
3927audioStreamManager.getCurrentAudioCapturerInfoArray(async (err: BusinessError, AudioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray) => {
3928  console.info('getCurrentAudioCapturerInfoArray **** Get Callback Called ****');
3929  if (err) {
3930    console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
3931  } else {
3932    if (AudioCapturerChangeInfoArray != null) {
3933      for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
3934        console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
3935        console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
3936        console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
3937        console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
3938        console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);
3939        for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
3940          console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
3941          console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
3942          console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
3943          console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
3944          console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
3945          console.info(`SampleRate: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
3946          console.info(`ChannelCount: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
3947          console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
3948        }
3949      }
3950    }
3951  }
3952});
3953```
3954
3955### getCurrentAudioCapturerInfoArray<sup>9+</sup>
3956
3957getCurrentAudioCapturerInfoArray(): Promise&lt;AudioCapturerChangeInfoArray&gt;
3958
3959Obtains the information about the current audio capturer. This API uses a promise to return the result.
3960
3961**System capability**: SystemCapability.Multimedia.Audio.Renderer
3962
3963**Return value**
3964
3965| Type                                                         | Description                                            |
3966| ------------------------------------------------------------ | ------------------------------------------------------ |
3967| Promise<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Promise used to return the audio capturer information. |
3968
3969**Example**
3970
3971```ts
3972import { BusinessError } from '@ohos.base';
3973async function getCurrentAudioCapturerInfoArray(){
3974  await audioStreamManager.getCurrentAudioCapturerInfoArray().then((AudioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray) => {
3975    console.info('getCurrentAudioCapturerInfoArray **** Get Promise Called ****');
3976    if (AudioCapturerChangeInfoArray != null) {
3977      for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
3978        console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
3979        console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
3980        console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
3981        console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
3982        console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);
3983        for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
3984          console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
3985          console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
3986          console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
3987          console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
3988          console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
3989          console.info(`SampleRate: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
3990          console.info(`ChannelCount: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
3991          console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
3992        }
3993      }
3994    }
3995  }).catch((err: BusinessError) => {
3996    console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
3997  });
3998}
3999```
4000
4001### getCurrentAudioCapturerInfoArraySync<sup>10+</sup>
4002
4003getCurrentAudioCapturerInfoArraySync(): AudioCapturerChangeInfoArray
4004
4005Obtains the information about the current audio capturer. This API returns the result synchronously.
4006
4007**System capability**: SystemCapability.Multimedia.Audio.Capturer
4008
4009**Return value**
4010
4011| Type                                                         | Description                 |
4012| ------------------------------------------------------------ | --------------------------- |
4013| [AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9) | Audio capturer information. |
4014
4015**Example**
4016
4017```ts
4018import { BusinessError } from '@ohos.base';
4019
4020try {
4021  let audioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray = audioStreamManager.getCurrentAudioCapturerInfoArraySync();
4022  console.info('getCurrentAudioCapturerInfoArraySync success.');
4023  if (audioCapturerChangeInfoArray != null) {
4024    for (let i = 0; i < audioCapturerChangeInfoArray.length; i++) {
4025      console.info(`StreamId for ${i} is: ${audioCapturerChangeInfoArray[i].streamId}`);
4026      console.info(`ClientUid for ${i} is: ${audioCapturerChangeInfoArray[i].clientUid}`);
4027      console.info(`Source for ${i} is: ${audioCapturerChangeInfoArray[i].capturerInfo.source}`);
4028      console.info(`Flag  ${i} is: ${audioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
4029      console.info(`State for ${i} is: ${audioCapturerChangeInfoArray[i].capturerState}`);
4030      for (let j = 0; j < audioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
4031        console.info(`Id: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
4032        console.info(`Type: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
4033        console.info(`Role: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
4034        console.info(`Name: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
4035        console.info(`Address: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
4036        console.info(`SampleRate: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
4037        console.info(`ChannelCount: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
4038        console.info(`ChannelMask: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
4039      }
4040    }
4041  }
4042} catch (err) {
4043  let error = err as BusinessError;
4044  console.error(`getCurrentAudioCapturerInfoArraySync ERROR: ${error}`);
4045}
4046```
4047
4048### on('audioRendererChange')<sup>9+</sup>
4049
4050on(type: 'audioRendererChange', callback: Callback&lt;AudioRendererChangeInfoArray&gt;): void
4051
4052Subscribes to audio renderer change events.
4053
4054**System capability**: SystemCapability.Multimedia.Audio.Renderer
4055
4056**Parameters**
4057
4058| Name     | Type                                                         | Mandatory | Description                                                  |
4059| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4060| type     | string                                                       | Yes       | Event type. The event `'audioRendererChange'` is triggered when the audio renderer is changed. |
4061| callback | Callback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Yes       | Callback used to return the result.                          |
4062
4063**Error codes**
4064
4065For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4066
4067| ID      | Error Message                  |
4068| ------- | ------------------------------ |
4069| 6800101 | if input parameter value error |
4070
4071**Example**
4072
4073```ts
4074audioStreamManager.on('audioRendererChange',  (AudioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray) => {
4075  for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
4076    let AudioRendererChangeInfo: audio.AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
4077    console.info(`## RendererChange on is called for ${i} ##`);
4078    console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
4079    console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`);
4080    console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
4081    console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
4082    console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
4083    console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`);
4084    for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
4085      console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
4086      console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
4087      console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
4088      console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
4089      console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
4090      console.info(`SampleRate: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
4091      console.info(`ChannelCount: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
4092      console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
4093    }
4094  }
4095});
4096```
4097
4098### off('audioRendererChange')<sup>9+</sup>
4099
4100off(type: 'audioRendererChange'): void
4101
4102Unsubscribes from audio renderer change events.
4103
4104**System capability**: SystemCapability.Multimedia.Audio.Renderer
4105
4106**Parameters**
4107
4108| Name | Type   | Mandatory | Description                                                  |
4109| ---- | ------ | --------- | ------------------------------------------------------------ |
4110| type | string | Yes       | Event type. The event `'audioRendererChange'` is triggered when the audio renderer is changed. |
4111
4112**Error codes**
4113
4114For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4115
4116| ID      | Error Message                  |
4117| ------- | ------------------------------ |
4118| 6800101 | if input parameter value error |
4119
4120**Example**
4121
4122```ts
4123audioStreamManager.off('audioRendererChange');
4124console.info('######### RendererChange Off is called #########');
4125```
4126
4127### on('audioCapturerChange')<sup>9+</sup>
4128
4129on(type: 'audioCapturerChange', callback: Callback&lt;AudioCapturerChangeInfoArray&gt;): void
4130
4131Subscribes to audio capturer change events.
4132
4133**System capability**: SystemCapability.Multimedia.Audio.Capturer
4134
4135**Parameters**
4136
4137| Name     | Type                                                         | Mandatory | Description                                                  |
4138| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4139| type     | string                                                       | Yes       | Event type. The event `'audioCapturerChange'` is triggered when the audio capturer is changed. |
4140| callback | Callback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Yes       | Callback used to return the result.                          |
4141
4142**Error codes**
4143
4144For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4145
4146| ID      | Error Message                  |
4147| ------- | ------------------------------ |
4148| 6800101 | if input parameter value error |
4149
4150**Example**
4151
4152```ts
4153audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray) =>  {
4154  for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
4155    console.info(`## CapChange on is called for element ${i} ##`);
4156    console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
4157    console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
4158    console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
4159    console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
4160    console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);
4161    let devDescriptor: audio.AudioCapturerChangeInfo = AudioCapturerChangeInfoArray[i].deviceDescriptors;
4162    for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
4163      console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
4164      console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
4165      console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
4166      console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
4167      console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
4168      console.info(`SampleRate: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
4169      console.info(`ChannelCount: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
4170      console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
4171    }
4172  }
4173});
4174
4175```
4176
4177### off('audioCapturerChange')<sup>9+</sup>
4178
4179off(type: 'audioCapturerChange'): void;
4180
4181Unsubscribes from audio capturer change events.
4182
4183**System capability**: SystemCapability.Multimedia.Audio.Capturer
4184
4185**Parameters**
4186
4187| Name | Type   | Mandatory | Description                                                  |
4188| ---- | ------ | --------- | ------------------------------------------------------------ |
4189| type | string | Yes       | Event type. The event `'audioCapturerChange'` is triggered when the audio capturer is changed. |
4190
4191**Error codes**
4192
4193For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4194
4195| ID      | Error Message                  |
4196| ------- | ------------------------------ |
4197| 6800101 | if input parameter value error |
4198
4199**Example**
4200
4201```ts
4202audioStreamManager.off('audioCapturerChange');
4203console.info('######### CapturerChange Off is called #########');
4204
4205
4206```
4207
4208### isActive<sup>9+</sup>
4209
4210isActive(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
4211
4212Checks whether a stream is active. This API uses an asynchronous callback to return the result.
4213
4214**System capability**: SystemCapability.Multimedia.Audio.Renderer
4215
4216**Parameters**
4217
4218| Name       | Type                                | Mandatory | Description                                                  |
4219| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------ |
4220| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream types.                                          |
4221| callback   | AsyncCallback&lt;boolean&gt;        | Yes       | Callback used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite. |
4222
4223**Example**
4224
4225```ts
4226import { BusinessError } from '@ohos.base';
4227audioStreamManager.isActive(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => {
4228if (err) {
4229  console.error(`Failed to obtain the active status of the stream. ${err}`);
4230  return;
4231}
4232  console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`);
4233});
4234
4235```
4236
4237### isActive<sup>9+</sup>
4238
4239isActive(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
4240
4241Checks whether a stream is active. This API uses a promise to return the result.
4242
4243**System capability**: SystemCapability.Multimedia.Audio.Renderer
4244
4245**Parameters**
4246
4247| Name       | Type                                | Mandatory | Description         |
4248| ---------- | ----------------------------------- | --------- | ------------------- |
4249| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream types. |
4250
4251**Return value**
4252
4253| Type                   | Description                                                  |
4254| ---------------------- | ------------------------------------------------------------ |
4255| 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. |
4256
4257**Example**
4258
4259```ts
4260audioStreamManager.isActive(audio.AudioVolumeType.MEDIA).then((value: boolean) => {
4261  console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`);
4262});
4263
4264```
4265
4266### isActiveSync<sup>10+</sup>
4267
4268isActiveSync(volumeType: AudioVolumeType): boolean
4269
4270Checks whether a stream is active. This API returns the result synchronously.
4271
4272**System capability**: SystemCapability.Multimedia.Audio.Renderer
4273
4274**Parameters**
4275
4276| Name       | Type                                | Mandatory | Description         |
4277| ---------- | ----------------------------------- | --------- | ------------------- |
4278| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream types. |
4279
4280**Return value**
4281
4282| Type    | Description                                                  |
4283| ------- | ------------------------------------------------------------ |
4284| boolean | Returns **true** if the stream is active; returns **false** otherwise. |
4285
4286**Error codes**
4287
4288For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4289
4290| ID      | Error Message           |
4291| ------- | ----------------------- |
4292| 6800101 | invalid parameter error |
4293
4294**Example**
4295
4296```ts
4297import { BusinessError } from '@ohos.base';
4298
4299try {
4300  let value: boolean = audioStreamManager.isActiveSync(audio.AudioVolumeType.MEDIA);
4301  console.info(`Indicate that the active status of the stream is obtained ${value}.`);
4302} catch (err) {
4303  let error = err as BusinessError;
4304  console.error(`Failed to obtain the active status of the stream ${error}.`);
4305}
4306
4307```
4308
4309### getAudioEffectInfoArray<sup>10+</sup>
4310
4311getAudioEffectInfoArray(usage: StreamUsage, callback: AsyncCallback&lt;AudioEffectInfoArray&gt;): void
4312
4313Obtains information about the sound effect mode in use. This API uses an asynchronous callback to return the result.
4314
4315**System capability**: SystemCapability.Multimedia.Audio.Renderer
4316
4317**Parameters**
4318
4319| Name     | Type                                                         | Mandatory | Description                                                  |
4320| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4321| usage    | [StreamUsage](#streamusage)                                  | Yes       | Audio stream usage.                                          |
4322| callback | AsyncCallback<[AudioEffectInfoArray](#audioeffectinfoarray10)> | Yes       | Callback used to return the information about the sound effect mode obtained. |
4323
4324**Error codes**
4325
4326For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4327
4328| ID      | Error Message                                |
4329| ------- | -------------------------------------------- |
4330| 6800101 | Invalid parameter error. Return by callback. |
4331
4332**Example**
4333
4334```ts
4335import { BusinessError } from '@ohos.base';
4336audioStreamManager.getAudioEffectInfoArray(audio.StreamUsage.STREAM_USAGE_MEDIA, async (err: BusinessError, audioEffectInfoArray: audio.AudioEffectInfoArray) => {
4337  console.info('getAudioEffectInfoArray **** Get Callback Called ****');
4338  if (err) {
4339    console.error(`getAudioEffectInfoArray :ERROR: ${err}`);
4340    return;
4341  } else {
4342    console.info(`The effect modes are: ${audioEffectInfoArray}`);
4343  }
4344});
4345
4346```
4347
4348### getAudioEffectInfoArray<sup>10+</sup>
4349
4350getAudioEffectInfoArray(usage: StreamUsage): Promise&lt;AudioEffectInfoArray&gt;
4351
4352Obtains information about the sound effect mode in use. This API uses a promise to return the result.
4353
4354**System capability**: SystemCapability.Multimedia.Audio.Renderer
4355
4356**Parameters**
4357
4358| Name  | Type                        | Mandatory | Description         |
4359| ----- | --------------------------- | --------- | ------------------- |
4360| usage | [StreamUsage](#streamusage) | Yes       | Audio stream usage. |
4361
4362**Return value**
4363
4364| Type                                                     | Description                                                  |
4365| -------------------------------------------------------- | ------------------------------------------------------------ |
4366| Promise<[AudioEffectInfoArray](#audioeffectinfoarray10)> | Promise used to return the information about the sound effect mode obtained. |
4367
4368**Error codes**
4369
4370For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4371
4372| ID      | Error Message                               |
4373| ------- | ------------------------------------------- |
4374| 6800101 | Invalid parameter error. Return by promise. |
4375
4376**Example**
4377
4378```ts
4379import { BusinessError } from '@ohos.base';
4380audioStreamManager.getAudioEffectInfoArray(audio.StreamUsage.STREAM_USAGE_MEDIA).then((audioEffectInfoArray: audio.AudioEffectInfoArray) => {
4381  console.info('getAudioEffectInfoArray ######### Get Promise is called ##########');
4382  console.info(`The effect modes are: ${audioEffectInfoArray}`);
4383}).catch((err: BusinessError) => {
4384  console.error(`getAudioEffectInfoArray :ERROR: ${err}`);
4385});
4386
4387```
4388
4389### getAudioEffectInfoArraySync<sup>10+</sup>
4390
4391getAudioEffectInfoArraySync(usage: StreamUsage): AudioEffectInfoArray
4392
4393Obtains information about the sound effect mode in use. This API returns the result synchronously.
4394
4395**System capability**: SystemCapability.Multimedia.Audio.Renderer
4396
4397**Parameters**
4398
4399| Name  | Type                        | Mandatory | Description         |
4400| ----- | --------------------------- | --------- | ------------------- |
4401| usage | [StreamUsage](#streamusage) | Yes       | Audio stream usage. |
4402
4403**Return value**
4404
4405| Type                                            | Description                              |
4406| ----------------------------------------------- | ---------------------------------------- |
4407| [AudioEffectInfoArray](#audioeffectinfoarray10) | Information about the sound effect mode. |
4408
4409**Error codes**
4410
4411For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4412
4413| ID      | Error Message           |
4414| ------- | ----------------------- |
4415| 6800101 | invalid parameter error |
4416
4417**Example**
4418
4419```ts
4420import { BusinessError } from '@ohos.base';
4421
4422try {
4423  let audioEffectInfoArray: audio.AudioEffectInfoArray = audioStreamManager.getAudioEffectInfoArraySync(audio.StreamUsage.STREAM_USAGE_MEDIA);
4424  console.info(`The effect modes are: ${audioEffectInfoArray}`);
4425} catch (err) {
4426  let error = err as BusinessError;
4427  console.error(`getAudioEffectInfoArraySync ERROR: ${error}`);
4428}
4429
4430```
4431
4432## AudioRoutingManager<sup>9+</sup>
4433
4434Implements audio routing management. Before calling any API in **AudioRoutingManager**, you must use [getRoutingManager](#getroutingmanager9) to obtain an **AudioRoutingManager** instance.
4435
4436### getDevices<sup>9+</sup>
4437
4438getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
4439
4440Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the result.
4441
4442**System capability**: SystemCapability.Multimedia.Audio.Device
4443
4444**Parameters**
4445
4446| Name       | Type                                                         | Mandatory | Description                              |
4447| ---------- | ------------------------------------------------------------ | --------- | ---------------------------------------- |
4448| deviceFlag | [DeviceFlag](#deviceflag)                                    | Yes       | Audio device flag.                       |
4449| callback   | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Yes       | Callback used to return the device list. |
4450
4451**Example**
4452
4453```ts
4454import { BusinessError } from '@ohos.base';
4455audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err: BusinessError, value: audio.AudioDeviceDescriptors) => {
4456  if (err) {
4457    console.error(`Failed to obtain the device list. ${err}`);
4458    return;
4459  }
4460  console.info('Callback invoked to indicate that the device list is obtained.');
4461});
4462
4463```
4464
4465### getDevices<sup>9+</sup>
4466
4467getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
4468
4469Obtains the audio devices with a specific flag. This API uses a promise to return the result.
4470
4471**System capability**: SystemCapability.Multimedia.Audio.Device
4472
4473**Parameters**
4474
4475| Name       | Type                      | Mandatory | Description        |
4476| ---------- | ------------------------- | --------- | ------------------ |
4477| deviceFlag | [DeviceFlag](#deviceflag) | Yes       | Audio device flag. |
4478
4479**Return value**
4480
4481| Type                                                         | Description                             |
4482| ------------------------------------------------------------ | --------------------------------------- |
4483| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the device list. |
4484
4485**Example**
4486
4487```ts
4488audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data: audio.AudioDeviceDescriptors) => {
4489  console.info('Promise returned to indicate that the device list is obtained.');
4490});
4491
4492```
4493
4494### getDevicesSync<sup>10+</sup>
4495
4496getDevicesSync(deviceFlag: DeviceFlag): AudioDeviceDescriptors
4497
4498Obtains the audio devices with a specific flag. This API returns the result synchronously.
4499
4500**System capability**: SystemCapability.Multimedia.Audio.Device
4501
4502**Parameters**
4503
4504| Name       | Type                      | Mandatory | Description        |
4505| ---------- | ------------------------- | --------- | ------------------ |
4506| deviceFlag | [DeviceFlag](#deviceflag) | Yes       | Audio device flag. |
4507
4508**Return value**
4509
4510| Type                                              | Description  |
4511| ------------------------------------------------- | ------------ |
4512| [AudioDeviceDescriptors](#audiodevicedescriptors) | Device list. |
4513
4514**Error codes**
4515
4516For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4517
4518| ID      | Error Message           |
4519| ------- | ----------------------- |
4520| 6800101 | invalid parameter error |
4521
4522**Example**
4523
4524```ts
4525import { BusinessError } from '@ohos.base';
4526
4527try {
4528  let data: audio.AudioDeviceDescriptors = audioRoutingManager.getDevicesSync(audio.DeviceFlag.OUTPUT_DEVICES_FLAG);
4529  console.info(`Indicate that the device list is obtained ${data}`);
4530} catch (err) {
4531  let error = err as BusinessError;
4532  console.error(`Failed to obtain the device list. ${error}`);
4533}
4534
4535```
4536
4537### on('deviceChange')<sup>9+</sup>
4538
4539on(type: 'deviceChange', deviceFlag: DeviceFlag, callback: Callback<DeviceChangeAction\>): void
4540
4541Subscribes to device change events. When a device is connected or disconnected, registered clients will receive the callback.
4542
4543**System capability**: SystemCapability.Multimedia.Audio.Device
4544
4545**Parameters**
4546
4547| Name       | Type                                                 | Mandatory | Description                                                  |
4548| :--------- | :--------------------------------------------------- | :-------- | :----------------------------------------------------------- |
4549| type       | string                                               | Yes       | Event type. The event **'deviceChange'** is triggered when the device connection status is changed. |
4550| deviceFlag | [DeviceFlag](#deviceflag)                            | Yes       | Audio device flag.                                           |
4551| callback   | Callback<[DeviceChangeAction](#devicechangeaction)\> | Yes       | Callback used to return the device update details.           |
4552
4553**Error codes**
4554
4555For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4556
4557| ID      | Error Message                  |
4558| ------- | ------------------------------ |
4559| 6800101 | if input parameter value error |
4560
4561**Example**
4562
4563```ts
4564audioRoutingManager.on('deviceChange', audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (deviceChanged: audio.DeviceChangeAction) => {
4565  console.info('device change type : ' + deviceChanged.type);
4566  console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
4567  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole);
4568  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType);
4569});
4570
4571```
4572
4573### off('deviceChange')<sup>9+</sup>
4574
4575off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void
4576
4577Unsubscribes from device change events.
4578
4579**System capability**: SystemCapability.Multimedia.Audio.Device
4580
4581**Parameters**
4582
4583| Name     | Type                                                | Mandatory | Description                                                  |
4584| -------- | --------------------------------------------------- | --------- | ------------------------------------------------------------ |
4585| type     | string                                              | Yes       | Event type. The event **'deviceChange'** is triggered when the device connection status is changed. |
4586| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | No        | Callback used to return the device update details.           |
4587
4588**Error codes**
4589
4590For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4591
4592| ID      | Error Message                  |
4593| ------- | ------------------------------ |
4594| 6800101 | if input parameter value error |
4595
4596**Example**
4597
4598```ts
4599audioRoutingManager.off('deviceChange');
4600
4601```
4602
4603### selectInputDevice<sup>9+</sup>
4604
4605selectInputDevice(inputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
4606
4607Selects an audio input device. Only one input device can be selected. This API uses an asynchronous callback to return the result.
4608
4609**System API**: This is a system API.
4610
4611**System capability**: SystemCapability.Multimedia.Audio.Device
4612
4613**Parameters**
4614
4615| Name              | Type                                              | Mandatory | Description                         |
4616| ----------------- | ------------------------------------------------- | --------- | ----------------------------------- |
4617| inputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes       | Input device.                       |
4618| callback          | AsyncCallback&lt;void&gt;                         | Yes       | Callback used to return the result. |
4619
4620**Example**
4621
4622```ts
4623import audio from '@ohos.multimedia.audio';
4624import { BusinessError } from '@ohos.base';
4625let inputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{
4626  deviceRole : audio.DeviceRole.INPUT_DEVICE,
4627  deviceType : audio.DeviceType.EARPIECE,
4628  id : 1,
4629  name : "",
4630  address : "",
4631  sampleRates : [44100],
4632  channelCounts : [2],
4633  channelMasks : [0],
4634  networkId : audio.LOCAL_NETWORK_ID,
4635  interruptGroupId : 1,
4636  volumeGroupId : 1,
4637  displayName : "",
4638}];
4639
4640async function selectInputDevice(){
4641  audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor, (err: BusinessError) => {
4642    if (err) {
4643      console.error(`Result ERROR: ${err}`);
4644    } else {
4645      console.info('Select input devices result callback: SUCCESS');
4646    }
4647  });
4648}
4649
4650```
4651
4652### selectInputDevice<sup>9+</sup>
4653
4654selectInputDevice(inputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
4655
4656**System API**: This is a system API.
4657
4658Selects an audio input device. Only one input device can be selected. This API uses a promise to return the result.
4659
4660**System capability**: SystemCapability.Multimedia.Audio.Device
4661
4662**Parameters**
4663
4664| Name              | Type                                              | Mandatory | Description   |
4665| ----------------- | ------------------------------------------------- | --------- | ------------- |
4666| inputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes       | Input device. |
4667
4668**Return value**
4669
4670| Type                | Description                        |
4671| ------------------- | ---------------------------------- |
4672| Promise&lt;void&gt; | Promise used to return the result. |
4673
4674**Example**
4675
4676```ts
4677import audio from '@ohos.multimedia.audio';
4678import { BusinessError } from '@ohos.base';
4679let inputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{
4680  deviceRole : audio.DeviceRole.INPUT_DEVICE,
4681  deviceType : audio.DeviceType.EARPIECE,
4682  id : 1,
4683  name : "",
4684  address : "",
4685  sampleRates : [44100],
4686  channelCounts : [2],
4687  channelMasks : [0],
4688  networkId : audio.LOCAL_NETWORK_ID,
4689  interruptGroupId : 1,
4690  volumeGroupId : 1,
4691  displayName : "",
4692}];
4693
4694async function getRoutingManager(){
4695  audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor).then(() => {
4696    console.info('Select input devices result promise: SUCCESS');
4697  }).catch((err: BusinessError) => {
4698    console.error(`Result ERROR: ${err}`);
4699  });
4700}
4701
4702```
4703
4704### setCommunicationDevice<sup>9+</sup>
4705
4706setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
4707
4708Sets a communication device to the active state. This API uses an asynchronous callback to return the result.
4709
4710**System capability**: SystemCapability.Multimedia.Audio.Communication
4711
4712**Parameters**
4713
4714| Name       | Type                                                 | Mandatory | Description                                                  |
4715| ---------- | ---------------------------------------------------- | --------- | ------------------------------------------------------------ |
4716| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes       | Communication device type.                                   |
4717| active     | boolean                                              | Yes       | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite. |
4718| callback   | AsyncCallback&lt;void&gt;                            | Yes       | Callback used to return the result.                          |
4719
4720**Example**
4721
4722```ts
4723import { BusinessError } from '@ohos.base';
4724audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true, (err: BusinessError) => {
4725  if (err) {
4726    console.error(`Failed to set the active status of the device. ${err}`);
4727    return;
4728  }
4729  console.info('Callback invoked to indicate that the device is set to the active status.');
4730});
4731
4732```
4733
4734### setCommunicationDevice<sup>9+</sup>
4735
4736setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean): Promise&lt;void&gt;
4737
4738Sets a communication device to the active state. This API uses a promise to return the result.
4739
4740**System capability**: SystemCapability.Multimedia.Audio.Communication
4741
4742**Parameters**
4743
4744| Name       | Type                                                 | Mandatory | Description                                                  |
4745| ---------- | ---------------------------------------------------- | --------- | ------------------------------------------------------------ |
4746| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes       | Communication device type.                                   |
4747| active     | boolean                                              | Yes       | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite. |
4748
4749**Return value**
4750
4751| Type                | Description                        |
4752| ------------------- | ---------------------------------- |
4753| Promise&lt;void&gt; | Promise used to return the result. |
4754
4755**Example**
4756
4757```ts
4758audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true).then(() => {
4759  console.info('Promise returned to indicate that the device is set to the active status.');
4760});
4761
4762```
4763
4764### isCommunicationDeviceActive<sup>9+</sup>
4765
4766isCommunicationDeviceActive(deviceType: CommunicationDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
4767
4768Checks whether a communication device is active. This API uses an asynchronous callback to return the result.
4769
4770**System capability**: SystemCapability.Multimedia.Audio.Communication
4771
4772**Parameters**
4773
4774| Name       | Type                                                 | Mandatory | Description                                             |
4775| ---------- | ---------------------------------------------------- | --------- | ------------------------------------------------------- |
4776| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes       | Communication device type.                              |
4777| callback   | AsyncCallback&lt;boolean&gt;                         | Yes       | Callback used to return the active state of the device. |
4778
4779**Example**
4780
4781```ts
4782import { BusinessError } from '@ohos.base';
4783audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER, (err: BusinessError, value: boolean) => {
4784  if (err) {
4785    console.error(`Failed to obtain the active status of the device. ${err}`);
4786    return;
4787  }
4788  console.info('Callback invoked to indicate that the active status of the device is obtained.');
4789});
4790
4791```
4792
4793### isCommunicationDeviceActive<sup>9+</sup>
4794
4795isCommunicationDeviceActive(deviceType: CommunicationDeviceType): Promise&lt;boolean&gt;
4796
4797Checks whether a communication device is active. This API uses a promise to return the result.
4798
4799**System capability**: SystemCapability.Multimedia.Audio.Communication
4800
4801**Parameters**
4802
4803| Name       | Type                                                 | Mandatory | Description                |
4804| ---------- | ---------------------------------------------------- | --------- | -------------------------- |
4805| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes       | Communication device type. |
4806
4807**Return value**
4808
4809| Type                   | Description                                            |
4810| ---------------------- | ------------------------------------------------------ |
4811| Promise&lt;boolean&gt; | Promise used to return the active state of the device. |
4812
4813**Example**
4814
4815```ts
4816audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER).then((value: boolean) => {
4817  console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
4818});
4819
4820```
4821
4822### isCommunicationDeviceActiveSync<sup>10+</sup>
4823
4824isCommunicationDeviceActiveSync(deviceType: CommunicationDeviceType): boolean
4825
4826Checks whether a communication device is active. This API returns the result synchronously.
4827
4828**System capability**: SystemCapability.Multimedia.Audio.Communication
4829
4830**Parameters**
4831
4832| Name       | Type                                                 | Mandatory | Description                |
4833| ---------- | ---------------------------------------------------- | --------- | -------------------------- |
4834| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes       | Communication device type. |
4835
4836**Return value**
4837
4838| Type    | Description                 |
4839| ------- | --------------------------- |
4840| boolean | Active state of the device. |
4841
4842**Error codes**
4843
4844For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
4845
4846| ID      | Error Message           |
4847| ------- | ----------------------- |
4848| 6800101 | invalid parameter error |
4849
4850**Example**
4851
4852```ts
4853import { BusinessError } from '@ohos.base';
4854
4855try {
4856  let value: boolean = audioRoutingManager.isCommunicationDeviceActiveSync(audio.CommunicationDeviceType.SPEAKER);
4857  console.info(`Indicate that the active status of the device is obtained ${value}.`);
4858} catch (err) {
4859  let error = err as BusinessError;
4860  console.error(`Failed to obtain the active status of the device ${error}.`);
4861}
4862
4863```
4864
4865### selectOutputDevice<sup>9+</sup>
4866
4867selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
4868
4869Selects an audio output device. Currently, only one output device can be selected. This API uses an asynchronous callback to return the result.
4870
4871**System API**: This is a system API.
4872
4873**System capability**: SystemCapability.Multimedia.Audio.Device
4874
4875**Parameters**
4876
4877| Name               | Type                                              | Mandatory | Description                         |
4878| ------------------ | ------------------------------------------------- | --------- | ----------------------------------- |
4879| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes       | Output device.                      |
4880| callback           | AsyncCallback&lt;void&gt;                         | Yes       | Callback used to return the result. |
4881
4882**Example**
4883
4884```ts
4885import audio from '@ohos.multimedia.audio';
4886import { BusinessError } from '@ohos.base';
4887let outputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{
4888  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
4889  deviceType : audio.DeviceType.SPEAKER,
4890  id : 1,
4891  name : "",
4892  address : "",
4893  sampleRates : [44100],
4894  channelCounts : [2],
4895  channelMasks : [0],
4896  networkId : audio.LOCAL_NETWORK_ID,
4897  interruptGroupId : 1,
4898  volumeGroupId : 1,
4899  displayName : "",
4900}];
4901
4902async function selectOutputDevice(){
4903  audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor, (err: BusinessError) => {
4904    if (err) {
4905      console.error(`Result ERROR: ${err}`);
4906    } else {
4907      console.info('Select output devices result callback: SUCCESS'); }
4908  });
4909}
4910
4911```
4912
4913### selectOutputDevice<sup>9+</sup>
4914
4915selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
4916
4917**System API**: This is a system API.
4918
4919Selects an audio output device. Currently, only one output device can be selected. This API uses a promise to return the result.
4920
4921**System capability**: SystemCapability.Multimedia.Audio.Device
4922
4923**Parameters**
4924
4925| Name               | Type                                              | Mandatory | Description    |
4926| ------------------ | ------------------------------------------------- | --------- | -------------- |
4927| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes       | Output device. |
4928
4929**Return value**
4930
4931| Type                | Description                        |
4932| ------------------- | ---------------------------------- |
4933| Promise&lt;void&gt; | Promise used to return the result. |
4934
4935**Example**
4936
4937```ts
4938import audio from '@ohos.multimedia.audio';
4939import { BusinessError } from '@ohos.base';
4940let outputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{
4941  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
4942  deviceType : audio.DeviceType.SPEAKER,
4943  id : 1,
4944  name : "",
4945  address : "",
4946  sampleRates : [44100],
4947  channelCounts : [2],
4948  channelMasks : [0],
4949  networkId : audio.LOCAL_NETWORK_ID,
4950  interruptGroupId : 1,
4951  volumeGroupId : 1,
4952  displayName : "",
4953}];
4954
4955async function selectOutputDevice(){
4956  audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor).then(() => {
4957    console.info('Select output devices result promise: SUCCESS');
4958  }).catch((err: BusinessError) => {
4959    console.error(`Result ERROR: ${err}`);
4960  });
4961}
4962
4963```
4964
4965### selectOutputDeviceByFilter<sup>9+</sup>
4966
4967selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
4968
4969**System API**: This is a system API.
4970
4971Selects 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.
4972
4973**System capability**: SystemCapability.Multimedia.Audio.Device
4974
4975**Parameters**
4976
4977| Name               | Type                                              | Mandatory | Description                         |
4978| ------------------ | ------------------------------------------------- | --------- | ----------------------------------- |
4979| filter             | [AudioRendererFilter](#audiorendererfilter9)      | Yes       | Filter criteria.                    |
4980| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes       | Output device.                      |
4981| callback           | AsyncCallback&lt;void&gt;                         | Yes       | Callback used to return the result. |
4982
4983**Example**
4984
4985```ts
4986import audio from '@ohos.multimedia.audio';
4987import { BusinessError } from '@ohos.base';
4988let outputAudioRendererFilter: audio.AudioRendererFilter = {
4989  uid : 20010041,
4990  rendererInfo : {
4991    content : audio.ContentType.CONTENT_TYPE_MUSIC,
4992    usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
4993    rendererFlags : 0
4994  },
4995  rendererId : 0
4996};
4997
4998let outputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{
4999  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
5000  deviceType : audio.DeviceType.SPEAKER,
5001  id : 1,
5002  name : "",
5003  address : "",
5004  sampleRates : [44100],
5005  channelCounts : [2],
5006  channelMasks : [0],
5007  networkId : audio.LOCAL_NETWORK_ID,
5008  interruptGroupId : 1,
5009  volumeGroupId : 1,
5010  displayName : "",
5011}];
5012
5013async function selectOutputDeviceByFilter(){
5014  audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor, (err: BusinessError) => {
5015    if (err) {
5016      console.error(`Result ERROR: ${err}`);
5017    } else {
5018      console.info('Select output devices by filter result callback: SUCCESS'); }
5019  });
5020}
5021
5022```
5023
5024### selectOutputDeviceByFilter<sup>9+</sup>
5025
5026selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
5027
5028**System API**: This is a system API.
5029
5030Selects 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.
5031
5032**System capability**: SystemCapability.Multimedia.Audio.Device
5033
5034**Parameters**
5035
5036| Name               | Type                                              | Mandatory | Description      |
5037| ------------------ | ------------------------------------------------- | --------- | ---------------- |
5038| filter             | [AudioRendererFilter](#audiorendererfilter9)      | Yes       | Filter criteria. |
5039| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes       | Output device.   |
5040
5041**Return value**
5042
5043| Type                | Description                        |
5044| ------------------- | ---------------------------------- |
5045| Promise&lt;void&gt; | Promise used to return the result. |
5046
5047**Example**
5048
5049```ts
5050import audio from '@ohos.multimedia.audio';
5051import { BusinessError } from '@ohos.base';
5052let outputAudioRendererFilter: audio.AudioRendererFilter = {
5053  uid : 20010041,
5054  rendererInfo : {
5055    content : audio.ContentType.CONTENT_TYPE_MUSIC,
5056    usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
5057    rendererFlags : 0
5058  },
5059  rendererId : 0
5060};
5061
5062let outputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{
5063  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
5064  deviceType : audio.DeviceType.SPEAKER,
5065  id : 1,
5066  name : "",
5067  address : "",
5068  sampleRates : [44100],
5069  channelCounts : [2],
5070  channelMasks : [0],
5071  networkId : audio.LOCAL_NETWORK_ID,
5072  interruptGroupId : 1,
5073  volumeGroupId : 1,
5074  displayName : "",
5075}];
5076
5077async function selectOutputDeviceByFilter(){
5078  audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor).then(() => {
5079    console.info('Select output devices by filter result promise: SUCCESS');
5080  }).catch((err: BusinessError) => {
5081    console.error(`Result ERROR: ${err}`);
5082  })
5083}
5084
5085```
5086
5087### getPreferOutputDeviceForRendererInfo<sup>10+</sup>
5088
5089getPreferOutputDeviceForRendererInfo(rendererInfo: AudioRendererInfo, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
5090
5091Obtains the output device with the highest priority based on the audio renderer information. This API uses an asynchronous callback to return the result.
5092
5093**System capability**: SystemCapability.Multimedia.Audio.Device
5094
5095**Parameters**
5096
5097| Name         | Type                                                         | Mandatory | Description                                                  |
5098| ------------ | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
5099| rendererInfo | [AudioRendererInfo](#audiorendererinfo8)                     | Yes       | Audio renderer information.                                  |
5100| callback     | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Yes       | Callback used to return the information about the output device with the highest priority. |
5101
5102**Error codes**
5103
5104For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5105
5106| ID      | Error Message                                       |
5107| ------- | --------------------------------------------------- |
5108| 6800101 | Input parameter value error. Return by callback. |
5109| 6800301 | System error. Return by callback.                |
5110
5111**Example**
5112```ts
5113import audio from '@ohos.multimedia.audio';
5114import { BusinessError } from '@ohos.base';
5115let rendererInfo: audio.AudioRendererInfo = {
5116  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
5117  rendererFlags : 0
5118}
5119
5120async function getPreferOutputDevice() {
5121  audioRoutingManager.getPreferOutputDeviceForRendererInfo(rendererInfo, (err: BusinessError, desc: audio.AudioDeviceDescriptors) => {
5122    if (err) {
5123      console.error(`Result ERROR: ${err}`);
5124    } else {
5125      console.info(`device descriptor: ${desc}`);
5126    }
5127  });
5128}
5129```
5130
5131### getPreferOutputDeviceForRendererInfo<sup>10+</sup>
5132getPreferOutputDeviceForRendererInfo(rendererInfo: AudioRendererInfo): Promise&lt;AudioDeviceDescriptors&gt;
5133
5134Obtains the output device with the highest priority based on the audio renderer information. This API uses a promise to return the result.
5135
5136**System capability**: SystemCapability.Multimedia.Audio.Device
5137
5138**Parameters**
5139
5140| Name         | Type                                     | Mandatory | Description                 |
5141| ------------ | ---------------------------------------- | --------- | --------------------------- |
5142| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes       | Audio renderer information. |
5143
5144**Return value**
5145
5146| Type                                                         | Description                                                  |
5147| ------------------------------------------------------------ | ------------------------------------------------------------ |
5148| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the information about the output device with the highest priority. |
5149
5150**Error codes**
5151
5152For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5153
5154| ID      | Error Message                                      |
5155| ------- | -------------------------------------------------- |
5156| 6800101 | Input parameter value error. Return by promise. |
5157| 6800301 | System error. Return by promise.                |
5158
5159**Example**
5160
5161```ts
5162import audio from '@ohos.multimedia.audio';
5163import { BusinessError } from '@ohos.base';
5164let rendererInfo: audio.AudioRendererInfo = {
5165  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
5166  rendererFlags : 0
5167}
5168
5169async function getPreferOutputDevice() {
5170  audioRoutingManager.getPreferOutputDeviceForRendererInfo(rendererInfo).then((desc: audio.AudioDeviceDescriptors) => {
5171    console.info(`device descriptor: ${desc}`);
5172  }).catch((err: BusinessError) => {
5173    console.error(`Result ERROR: ${err}`);
5174  })
5175}
5176```
5177### getPreferredOutputDeviceForRendererInfoSync<sup>10+</sup>
5178getPreferredOutputDeviceForRendererInfoSync(rendererInfo: AudioRendererInfo): AudioDeviceDescriptors
5179
5180Obtains the output device with the highest priority based on the audio renderer information. This API returns the result synchronously.
5181
5182**System capability**: SystemCapability.Multimedia.Audio.Device
5183
5184**Parameters**
5185
5186| Name         | Type                                     | Mandatory | Description                 |
5187| ------------ | ---------------------------------------- | --------- | --------------------------- |
5188| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes       | Audio renderer information. |
5189
5190**Return value**
5191
5192| Type                                              | Description                                                  |
5193| ------------------------------------------------- | ------------------------------------------------------------ |
5194| [AudioDeviceDescriptors](#audiodevicedescriptors) | Information about the output device with the highest priority. |
5195
5196**Error codes**
5197
5198For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5199
5200| ID      | Error Message            |
5201| ------- | ------------------------ |
5202| 6800101 | invalid parameter error.   |
5203
5204**Example**
5205
5206```ts
5207import audio from '@ohos.multimedia.audio';
5208import { BusinessError } from '@ohos.base';
5209
5210let rendererInfo: audio.AudioRendererInfo = {
5211  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
5212  rendererFlags : 0
5213}
5214
5215try {
5216  let desc: audio.AudioDeviceDescriptors = audioRoutingManager.getPreferredOutputDeviceForRendererInfoSync(rendererInfo);
5217  console.info(`device descriptor: ${desc}`);
5218} catch (err) {
5219  let error = err as BusinessError;
5220  console.error(`Result ERROR: ${error}`);
5221}
5222```
5223
5224### on('preferOutputDeviceChangeForRendererInfo')<sup>10+</sup>
5225
5226on(type: 'preferOutputDeviceChangeForRendererInfo', rendererInfo: AudioRendererInfo, callback: Callback<AudioDeviceDescriptors\>): void
5227
5228Subscribes to the change of the output device with the highest priority. This API uses an asynchronous callback to return the result.
5229
5230**System capability**: SystemCapability.Multimedia.Audio.Device
5231
5232**Parameters**
5233
5234| Name         | Type                                                         | Mandatory | Description                                                  |
5235| :----------- | :----------------------------------------------------------- | :-------- | :----------------------------------------------------------- |
5236| type         | string                                                       | Yes       | Event type. The event **'preferOutputDeviceChangeForRendererInfo'** is triggered when the output device with the highest priority is changed. |
5237| rendererInfo | [AudioRendererInfo](#audiorendererinfo8)                     | Yes       | Audio renderer information.                                  |
5238| callback     | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)\> | Yes       | Callback used to return the information about the output device with the highest priority. |
5239
5240**Error codes**
5241
5242For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5243
5244| ID      | Error Message                  |
5245| ------- | ------------------------------ |
5246| 6800101 | if input parameter value error              |
5247
5248**Example**
5249
5250```ts
5251import audio from '@ohos.multimedia.audio';
5252let rendererInfo: audio.AudioRendererInfo = {
5253  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
5254  rendererFlags : 0
5255}
5256
5257audioRoutingManager.on('preferOutputDeviceChangeForRendererInfo', rendererInfo, (desc: audio.AudioDeviceDescriptors) => {
5258  console.info(`device descriptor: ${desc}`);
5259});
5260```
5261
5262### off('preferOutputDeviceChangeForRendererInfo')<sup>10+</sup>
5263
5264off(type: 'preferOutputDeviceChangeForRendererInfo', callback?: Callback<AudioDeviceDescriptors\>): void
5265
5266Unsubscribes from the change of the output device with the highest priority.
5267
5268**System capability**: SystemCapability.Multimedia.Audio.Device
5269
5270**Parameters**
5271
5272| Name     | Type                                                        | Mandatory | Description                                                  |
5273| -------- | ----------------------------------------------------------- | --------- | ------------------------------------------------------------ |
5274| type     | string                                                      | Yes       | Event type. The event **'preferOutputDeviceChangeForRendererInfo'** is triggered when the output device with the highest priority is changed. |
5275| callback | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | No        | Callback used for unsubscription.                            |
5276
5277**Error codes**
5278
5279For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5280
5281| ID      | Error Message                  |
5282| ------- | ------------------------------ |
5283| 6800101 | if input parameter value error              |
5284
5285**Example**
5286
5287```ts
5288audioRoutingManager.off('preferOutputDeviceChangeForRendererInfo');
5289```
5290
5291### getPreferredInputDeviceForCapturerInfo<sup>10+</sup>
5292
5293getPreferredInputDeviceForCapturerInfo(capturerInfo: AudioCapturerInfo, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
5294
5295Obtains the input device with the highest priority based on the audio capturer information. This API uses an asynchronous callback to return the result.
5296
5297**System capability**: SystemCapability.Multimedia.Audio.Device
5298
5299**Parameters**
5300
5301| Name         | Type                                                         | Mandatory | Description                                                  |
5302| ------------ | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
5303| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8)                     | Yes       | Audio capturer information.                                  |
5304| callback     | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Yes       | Callback used to return the information about the input device with the highest priority. |
5305
5306**Error codes**
5307
5308For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5309
5310| ID      | Error Message                                |
5311| ------- | --------------------------------------------|
5312| 6800101 | Invalid parameter error. Return by callback.|
5313| 6800301 | System error. Return by callback.           |
5314
5315**Example**
5316```ts
5317import audio from '@ohos.multimedia.audio';
5318import { BusinessError } from '@ohos.base';
5319let capturerInfo: audio.AudioCapturerInfo = {
5320  source: audio.SourceType.SOURCE_TYPE_MIC,
5321  capturerFlags: 0
5322}
5323
5324audioRoutingManager.getPreferredInputDeviceForCapturerInfo(capturerInfo, (err: BusinessError, desc: audio.AudioDeviceDescriptors) => {
5325  if (err) {
5326    console.error(`Result ERROR: ${err}`);
5327  } else {
5328    console.info(`device descriptor: ${desc}`);
5329  }
5330});
5331```
5332
5333### getPreferredInputDeviceForCapturerInfo<sup>10+</sup>
5334
5335getPreferredInputDeviceForCapturerInfo(capturerInfo: AudioCapturerInfo): Promise&lt;AudioDeviceDescriptors&gt;
5336
5337Obtains the input device with the highest priority based on the audio capturer information. This API uses a promise to return the result.
5338
5339**System capability**: SystemCapability.Multimedia.Audio.Device
5340
5341**Parameters**
5342
5343| Name         | Type                                     | Mandatory | Description                 |
5344| ------------ | ---------------------------------------- | --------- | --------------------------- |
5345| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8) | Yes       | Audio capturer information. |
5346
5347**Return value**
5348
5349| Type                                                         | Description                                                  |
5350| ------------------------------------------------------------ | ------------------------------------------------------------ |
5351| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the information about the input device with the highest priority. |
5352
5353**Error codes**
5354
5355For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5356
5357| ID      | Error Message                               |
5358| ------- | ------------------------------------------- |
5359| 6800101 | Invalid parameter error. Return by promise. |
5360| 6800301 | System error. Return by promise.            |
5361
5362**Example**
5363
5364```ts
5365import audio from '@ohos.multimedia.audio';
5366import { BusinessError } from '@ohos.base';
5367let capturerInfo: audio.AudioCapturerInfo = {
5368  source: audio.SourceType.SOURCE_TYPE_MIC,
5369  capturerFlags: 0
5370}
5371
5372audioRoutingManager.getPreferredInputDeviceForCapturerInfo(capturerInfo).then((desc: audio.AudioDeviceDescriptors) => {
5373  console.info(`device descriptor: ${desc}`);
5374}).catch((err: BusinessError) => {
5375  console.error(`Result ERROR: ${err}`);
5376});
5377```
5378
5379### getPreferredInputDeviceForCapturerInfoSync<sup>10+</sup>
5380
5381getPreferredInputDeviceForCapturerInfoSync(capturerInfo: AudioCapturerInfo): AudioDeviceDescriptors
5382
5383Obtains the input device with the highest priority based on the audio capturer information. This API returns the result synchronously.
5384
5385**System capability**: SystemCapability.Multimedia.Audio.Device
5386
5387**Parameters**
5388
5389| Name         | Type                                     | Mandatory | Description                 |
5390| ------------ | ---------------------------------------- | --------- | --------------------------- |
5391| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8) | Yes       | Audio capturer information. |
5392
5393**Return value**
5394
5395| Type                                              | Description                                                  |
5396| ------------------------------------------------- | ------------------------------------------------------------ |
5397| [AudioDeviceDescriptors](#audiodevicedescriptors) | Information about the input device with the highest priority. |
5398
5399**Error codes**
5400
5401For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5402
5403| ID      | Error Message           |
5404| ------- | ----------------------- |
5405| 6800101 | invalid parameter error               |
5406
5407**Example**
5408
5409```ts
5410import audio from '@ohos.multimedia.audio';
5411import { BusinessError } from '@ohos.base';
5412
5413let capturerInfo: audio.AudioCapturerInfo = {
5414  source: audio.SourceType.SOURCE_TYPE_MIC,
5415  capturerFlags: 0
5416}
5417
5418try {
5419  let desc: audio.AudioDeviceDescriptors = audioRoutingManager.getPreferredInputDeviceForCapturerInfoSync(capturerInfo);
5420  console.info(`device descriptor: ${desc}`);
5421} catch (err) {
5422  let error = err as BusinessError;
5423  console.error(`Result ERROR: ${error}`);
5424}
5425```
5426
5427### on('preferredInputDeviceChangeForCapturerInfo')<sup>10+</sup>
5428
5429on(type: 'preferredInputDeviceChangeForCapturerInfo', capturerInfo: AudioCapturerInfo, callback: Callback<AudioDeviceDescriptors\>): void
5430
5431Subscribes to the change of the input device with the highest priority. This API uses an asynchronous callback to return the result.
5432
5433**System capability**: SystemCapability.Multimedia.Audio.Device
5434
5435**Parameters**
5436
5437| Name         | Type                                                         | Mandatory | Description                                                  |
5438| :----------- | :----------------------------------------------------------- | :-------- | :----------------------------------------------------------- |
5439| type         | string                                                       | Yes       | Event type. The event **'preferredInputDeviceChangeForCapturerInfo'** is triggered when the input device with the highest priority is changed. |
5440| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8)                     | Yes       | Audio capturer information.                                  |
5441| callback     | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)\> | Yes       | Callback used to return the information about the input device with the highest priority. |
5442
5443**Error codes**
5444
5445For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5446
5447| ID      | Error Message                  |
5448| ------- | ------------------------------ |
5449| 6800101 | if input parameter value error              |
5450
5451**Example**
5452
5453```ts
5454import audio from '@ohos.multimedia.audio';
5455let capturerInfo: audio.AudioCapturerInfo = {
5456  source: audio.SourceType.SOURCE_TYPE_MIC,
5457  capturerFlags: 0
5458}
5459
5460audioRoutingManager.on('preferredInputDeviceChangeForCapturerInfo', capturerInfo, (desc: audio.AudioDeviceDescriptors) => {
5461  console.info(`device descriptor: ${desc}`);
5462});
5463```
5464
5465### off('preferredInputDeviceChangeForCapturerInfo')<sup>10+</sup>
5466
5467off(type: 'preferredInputDeviceChangeForCapturerInfo', callback?: Callback<AudioDeviceDescriptors\>): void
5468
5469Unsubscribes from the change of the input device with the highest priority.
5470
5471**System capability**: SystemCapability.Multimedia.Audio.Device
5472
5473**Parameters**
5474
5475| Name     | Type                                                        | Mandatory | Description                                                  |
5476| -------- | ----------------------------------------------------------- | --------- | ------------------------------------------------------------ |
5477| type     | string                                                      | Yes       | Event type. The event **'preferredInputDeviceChangeForCapturerInfo'** is triggered when the input device with the highest priority is changed. |
5478| callback | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | No        | Callback used for unsubscription.                            |
5479
5480**Error codes**
5481
5482For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5483
5484| ID      | Error Message                  |
5485| ------- | ------------------------------ |
5486| 6800101 | if input parameter value error              |
5487
5488**Example**
5489
5490```ts
5491audioRoutingManager.off('preferredInputDeviceChangeForCapturerInfo');
5492```
5493
5494## AudioRendererChangeInfoArray<sup>9+</sup>
5495
5496Defines an **AudioRenderChangeInfo** array, which is read-only.
5497
5498**System capability**: SystemCapability.Multimedia.Audio.Renderer
5499
5500## AudioRendererChangeInfo<sup>9+</sup>
5501
5502Describes the audio renderer change event.
5503
5504**System capability**: SystemCapability.Multimedia.Audio.Renderer
5505
5506| Name              | Type                                              | Readable | Writable | Description                                                |
5507| ----------------- | ------------------------------------------------- | -------- | -------- | ---------------------------------------------------------- |
5508| streamId          | number                                            | Yes      | No       | Unique ID of an audio stream.                              |
5509| clientUid         | number                                            | Yes      | No       | UID of the audio renderer client.<br>This is a system API. |
5510| rendererInfo      | [AudioRendererInfo](#audiorendererinfo8)          | Yes      | No       | Audio renderer information.                                |
5511| rendererState     | [AudioState](#audiostate)                         | Yes      | No       | Audio state.<br>This is a system API.                      |
5512| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes      | No       | Audio device description.                                  |
5513
5514**Example**
5515
5516```ts
5517import audio from '@ohos.multimedia.audio';
5518
5519const audioManager = audio.getAudioManager();
5520let audioStreamManager = audioManager.getStreamManager();
5521let resultFlag = false;
5522
5523audioStreamManager.on('audioRendererChange',  (AudioRendererChangeInfoArray) => {
5524  for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
5525    console.info(`## RendererChange on is called for ${i} ##`);
5526    console.info(`StreamId for ${i} is: ${AudioRendererChangeInfoArray[i].streamId}`);
5527    console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfoArray[i].clientUid}`);
5528    console.info(`Content for ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.content}`);
5529    console.info(`Stream for ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.usage}`);
5530    console.info(`Flag ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.rendererFlags}`);
5531    console.info(`State for ${i} is: ${AudioRendererChangeInfoArray[i].rendererState}`);
5532    let devDescriptor = AudioRendererChangeInfoArray[i].deviceDescriptors;
5533    for (let j = 0; j < AudioRendererChangeInfoArray[i].deviceDescriptors.length; j++) {
5534      console.info(`Id: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].id}`);
5535      console.info(`Type: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
5536      console.info(`Role: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
5537      console.info(`Name: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].name}`);
5538      console.info(`Addr: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].address}`);
5539      console.info(`SR: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
5540      console.info(`C ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
5541      console.info(`CM: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
5542    }
5543    if (AudioRendererChangeInfoArray[i].rendererState == 1 && devDescriptor != null) {
5544      resultFlag = true;
5545      console.info(`ResultFlag for ${i} is: ${resultFlag}`);
5546    }
5547  }
5548});
5549```
5550
5551
5552## AudioCapturerChangeInfoArray<sup>9+</sup>
5553
5554Defines an **AudioCapturerChangeInfo** array, which is read-only.
5555
5556**System capability**: SystemCapability.Multimedia.Audio.Capturer
5557
5558## AudioCapturerChangeInfo<sup>9+</sup>
5559
5560Describes the audio capturer change event.
5561
5562**System capability**: SystemCapability.Multimedia.Audio.Capturer
5563
5564| Name                | Type                                              | Readable | Writable | Description                                                  |
5565| ------------------- | ------------------------------------------------- | -------- | -------- | ------------------------------------------------------------ |
5566| streamId            | number                                            | Yes      | No       | Unique ID of an audio stream.                                |
5567| clientUid           | number                                            | Yes      | No       | UID of the audio capturer client.<br>This is a system API.   |
5568| capturerInfo        | [AudioCapturerInfo](#audiocapturerinfo8)          | Yes      | No       | Audio capturer information.                                  |
5569| capturerState       | [AudioState](#audiostate)                         | Yes      | No       | Audio state.<br>This is a system API.                        |
5570| deviceDescriptors   | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes      | No       | Audio device description.                                    |
5571
5572**Example**
5573
5574```ts
5575import audio from '@ohos.multimedia.audio';
5576
5577const audioManager = audio.getAudioManager();
5578let audioStreamManager = audioManager.getStreamManager();
5579
5580let resultFlag = false;
5581audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) =>  {
5582  for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
5583    console.info(`## CapChange on is called for element ${i} ##`);
5584    console.info(`StrId for  ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
5585    console.info(`CUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
5586    console.info(`Src for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
5587    console.info(`Flag ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
5588    console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);
5589    let devDescriptor = AudioCapturerChangeInfoArray[i].deviceDescriptors;
5590    for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
5591      console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
5592      console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
5593      console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
5594      console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
5595      console.info(`Addr: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
5596      console.info(`SR: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
5597      console.info(`C ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
5598      console.info(`CM ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
5599    }
5600    if (AudioCapturerChangeInfoArray[i].capturerState == 1 && devDescriptor != null) {
5601      resultFlag = true;
5602      console.info(`ResultFlag for element ${i} is: ${resultFlag}`);
5603    }
5604  }
5605});
5606```
5607
5608## AudioEffectInfoArray<sup>10+</sup>
5609
5610Defines 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.
5611
5612## AudioDeviceDescriptors
5613
5614Defines an [AudioDeviceDescriptor](#audiodevicedescriptor) array, which is read-only.
5615
5616## AudioDeviceDescriptor
5617
5618Describes an audio device.
5619
5620**System capability**: SystemCapability.Multimedia.Audio.Device
5621
5622| Name                          | Type                                                  | Readable | Writable | Description                                                  |
5623| ----------------------------- | ----------------------------------------------------- | -------- | -------- | ------------------------------------------------------------ |
5624| deviceRole                    | [DeviceRole](#devicerole)                             | Yes      | No       | Device role.                                                 |
5625| deviceType                    | [DeviceType](#devicetype)                             | Yes      | No       | Device type.                                                 |
5626| id<sup>9+</sup>               | number                                                | Yes      | No       | Device ID, which is unique.                                  |
5627| name<sup>9+</sup>             | string                                                | Yes      | No       | Device name.<br>For a Bluetooth device, you must request the **ohos.permission.USE_BLUETOOTH** permission. |
5628| address<sup>9+</sup>          | string                                                | Yes      | No       | Device address.<br>For a Bluetooth device, you must request the **ohos.permission.USE_BLUETOOTH** permission. |
5629| sampleRates<sup>9+</sup>      | Array&lt;number&gt;                                   | Yes      | No       | Supported sampling rates.                                    |
5630| channelCounts<sup>9+</sup>    | Array&lt;number&gt;                                   | Yes      | No       | Number of channels supported.                                |
5631| channelMasks<sup>9+</sup>     | Array&lt;number&gt;                                   | Yes      | No       | Supported channel masks.                                     |
5632| displayName<sup>10+</sup>     | string                                                | Yes      | No       | Display name of the device.                                  |
5633| networkId<sup>9+</sup>        | string                                                | Yes      | No       | ID of the device network.<br>This is a system API.           |
5634| interruptGroupId<sup>9+</sup> | number                                                | Yes      | No       | ID of the interruption group to which the device belongs.<br>This is a system API. |
5635| volumeGroupId<sup>9+</sup>    | number                                                | Yes      | No       | ID of the volume group to which the device belongs.<br>This is a system API. |
5636
5637**Example**
5638
5639```ts
5640import audio from '@ohos.multimedia.audio';
5641
5642function displayDeviceProp(value: audio.AudioDeviceDescriptor) {
5643  deviceRoleValue = value.deviceRole;
5644  deviceTypeValue = value.deviceType;
5645}
5646
5647let deviceRoleValue: audio.DeviceRole | undefined = undefined;;
5648let deviceTypeValue: audio.DeviceType | undefined = undefined;;
5649audio.getAudioManager().getDevices(1).then((value: audio.AudioDeviceDescriptors) => {
5650  console.info('AudioFrameworkTest: Promise: getDevices OUTPUT_DEVICES_FLAG');
5651  value.forEach(displayDeviceProp);
5652  if (deviceTypeValue != undefined && deviceRoleValue != undefined){
5653    console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  PASS');
5654  } else {
5655    console.error('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  FAIL');
5656  }
5657});
5658```
5659
5660## AudioRendererFilter<sup>9+</sup>
5661
5662Implements filter criteria. Before calling **selectOutputDeviceByFilter**, you must obtain an **AudioRendererFilter** instance.
5663
5664**System API**: This is a system API.
5665
5666| Name         | Type                                     | Mandatory | Description                                                  |
5667| ------------ | ---------------------------------------- | --------- | ------------------------------------------------------------ |
5668| uid          | number                                   | No        | Application ID.<br> **System capability**: SystemCapability.Multimedia.Audio.Core |
5669| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | No        | Audio renderer information.<br> **System capability**: SystemCapability.Multimedia.Audio.Renderer |
5670| rendererId   | number                                   | No        | Unique ID of an audio stream.<br> **System capability**: SystemCapability.Multimedia.Audio.Renderer |
5671
5672**Example**
5673
5674```ts
5675import audio from '@ohos.multimedia.audio';
5676let outputAudioRendererFilter: audio.AudioRendererFilter = {
5677  uid : 20010041,
5678  rendererInfo : {
5679    content : audio.ContentType.CONTENT_TYPE_MUSIC,
5680    usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
5681    rendererFlags : 0
5682  },
5683  rendererId : 0
5684};
5685```
5686
5687## AudioRenderer<sup>8+</sup>
5688
5689Provides APIs for audio rendering. Before calling any API in **AudioRenderer**, you must use [createAudioRenderer](#audiocreateaudiorenderer8) to create an **AudioRenderer** instance.
5690
5691### Attributes
5692
5693**System capability**: SystemCapability.Multimedia.Audio.Renderer
5694
5695| Name               | Type                       | Readable | Writable | Description           |
5696| ------------------ | -------------------------- | -------- | -------- | --------------------- |
5697| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes      | No       | Audio renderer state. |
5698
5699**Example**
5700
5701```ts
5702import audio from '@ohos.multimedia.audio';
5703let state: audio.AudioState = audioRenderer.state;
5704```
5705
5706### getRendererInfo<sup>8+</sup>
5707
5708getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void
5709
5710Obtains the renderer information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
5711
5712**System capability**: SystemCapability.Multimedia.Audio.Renderer
5713
5714**Parameters**
5715
5716| Name     | Type                                                     | Mandatory | Description                                       |
5717| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ |
5718| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | Yes       | Callback used to return the renderer information. |
5719
5720**Example**
5721
5722```ts
5723import { BusinessError } from '@ohos.base';
5724audioRenderer.getRendererInfo((err: BusinessError, rendererInfo: audio.AudioRendererInfo) => {
5725  console.info('Renderer GetRendererInfo:');
5726  console.info(`Renderer content: ${rendererInfo.content}`);
5727  console.info(`Renderer usage: ${rendererInfo.usage}`);
5728  console.info(`Renderer flags: ${rendererInfo.rendererFlags}`);
5729});
5730```
5731
5732### getRendererInfo<sup>8+</sup>
5733
5734getRendererInfo(): Promise<AudioRendererInfo\>
5735
5736Obtains the renderer information of this **AudioRenderer** instance. This API uses a promise to return the result.
5737
5738**System capability**: SystemCapability.Multimedia.Audio.Renderer
5739
5740**Return value**
5741
5742| Type                                               | Description                                      |
5743| -------------------------------------------------- | ------------------------------------------------ |
5744| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information. |
5745
5746**Example**
5747
5748```ts
5749import { BusinessError } from '@ohos.base';
5750audioRenderer.getRendererInfo().then((rendererInfo: audio.AudioRendererInfo) => {
5751  console.info('Renderer GetRendererInfo:');
5752  console.info(`Renderer content: ${rendererInfo.content}`);
5753  console.info(`Renderer usage: ${rendererInfo.usage}`);
5754  console.info(`Renderer flags: ${rendererInfo.rendererFlags}`)
5755}).catch((err: BusinessError) => {
5756  console.error(`AudioFrameworkRenderLog: RendererInfo :ERROR: ${err}`);
5757});
5758```
5759
5760### getRendererInfoSync<sup>10+</sup>
5761
5762getRendererInfoSync(): AudioRendererInfo
5763
5764Obtains the renderer information of this **AudioRenderer** instance. This API returns the result synchronously.
5765
5766**System capability**: SystemCapability.Multimedia.Audio.Renderer
5767
5768**Return value**
5769
5770| Type                                     | Description                 |
5771| ---------------------------------------- | --------------------------- |
5772| [AudioRendererInfo](#audiorendererinfo8) | Audio renderer information. |
5773
5774**Example**
5775
5776```ts
5777import { BusinessError } from '@ohos.base';
5778
5779try {
5780  let rendererInfo: audio.AudioRendererInfo = audioRenderer.getRendererInfoSync();
5781  console.info(`Renderer content: ${rendererInfo.content}`);
5782  console.info(`Renderer usage: ${rendererInfo.usage}`);
5783  console.info(`Renderer flags: ${rendererInfo.rendererFlags}`)
5784} catch (err) {
5785  let error = err as BusinessError;
5786  console.error(`AudioFrameworkRenderLog: RendererInfo :ERROR: ${error}`);
5787}
5788```
5789
5790### getStreamInfo<sup>8+</sup>
5791
5792getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
5793
5794Obtains the stream information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
5795
5796**System capability**: SystemCapability.Multimedia.Audio.Renderer
5797
5798**Parameters**
5799
5800| Name     | Type                                                 | Mandatory | Description                                     |
5801| :------- | :--------------------------------------------------- | :-------- | :---------------------------------------------- |
5802| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes       | Callback used to return the stream information. |
5803
5804**Example**
5805
5806```ts
5807import { BusinessError } from '@ohos.base';
5808audioRenderer.getStreamInfo((err: BusinessError, streamInfo: audio.AudioStreamInfo) => {
5809  console.info('Renderer GetStreamInfo:');
5810  console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
5811  console.info(`Renderer channel: ${streamInfo.channels}`);
5812  console.info(`Renderer format: ${streamInfo.sampleFormat}`);
5813  console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
5814});
5815```
5816
5817### getStreamInfo<sup>8+</sup>
5818
5819getStreamInfo(): Promise<AudioStreamInfo\>
5820
5821Obtains the stream information of this **AudioRenderer** instance. This API uses a promise to return the result.
5822
5823**System capability**: SystemCapability.Multimedia.Audio.Renderer
5824
5825**Return value**
5826
5827| Type                                           | Description                                    |
5828| :--------------------------------------------- | :--------------------------------------------- |
5829| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
5830
5831**Example**
5832
5833```ts
5834import { BusinessError } from '@ohos.base';
5835audioRenderer.getStreamInfo().then((streamInfo: audio.AudioStreamInfo) => {
5836  console.info('Renderer GetStreamInfo:');
5837  console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
5838  console.info(`Renderer channel: ${streamInfo.channels}`);
5839  console.info(`Renderer format: ${streamInfo.sampleFormat}`);
5840  console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
5841}).catch((err: BusinessError) => {
5842  console.error(`ERROR: ${err}`);
5843});
5844```
5845
5846### getStreamInfoSync<sup>10+</sup>
5847
5848getStreamInfoSync(): AudioStreamInfo
5849
5850Obtains the stream information of this **AudioRenderer** instance. This API returns the result synchronously.
5851
5852**System capability**: SystemCapability.Multimedia.Audio.Renderer
5853
5854**Return value**
5855
5856| Type                                 | Description         |
5857| :----------------------------------- | :------------------ |
5858| [AudioStreamInfo](#audiostreaminfo8) | Stream information. |
5859
5860**Example**
5861
5862```ts
5863import { BusinessError } from '@ohos.base';
5864
5865try {
5866  let streamInfo: audio.AudioStreamInfo = audioRenderer.getStreamInfoSync();
5867  console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
5868  console.info(`Renderer channel: ${streamInfo.channels}`);
5869  console.info(`Renderer format: ${streamInfo.sampleFormat}`);
5870  console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
5871} catch (err) {
5872  let error = err as BusinessError;
5873  console.error(`ERROR: ${error}`);
5874}
5875```
5876
5877### getAudioStreamId<sup>9+</sup>
5878
5879getAudioStreamId(callback: AsyncCallback<number\>): void
5880
5881Obtains the stream ID of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
5882
5883**System capability**: SystemCapability.Multimedia.Audio.Renderer
5884
5885**Parameters**
5886
5887| Name     | Type                   | Mandatory | Description                            |
5888| :------- | :--------------------- | :-------- | :------------------------------------- |
5889| callback | AsyncCallback<number\> | Yes       | Callback used to return the stream ID. |
5890
5891**Example**
5892
5893```ts
5894import { BusinessError } from '@ohos.base';
5895audioRenderer.getAudioStreamId((err: BusinessError, streamid: number) => {
5896  console.info(`Renderer GetStreamId: ${streamid}`);
5897});
5898```
5899
5900### getAudioStreamId<sup>9+</sup>
5901
5902getAudioStreamId(): Promise<number\>
5903
5904Obtains the stream ID of this **AudioRenderer** instance. This API uses a promise to return the result.
5905
5906**System capability**: SystemCapability.Multimedia.Audio.Renderer
5907
5908**Return value**
5909
5910| Type             | Description                           |
5911| :--------------- | :------------------------------------ |
5912| Promise<number\> | Promise used to return the stream ID. |
5913
5914**Example**
5915
5916```ts
5917import { BusinessError } from '@ohos.base';
5918audioRenderer.getAudioStreamId().then((streamid: number) => {
5919  console.info(`Renderer getAudioStreamId: ${streamid}`);
5920}).catch((err: BusinessError) => {
5921  console.error(`ERROR: ${err}`);
5922});
5923```
5924
5925### getAudioStreamIdSync<sup>10+</sup>
5926
5927getAudioStreamIdSync(): number
5928
5929Obtains the stream ID of this **AudioRenderer** instance. This API returns the result synchronously.
5930
5931**System capability**: SystemCapability.Multimedia.Audio.Renderer
5932
5933**Return value**
5934
5935| Type   | Description |
5936| :----- | :---------- |
5937| number | Stream ID.  |
5938
5939**Example**
5940
5941```ts
5942import { BusinessError } from '@ohos.base';
5943
5944try {
5945  let streamid: number = audioRenderer.getAudioStreamIdSync();
5946  console.info(`Renderer getAudioStreamIdSync: ${streamid}`);
5947} catch (err) {
5948  let error = err as BusinessError;
5949  console.error(`ERROR: ${error}`);
5950}
5951```
5952
5953### setAudioEffectMode<sup>10+</sup>
5954
5955setAudioEffectMode(mode: AudioEffectMode, callback: AsyncCallback\<void>): void
5956
5957Sets an audio effect mode. This API uses an asynchronous callback to return the result.
5958
5959**System capability**: SystemCapability.Multimedia.Audio.Renderer
5960
5961**Parameters**
5962
5963| Name     | Type                                  | Mandatory | Description                         |
5964| -------- | ------------------------------------- | --------- | ----------------------------------- |
5965| mode     | [AudioEffectMode](#audioeffectmode10) | Yes       | Audio effect mode to set.           |
5966| callback | AsyncCallback\<void>                  | Yes       | Callback used to return the result. |
5967
5968**Error codes**
5969
5970For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
5971
5972| ID      | Error Message                                |
5973| ------- | -------------------------------------------- |
5974| 6800101 | Invalid parameter error. Return by callback.  |
5975
5976**Example**
5977
5978```ts
5979import { BusinessError } from '@ohos.base';
5980audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_DEFAULT, (err: BusinessError) => {
5981  if (err) {
5982    console.error('Failed to set params');
5983  } else {
5984    console.info('Callback invoked to indicate a successful audio effect mode setting.');
5985  }
5986});
5987```
5988
5989### setAudioEffectMode<sup>10+</sup>
5990
5991setAudioEffectMode(mode: AudioEffectMode): Promise\<void>
5992
5993Sets an audio effect mode. This API uses a promise to return the result.
5994
5995**System capability**: SystemCapability.Multimedia.Audio.Renderer
5996
5997**Parameters**
5998
5999| Name | Type                                  | Mandatory | Description               |
6000| ---- | ------------------------------------- | --------- | ------------------------- |
6001| mode | [AudioEffectMode](#audioeffectmode10) | Yes       | Audio effect mode to set. |
6002
6003**Return value**
6004
6005| Type           | Description                        |
6006| -------------- | ---------------------------------- |
6007| Promise\<void> | Promise used to return the result. |
6008
6009**Error codes**
6010
6011For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
6012
6013| ID      | Error Message                               |
6014| ------- | ------------------------------------------- |
6015| 6800101 | Invalid parameter error. Return by promise.  |
6016
6017**Example**
6018
6019```ts
6020import { BusinessError } from '@ohos.base';
6021audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_DEFAULT).then(() => {
6022  console.info('setAudioEffectMode SUCCESS');
6023}).catch((err: BusinessError) => {
6024  console.error(`ERROR: ${err}`);
6025});
6026```
6027
6028### getAudioEffectMode<sup>10+</sup>
6029
6030getAudioEffectMode(callback: AsyncCallback\<AudioEffectMode>): void
6031
6032Obtains the audio effect mode in use. This API uses an asynchronous callback to return the result.
6033
6034**System capability**: SystemCapability.Multimedia.Audio.Renderer
6035
6036**Parameters**
6037
6038| Name     | Type                                                 | Mandatory | Description                                    |
6039| -------- | ---------------------------------------------------- | --------- | ---------------------------------------------- |
6040| callback | AsyncCallback<[AudioEffectMode](#audioeffectmode10)> | Yes       | Callback used to return the audio effect mode. |
6041
6042**Example**
6043
6044```ts
6045import { BusinessError } from '@ohos.base';
6046audioRenderer.getAudioEffectMode((err: BusinessError, effectmode: audio.AudioEffectMode) => {
6047  if (err) {
6048    console.error('Failed to get params');
6049  } else {
6050    console.info(`getAudioEffectMode: ${effectmode}`);
6051  }
6052});
6053```
6054
6055### getAudioEffectMode<sup>10+</sup>
6056
6057getAudioEffectMode(): Promise\<AudioEffectMode>
6058
6059Obtains the audio effect mode in use. This API uses a promise to return the result.
6060
6061**System capability**: SystemCapability.Multimedia.Audio.Renderer
6062
6063**Return value**
6064
6065| Type                                           | Description                                   |
6066| ---------------------------------------------- | --------------------------------------------- |
6067| Promise<[AudioEffectMode](#audioeffectmode10)> | Promise used to return the audio effect mode. |
6068
6069**Example**
6070
6071```ts
6072import { BusinessError } from '@ohos.base';
6073audioRenderer.getAudioEffectMode().then((effectmode: audio.AudioEffectMode) => {
6074  console.info(`getAudioEffectMode: ${effectmode}`);
6075}).catch((err: BusinessError) => {
6076  console.error(`ERROR: ${err}`);
6077});
6078```
6079
6080### start<sup>8+</sup>
6081
6082start(callback: AsyncCallback<void\>): void
6083
6084Starts the renderer. This API uses an asynchronous callback to return the result.
6085
6086**System capability**: SystemCapability.Multimedia.Audio.Renderer
6087
6088**Parameters**
6089
6090| Name     | Type                 | Mandatory | Description                         |
6091| -------- | -------------------- | --------- | ----------------------------------- |
6092| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
6093
6094**Example**
6095
6096```ts
6097import { BusinessError } from '@ohos.base';
6098audioRenderer.start((err: BusinessError) => {
6099  if (err) {
6100    console.error('Renderer start failed.');
6101  } else {
6102    console.info('Renderer start success.');
6103  }
6104});
6105```
6106
6107### start<sup>8+</sup>
6108
6109start(): Promise<void\>
6110
6111Starts the renderer. This API uses a promise to return the result.
6112
6113**System capability**: SystemCapability.Multimedia.Audio.Renderer
6114
6115**Return value**
6116
6117| Type           | Description                        |
6118| -------------- | ---------------------------------- |
6119| Promise\<void> | Promise used to return the result. |
6120
6121**Example**
6122
6123```ts
6124import { BusinessError } from '@ohos.base';
6125audioRenderer.start().then(() => {
6126  console.info('Renderer started');
6127}).catch((err: BusinessError) => {
6128  console.error(`ERROR: ${err}`);
6129});
6130```
6131
6132### pause<sup>8+</sup>
6133
6134pause(callback: AsyncCallback\<void>): void
6135
6136Pauses rendering. This API uses an asynchronous callback to return the result.
6137
6138**System capability**: SystemCapability.Multimedia.Audio.Renderer
6139
6140**Parameters**
6141
6142| Name     | Type                 | Mandatory | Description                         |
6143| -------- | -------------------- | --------- | ----------------------------------- |
6144| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
6145
6146**Example**
6147
6148```ts
6149import { BusinessError } from '@ohos.base';
6150audioRenderer.pause((err: BusinessError) => {
6151  if (err) {
6152    console.error('Renderer pause failed');
6153  } else {
6154    console.info('Renderer paused.');
6155  }
6156});
6157```
6158
6159### pause<sup>8+</sup>
6160
6161pause(): Promise\<void>
6162
6163Pauses rendering. This API uses a promise to return the result.
6164
6165**System capability**: SystemCapability.Multimedia.Audio.Renderer
6166
6167**Return value**
6168
6169| Type           | Description                        |
6170| -------------- | ---------------------------------- |
6171| Promise\<void> | Promise used to return the result. |
6172
6173**Example**
6174
6175```ts
6176import { BusinessError } from '@ohos.base';
6177audioRenderer.pause().then(() => {
6178  console.info('Renderer paused');
6179}).catch((err: BusinessError) => {
6180  console.error(`ERROR: ${err}`);
6181});
6182```
6183
6184### drain<sup>8+</sup>
6185
6186drain(callback: AsyncCallback\<void>): void
6187
6188Drains the playback buffer. This API uses an asynchronous callback to return the result.
6189
6190**System capability**: SystemCapability.Multimedia.Audio.Renderer
6191
6192**Parameters**
6193
6194| Name     | Type                 | Mandatory | Description                         |
6195| -------- | -------------------- | --------- | ----------------------------------- |
6196| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
6197
6198**Example**
6199
6200```ts
6201import { BusinessError } from '@ohos.base';
6202audioRenderer.drain((err: BusinessError) => {
6203  if (err) {
6204    console.error('Renderer drain failed');
6205  } else {
6206    console.info('Renderer drained.');
6207  }
6208});
6209```
6210
6211### drain<sup>8+</sup>
6212
6213drain(): Promise\<void>
6214
6215Drains the playback buffer. This API uses a promise to return the result.
6216
6217**System capability**: SystemCapability.Multimedia.Audio.Renderer
6218
6219**Return value**
6220
6221| Type           | Description                        |
6222| -------------- | ---------------------------------- |
6223| Promise\<void> | Promise used to return the result. |
6224
6225**Example**
6226
6227```ts
6228import { BusinessError } from '@ohos.base';
6229audioRenderer.drain().then(() => {
6230  console.info('Renderer drained successfully');
6231}).catch((err: BusinessError) => {
6232  console.error(`ERROR: ${err}`);
6233});
6234```
6235
6236### stop<sup>8+</sup>
6237
6238stop(callback: AsyncCallback\<void>): void
6239
6240Stops rendering. This API uses an asynchronous callback to return the result.
6241
6242**System capability**: SystemCapability.Multimedia.Audio.Renderer
6243
6244**Parameters**
6245
6246| Name     | Type                 | Mandatory | Description                         |
6247| -------- | -------------------- | --------- | ----------------------------------- |
6248| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
6249
6250**Example**
6251
6252```ts
6253import { BusinessError } from '@ohos.base';
6254audioRenderer.stop((err: BusinessError) => {
6255  if (err) {
6256    console.error('Renderer stop failed');
6257  } else {
6258    console.info('Renderer stopped.');
6259  }
6260});
6261```
6262
6263### stop<sup>8+</sup>
6264
6265stop(): Promise\<void>
6266
6267Stops rendering. This API uses a promise to return the result.
6268
6269**System capability**: SystemCapability.Multimedia.Audio.Renderer
6270
6271**Return value**
6272
6273| Type           | Description                        |
6274| -------------- | ---------------------------------- |
6275| Promise\<void> | Promise used to return the result. |
6276
6277**Example**
6278
6279```ts
6280import { BusinessError } from '@ohos.base';
6281audioRenderer.stop().then(() => {
6282  console.info('Renderer stopped successfully');
6283}).catch((err: BusinessError) => {
6284  console.error(`ERROR: ${err}`);
6285});
6286```
6287
6288### release<sup>8+</sup>
6289
6290release(callback: AsyncCallback\<void>): void
6291
6292Releases the renderer. This API uses an asynchronous callback to return the result.
6293
6294**System capability**: SystemCapability.Multimedia.Audio.Renderer
6295
6296**Parameters**
6297
6298| Name     | Type                 | Mandatory | Description                         |
6299| -------- | -------------------- | --------- | ----------------------------------- |
6300| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
6301
6302**Example**
6303
6304```ts
6305import { BusinessError } from '@ohos.base';
6306audioRenderer.release((err: BusinessError) => {
6307  if (err) {
6308    console.error('Renderer release failed');
6309  } else {
6310    console.info('Renderer released.');
6311  }
6312});
6313```
6314
6315### release<sup>8+</sup>
6316
6317release(): Promise\<void>
6318
6319Releases the renderer. This API uses a promise to return the result.
6320
6321**System capability**: SystemCapability.Multimedia.Audio.Renderer
6322
6323**Return value**
6324
6325| Type           | Description                        |
6326| -------------- | ---------------------------------- |
6327| Promise\<void> | Promise used to return the result. |
6328
6329**Example**
6330
6331```ts
6332import { BusinessError } from '@ohos.base';
6333audioRenderer.release().then(() => {
6334  console.info('Renderer released successfully');
6335}).catch((err: BusinessError) => {
6336  console.error(`ERROR: ${err}`);
6337});
6338```
6339
6340### write<sup>8+</sup>
6341
6342write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void
6343
6344Writes the buffer. This API uses an asynchronous callback to return the result.
6345
6346**System capability**: SystemCapability.Multimedia.Audio.Renderer
6347
6348**Parameters**
6349
6350| Name     | Type                   | Mandatory | Description                                                  |
6351| -------- | ---------------------- | --------- | ------------------------------------------------------------ |
6352| buffer   | ArrayBuffer            | Yes       | Buffer to be written.                                        |
6353| callback | AsyncCallback\<number> | Yes       | Callback used to return the result. If the operation is successful, the number of bytes written is returned; otherwise, an error code is returned. |
6354
6355**Example**
6356
6357```ts
6358import { BusinessError } from '@ohos.base';
6359let bufferSize: number;
6360class Options {
6361  offset?: number;
6362  length?: number;
6363}
6364audioRenderer.getBufferSize().then((data: number)=> {
6365  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
6366  bufferSize = data;
6367  console.info(`Buffer size: ${bufferSize}`);
6368  let path = getContext().cacheDir;
6369  let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
6370  let file: fs.File = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
6371  fs.stat(filePath).then(async (stat: fs.Stat) => {
6372    let buf = new ArrayBuffer(bufferSize);
6373    let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1);
6374    for (let i = 0;i < len; i++) {
6375      let options: Options = {
6376        offset: i * bufferSize,
6377        length: bufferSize
6378      }
6379      let readsize: number = await fs.read(file.fd, buf, options)
6380      let writeSize: number = await new Promise((resolve,reject)=>{
6381        audioRenderer.write(buf,(err: BusinessError, writeSize: number)=>{
6382          if(err){
6383            reject(err)
6384          }else{
6385            resolve(writeSize)
6386          }
6387        })
6388      })
6389    }
6390  });
6391  }).catch((err: BusinessError) => {
6392    console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
6393});
6394
6395
6396```
6397
6398### write<sup>8+</sup>
6399
6400write(buffer: ArrayBuffer): Promise\<number>
6401
6402Writes the buffer. This API uses a promise to return the result.
6403
6404**System capability**: SystemCapability.Multimedia.Audio.Renderer
6405
6406**Return value**
6407
6408| Type             | Description                                                  |
6409| ---------------- | ------------------------------------------------------------ |
6410| Promise\<number> | Promise used to return the result. If the operation is successful, the number of bytes written is returned; otherwise, an error code is returned. |
6411
6412**Example**
6413
6414```ts
6415import { BusinessError } from '@ohos.base';
6416let bufferSize: number;
6417class Options {
6418  offset?: number;
6419  length?: number;
6420}
6421audioRenderer.getBufferSize().then((data: number) => {
6422  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
6423  bufferSize = data;
6424  console.info(`BufferSize: ${bufferSize}`);
6425  let path = getContext().cacheDir;
6426  let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
6427  let file: fs.File = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
6428  fs.stat(filePath).then(async (stat: fs.Stat) => {
6429    let buf = new ArrayBuffer(bufferSize);
6430    let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1);
6431    for (let i = 0;i < len; i++) {
6432      let options: Options = {
6433        offset: i * bufferSize,
6434        length: bufferSize
6435      }
6436      let readsize: number = await fs.read(file.fd, buf, options)
6437      try{
6438        let writeSize: number = await audioRenderer.write(buf);
6439      } catch(err) {
6440        let error = err as BusinessError;
6441        console.error(`audioRenderer.write err: ${error}`);
6442      }
6443    }
6444  });
6445  }).catch((err: BusinessError) => {
6446    console.info(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
6447});
6448```
6449
6450### getAudioTime<sup>8+</sup>
6451
6452getAudioTime(callback: AsyncCallback\<number>): void
6453
6454Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result.
6455
6456**System capability**: SystemCapability.Multimedia.Audio.Renderer
6457
6458**Parameters**
6459
6460| Name     | Type                   | Mandatory | Description                            |
6461| -------- | ---------------------- | --------- | -------------------------------------- |
6462| callback | AsyncCallback\<number> | Yes       | Callback used to return the timestamp. |
6463
6464**Example**
6465
6466```ts
6467import { BusinessError } from '@ohos.base';
6468audioRenderer.getAudioTime((err: BusinessError, timestamp: number) => {
6469  console.info(`Current timestamp: ${timestamp}`);
6470});
6471```
6472
6473### getAudioTime<sup>8+</sup>
6474
6475getAudioTime(): Promise\<number>
6476
6477Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
6478
6479**System capability**: SystemCapability.Multimedia.Audio.Renderer
6480
6481**Return value**
6482
6483| Type             | Description                           |
6484| ---------------- | ------------------------------------- |
6485| Promise\<number> | Promise used to return the timestamp. |
6486
6487**Example**
6488
6489```ts
6490import { BusinessError } from '@ohos.base';
6491audioRenderer.getAudioTime().then((timestamp: number) => {
6492  console.info(`Current timestamp: ${timestamp}`);
6493}).catch((err: BusinessError) => {
6494  console.error(`ERROR: ${err}`);
6495});
6496```
6497
6498### getAudioTimeSync<sup>10+</sup>
6499
6500getAudioTimeSync(): number
6501
6502Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API returns the result synchronously.
6503
6504**System capability**: SystemCapability.Multimedia.Audio.Renderer
6505
6506**Return value**
6507
6508| Type   | Description |
6509| ------ | ----------- |
6510| number | Timestamp.  |
6511
6512**Example**
6513
6514```ts
6515import { BusinessError } from '@ohos.base';
6516
6517try {
6518  let timestamp: number = audioRenderer.getAudioTimeSync();
6519  console.info(`Current timestamp: ${timestamp}`);
6520} catch (err) {
6521  let error = err as BusinessError;
6522  console.error(`ERROR: ${error}`);
6523}
6524```
6525
6526### getBufferSize<sup>8+</sup>
6527
6528getBufferSize(callback: AsyncCallback\<number>): void
6529
6530Obtains a reasonable minimum buffer size in bytes for rendering. This API uses an asynchronous callback to return the result.
6531
6532**System capability**: SystemCapability.Multimedia.Audio.Renderer
6533
6534**Parameters**
6535
6536| Name     | Type                   | Mandatory | Description                              |
6537| -------- | ---------------------- | --------- | ---------------------------------------- |
6538| callback | AsyncCallback\<number> | Yes       | Callback used to return the buffer size. |
6539
6540**Example**
6541
6542```ts
6543import { BusinessError } from '@ohos.base';
6544let bufferSize: number;
6545audioRenderer.getBufferSize((err: BusinessError, data: number) => {
6546  if (err) {
6547    console.error('getBufferSize error');
6548  } else {
6549    console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
6550    bufferSize = data;
6551  }
6552});
6553```
6554
6555### getBufferSize<sup>8+</sup>
6556
6557getBufferSize(): Promise\<number>
6558
6559Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a promise to return the result.
6560
6561**System capability**: SystemCapability.Multimedia.Audio.Renderer
6562
6563**Return value**
6564
6565| Type             | Description                             |
6566| ---------------- | --------------------------------------- |
6567| Promise\<number> | Promise used to return the buffer size. |
6568
6569**Example**
6570
6571```ts
6572import { BusinessError } from '@ohos.base';
6573let bufferSize: number;
6574audioRenderer.getBufferSize().then((data: number) => {
6575  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
6576  bufferSize = data;
6577}).catch((err: BusinessError) => {
6578  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
6579});
6580```
6581
6582### getBufferSizeSync<sup>10+</sup>
6583
6584getBufferSizeSync(): number
6585
6586Obtains a reasonable minimum buffer size in bytes for rendering. This API returns the result synchronously.
6587
6588**System capability**: SystemCapability.Multimedia.Audio.Renderer
6589
6590**Return value**
6591
6592| Type   | Description  |
6593| ------ | ------------ |
6594| number | Buffer size. |
6595
6596**Example**
6597
6598```ts
6599import { BusinessError } from '@ohos.base';
6600
6601let bufferSize: number = 0;
6602try {
6603  bufferSize = audioRenderer.getBufferSizeSync();
6604  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${bufferSize}`);
6605} catch (err) {
6606  let error = err as BusinessError;
6607  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${error}`);
6608}
6609```
6610
6611### setRenderRate<sup>8+</sup>
6612
6613setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\<void>): void
6614
6615Sets the render rate. This API uses an asynchronous callback to return the result.
6616
6617**System capability**: SystemCapability.Multimedia.Audio.Renderer
6618
6619**Parameters**
6620
6621| Name     | Type                                     | Mandatory | Description                         |
6622| -------- | ---------------------------------------- | --------- | ----------------------------------- |
6623| rate     | [AudioRendererRate](#audiorendererrate8) | Yes       | Audio render rate.                  |
6624| callback | AsyncCallback\<void>                     | Yes       | Callback used to return the result. |
6625
6626**Example**
6627
6628```ts
6629import { BusinessError } from '@ohos.base';
6630audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err: BusinessError) => {
6631  if (err) {
6632    console.error('Failed to set params');
6633  } else {
6634    console.info('Callback invoked to indicate a successful render rate setting.');
6635  }
6636});
6637```
6638
6639### setRenderRate<sup>8+</sup>
6640
6641setRenderRate(rate: AudioRendererRate): Promise\<void>
6642
6643Sets the render rate. This API uses a promise to return the result.
6644
6645**System capability**: SystemCapability.Multimedia.Audio.Renderer
6646
6647**Parameters**
6648
6649| Name | Type                                     | Mandatory | Description        |
6650| ---- | ---------------------------------------- | --------- | ------------------ |
6651| rate | [AudioRendererRate](#audiorendererrate8) | Yes       | Audio render rate. |
6652
6653**Return value**
6654
6655| Type           | Description                        |
6656| -------------- | ---------------------------------- |
6657| Promise\<void> | Promise used to return the result. |
6658
6659**Example**
6660
6661```ts
6662import { BusinessError } from '@ohos.base';
6663audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
6664  console.info('setRenderRate SUCCESS');
6665}).catch((err: BusinessError) => {
6666  console.error(`ERROR: ${err}`);
6667});
6668```
6669
6670### getRenderRate<sup>8+</sup>
6671
6672getRenderRate(callback: AsyncCallback\<AudioRendererRate>): void
6673
6674Obtains the current render rate. This API uses an asynchronous callback to return the result.
6675
6676**System capability**: SystemCapability.Multimedia.Audio.Renderer
6677
6678**Parameters**
6679
6680| Name     | Type                                                    | Mandatory | Description                                    |
6681| -------- | ------------------------------------------------------- | --------- | ---------------------------------------------- |
6682| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | Yes       | Callback used to return the audio render rate. |
6683
6684**Example**
6685
6686```ts
6687import { BusinessError } from '@ohos.base';
6688audioRenderer.getRenderRate((err: BusinessError, renderrate: audio.AudioRendererRate) => {
6689  console.info(`getRenderRate: ${renderrate}`);
6690});
6691```
6692
6693### getRenderRate<sup>8+</sup>
6694
6695getRenderRate(): Promise\<AudioRendererRate>
6696
6697Obtains the current render rate. This API uses a promise to return the result.
6698
6699**System capability**: SystemCapability.Multimedia.Audio.Renderer
6700
6701**Return value**
6702
6703| Type                                              | Description                                   |
6704| ------------------------------------------------- | --------------------------------------------- |
6705| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the audio render rate. |
6706
6707**Example**
6708
6709```ts
6710import { BusinessError } from '@ohos.base';
6711audioRenderer.getRenderRate().then((renderRate: audio.AudioRendererRate) => {
6712  console.info(`getRenderRate: ${renderRate}`);
6713}).catch((err: BusinessError) => {
6714  console.error(`ERROR: ${err}`);
6715});
6716```
6717
6718### getRenderRateSync<sup>10+</sup>
6719
6720getRenderRateSync(): AudioRendererRate
6721
6722Obtains the current render rate. This API returns the result synchronously.
6723
6724**System capability**: SystemCapability.Multimedia.Audio.Renderer
6725
6726**Return value**
6727
6728| Type                                     | Description        |
6729| ---------------------------------------- | ------------------ |
6730| [AudioRendererRate](#audiorendererrate8) | Audio render rate. |
6731
6732**Example**
6733
6734```ts
6735import { BusinessError } from '@ohos.base';
6736
6737try {
6738  let renderRate: audio.AudioRendererRate = audioRenderer.getRenderRateSync();
6739  console.info(`getRenderRate: ${renderRate}`);
6740} catch (err) {
6741  let error = err as BusinessError;
6742  console.error(`ERROR: ${error}`);
6743}
6744```
6745
6746### setInterruptMode<sup>9+</sup>
6747
6748setInterruptMode(mode: InterruptMode): Promise&lt;void&gt;
6749
6750Sets the audio interruption mode for the application. This API uses a promise to return the result.
6751
6752**System capability**: SystemCapability.Multimedia.Audio.Interrupt
6753
6754**Parameters**
6755
6756| Name | Type                             | Mandatory | Description              |
6757| ---- | -------------------------------- | --------- | ------------------------ |
6758| mode | [InterruptMode](#interruptmode9) | Yes       | Audio interruption mode. |
6759
6760**Return value**
6761
6762| Type                | Description                                                  |
6763| ------------------- | ------------------------------------------------------------ |
6764| Promise&lt;void&gt; | Promise used to return the result. If the operation is successful, **undefined** is returned. Otherwise, **error** is returned. |
6765
6766**Example**
6767
6768```ts
6769import { BusinessError } from '@ohos.base';
6770let mode = 0;
6771audioRenderer.setInterruptMode(mode).then(() => {
6772  console.info('setInterruptMode Success!');
6773}).catch((err: BusinessError) => {
6774  console.error(`setInterruptMode Fail: ${err}`);
6775});
6776```
6777### setInterruptMode<sup>9+</sup>
6778
6779setInterruptMode(mode: InterruptMode, callback: AsyncCallback\<void>): void
6780
6781Sets the audio interruption mode for the application. This API uses an asynchronous callback to return the result.
6782
6783**System capability**: SystemCapability.Multimedia.Audio.Interrupt
6784
6785**Parameters**
6786
6787| Name     | Type                             | Mandatory | Description                         |
6788| -------- | -------------------------------- | --------- | ----------------------------------- |
6789| mode     | [InterruptMode](#interruptmode9) | Yes       | Audio interruption mode.            |
6790| callback | AsyncCallback\<void>             | Yes       | Callback used to return the result. |
6791
6792**Example**
6793
6794```ts
6795import { BusinessError } from '@ohos.base';
6796let mode = 1;
6797audioRenderer.setInterruptMode(mode, (err: BusinessError) => {
6798  if(err){
6799    console.error(`setInterruptMode Fail: ${err}`);
6800  }
6801  console.info('setInterruptMode Success!');
6802});
6803```
6804
6805### setInterruptModeSync<sup>10+</sup>
6806
6807setInterruptModeSync(mode: InterruptMode): void
6808
6809Sets the audio interruption mode for the application. This API returns the result synchronously.
6810
6811**System capability**: SystemCapability.Multimedia.Audio.Interrupt
6812
6813**Parameters**
6814
6815| Name | Type                             | Mandatory | Description              |
6816| ---- | -------------------------------- | --------- | ------------------------ |
6817| mode | [InterruptMode](#interruptmode9) | Yes       | Audio interruption mode. |
6818
6819**Error codes**
6820
6821For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
6822
6823| ID      | Error Message           |
6824| ------- | ----------------------- |
6825| 6800101 | invalid parameter error              |
6826
6827**Example**
6828
6829```ts
6830import { BusinessError } from '@ohos.base';
6831
6832try {
6833  audioRenderer.setInterruptModeSync(0);
6834  console.info('setInterruptMode Success!');
6835} catch (err) {
6836  let error = err as BusinessError;
6837  console.error(`setInterruptMode Fail: ${error}`);
6838}
6839```
6840
6841### setVolume<sup>9+</sup>
6842
6843setVolume(volume: number): Promise&lt;void&gt;
6844
6845Sets the volume for the application. This API uses a promise to return the result.
6846
6847**System capability**: SystemCapability.Multimedia.Audio.Renderer
6848
6849**Parameters**
6850
6851| Name   | Type   | Mandatory | Description                                                  |
6852| ------ | ------ | --------- | ------------------------------------------------------------ |
6853| volume | number | Yes       | Volume to set, which can be within the range from 0.0 to 1.0. |
6854
6855**Return value**
6856
6857| Type                | Description                                                  |
6858| ------------------- | ------------------------------------------------------------ |
6859| Promise&lt;void&gt; | Promise used to return the result. If the operation is successful, **undefined** is returned. Otherwise, **error** is returned. |
6860
6861**Example**
6862
6863```ts
6864import { BusinessError } from '@ohos.base';
6865audioRenderer.setVolume(0.5).then(() => {
6866  console.info('setVolume Success!');
6867}).catch((err: BusinessError) => {
6868  console.error(`setVolume Fail: ${err}`);
6869});
6870```
6871### setVolume<sup>9+</sup>
6872
6873setVolume(volume: number, callback: AsyncCallback\<void>): void
6874
6875Sets the volume for the application. This API uses an asynchronous callback to return the result.
6876
6877**System capability**: SystemCapability.Multimedia.Audio.Renderer
6878
6879**Parameters**
6880
6881| Name     | Type                 | Mandatory | Description                                                  |
6882| -------- | -------------------- | --------- | ------------------------------------------------------------ |
6883| volume   | number               | Yes       | Volume to set, which can be within the range from 0.0 to 1.0. |
6884| callback | AsyncCallback\<void> | Yes       | Callback used to return the result.                          |
6885
6886**Example**
6887
6888```ts
6889import { BusinessError } from '@ohos.base';
6890audioRenderer.setVolume(0.5, (err: BusinessError) => {
6891  if(err){
6892    console.error(`setVolume Fail: ${err}`);
6893  }
6894  console.info('setVolume Success!');
6895});
6896```
6897
6898### getMinStreamVolume<sup>10+</sup>
6899
6900getMinStreamVolume(callback: AsyncCallback&lt;number&gt;): void
6901
6902Obtains the minimum volume of the application from the perspective of an audio stream. This API uses an asynchronous callback to return the result.
6903
6904**System capability**: SystemCapability.Multimedia.Audio.Renderer
6905
6906**Parameters**
6907
6908| Name     | Type                        | Mandatory | Description                                                  |
6909| -------- | --------------------------- | --------- | ------------------------------------------------------------ |
6910| callback | AsyncCallback&lt;number&gt; | Yes       | Callback used to return the minimum volume, ranging from 0 to 1. |
6911
6912**Example**
6913
6914```ts
6915import { BusinessError } from '@ohos.base';
6916audioRenderer.getMinStreamVolume((err: BusinessError, minVolume: number) => {
6917  if (err) {
6918    console.error(`getMinStreamVolume error: ${err}`);
6919  } else {
6920    console.info(`getMinStreamVolume Success! ${minVolume}`);
6921  }
6922});
6923```
6924### getMinStreamVolume<sup>10+</sup>
6925
6926getMinStreamVolume(): Promise&lt;number&gt;
6927
6928Obtains the minimum volume of the application from the perspective of an audio stream. This API uses a promise to return the result.
6929
6930**System capability**: SystemCapability.Multimedia.Audio.Renderer
6931
6932**Return value**
6933
6934| Type                  | Description                                                  |
6935| --------------------- | ------------------------------------------------------------ |
6936| Promise&lt;number&gt; | Promise used to return the minimum volume, ranging from 0 to 1. |
6937
6938**Example**
6939
6940```ts
6941import { BusinessError } from '@ohos.base';
6942audioRenderer.getMinStreamVolume().then((value: number) => {
6943  console.info(`Get min stream volume Success! ${value}`);
6944}).catch((err: BusinessError) => {
6945  console.error(`Get min stream volume Fail: ${err}`);
6946});
6947```
6948
6949### getMinStreamVolumeSync<sup>10+</sup>
6950
6951getMinStreamVolumeSync(): number
6952
6953Obtains the minimum volume of the application from the perspective of an audio stream. This API returns the result synchronously.
6954
6955**System capability**: SystemCapability.Multimedia.Audio.Renderer
6956
6957**Return value**
6958
6959| Type   | Description                          |
6960| ------ | ------------------------------------ |
6961| number | Minimum volume, ranging from 0 to 1. |
6962
6963**Example**
6964
6965```ts
6966import { BusinessError } from '@ohos.base';
6967
6968try {
6969  let value: number = audioRenderer.getMinStreamVolumeSync();
6970  console.info(`Get min stream volume Success! ${value}`);
6971} catch (err) {
6972  let error = err as BusinessError;
6973  console.error(`Get min stream volume Fail: ${error}`);
6974}
6975```
6976
6977### getMaxStreamVolume<sup>10+</sup>
6978
6979getMaxStreamVolume(callback: AsyncCallback&lt;number&gt;): void
6980
6981Obtains the maximum volume of the application from the perspective of an audio stream. This API uses an asynchronous callback to return the result.
6982
6983**System capability**: SystemCapability.Multimedia.Audio.Renderer
6984
6985**Parameters**
6986
6987| Name     | Type                        | Mandatory | Description                                                  |
6988| -------- | --------------------------- | --------- | ------------------------------------------------------------ |
6989| callback | AsyncCallback&lt;number&gt; | Yes       | Callback used to return the maximum volume, ranging from 0 to 1. |
6990
6991**Example**
6992
6993```ts
6994import { BusinessError } from '@ohos.base';
6995audioRenderer.getMaxStreamVolume((err: BusinessError, maxVolume: number) => {
6996  if (err) {
6997    console.error(`getMaxStreamVolume Fail: ${err}`);
6998  } else {
6999    console.info(`getMaxStreamVolume Success! ${maxVolume}`);
7000  }
7001});
7002```
7003### getMaxStreamVolume<sup>10+</sup>
7004
7005getMaxStreamVolume(): Promise&lt;number&gt;
7006
7007Obtains the maximum volume of the application from the perspective of an audio stream. This API uses a promise to return the result.
7008
7009**System capability**: SystemCapability.Multimedia.Audio.Renderer
7010
7011**Return value**
7012
7013| Type                  | Description                                                  |
7014| --------------------- | ------------------------------------------------------------ |
7015| Promise&lt;number&gt; | Promise used to return the maximum volume, ranging from 0 to 1. |
7016
7017**Example**
7018
7019```ts
7020import { BusinessError } from '@ohos.base';
7021audioRenderer.getMaxStreamVolume().then((value: number) => {
7022  console.info(`Get max stream volume Success! ${value}`);
7023}).catch((err: BusinessError) => {
7024  console.error(`Get max stream volume Fail: ${err}`);
7025});
7026```
7027
7028### getMaxStreamVolumeSync<sup>10+</sup>
7029
7030getMaxStreamVolumeSync(): number
7031
7032Obtains the maximum volume of the application from the perspective of an audio stream. This API returns the result synchronously.
7033
7034**System capability**: SystemCapability.Multimedia.Audio.Renderer
7035
7036**Return value**
7037
7038| Type   | Description                          |
7039| ------ | ------------------------------------ |
7040| number | Maximum volume, ranging from 0 to 1. |
7041
7042**Example**
7043
7044```ts
7045import { BusinessError } from '@ohos.base';
7046
7047try {
7048  let value: number = audioRenderer.getMaxStreamVolumeSync();
7049  console.info(`Get max stream volume Success! ${value}`);
7050} catch (err) {
7051  let error = err as BusinessError;
7052  console.error(`Get max stream volume Fail: ${error}`);
7053}
7054```
7055
7056### getUnderflowCount<sup>10+</sup>
7057
7058getUnderflowCount(callback: AsyncCallback&lt;number&gt;): void
7059
7060Obtains the number of underflow audio frames in the audio stream that is being played. This API uses an asynchronous callback to return the result.
7061
7062**System capability**: SystemCapability.Multimedia.Audio.Renderer
7063
7064**Parameters**
7065
7066| Name     | Type                        | Mandatory | Description                                                  |
7067| -------- | --------------------------- | --------- | ------------------------------------------------------------ |
7068| callback | AsyncCallback&lt;number&gt; | Yes       | Callback used to return the number of underflow audio frames. |
7069
7070**Example**
7071
7072```ts
7073import { BusinessError } from '@ohos.base';
7074audioRenderer.getUnderflowCount((err: BusinessError, underflowCount: number) => {
7075  if (err) {
7076    console.error(`getUnderflowCount Fail: ${err}`);
7077  } else {
7078    console.info(`getUnderflowCount Success! ${underflowCount}`);
7079  }
7080});
7081```
7082### getUnderflowCount<sup>10+</sup>
7083
7084getUnderflowCount(): Promise&lt;number&gt;
7085
7086Obtains the number of underflow audio frames in the audio stream that is being played. This API uses a promise to return the result.
7087
7088**System capability**: SystemCapability.Multimedia.Audio.Renderer
7089
7090**Return value**
7091
7092| Type                  | Description                                                  |
7093| --------------------- | ------------------------------------------------------------ |
7094| Promise&lt;number&gt; | Promise used to return the number of underflow audio frames. |
7095
7096**Example**
7097
7098```ts
7099import { BusinessError } from '@ohos.base';
7100audioRenderer.getUnderflowCount().then((value: number) => {
7101  console.info(`Get underflow count Success! ${value}`);
7102}).catch((err: BusinessError) => {
7103  console.error(`Get underflow count Fail: ${err}`);
7104});
7105```
7106
7107### getUnderflowCountSync<sup>10+</sup>
7108
7109getUnderflowCountSync(): number
7110
7111Obtains the number of underflow audio frames in the audio stream that is being played. This API returns the result synchronously.
7112
7113**System capability**: SystemCapability.Multimedia.Audio.Renderer
7114
7115**Return value**
7116
7117| Type   | Description                       |
7118| ------ | --------------------------------- |
7119| number | Number of underflow audio frames. |
7120
7121**Example**
7122
7123```ts
7124import { BusinessError } from '@ohos.base';
7125
7126try {
7127  let value: number = audioRenderer.getUnderflowCountSync();
7128  console.info(`Get underflow count Success! ${value}`);
7129} catch (err) {
7130  let error = err as BusinessError;
7131  console.error(`Get underflow count Fail: ${error}`);
7132}
7133```
7134
7135### getCurrentOutputDevices<sup>10+</sup>
7136
7137getCurrentOutputDevices(callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
7138
7139Obtains the output device descriptors of the audio streams. This API uses an asynchronous callback to return the result.
7140
7141**System capability**: SystemCapability.Multimedia.Audio.Device
7142
7143**Parameters**
7144
7145| Name     | Type                                        | Mandatory | Description                                            |
7146| -------- | ------------------------------------------- | --------- | ------------------------------------------------------ |
7147| callback | AsyncCallback&lt;AudioDeviceDescriptors&gt; | Yes       | Callback used to return the output device descriptors. |
7148
7149**Example**
7150
7151```ts
7152import { BusinessError } from '@ohos.base';
7153audioRenderer.getCurrentOutputDevices((err: BusinessError, deviceInfo: audio.AudioDeviceDescriptors) => {
7154  if (err) {
7155    console.error(`getCurrentOutputDevices Fail: ${err}`);
7156  } else {
7157    for (let i = 0; i < deviceInfo.length; i++) {
7158      console.info(`DeviceInfo id: ${deviceInfo[i].id}`);
7159      console.info(`DeviceInfo type: ${deviceInfo[i].deviceType}`);
7160      console.info(`DeviceInfo role: ${deviceInfo[i].deviceRole}`);
7161      console.info(`DeviceInfo name: ${deviceInfo[i].name}`);
7162      console.info(`DeviceInfo address: ${deviceInfo[i].address}`);
7163      console.info(`DeviceInfo samplerate: ${deviceInfo[i].sampleRates[0]}`);
7164      console.info(`DeviceInfo channelcount: ${deviceInfo[i].channelCounts[0]}`);
7165      console.info(`DeviceInfo channelmask: ${deviceInfo[i].channelMasks[0]}`);
7166    }
7167  }
7168});
7169```
7170### getCurrentOutputDevices<sup>10+</sup>
7171
7172getCurrentOutputDevices(): Promise&lt;AudioDeviceDescriptors&gt;
7173
7174Obtains the output device descriptors of the audio streams. This API uses a promise to return the result.
7175
7176**System capability**: SystemCapability.Multimedia.Audio.Device
7177
7178**Return value**
7179
7180| Type                                  | Description                                           |
7181| ------------------------------------- | ----------------------------------------------------- |
7182| Promise&lt;AudioDeviceDescriptors&gt; | Promise used to return the output device descriptors. |
7183
7184**Example**
7185
7186```ts
7187import { BusinessError } from '@ohos.base';
7188audioRenderer.getCurrentOutputDevices().then((deviceInfo: audio.AudioDeviceDescriptors) => {
7189  for (let i = 0; i < deviceInfo.length; i++) {
7190    console.info(`DeviceInfo id: ${deviceInfo[i].id}`);
7191    console.info(`DeviceInfo type: ${deviceInfo[i].deviceType}`);
7192    console.info(`DeviceInfo role: ${deviceInfo[i].deviceRole}`);
7193    console.info(`DeviceInfo name: ${deviceInfo[i].name}`);
7194    console.info(`DeviceInfo address: ${deviceInfo[i].address}`);
7195    console.info(`DeviceInfo samplerate: ${deviceInfo[i].sampleRates[0]}`);
7196    console.info(`DeviceInfo channelcount: ${deviceInfo[i].channelCounts[0]}`);
7197    console.info(`DeviceInfo channelmask: ${deviceInfo[i].channelMasks[0]}`);
7198  }
7199}).catch((err: BusinessError) => {
7200  console.error(`Get current output devices Fail: ${err}`);
7201});
7202```
7203
7204### getCurrentOutputDevicesSync<sup>10+</sup>
7205
7206getCurrentOutputDevicesSync(): AudioDeviceDescriptors
7207
7208Obtains the output device descriptors of the audio streams. This API returns the result synchronously.
7209
7210**System capability**: SystemCapability.Multimedia.Audio.Device
7211
7212**Return value**
7213
7214| Type                   | Description                |
7215| ---------------------- | -------------------------- |
7216| AudioDeviceDescriptors | Output device descriptors. |
7217
7218**Example**
7219
7220```ts
7221import { BusinessError } from '@ohos.base';
7222
7223try {
7224  let deviceInfo: audio.AudioDeviceDescriptors = audioRenderer.getCurrentOutputDevicesSync();
7225  for (let i = 0; i < deviceInfo.length; i++) {
7226    console.info(`DeviceInfo id: ${deviceInfo[i].id}`);
7227    console.info(`DeviceInfo type: ${deviceInfo[i].deviceType}`);
7228    console.info(`DeviceInfo role: ${deviceInfo[i].deviceRole}`);
7229    console.info(`DeviceInfo name: ${deviceInfo[i].name}`);
7230    console.info(`DeviceInfo address: ${deviceInfo[i].address}`);
7231    console.info(`DeviceInfo samplerate: ${deviceInfo[i].sampleRates[0]}`);
7232    console.info(`DeviceInfo channelcount: ${deviceInfo[i].channelCounts[0]}`);
7233    console.info(`DeviceInfo channelmask: ${deviceInfo[i].channelMasks[0]}`);
7234  }
7235} catch (err) {
7236  let error = err as BusinessError;
7237  console.error(`Get current output devices Fail: ${error}`);
7238}
7239```
7240
7241### on('audioInterrupt')<sup>9+</sup>
7242
7243on(type: 'audioInterrupt', callback: Callback\<InterruptEvent>): void
7244
7245Subscribes to audio interruption events. This API uses a callback to obtain interrupt events.
7246
7247Same 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.
7248
7249**System capability**: SystemCapability.Multimedia.Audio.Interrupt
7250
7251**Parameters**
7252
7253| Name     | Type                                           | Mandatory | Description                                                  |
7254| -------- | ---------------------------------------------- | --------- | ------------------------------------------------------------ |
7255| type     | string                                         | Yes       | Event type. The event **'audioInterrupt'** is triggered when audio rendering is interrupted. |
7256| callback | Callback\<[InterruptEvent](#interruptevent9)\> | Yes       | Callback used to return the audio interruption event.        |
7257
7258**Error codes**
7259
7260For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
7261
7262| ID      | Error Message                  |
7263| ------- | ------------------------------ |
7264| 6800101 | if input parameter value error              |
7265
7266**Example**
7267
7268```ts
7269import audio from '@ohos.multimedia.audio';
7270
7271let isPlaying: boolean; // An identifier specifying whether rendering is in progress.
7272let isDucked: boolean; // An identifier specifying whether the audio volume is reduced.
7273onAudioInterrupt();
7274
7275async function onAudioInterrupt(){
7276  audioRenderer.on('audioInterrupt', (interruptEvent: audio.InterruptEvent) => {
7277    if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
7278      // The system forcibly interrupts audio rendering. The application must update the status and displayed content accordingly.
7279      switch (interruptEvent.hintType) {
7280        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
7281          // 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.
7282          console.info('Force paused. Update playing status and stop writing');
7283          isPlaying = false; // A simplified processing indicating several operations for switching the application to the paused state.
7284          break;
7285        case audio.InterruptHint.INTERRUPT_HINT_STOP:
7286          // The audio stream has been stopped and permanently loses the focus. The user must manually trigger the operation to resume rendering.
7287          console.info('Force stopped. Update playing status and stop writing');
7288          isPlaying = false; // A simplified processing indicating several operations for switching the application to the paused state.
7289          break;
7290        case audio.InterruptHint.INTERRUPT_HINT_DUCK:
7291          // The audio stream is rendered at a reduced volume.
7292          console.info('Force ducked. Update volume status');
7293          isDucked = true; // A simplified processing indicating several operations for updating the volume status.
7294          break;
7295        case audio.InterruptHint.INTERRUPT_HINT_UNDUCK:
7296          // The audio stream is rendered at the normal volume.
7297          console.info('Force ducked. Update volume status');
7298          isDucked = false; // A simplified processing indicating several operations for updating the volume status.
7299          break;
7300        default:
7301          console.info('Invalid interruptEvent');
7302          break;
7303      }
7304    } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
7305      // The application can choose to take action or ignore.
7306      switch (interruptEvent.hintType) {
7307        case audio.InterruptHint.INTERRUPT_HINT_RESUME:
7308          // 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.)
7309          console.info('Resume force paused renderer or ignore');
7310          // To continue rendering, the application must perform the required operations.
7311          break;
7312        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
7313          // It is recommended that the application pause rendering.
7314          console.info('Choose to pause or ignore');
7315          // To pause rendering, the application must perform the required operations.
7316          break;
7317        case audio.InterruptHint.INTERRUPT_HINT_STOP:
7318          // It is recommended that the application stop rendering.
7319          console.info('Choose to stop or ignore');
7320          // To stop rendering, the application must perform the required operations.
7321          break;
7322        case audio.InterruptHint.INTERRUPT_HINT_DUCK:
7323          // It is recommended that the application reduce the volume for rendering.
7324          console.info('Choose to duck or ignore');
7325          // To decrease the volume for rendering, the application must perform the required operations.
7326          break;
7327        case audio.InterruptHint.INTERRUPT_HINT_UNDUCK:
7328          // It is recommended that the application resume rendering at the normal volume.
7329          console.info('Choose to unduck or ignore');
7330          // To resume rendering at the normal volume, the application must perform the required operations.
7331          break;
7332        default:
7333          break;
7334      }
7335    }
7336  });
7337}
7338```
7339
7340### on('markReach')<sup>8+</sup>
7341
7342on(type: 'markReach', frame: number, callback: Callback&lt;number&gt;): void
7343
7344Subscribes to mark reached events. When the number of frames rendered reaches the value of the **frame** parameter, a callback is invoked.
7345
7346**System capability**: SystemCapability.Multimedia.Audio.Renderer
7347
7348**Parameters**
7349
7350| Name     | Type              | Mandatory | Description                                                  |
7351| :------- | :---------------- | :-------- | :----------------------------------------------------------- |
7352| type     | string            | Yes       | Event type. The value is fixed at **'markReach'**.           |
7353| frame    | number            | Yes       | Number of frames to trigger the event. The value must be greater than **0**. |
7354| callback | Callback\<number> | Yes       | Callback invoked when the event is triggered.                |
7355
7356**Example**
7357
7358```ts
7359audioRenderer.on('markReach', 1000, (position: number) => {
7360  if (position == 1000) {
7361    console.info('ON Triggered successfully');
7362  }
7363});
7364```
7365
7366
7367### off('markReach') <sup>8+</sup>
7368
7369off(type: 'markReach'): void
7370
7371Unsubscribes from mark reached events.
7372
7373**System capability**: SystemCapability.Multimedia.Audio.Renderer
7374
7375**Parameters**
7376
7377| Name | Type   | Mandatory | Description                                        |
7378| :--- | :----- | :-------- | :------------------------------------------------- |
7379| type | string | Yes       | Event type. The value is fixed at **'markReach'**. |
7380
7381**Example**
7382
7383```ts
7384audioRenderer.off('markReach');
7385```
7386
7387### on('periodReach') <sup>8+</sup>
7388
7389on(type: 'periodReach', frame: number, callback: Callback&lt;number&gt;): void
7390
7391Subscribes 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.
7392
7393**System capability**: SystemCapability.Multimedia.Audio.Renderer
7394
7395**Parameters**
7396
7397| Name     | Type              | Mandatory | Description                                                  |
7398| :------- | :---------------- | :-------- | :----------------------------------------------------------- |
7399| type     | string            | Yes       | Event type. The value is fixed at **'periodReach'**.         |
7400| frame    | number            | Yes       | Number of frames to trigger the event. The value must be greater than **0**. |
7401| callback | Callback\<number> | Yes       | Callback invoked when the event is triggered.                |
7402
7403**Example**
7404
7405```ts
7406audioRenderer.on('periodReach', 1000, (position: number) => {
7407  if (position == 1000) {
7408    console.info('ON Triggered successfully');
7409  }
7410});
7411```
7412
7413### off('periodReach') <sup>8+</sup>
7414
7415off(type: 'periodReach'): void
7416
7417Unsubscribes from period reached events.
7418
7419**System capability**: SystemCapability.Multimedia.Audio.Renderer
7420
7421**Parameters**
7422
7423| Name | Type   | Mandatory | Description                                          |
7424| :--- | :----- | :-------- | :--------------------------------------------------- |
7425| type | string | Yes       | Event type. The value is fixed at **'periodReach'**. |
7426
7427**Example**
7428
7429```ts
7430audioRenderer.off('periodReach')
7431```
7432
7433### on('stateChange') <sup>8+</sup>
7434
7435on(type: 'stateChange', callback: Callback<AudioState\>): void
7436
7437Subscribes to state change events.
7438
7439**System capability**: SystemCapability.Multimedia.Audio.Renderer
7440
7441**Parameters**
7442
7443| Name     | Type                                  | Mandatory | Description                                                  |
7444| :------- | :------------------------------------ | :-------- | :----------------------------------------------------------- |
7445| type     | string                                | Yes       | Event type. The value **stateChange** means the state change event. |
7446| callback | Callback\<[AudioState](#audiostate8)> | Yes       | Callback used to return the state change.                    |
7447
7448**Example**
7449
7450```ts
7451audioRenderer.on('stateChange', (state: audio.AudioState) => {
7452  if (state == 1) {
7453    console.info('audio renderer state is: STATE_PREPARED');
7454  }
7455  if (state == 2) {
7456    console.info('audio renderer state is: STATE_RUNNING');
7457  }
7458});
7459```
7460
7461### on('outputDeviceChange') <sup>10+</sup>
7462
7463on(type: 'outputDeviceChange', callback: Callback\<AudioDeviceDescriptors>): void;
7464
7465Subscribes to audio output device change events.
7466
7467**System capability**: SystemCapability.Multimedia.Audio.Device
7468
7469**Parameters**
7470
7471| Name     | Type                                                         | Mandatory | Description                                                  |
7472| :------- | :----------------------------------------------------------- | :-------- | :----------------------------------------------------------- |
7473| type     | string                                                       | Yes       | Event type. The event **'outputDeviceChange'** is triggered when the audio output device is changed. |
7474| callback | Callback\<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Yes       | Callback used to return the audio output device change.      |
7475
7476**Error codes**
7477
7478| ID      | Error Message                   |
7479| ------- | ------------------------------- |
7480| 6800101 | if input parameter value error.              |
7481
7482**Example**
7483
7484```ts
7485audioRenderer.on('outputDeviceChange', (deviceInfo: audio.AudioDeviceDescriptors) => {
7486  console.info(`DeviceInfo id: ${deviceInfo[0].id}`);
7487  console.info(`DeviceInfo name: ${deviceInfo[0].name}`);
7488  console.info(`DeviceInfo address: ${deviceInfo[0].address}`);
7489});
7490```
7491### off('outputDeviceChange') <sup>10+</sup>
7492
7493off(type: 'outputDeviceChange', callback?: Callback\<AudioDeviceDescriptors>): void;
7494
7495Unsubscribes from audio output device change events.
7496
7497**System capability**: SystemCapability.Multimedia.Audio.Device
7498
7499**Parameters**
7500
7501| Name     | Type                                                         | Mandatory | Description                                                  |
7502| :------- | :----------------------------------------------------------- | :-------- | :----------------------------------------------------------- |
7503| type     | string                                                       | Yes       | Event type. The event **'outputDeviceChange'** is triggered when the audio output device is changed. |
7504| callback | Callback\<[AudioDeviceDescriptors](#audiodevicedescriptors)> | No        | Callback used for unsubscription.                            |
7505
7506**Error codes**
7507
7508| ID      | Error Message                   |
7509| ------- | ------------------------------- |
7510| 6800101 | if input parameter value error.              |
7511
7512**Example**
7513
7514```ts
7515audioRenderer.off('outputDeviceChange', (deviceInfo: audio.AudioDeviceDescriptors) => {
7516  console.info(`DeviceInfo id: ${deviceInfo[0].id}`);
7517  console.info(`DeviceInfo name: ${deviceInfo[0].name}`);
7518  console.info(`DeviceInfo address: ${deviceInfo[0].address}`);
7519});
7520```
7521
7522## AudioCapturer<sup>8+</sup>
7523
7524Provides APIs for audio capture. Before calling any API in **AudioCapturer**, you must use [createAudioCapturer](#audiocreateaudiocapturer8) to create an **AudioCapturer** instance.
7525
7526### Attributes
7527
7528**System capability**: SystemCapability.Multimedia.Audio.Capturer
7529
7530| Name               | Type                       | Readable | Writable | Description           |
7531| :----------------- | :------------------------- | :------- | :------- | :-------------------- |
7532| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes      | No       | Audio capturer state. |
7533
7534**Example**
7535
7536```ts
7537import audio from '@ohos.multimedia.audio';
7538let state: audio.AudioState = audioCapturer.state;
7539```
7540
7541### getCapturerInfo<sup>8+</sup>
7542
7543getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void
7544
7545Obtains the capturer information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
7546
7547**System capability**: SystemCapability.Multimedia.Audio.Capturer
7548
7549**Parameters**
7550
7551| Name     | Type                              | Mandatory | Description                                       |
7552| :------- | :-------------------------------- | :-------- | :------------------------------------------------ |
7553| callback | AsyncCallback<AudioCapturerInfo\> | Yes       | Callback used to return the capturer information. |
7554
7555**Example**
7556
7557```ts
7558import { BusinessError } from '@ohos.base';
7559audioCapturer.getCapturerInfo((err: BusinessError, capturerInfo: audio.AudioCapturerInfo) => {
7560  if (err) {
7561    console.error('Failed to get capture info');
7562  } else {
7563    console.info('Capturer getCapturerInfo:');
7564    console.info(`Capturer source: ${capturerInfo.source}`);
7565    console.info(`Capturer flags: ${capturerInfo.capturerFlags}`);
7566  }
7567});
7568```
7569
7570
7571### getCapturerInfo<sup>8+</sup>
7572
7573getCapturerInfo(): Promise<AudioCapturerInfo\>
7574
7575Obtains the capturer information of this **AudioCapturer** instance. This API uses a promise to return the result.
7576
7577**System capability**: SystemCapability.Multimedia.Audio.Capturer
7578
7579**Return value**
7580
7581| Type                                              | Description                                      |
7582| :------------------------------------------------ | :----------------------------------------------- |
7583| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information. |
7584
7585**Example**
7586
7587```ts
7588import { BusinessError } from '@ohos.base';
7589audioCapturer.getCapturerInfo().then((audioParamsGet: audio.AudioCapturerInfo) => {
7590  if (audioParamsGet != undefined) {
7591    console.info('AudioFrameworkRecLog: Capturer CapturerInfo:');
7592    console.info(`AudioFrameworkRecLog: Capturer SourceType: ${audioParamsGet.source}`);
7593    console.info(`AudioFrameworkRecLog: Capturer capturerFlags: ${audioParamsGet.capturerFlags}`);
7594  } else {
7595    console.info(`AudioFrameworkRecLog: audioParamsGet is : ${audioParamsGet}`);
7596    console.info('AudioFrameworkRecLog: audioParams getCapturerInfo are incorrect');
7597  }
7598}).catch((err: BusinessError) => {
7599  console.error(`AudioFrameworkRecLog: CapturerInfo :ERROR: ${err}`);
7600})
7601```
7602
7603### getCapturerInfoSync<sup>10+</sup>
7604
7605getCapturerInfoSync(): AudioCapturerInfo
7606
7607Obtains the capturer information of this **AudioCapturer** instance. This API returns the result synchronously.
7608
7609**System capability**: SystemCapability.Multimedia.Audio.Capturer
7610
7611**Return value**
7612
7613| Type                                    | Description           |
7614| :-------------------------------------- | :-------------------- |
7615| [AudioCapturerInfo](#audiocapturerinfo) | Capturer information. |
7616
7617**Example**
7618
7619```ts
7620import { BusinessError } from '@ohos.base';
7621
7622try {
7623  let audioParamsGet: audio.AudioCapturerInfo = audioCapturer.getCapturerInfoSync();
7624  console.info(`AudioFrameworkRecLog: Capturer SourceType: ${audioParamsGet.source}`);
7625  console.info(`AudioFrameworkRecLog: Capturer capturerFlags: ${audioParamsGet.capturerFlags}`);
7626} catch (err) {
7627  let error = err as BusinessError;
7628  console.error(`AudioFrameworkRecLog: CapturerInfo :ERROR: ${error}`);
7629}
7630```
7631
7632### getStreamInfo<sup>8+</sup>
7633
7634getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
7635
7636Obtains the stream information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
7637
7638**System capability**: SystemCapability.Multimedia.Audio.Capturer
7639
7640**Parameters**
7641
7642| Name     | Type                                                 | Mandatory | Description                                     |
7643| :------- | :--------------------------------------------------- | :-------- | :---------------------------------------------- |
7644| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes       | Callback used to return the stream information. |
7645
7646**Example**
7647
7648```ts
7649import { BusinessError } from '@ohos.base';
7650audioCapturer.getStreamInfo((err: BusinessError, streamInfo: audio.AudioStreamInfo) => {
7651  if (err) {
7652    console.error('Failed to get stream info');
7653  } else {
7654    console.info('Capturer GetStreamInfo:');
7655    console.info(`Capturer sampling rate: ${streamInfo.samplingRate}`);
7656    console.info(`Capturer channel: ${streamInfo.channels}`);
7657    console.info(`Capturer format: ${streamInfo.sampleFormat}`);
7658    console.info(`Capturer encoding type: ${streamInfo.encodingType}`);
7659  }
7660});
7661```
7662
7663### getStreamInfo<sup>8+</sup>
7664
7665getStreamInfo(): Promise<AudioStreamInfo\>
7666
7667Obtains the stream information of this **AudioCapturer** instance. This API uses a promise to return the result.
7668
7669**System capability**: SystemCapability.Multimedia.Audio.Capturer
7670
7671**Return value**
7672
7673| Type                                           | Description                                    |
7674| :--------------------------------------------- | :--------------------------------------------- |
7675| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
7676
7677**Example**
7678
7679```ts
7680import { BusinessError } from '@ohos.base';
7681audioCapturer.getStreamInfo().then((audioParamsGet: audio.AudioStreamInfo) => {
7682  console.info('getStreamInfo:');
7683  console.info(`sampleFormat: ${audioParamsGet.sampleFormat}`);
7684  console.info(`samplingRate: ${audioParamsGet.samplingRate}`);
7685  console.info(`channels: ${audioParamsGet.channels}`);
7686  console.info(`encodingType: ${audioParamsGet.encodingType}`);
7687}).catch((err: BusinessError) => {
7688  console.error(`getStreamInfo :ERROR: ${err}`);
7689});
7690```
7691
7692### getStreamInfoSync<sup>10+</sup>
7693
7694getStreamInfoSync(): AudioStreamInfo
7695
7696Obtains the stream information of this **AudioCapturer** instance. This API returns the result synchronously.
7697
7698**System capability**: SystemCapability.Multimedia.Audio.Capturer
7699
7700**Return value**
7701
7702| Type                                 | Description         |
7703| :----------------------------------- | :------------------ |
7704| [AudioStreamInfo](#audiostreaminfo8) | Stream information. |
7705
7706**Example**
7707
7708```ts
7709import { BusinessError } from '@ohos.base';
7710
7711try {
7712  let audioParamsGet: audio.AudioStreamInfo = audioCapturer.getStreamInfoSync();
7713  console.info(`sampleFormat: ${audioParamsGet.sampleFormat}`);
7714  console.info(`samplingRate: ${audioParamsGet.samplingRate}`);
7715  console.info(`channels: ${audioParamsGet.channels}`);
7716  console.info(`encodingType: ${audioParamsGet.encodingType}`);
7717} catch (err) {
7718  let error = err as BusinessError;
7719  console.error(`getStreamInfo :ERROR: ${error}`);
7720}
7721```
7722
7723### getAudioStreamId<sup>9+</sup>
7724
7725getAudioStreamId(callback: AsyncCallback<number\>): void
7726
7727Obtains the stream ID of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
7728
7729**System capability**: SystemCapability.Multimedia.Audio.Capturer
7730
7731**Parameters**
7732
7733| Name     | Type                   | Mandatory | Description                            |
7734| :------- | :--------------------- | :-------- | :------------------------------------- |
7735| callback | AsyncCallback<number\> | Yes       | Callback used to return the stream ID. |
7736
7737**Example**
7738
7739```ts
7740import { BusinessError } from '@ohos.base';
7741audioCapturer.getAudioStreamId((err: BusinessError, streamid: number) => {
7742  console.info(`audioCapturer GetStreamId: ${streamid}`);
7743});
7744```
7745
7746### getAudioStreamId<sup>9+</sup>
7747
7748getAudioStreamId(): Promise<number\>
7749
7750Obtains the stream ID of this **AudioCapturer** instance. This API uses a promise to return the result.
7751
7752**System capability**: SystemCapability.Multimedia.Audio.Capturer
7753
7754**Return value**
7755
7756| Type             | Description                           |
7757| :--------------- | :------------------------------------ |
7758| Promise<number\> | Promise used to return the stream ID. |
7759
7760**Example**
7761
7762```ts
7763import { BusinessError } from '@ohos.base';
7764audioCapturer.getAudioStreamId().then((streamid: number) => {
7765  console.info(`audioCapturer getAudioStreamId: ${streamid}`);
7766}).catch((err: BusinessError) => {
7767  console.error(`ERROR: ${err}`);
7768});
7769```
7770
7771### getAudioStreamIdSync<sup>10+</sup>
7772
7773getAudioStreamIdSync(): number
7774
7775Obtains the stream ID of this **AudioCapturer** instance. This API returns the result synchronously.
7776
7777**System capability**: SystemCapability.Multimedia.Audio.Capturer
7778
7779**Return value**
7780
7781| Type   | Description |
7782| :----- | :---------- |
7783| number | Stream ID.  |
7784
7785**Example**
7786
7787```ts
7788import { BusinessError } from '@ohos.base';
7789
7790try {
7791  let streamid: number = audioCapturer.getAudioStreamIdSync();
7792  console.info(`audioCapturer getAudioStreamIdSync: ${streamid}`);
7793} catch (err) {
7794  let error = err as BusinessError;
7795  console.error(`ERROR: ${error}`);
7796}
7797```
7798
7799### start<sup>8+</sup>
7800
7801start(callback: AsyncCallback<void\>): void
7802
7803Starts capturing. This API uses an asynchronous callback to return the result.
7804
7805**System capability**: SystemCapability.Multimedia.Audio.Capturer
7806
7807**Parameters**
7808
7809| Name     | Type                 | Mandatory | Description                         |
7810| :------- | :------------------- | :-------- | :---------------------------------- |
7811| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
7812
7813**Example**
7814
7815```ts
7816import { BusinessError } from '@ohos.base';
7817audioCapturer.start((err: BusinessError) => {
7818  if (err) {
7819    console.error('Capturer start failed.');
7820  } else {
7821    console.info('Capturer start success.');
7822  }
7823});
7824```
7825
7826
7827### start<sup>8+</sup>
7828
7829start(): Promise<void\>
7830
7831Starts capturing. This API uses a promise to return the result.
7832
7833**System capability**: SystemCapability.Multimedia.Audio.Capturer
7834
7835**Return value**
7836
7837| Type           | Description                        |
7838| :------------- | :--------------------------------- |
7839| Promise<void\> | Promise used to return the result. |
7840
7841**Example**
7842
7843```ts
7844import { BusinessError } from '@ohos.base';
7845audioCapturer.start().then(() => {
7846  console.info('AudioFrameworkRecLog: ---------START---------');
7847  console.info('AudioFrameworkRecLog: Capturer started: SUCCESS');
7848  console.info(`AudioFrameworkRecLog: AudioCapturer: STATE: ${audioCapturer.state}`);
7849  console.info('AudioFrameworkRecLog: Capturer started: SUCCESS');
7850  if ((audioCapturer.state == audio.AudioState.STATE_RUNNING)) {
7851    console.info('AudioFrameworkRecLog: AudioCapturer is in Running State');
7852  }
7853}).catch((err: BusinessError) => {
7854  console.info(`AudioFrameworkRecLog: Capturer start :ERROR : ${err}`);
7855});
7856```
7857
7858### stop<sup>8+</sup>
7859
7860stop(callback: AsyncCallback<void\>): void
7861
7862Stops capturing. This API uses an asynchronous callback to return the result.
7863
7864**System capability**: SystemCapability.Multimedia.Audio.Capturer
7865
7866**Parameters**
7867
7868| Name     | Type                 | Mandatory | Description                         |
7869| :------- | :------------------- | :-------- | :---------------------------------- |
7870| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
7871
7872**Example**
7873
7874```ts
7875import { BusinessError } from '@ohos.base';
7876audioCapturer.stop((err: BusinessError) => {
7877  if (err) {
7878    console.error('Capturer stop failed');
7879  } else {
7880    console.info('Capturer stopped.');
7881  }
7882});
7883```
7884
7885
7886### stop<sup>8+</sup>
7887
7888stop(): Promise<void\>
7889
7890Stops capturing. This API uses a promise to return the result.
7891
7892**System capability**: SystemCapability.Multimedia.Audio.Capturer
7893
7894**Return value**
7895
7896| Type           | Description                        |
7897| :------------- | :--------------------------------- |
7898| Promise<void\> | Promise used to return the result. |
7899
7900**Example**
7901
7902```ts
7903import { BusinessError } from '@ohos.base';
7904audioCapturer.stop().then(() => {
7905  console.info('AudioFrameworkRecLog: ---------STOP RECORD---------');
7906  console.info('AudioFrameworkRecLog: Capturer stopped: SUCCESS');
7907  if ((audioCapturer.state == audio.AudioState.STATE_STOPPED)){
7908    console.info('AudioFrameworkRecLog: State is Stopped:');
7909  }
7910}).catch((err: BusinessError) => {
7911  console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
7912});
7913```
7914
7915### release<sup>8+</sup>
7916
7917release(callback: AsyncCallback<void\>): void
7918
7919Releases this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
7920
7921**System capability**: SystemCapability.Multimedia.Audio.Capturer
7922
7923**Parameters**
7924
7925| Name     | Type                 | Mandatory | Description                         |
7926| :------- | :------------------- | :-------- | :---------------------------------- |
7927| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
7928
7929**Example**
7930
7931```ts
7932import { BusinessError } from '@ohos.base';
7933audioCapturer.release((err: BusinessError) => {
7934  if (err) {
7935    console.error('capturer release failed');
7936  } else {
7937    console.info('capturer released.');
7938  }
7939});
7940```
7941
7942
7943### release<sup>8+</sup>
7944
7945release(): Promise<void\>
7946
7947Releases this **AudioCapturer** instance. This API uses a promise to return the result.
7948
7949**System capability**: SystemCapability.Multimedia.Audio.Capturer
7950
7951**Return value**
7952
7953| Type           | Description                        |
7954| :------------- | :--------------------------------- |
7955| Promise<void\> | Promise used to return the result. |
7956
7957**Example**
7958
7959```ts
7960import { BusinessError } from '@ohos.base';
7961audioCapturer.release().then(() => {
7962  console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
7963  console.info('AudioFrameworkRecLog: Capturer release : SUCCESS');
7964  console.info(`AudioFrameworkRecLog: AudioCapturer : STATE : ${audioCapturer.state}`);
7965}).catch((err: BusinessError) => {
7966  console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
7967});
7968```
7969
7970### read<sup>8+</sup>
7971
7972read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void
7973
7974Reads the buffer. This API uses an asynchronous callback to return the result.
7975
7976**System capability**: SystemCapability.Multimedia.Audio.Capturer
7977
7978**Parameters**
7979
7980| Name           | Type                        | Mandatory | Description                          |
7981| :------------- | :-------------------------- | :-------- | :----------------------------------- |
7982| size           | number                      | Yes       | Number of bytes to read.             |
7983| isBlockingRead | boolean                     | Yes       | Whether to block the read operation. |
7984| callback       | AsyncCallback<ArrayBuffer\> | Yes       | Callback used to return the buffer.  |
7985
7986**Example**
7987
7988```ts
7989import { BusinessError } from '@ohos.base';
7990let bufferSize: number = 0;
7991audioCapturer.getBufferSize().then((data: number) => {
7992  console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ${data}`);
7993  bufferSize = data;
7994}).catch((err: BusinessError) => {
7995  console.error(`AudioFrameworkRecLog: getBufferSize: ERROR: ${err}`);
7996});
7997audioCapturer.read(bufferSize, true, (err: BusinessError, buffer: number) => {
7998  if (!err) {
7999    console.info('Success in reading the buffer data');
8000  }
8001});
8002```
8003
8004### read<sup>8+</sup>
8005
8006read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
8007
8008Reads the buffer. This API uses a promise to return the result.
8009
8010**System capability**: SystemCapability.Multimedia.Audio.Capturer
8011
8012**Parameters**
8013
8014| Name           | Type    | Mandatory | Description                          |
8015| :------------- | :------ | :-------- | :----------------------------------- |
8016| size           | number  | Yes       | Number of bytes to read.             |
8017| isBlockingRead | boolean | Yes       | Whether to block the read operation. |
8018
8019**Return value**
8020
8021| Type                  | Description                                                  |
8022| :-------------------- | :----------------------------------------------------------- |
8023| Promise<ArrayBuffer\> | Promise used to return the result. If the operation is successful, the buffer data read is returned; otherwise, an error code is returned. |
8024
8025**Example**
8026
8027```ts
8028import { BusinessError } from '@ohos.base';
8029let bufferSize: number = 0;
8030audioCapturer.getBufferSize().then((data: number) => {
8031  console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ${data}`);
8032  bufferSize = data;
8033}).catch((err: BusinessError) => {
8034  console.info(`AudioFrameworkRecLog: getBufferSize: ERROR ${err}`);
8035});
8036console.info(`Buffer size: ${bufferSize}`);
8037audioCapturer.read(bufferSize, true).then((buffer: number) => {
8038  console.info('buffer read successfully');
8039}).catch((err: BusinessError) => {
8040  console.info(`ERROR : ${err}`);
8041});
8042```
8043
8044### getAudioTime<sup>8+</sup>
8045
8046getAudioTime(callback: AsyncCallback<number\>): void
8047
8048Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result.
8049
8050**System capability**: SystemCapability.Multimedia.Audio.Capturer
8051
8052**Parameters**
8053
8054| Name     | Type                   | Mandatory | Description                         |
8055| :------- | :--------------------- | :-------- | :---------------------------------- |
8056| callback | AsyncCallback<number\> | Yes       | Callback used to return the result. |
8057
8058**Example**
8059
8060```ts
8061import { BusinessError } from '@ohos.base';
8062audioCapturer.getAudioTime((err: BusinessError, timestamp: number) => {
8063  console.info(`Current timestamp: ${timestamp}`);
8064});
8065```
8066
8067### getAudioTime<sup>8+</sup>
8068
8069getAudioTime(): Promise<number\>
8070
8071Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
8072
8073**System capability**: SystemCapability.Multimedia.Audio.Capturer
8074
8075**Return value**
8076
8077| Type             | Description                           |
8078| :--------------- | :------------------------------------ |
8079| Promise<number\> | Promise used to return the timestamp. |
8080
8081**Example**
8082
8083```ts
8084import { BusinessError } from '@ohos.base';
8085audioCapturer.getAudioTime().then((audioTime: number) => {
8086  console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTime : Success ${audioTime}`);
8087}).catch((err: BusinessError) => {
8088  console.info(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
8089});
8090```
8091
8092### getAudioTimeSync<sup>10+</sup>
8093
8094getAudioTimeSync(): number
8095
8096Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API returns the result synchronously.
8097
8098**System capability**: SystemCapability.Multimedia.Audio.Capturer
8099
8100**Return value**
8101
8102| Type   | Description |
8103| :----- | :---------- |
8104| number | Timestamp.  |
8105
8106**Example**
8107
8108```ts
8109import { BusinessError } from '@ohos.base';
8110
8111try {
8112  let audioTime: number = audioCapturer.getAudioTimeSync();
8113  console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTimeSync : Success ${audioTime}`);
8114} catch (err) {
8115  let error = err as BusinessError;
8116  console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTimeSync : ERROR : ${error}`);
8117}
8118```
8119
8120### getBufferSize<sup>8+</sup>
8121
8122getBufferSize(callback: AsyncCallback<number\>): void
8123
8124Obtains a reasonable minimum buffer size in bytes for capturing. This API uses an asynchronous callback to return the result.
8125
8126**System capability**: SystemCapability.Multimedia.Audio.Capturer
8127
8128**Parameters**
8129
8130| Name     | Type                   | Mandatory | Description                              |
8131| :------- | :--------------------- | :-------- | :--------------------------------------- |
8132| callback | AsyncCallback<number\> | Yes       | Callback used to return the buffer size. |
8133
8134**Example**
8135
8136```ts
8137import { BusinessError } from '@ohos.base';
8138audioCapturer.getBufferSize((err: BusinessError, bufferSize: number) => {
8139  if (!err) {
8140    console.info(`BufferSize : ${bufferSize}`);
8141    audioCapturer.read(bufferSize, true).then((buffer: number) => {
8142      console.info(`Buffer read is ${buffer}`);
8143    }).catch((err: BusinessError) => {
8144      console.error(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
8145    });
8146  }
8147});
8148```
8149
8150### getBufferSize<sup>8+</sup>
8151
8152getBufferSize(): Promise<number\>
8153
8154Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a promise to return the result.
8155
8156**System capability**: SystemCapability.Multimedia.Audio.Capturer
8157
8158**Return value**
8159
8160| Type             | Description                             |
8161| :--------------- | :-------------------------------------- |
8162| Promise<number\> | Promise used to return the buffer size. |
8163
8164**Example**
8165
8166```ts
8167import { BusinessError } from '@ohos.base';
8168let bufferSize: number = 0;
8169audioCapturer.getBufferSize().then((data: number) => {
8170  console.info(`AudioFrameworkRecLog: getBufferSize :SUCCESS ${data}`);
8171  bufferSize = data;
8172}).catch((err: BusinessError) => {
8173  console.info(`AudioFrameworkRecLog: getBufferSize :ERROR : ${err}`);
8174});
8175```
8176
8177### getBufferSizeSync<sup>10+</sup>
8178
8179getBufferSizeSync(): number
8180
8181Obtains a reasonable minimum buffer size in bytes for capturing. This API returns the result synchronously.
8182
8183**System capability**: SystemCapability.Multimedia.Audio.Capturer
8184
8185**Return value**
8186
8187| Type   | Description  |
8188| :----- | :----------- |
8189| number | Buffer size. |
8190
8191**Example**
8192
8193```ts
8194import { BusinessError } from '@ohos.base';
8195
8196let bufferSize: number = 0;
8197try {
8198  bufferSize = audioCapturer.getBufferSizeSync();
8199  console.info(`AudioFrameworkRecLog: getBufferSizeSync :SUCCESS ${bufferSize}`);
8200} catch (err) {
8201  let error = err as BusinessError;
8202  console.info(`AudioFrameworkRecLog: getBufferSizeSync :ERROR : ${error}`);
8203}
8204```
8205
8206### on('audioInterrupt')<sup>10+</sup>
8207
8208on(type: 'audioInterrupt', callback: Callback\<InterruptEvent>): void
8209
8210Subscribes to audio interruption events. This API uses a callback to obtain interrupt events.
8211
8212Same 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.
8213
8214**System capability**: SystemCapability.Multimedia.Audio.Interrupt
8215
8216**Parameters**
8217
8218| Name     | Type                                           | Mandatory | Description                                                  |
8219| -------- | ---------------------------------------------- | --------- | ------------------------------------------------------------ |
8220| type     | string                                         | Yes       | Event type. The event **'audioInterrupt'** is triggered when audio capturing is interrupted. |
8221| callback | Callback\<[InterruptEvent](#interruptevent9)\> | Yes       | Callback used to return the audio interruption event.        |
8222
8223**Error codes**
8224
8225For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
8226
8227| ID      | Error Message                  |
8228| ------- | ------------------------------ |
8229| 6800101 | if input parameter value error              |
8230
8231**Example**
8232
8233```ts
8234import audio from '@ohos.multimedia.audio';
8235let isCapturing: boolean; // An identifier specifying whether capturing is in progress.
8236onAudioInterrupt();
8237
8238async function onAudioInterrupt(){
8239  audioCapturer.on('audioInterrupt', (interruptEvent: audio.InterruptEvent) => {
8240    if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
8241      // The system forcibly interrupts audio capturing. The application must update the status and displayed content accordingly.
8242      switch (interruptEvent.hintType) {
8243        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
8244          // 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.
8245          console.info('Force paused. Update capturing status and stop reading');
8246          isCapturing = false; // A simplified processing indicating several operations for switching the application to the paused state.
8247          break;
8248        case audio.InterruptHint.INTERRUPT_HINT_STOP:
8249          // The audio stream has been stopped and permanently loses the focus. The user must manually trigger the operation to resume capturing.
8250          console.info('Force stopped. Update capturing status and stop reading');
8251          isCapturing = false; // A simplified processing indicating several operations for switching the application to the paused state.
8252          break;
8253        default:
8254          console.info('Invalid interruptEvent');
8255          break;
8256      }
8257    } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
8258      // The application can choose to take action or ignore.
8259      switch (interruptEvent.hintType) {
8260        case audio.InterruptHint.INTERRUPT_HINT_RESUME:
8261          // 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.)
8262          console.info('Resume force paused renderer or ignore');
8263          // To continue capturing, the application must perform the required operations.
8264          break;
8265        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
8266          // It is recommended that the application pause capturing.
8267          console.info('Choose to pause or ignore');
8268          // To pause capturing, the application must perform the required operations.
8269          break;
8270        case audio.InterruptHint.INTERRUPT_HINT_STOP:
8271          // It is recommended that the application stop capturing.
8272          console.info('Choose to stop or ignore');
8273          // To stop capturing, the application must perform the required operations.
8274          break;
8275        default:
8276          break;
8277      }
8278    }
8279  });
8280}
8281```
8282
8283### off('audioInterrupt')<sup>10+</sup>
8284
8285off(type: 'audioInterrupt'): void
8286
8287Unsubscribes from audio interruption events.
8288
8289**System capability**: SystemCapability.Multimedia.Audio.Interrupt
8290
8291**Parameters**
8292
8293| Name | Type   | Mandatory | Description                                                  |
8294| ---- | ------ | --------- | ------------------------------------------------------------ |
8295| type | string | Yes       | Event type. The event **'audioInterrupt'** is triggered when audio capturing is interrupted. |
8296
8297**Error codes**
8298
8299For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
8300
8301| ID      | Error Message                  |
8302| ------- | ------------------------------ |
8303| 6800101 | if input parameter value error              |
8304
8305**Example**
8306
8307```ts
8308audioCapturer.off('audioInterrupt');
8309```
8310
8311
8312### on('markReach')<sup>8+</sup>
8313
8314on(type: 'markReach', frame: number, callback: Callback&lt;number&gt;): void
8315
8316Subscribes to mark reached events. When the number of frames captured reaches the value of the **frame** parameter, a callback is invoked.
8317
8318**System capability**: SystemCapability.Multimedia.Audio.Capturer
8319
8320**Parameters**
8321
8322| Name     | Type              | Mandatory | Description                                                  |
8323| :------- | :---------------- | :-------- | :----------------------------------------------------------- |
8324| type     | string            | Yes       | Event type. The value is fixed at **'markReach'**.           |
8325| frame    | number            | Yes       | Number of frames to trigger the event. The value must be greater than **0**. |
8326| callback | Callback\<number> | Yes       | Callback invoked when the event is triggered.                |
8327
8328**Example**
8329
8330```ts
8331audioCapturer.on('markReach', 1000, (position: number) => {
8332  if (position == 1000) {
8333    console.info('ON Triggered successfully');
8334  }
8335});
8336```
8337
8338### off('markReach')<sup>8+</sup>
8339
8340off(type: 'markReach'): void
8341
8342Unsubscribes from mark reached events.
8343
8344**System capability**: SystemCapability.Multimedia.Audio.Capturer
8345
8346**Parameters**
8347
8348| Name | Type   | Mandatory | Description                                        |
8349| :--- | :----- | :-------- | :------------------------------------------------- |
8350| type | string | Yes       | Event type. The value is fixed at **'markReach'**. |
8351
8352**Example**
8353
8354```ts
8355audioCapturer.off('markReach');
8356```
8357
8358### on('periodReach')<sup>8+</sup>
8359
8360on(type: 'periodReach', frame: number, callback: Callback&lt;number&gt;): void
8361
8362Subscribes 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.
8363
8364**System capability**: SystemCapability.Multimedia.Audio.Capturer
8365
8366**Parameters**
8367
8368| Name     | Type              | Mandatory | Description                                                  |
8369| :------- | :---------------- | :-------- | :----------------------------------------------------------- |
8370| type     | string            | Yes       | Event type. The value is fixed at **'periodReach'**.         |
8371| frame    | number            | Yes       | Number of frames to trigger the event. The value must be greater than **0**. |
8372| callback | Callback\<number> | Yes       | Callback invoked when the event is triggered.                |
8373
8374**Example**
8375
8376```ts
8377audioCapturer.on('periodReach', 1000, (position: number) => {
8378  if (position == 1000) {
8379    console.info('ON Triggered successfully');
8380  }
8381});
8382```
8383
8384### off('periodReach')<sup>8+</sup>
8385
8386off(type: 'periodReach'): void
8387
8388Unsubscribes from period reached events.
8389
8390**System capability**: SystemCapability.Multimedia.Audio.Capturer
8391
8392**Parameters**
8393
8394| Name | Type   | Mandatory | Description                                          |
8395| :--- | :----- | :-------- | :--------------------------------------------------- |
8396| type | string | Yes       | Event type. The value is fixed at **'periodReach'**. |
8397
8398**Example**
8399
8400```ts
8401audioCapturer.off('periodReach')
8402```
8403
8404### on('stateChange') <sup>8+</sup>
8405
8406on(type: 'stateChange', callback: Callback<AudioState\>): void
8407
8408Subscribes to state change events.
8409
8410**System capability**: SystemCapability.Multimedia.Audio.Capturer
8411
8412**Parameters**
8413
8414| Name     | Type                                  | Mandatory | Description                                                  |
8415| :------- | :------------------------------------ | :-------- | :----------------------------------------------------------- |
8416| type     | string                                | Yes       | Event type. The value **stateChange** means the state change event. |
8417| callback | Callback\<[AudioState](#audiostate8)> | Yes       | Callback used to return the state change.                    |
8418
8419**Example**
8420
8421```ts
8422audioCapturer.on('stateChange', (state: audio.AudioState) => {
8423  if (state == 1) {
8424    console.info('audio capturer state is: STATE_PREPARED');
8425  }
8426  if (state == 2) {
8427    console.info('audio capturer state is: STATE_RUNNING');
8428  }
8429});
8430```
8431
8432## ToneType<sup>9+</sup>
8433
8434Enumerates the tone types of the player.
8435
8436**System API**: This is a system API.
8437
8438**System capability**: SystemCapability.Multimedia.Audio.Tone
8439
8440| Name                                             | Value | Description                                   |
8441| :----------------------------------------------- | :---- | :-------------------------------------------- |
8442| TONE_TYPE_DIAL_0                                 | 0     | DTMF tone of key 0.                           |
8443| TONE_TYPE_DIAL_1                                 | 1     | DTMF tone of key 1.                           |
8444| TONE_TYPE_DIAL_2                                 | 2     | DTMF tone of key 2.                           |
8445| TONE_TYPE_DIAL_3                                 | 3     | DTMF tone of key 3.                           |
8446| TONE_TYPE_DIAL_4                                 | 4     | DTMF tone of key 4.                           |
8447| TONE_TYPE_DIAL_5                                 | 5     | DTMF tone of key 5.                           |
8448| TONE_TYPE_DIAL_6                                 | 6     | DTMF tone of key 6.                           |
8449| TONE_TYPE_DIAL_7                                 | 7     | DTMF tone of key 7.                           |
8450| TONE_TYPE_DIAL_8                                 | 8     | DTMF tone of key 8.                           |
8451| TONE_TYPE_DIAL_9                                 | 9     | DTMF tone of key 9.                           |
8452| TONE_TYPE_DIAL_S                                 | 10    | DTMF tone of the star key (*).                |
8453| TONE_TYPE_DIAL_P                                 | 11    | DTMF tone of the pound key (#).               |
8454| TONE_TYPE_DIAL_A                                 | 12    | DTMF tone of key A.                           |
8455| TONE_TYPE_DIAL_B                                 | 13    | DTMF tone of key B.                           |
8456| TONE_TYPE_DIAL_C                                 | 14    | DTMF tone of key C.                           |
8457| TONE_TYPE_DIAL_D                                 | 15    | DTMF tone of key D.                           |
8458| TONE_TYPE_COMMON_SUPERVISORY_DIAL                | 100   | Supervisory tone - dial tone.                 |
8459| TONE_TYPE_COMMON_SUPERVISORY_BUSY                | 101   | Supervisory tone - busy.                      |
8460| TONE_TYPE_COMMON_SUPERVISORY_CONGESTION          | 102   | Supervisory tone - congestion.                |
8461| TONE_TYPE_COMMON_SUPERVISORY_RADIO_ACK           | 103   | Supervisory tone - radio path acknowledgment. |
8462| TONE_TYPE_COMMON_SUPERVISORY_RADIO_NOT_AVAILABLE | 104   | Supervisory tone - radio path not available.  |
8463| TONE_TYPE_COMMON_SUPERVISORY_CALL_WAITING        | 106   | Supervisory tone - call waiting tone.         |
8464| TONE_TYPE_COMMON_SUPERVISORY_RINGTONE            | 107   | Supervisory tone - ringing tone.              |
8465| TONE_TYPE_COMMON_PROPRIETARY_BEEP                | 200   | Proprietary tone - beep tone.                 |
8466| TONE_TYPE_COMMON_PROPRIETARY_ACK                 | 201   | Proprietary tone - ACK.                       |
8467| TONE_TYPE_COMMON_PROPRIETARY_PROMPT              | 203   | Proprietary tone - PROMPT.                    |
8468| TONE_TYPE_COMMON_PROPRIETARY_DOUBLE_BEEP         | 204   | Proprietary tone - double beep tone.          |
8469
8470## TonePlayer<sup>9+</sup>
8471
8472Provides APIs for playing and managing DTMF tones, such as dial tones, ringback tones, supervisory tones, and proprietary tones.
8473
8474**System API**: This is a system API.
8475
8476### load<sup>9+</sup>
8477
8478load(type: ToneType, callback: AsyncCallback&lt;void&gt;): void
8479
8480Loads the DTMF tone configuration. This API uses an asynchronous callback to return the result.
8481
8482**System API**: This is a system API.
8483
8484**System capability**: SystemCapability.Multimedia.Audio.Tone
8485
8486**Parameters**
8487
8488| Name     | Type                   | Mandatory | Description                         |
8489| :------- | :--------------------- | :-------- | :---------------------------------- |
8490| type     | [ToneType](#tonetype9) | Yes       | Tone type.                          |
8491| callback | AsyncCallback<void\>   | Yes       | Callback used to return the result. |
8492
8493**Example**
8494
8495```ts
8496import { BusinessError } from '@ohos.base';
8497tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_5, (err: BusinessError) => {
8498  if (err) {
8499    console.error(`callback call load failed error: ${err.message}`);
8500    return;
8501  } else {
8502    console.info('callback call load success');
8503  }
8504});
8505```
8506
8507### load<sup>9+</sup>
8508
8509load(type: ToneType): Promise&lt;void&gt;
8510
8511Loads the DTMF tone configuration. This API uses a promise to return the result.
8512
8513**System API**: This is a system API.
8514
8515**System capability**: SystemCapability.Multimedia.Audio.Tone
8516
8517**Parameters**
8518
8519| Name | Type                   | Mandatory | Description |
8520| :--- | :--------------------- | :-------- | ----------- |
8521| type | [ToneType](#tonetype9) | Yes       | Tone type.  |
8522
8523**Return value**
8524
8525| Type           | Description                        |
8526| :------------- | :--------------------------------- |
8527| Promise<void\> | Promise used to return the result. |
8528
8529**Example**
8530
8531```ts
8532tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_1).then(() => {
8533  console.info('promise call load ');
8534}).catch(() => {
8535  console.error('promise call load fail');
8536});
8537```
8538
8539### start<sup>9+</sup>
8540
8541start(callback: AsyncCallback&lt;void&gt;): void
8542
8543Starts DTMF tone playing. This API uses an asynchronous callback to return the result.
8544
8545**System API**: This is a system API.
8546
8547**System capability**: SystemCapability.Multimedia.Audio.Tone
8548
8549**Parameters**
8550
8551| Name     | Type                 | Mandatory | Description                         |
8552| :------- | :------------------- | :-------- | :---------------------------------- |
8553| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
8554
8555**Example**
8556
8557```ts
8558import { BusinessError } from '@ohos.base';
8559tonePlayer.start((err: BusinessError) => {
8560  if (err) {
8561    console.error(`callback call start failed error: ${err.message}`);
8562    return;
8563  } else {
8564    console.info('callback call start success');
8565  }
8566});
8567```
8568
8569### start<sup>9+</sup>
8570
8571start(): Promise&lt;void&gt;
8572
8573Starts DTMF tone playing. This API uses a promise to return the result.
8574
8575**System API**: This is a system API.
8576
8577**System capability**: SystemCapability.Multimedia.Audio.Tone
8578
8579**Return value**
8580
8581| Type           | Description                        |
8582| :------------- | :--------------------------------- |
8583| Promise<void\> | Promise used to return the result. |
8584
8585**Example**
8586
8587```ts
8588tonePlayer.start().then(() => {
8589  console.info('promise call start');
8590}).catch(() => {
8591  console.error('promise call start fail');
8592});
8593```
8594
8595### stop<sup>9+</sup>
8596
8597stop(callback: AsyncCallback&lt;void&gt;): void
8598
8599Stops the tone that is being played. This API uses an asynchronous callback to return the result.
8600
8601**System API**: This is a system API.
8602
8603**System capability**: SystemCapability.Multimedia.Audio.Tone
8604
8605**Parameters**
8606
8607| Name     | Type                 | Mandatory | Description                         |
8608| :------- | :------------------- | :-------- | :---------------------------------- |
8609| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
8610
8611**Example**
8612
8613```ts
8614import { BusinessError } from '@ohos.base';
8615tonePlayer.stop((err: BusinessError) => {
8616  if (err) {
8617    console.error(`callback call stop error: ${err.message}`);
8618    return;
8619  } else {
8620    console.error('callback call stop success ');
8621  }
8622});
8623```
8624
8625### stop<sup>9+</sup>
8626
8627stop(): Promise&lt;void&gt;
8628
8629Stops the tone that is being played. This API uses a promise to return the result.
8630
8631**System API**: This is a system API.
8632
8633**System capability**: SystemCapability.Multimedia.Audio.Tone
8634
8635**Return value**
8636
8637| Type           | Description                        |
8638| :------------- | :--------------------------------- |
8639| Promise<void\> | Promise used to return the result. |
8640
8641**Example**
8642
8643```ts
8644tonePlayer.stop().then(() => {
8645  console.info('promise call stop finish');
8646}).catch(() => {
8647  console.error('promise call stop fail');
8648});
8649```
8650
8651### release<sup>9+</sup>
8652
8653release(callback: AsyncCallback&lt;void&gt;): void
8654
8655Releases the resources associated with the **TonePlayer** instance. This API uses an asynchronous callback to return the result.
8656
8657**System API**: This is a system API.
8658
8659**System capability**: SystemCapability.Multimedia.Audio.Tone
8660
8661**Parameters**
8662
8663| Name     | Type                 | Mandatory | Description                         |
8664| :------- | :------------------- | :-------- | :---------------------------------- |
8665| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
8666
8667**Example**
8668
8669```ts
8670import { BusinessError } from '@ohos.base';
8671tonePlayer.release((err: BusinessError) => {
8672  if (err) {
8673    console.error(`callback call release failed error: ${err.message}`);
8674    return;
8675  } else {
8676    console.info('callback call release success ');
8677  }
8678});
8679```
8680
8681### release<sup>9+</sup>
8682
8683release(): Promise&lt;void&gt;
8684
8685Releases the resources associated with the **TonePlayer** instance. This API uses a promise to return the result.
8686
8687**System API**: This is a system API.
8688
8689**System capability**: SystemCapability.Multimedia.Audio.Tone
8690
8691**Return value**
8692
8693| Type           | Description                        |
8694| :------------- | :--------------------------------- |
8695| Promise<void\> | Promise used to return the result. |
8696
8697**Example**
8698
8699```ts
8700tonePlayer.release().then(() => {
8701  console.info('promise call release');
8702}).catch(() => {
8703  console.error('promise call release fail');
8704});
8705```
8706
8707## ActiveDeviceType<sup>(deprecated)</sup>
8708
8709Enumerates the active device types.
8710
8711> **NOTE**
8712>
8713> This API is deprecated since API version 9. You are advised to use [CommunicationDeviceType](#communicationdevicetype9) instead.
8714
8715**System capability**: SystemCapability.Multimedia.Audio.Device
8716
8717| Name          | Value | Description                                                  |
8718| ------------- | ----- | ------------------------------------------------------------ |
8719| SPEAKER       | 2     | Speaker.                                                     |
8720| BLUETOOTH_SCO | 7     | Bluetooth device using Synchronous Connection Oriented (SCO) links. |
8721
8722## InterruptActionType<sup>(deprecated)</sup>
8723
8724Enumerates the returned event types for audio interruption events.
8725
8726> **NOTE**
8727>
8728> This API is supported since API version 7 and deprecated since API version 9.
8729
8730**System capability**: SystemCapability.Multimedia.Audio.Renderer
8731
8732| Name           | Value | Description               |
8733| -------------- | ----- | ------------------------- |
8734| TYPE_ACTIVATED | 0     | Focus gain event.         |
8735| TYPE_INTERRUPT | 1     | Audio interruption event. |
8736
8737## AudioInterrupt<sup>(deprecated)</sup>
8738
8739Describes input parameters of audio interruption events.
8740
8741> **NOTE**
8742>
8743> This API is supported since API version 7 and deprecated since API version 9.
8744
8745**System capability**: SystemCapability.Multimedia.Audio.Renderer
8746
8747| Name            | Type                        | Mandatory | Description                                                  |
8748| --------------- | --------------------------- | --------- | ------------------------------------------------------------ |
8749| streamUsage     | [StreamUsage](#streamusage) | Yes       | Audio stream usage.                                          |
8750| contentType     | [ContentType](#contenttype) | Yes       | Audio content type.                                          |
8751| 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. |
8752
8753## InterruptAction<sup>(deprecated)</sup>
8754
8755Describes the callback invoked for audio interruption or focus gain events.
8756
8757> **NOTE**
8758>
8759> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [InterruptEvent](#interruptevent9).
8760
8761**System capability**: SystemCapability.Multimedia.Audio.Renderer
8762
8763| Name       | Type                                                  | Mandatory | Description                                                  |
8764| ---------- | ----------------------------------------------------- | --------- | ------------------------------------------------------------ |
8765| actionType | [InterruptActionType](#interruptactiontypedeprecated) | Yes       | Returned event type. The value **TYPE_ACTIVATED** means the focus gain event, and **TYPE_INTERRUPT** means the audio interruption event. |
8766| type       | [InterruptType](#interrupttype)                       | No        | Type of the audio interruption event.                        |
8767| hint       | [InterruptHint](#interrupthint)                       | No        | Hint provided along with the audio interruption event.       |
8768| 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. |