1# @ohos.multimedia.audio (音频管理)
2
3音频管理提供管理音频的一些基础能力,包括对音频音量、音频设备的管理,以及对音频数据的采集和渲染等。
4
5该模块提供以下音频相关的常用功能:
6
7- [AudioManager](#audiomanager):音频管理。
8- [AudioRenderer](#audiorenderer8):音频渲染,用于播放PCM(Pulse Code Modulation)音频数据。
9- [AudioCapturer](#audiocapturer8):音频采集,用于录制PCM音频数据。
10
11> **说明:**
12> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
13
14## 导入模块
15
16```ts
17import { audio } from '@kit.AudioKit';
18```
19
20## 常量
21
22| 名称                                    | 类型      | 可读  | 可写 | 说明               |
23| --------------------------------------- | ----------| ---- | ---- | ------------------ |
24| DEFAULT_VOLUME_GROUP_ID<sup>9+</sup>    | number    | 是   | 否   | 默认音量组id。<br> **系统能力:** SystemCapability.Multimedia.Audio.Volume       |
25| DEFAULT_INTERRUPT_GROUP_ID<sup>9+</sup> | number    | 是   | 否   | 默认音频中断组id。<br> **系统能力:** SystemCapability.Multimedia.Audio.Interrupt       |
26
27**示例:**
28
29```ts
30import { audio } from '@kit.AudioKit';
31
32const defaultVolumeGroupId = audio.DEFAULT_VOLUME_GROUP_ID;
33const defaultInterruptGroupId = audio.DEFAULT_INTERRUPT_GROUP_ID;
34```
35
36## audio.getAudioManager
37
38getAudioManager(): AudioManager
39
40获取音频管理器。
41
42**系统能力:** SystemCapability.Multimedia.Audio.Core
43
44**返回值:**
45
46| 类型                          | 说明         |
47| ----------------------------- | ------------ |
48| [AudioManager](#audiomanager) | 音频管理对象。 |
49
50**示例:**
51```ts
52import { audio } from '@kit.AudioKit';
53
54let audioManager = audio.getAudioManager();
55```
56
57## audio.createAudioRenderer<sup>8+</sup>
58
59createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\<AudioRenderer>): void
60
61获取音频渲染器。使用callback方式异步返回结果。
62
63**系统能力:** SystemCapability.Multimedia.Audio.Renderer
64
65**参数:**
66
67| 参数名   | 类型                                            | 必填 | 说明             |
68| -------- | ----------------------------------------------- | ---- | ---------------- |
69| options  | [AudioRendererOptions](#audiorendereroptions8)  | 是   | 配置渲染器。     |
70| callback | AsyncCallback<[AudioRenderer](#audiorenderer8)> | 是   | 回调函数。当获取音频渲染器成功,err为undefined,data为获取到的音频渲染器对象;否则为错误对象。 |
71
72**示例:**
73
74```ts
75import { audio } from '@kit.AudioKit';
76
77let audioStreamInfo: audio.AudioStreamInfo = {
78  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000,
79  channels: audio.AudioChannel.CHANNEL_2,
80  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
81  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
82};
83
84let audioRendererInfo: audio.AudioRendererInfo = {
85  usage: audio.StreamUsage.STREAM_USAGE_MUSIC,
86  rendererFlags: 0
87};
88
89let audioRendererOptions: audio.AudioRendererOptions = {
90  streamInfo: audioStreamInfo,
91  rendererInfo: audioRendererInfo
92};
93
94audio.createAudioRenderer(audioRendererOptions,(err, data) => {
95  if (err) {
96    console.error(`AudioRenderer Created: Error: ${err}`);
97  } else {
98    console.info('AudioRenderer Created: Success: SUCCESS');
99    let audioRenderer = data;
100  }
101});
102```
103
104## audio.createAudioRenderer<sup>8+</sup>
105
106createAudioRenderer(options: AudioRendererOptions): Promise<AudioRenderer\>
107
108获取音频渲染器。使用Promise方式异步返回结果。
109
110**系统能力:** SystemCapability.Multimedia.Audio.Renderer
111
112**参数:**
113
114| 参数名  | 类型                                           | 必填 | 说明         |
115| :------ | :--------------------------------------------- | :--- | :----------- |
116| options | [AudioRendererOptions](#audiorendereroptions8) | 是   | 配置渲染器。 |
117
118**返回值:**
119
120| 类型                                      | 说明             |
121| ----------------------------------------- | ---------------- |
122| Promise<[AudioRenderer](#audiorenderer8)> | Promise对象,返回音频渲染器对象。 |
123
124**示例:**
125
126```ts
127import { audio } from '@kit.AudioKit';
128import { BusinessError } from '@kit.BasicServicesKit';
129
130let audioStreamInfo: audio.AudioStreamInfo = {
131  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000,
132  channels: audio.AudioChannel.CHANNEL_2,
133  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
134  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
135};
136
137let audioRendererInfo: audio.AudioRendererInfo = {
138  usage: audio.StreamUsage.STREAM_USAGE_MUSIC,
139  rendererFlags: 0
140};
141
142let audioRendererOptions: audio.AudioRendererOptions = {
143  streamInfo: audioStreamInfo,
144  rendererInfo: audioRendererInfo
145};
146
147let audioRenderer: audio.AudioRenderer;
148
149audio.createAudioRenderer(audioRendererOptions).then((data) => {
150  audioRenderer = data;
151  console.info('AudioFrameworkRenderLog: AudioRenderer Created : Success : Stream Type: SUCCESS');
152}).catch((err: BusinessError) => {
153  console.error(`AudioFrameworkRenderLog: AudioRenderer Created : ERROR : ${err}`);
154});
155```
156
157## audio.createAudioCapturer<sup>8+</sup>
158
159createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback<AudioCapturer\>): void
160
161获取音频采集器。使用callback方式异步返回结果。
162
163**系统能力:** SystemCapability.Multimedia.Audio.Capturer
164
165**需要权限:** ohos.permission.MICROPHONE
166
167当设置Mic音频源(即[SourceType](#sourcetype8)为SOURCE_TYPE_MIC、SOURCE_TYPE_VOICE_RECOGNITION、SOURCE_TYPE_VOICE_COMMUNICATION、SOURCE_TYPE_VOICE_MESSAGE、SOURCE_TYPE_CAMCORDER)时需要该权限。
168
169**参数:**
170
171| 参数名   | 类型                                            | 必填 | 说明             |
172| :------- | :---------------------------------------------- | :--- | :--------------- |
173| options  | [AudioCapturerOptions](#audiocaptureroptions8)  | 是   | 配置音频采集器。 |
174| callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | 是   | Callback对象,成功将返回音频采集器对象,异常将返回error对象:<br>错误码6800301,表示包含参数校验异常、权限校验异常、系统处理异常(具体错误查看系统日志)。<br>错误码6800101,表示包含必选参数为空、参数类型错误。 |
175
176**示例:**
177
178```ts
179import { audio } from '@kit.AudioKit';
180
181let audioStreamInfo: audio.AudioStreamInfo = {
182  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000,
183  channels: audio.AudioChannel.CHANNEL_2,
184  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
185  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
186};
187
188let audioCapturerInfo: audio.AudioCapturerInfo = {
189  source: audio.SourceType.SOURCE_TYPE_MIC,
190  capturerFlags: 0
191};
192
193let audioCapturerOptions: audio.AudioCapturerOptions = {
194  streamInfo: audioStreamInfo,
195  capturerInfo: audioCapturerInfo
196};
197
198audio.createAudioCapturer(audioCapturerOptions, (err, data) => {
199  if (err) {
200    console.error(`AudioCapturer Created : Error: ${err}`);
201  } else {
202    console.info('AudioCapturer Created : Success : SUCCESS');
203    let audioCapturer = data;
204  }
205});
206```
207
208## audio.createAudioCapturer<sup>8+</sup>
209
210createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\>
211
212获取音频采集器。使用Promise 方式异步返回结果。
213
214**系统能力:** SystemCapability.Multimedia.Audio.Capturer
215
216**需要权限:** ohos.permission.MICROPHONE
217
218当设置Mic音频源(即[SourceType](#sourcetype8)为SOURCE_TYPE_MIC、SOURCE_TYPE_VOICE_RECOGNITION、SOURCE_TYPE_VOICE_COMMUNICATION、SOURCE_TYPE_VOICE_MESSAGE、SOURCE_TYPE_CAMCORDER)时需要该权限。
219
220**参数:**
221
222| 参数名  | 类型                                           | 必填 | 说明             |
223| :------ | :--------------------------------------------- | :--- | :--------------- |
224| options | [AudioCapturerOptions](#audiocaptureroptions8) | 是   | 配置音频采集器。 |
225
226**返回值:**
227
228| 类型                                      | 说明                   |
229| ----------------------------------------- |----------------------|
230| Promise<[AudioCapturer](#audiocapturer8)> | Promise对象,成功将返回音频采集器对象,异常将返回error对象:<br>错误码6800301,表示包含参数校验异常、权限校验异常、系统处理异常(具体错误查看系统日志)。<br>错误码6800101,表示包含必选参数为空、参数类型错误。 |
231
232**示例:**
233
234```ts
235import { audio } from '@kit.AudioKit';
236import { BusinessError } from '@kit.BasicServicesKit';
237
238let audioStreamInfo: audio.AudioStreamInfo = {
239  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000,
240  channels: audio.AudioChannel.CHANNEL_2,
241  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
242  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
243};
244
245let audioCapturerInfo: audio.AudioCapturerInfo = {
246  source: audio.SourceType.SOURCE_TYPE_MIC,
247  capturerFlags: 0
248};
249
250let audioCapturerOptions:audio.AudioCapturerOptions = {
251  streamInfo: audioStreamInfo,
252  capturerInfo: audioCapturerInfo
253};
254
255let audioCapturer: audio.AudioCapturer;
256
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## AudioVolumeType
266
267枚举,音频流类型。
268
269**系统能力:** SystemCapability.Multimedia.Audio.Volume
270
271| 名称                         | 值      | 说明       |
272| ---------------------------- | ------ | ---------- |
273| VOICE_CALL<sup>8+</sup>      | 0      | 语音电话。 |
274| RINGTONE                     | 2      | 铃声。     |
275| MEDIA                        | 3      | 媒体。     |
276| ALARM<sup>10+</sup>          | 4      | 闹钟。     |
277| ACCESSIBILITY<sup>10+</sup>  | 5      | 无障碍。   |
278| VOICE_ASSISTANT<sup>8+</sup> | 9      | 语音助手。 |
279
280## InterruptMode<sup>9+</sup>
281
282枚举,焦点模型。
283
284**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
285
286**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
287
288| 名称                         | 值      | 说明       |
289| ---------------------------- | ------ | ---------- |
290| SHARE_MODE                   | 0      | 共享焦点模式。 |
291| INDEPENDENT_MODE             | 1      | 独立焦点模式。 |
292
293## DeviceFlag
294
295枚举,可获取的设备种类。
296
297**系统能力:** SystemCapability.Multimedia.Audio.Device
298
299| 名称                            |  值     | 说明                        |
300| ------------------------------- | ------ |---------------------------|
301| OUTPUT_DEVICES_FLAG             | 1      | 输出设备。                     |
302| INPUT_DEVICES_FLAG              | 2      | 输入设备。                     |
303| ALL_DEVICES_FLAG                | 3      | 所有设备。                     |
304
305## DeviceUsage<sup>12+</sup>
306
307枚举,可获取的设备种类。
308
309**系统能力:** SystemCapability.Multimedia.Audio.Device
310
311| 名称                            |  值     | 说明                        |
312| ------------------------------- | ------ |---------------------------|
313| MEDIA_OUTPUT_DEVICES | 1      | 媒体输出设备。|
314| MEDIA_INPUT_DEVICES  | 2      | 媒体输入设备。|
315| ALL_MEDIA_DEVICES    | 3      | 所有媒体设备。|
316| CALL_OUTPUT_DEVICES  | 4      | 通话输出设备。|
317| CALL_INPUT_DEVICES   | 8      | 通话输入设备。|
318| ALL_CALL_DEVICES     | 12     | 所有通话设备。|
319
320## DeviceRole
321
322枚举,设备角色。
323
324**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
325
326**系统能力:** SystemCapability.Multimedia.Audio.Device
327
328| 名称          |  值    | 说明           |
329| ------------- | ------ | -------------- |
330| INPUT_DEVICE  | 1      | 输入设备角色。 |
331| OUTPUT_DEVICE | 2      | 输出设备角色。 |
332
333## DeviceType
334
335枚举,设备类型。
336
337**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
338
339**系统能力:** SystemCapability.Multimedia.Audio.Device
340
341| 名称                 | 值     | 说明                                                      |
342| ---------------------| ------ | --------------------------------------------------------- |
343| INVALID              | 0      | 无效设备。                                                |
344| EARPIECE             | 1      | 听筒。                                                    |
345| SPEAKER              | 2      | 扬声器。                                                  |
346| WIRED_HEADSET        | 3      | 有线耳机,带麦克风。                                      |
347| WIRED_HEADPHONES     | 4      | 有线耳机,无麦克风。                                      |
348| BLUETOOTH_SCO        | 7      | 蓝牙设备SCO(Synchronous Connection Oriented)连接。      |
349| BLUETOOTH_A2DP       | 8      | 蓝牙设备A2DP(Advanced Audio Distribution Profile)连接。 |
350| MIC                  | 15     | 麦克风。                                                  |
351| USB_HEADSET          | 22     | USB耳机,带麦克风。                                       |
352| DISPLAY_PORT<sup>12+</sup>        | 23     | DisplayPort(显示接口,简称DP),用于外接扩展设备。           |
353| REMOTE_CAST<sup>12+</sup>        | 24     | 音频被系统应用投送到其他远程的设备。           |
354| DEFAULT<sup>9+</sup> | 1000   | 默认设备类型。                                            |
355
356## CommunicationDeviceType<sup>9+</sup>
357
358枚举,用于通信的可用设备类型。
359
360**系统能力:** SystemCapability.Multimedia.Audio.Communication
361
362| 名称          | 值     | 说明          |
363| ------------- | ------ | -------------|
364| SPEAKER       | 2      | 扬声器。      |
365
366## AudioRingMode
367
368枚举,铃声模式。
369
370**系统能力:** SystemCapability.Multimedia.Audio.Communication
371
372| 名称                |  值    | 说明       |
373| ------------------- | ------ | ---------- |
374| RINGER_MODE_SILENT  | 0      | 静音模式。 |
375| RINGER_MODE_VIBRATE | 1      | 震动模式。 |
376| RINGER_MODE_NORMAL  | 2      | 响铃模式。 |
377
378## AudioSampleFormat<sup>8+</sup>
379
380枚举,音频采样格式。
381
382**系统能力:** SystemCapability.Multimedia.Audio.Core
383
384| 名称                                |  值    | 说明                       |
385| ---------------------------------- | ------ | -------------------------- |
386| SAMPLE_FORMAT_INVALID              | -1     | 无效格式。                 |
387| SAMPLE_FORMAT_U8                   | 0      | 无符号8位整数。            |
388| SAMPLE_FORMAT_S16LE                | 1      | 带符号的16位整数,小尾数。 |
389| SAMPLE_FORMAT_S24LE                | 2      | 带符号的24位整数,小尾数。 <br>由于系统限制,该采样格式仅部分设备支持,请根据实际情况使用。|
390| SAMPLE_FORMAT_S32LE                | 3      | 带符号的32位整数,小尾数。 <br>由于系统限制,该采样格式仅部分设备支持,请根据实际情况使用。|
391| SAMPLE_FORMAT_F32LE<sup>9+</sup>   | 4      | 带符号的32位浮点数,小尾数。 <br>由于系统限制,该采样格式仅部分设备支持,请根据实际情况使用。|
392
393## AudioErrors<sup>9+</sup>
394
395枚举,音频错误码。
396
397**系统能力:** SystemCapability.Multimedia.Audio.Core
398
399| 名称                 | 值      | 说明         |
400| ---------------------| --------| ----------------- |
401| ERROR_INVALID_PARAM  | 6800101 | 无效入参。         |
402| ERROR_NO_MEMORY      | 6800102 | 分配内存失败。     |
403| ERROR_ILLEGAL_STATE  | 6800103 | 状态不支持。       |
404| ERROR_UNSUPPORTED    | 6800104 | 参数选项不支持。    |
405| ERROR_TIMEOUT        | 6800105 | 处理超时。         |
406| ERROR_STREAM_LIMIT   | 6800201 | 音频流数量达到限制。|
407| ERROR_SYSTEM         | 6800301 | 系统处理异常。     |
408
409## AudioChannel<sup>8+</sup>
410
411枚举, 音频声道。
412
413**系统能力:** SystemCapability.Multimedia.Audio.Core
414
415| 名称      |  值       | 说明   |
416| --------- | -------- |------|
417| CHANNEL_1 | 1 | 单声道。 |
418| CHANNEL_2 | 2 | 双声道。 |
419| CHANNEL_3<sup>11+</sup> | 3 | 三声道。 |
420| CHANNEL_4<sup>11+</sup> | 4 | 四声道。 |
421| CHANNEL_5<sup>11+</sup> | 5 | 五声道。 |
422| CHANNEL_6<sup>11+</sup> | 6 | 六声道。 |
423| CHANNEL_7<sup>11+</sup> | 7 | 七声道。 |
424| CHANNEL_8<sup>11+</sup> | 8 | 八声道。 |
425| CHANNEL_9<sup>11+</sup> | 9 | 九声道。 |
426| CHANNEL_10<sup>11+</sup> | 10 | 十声道。 |
427| CHANNEL_12<sup>11+</sup> | 12 | 十二声道。 |
428| CHANNEL_14<sup>11+</sup> | 14 | 十四声道。 |
429| CHANNEL_16<sup>11+</sup> | 16 | 十六声道。 |
430
431## AudioSamplingRate<sup>8+</sup>
432
433枚举,音频采样率,具体设备支持的采样率规格会存在差异。
434
435**系统能力:** SystemCapability.Multimedia.Audio.Core
436
437| 名称              |  值    | 说明            |
438| ----------------- | ------ | --------------- |
439| SAMPLE_RATE_8000  | 8000   | 采样率为8000。  |
440| SAMPLE_RATE_11025 | 11025  | 采样率为11025。 |
441| SAMPLE_RATE_12000 | 12000  | 采样率为12000。 |
442| SAMPLE_RATE_16000 | 16000  | 采样率为16000。 |
443| SAMPLE_RATE_22050 | 22050  | 采样率为22050。 |
444| SAMPLE_RATE_24000 | 24000  | 采样率为24000。 |
445| SAMPLE_RATE_32000 | 32000  | 采样率为32000。 |
446| SAMPLE_RATE_44100 | 44100  | 采样率为44100。 |
447| SAMPLE_RATE_48000 | 48000  | 采样率为48000。 |
448| SAMPLE_RATE_64000 | 64000  | 采样率为64000。 |
449| SAMPLE_RATE_88200<sup>12+</sup> | 88200  | 采样率为88200。 |
450| SAMPLE_RATE_96000 | 96000  | 采样率为96000。 |
451| SAMPLE_RATE_176400<sup>12+</sup> | 176400  | 采样率为176400。 |
452| SAMPLE_RATE_192000<sup>12+</sup> | 192000  | 采样率为192000。 |
453
454## AudioEncodingType<sup>8+</sup>
455
456枚举,音频编码类型。
457
458**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
459
460**系统能力:** SystemCapability.Multimedia.Audio.Core
461
462| 名称                  |  值    | 说明      |
463| --------------------- | ------ | --------- |
464| ENCODING_TYPE_INVALID | -1     | 无效。    |
465| ENCODING_TYPE_RAW     | 0      | PCM编码。 |
466
467## AudioChannelLayout<sup>11+</sup>
468
469枚举,音频文件声道布局类型。
470
471**系统能力:** SystemCapability.Multimedia.Audio.Core
472
473| 名称                            |  值              | 说明                                          |
474| ------------------------------ | ---------------- | --------------------------------------------- |
475| CH_LAYOUT_UNKNOWN              | 0x0              | 未知声道布局。                                 |
476| CH_LAYOUT_MONO                 | 0x4              | 声道布局为MONO。                               |
477| CH_LAYOUT_STEREO               | 0x3              | 声道布局为STEREO。                             |
478| CH_LAYOUT_STEREO_DOWNMIX       | 0x60000000       | 声道布局为STEREO-DOWNMIX。                     |
479| CH_LAYOUT_2POINT1              | 0xB              | 声道布局为2.1。                                |
480| CH_LAYOUT_3POINT0              | 0x103            | 声道布局为3.0。                                |
481| CH_LAYOUT_SURROUND             | 0x7              | 声道布局为SURROUND。                           |
482| CH_LAYOUT_3POINT1              | 0xF              | 声道布局为3.1。                                |
483| CH_LAYOUT_4POINT0              | 0x107            | 声道布局为4.0。                                |
484| CH_LAYOUT_QUAD                 | 0x33             | 声道布局为QUAD。                               |
485| CH_LAYOUT_QUAD_SIDE            | 0x603            | 声道布局为QUAD-SIDE。                          |
486| CH_LAYOUT_2POINT0POINT2        | 0x3000000003     | 声道布局为2.0.2。                              |
487| CH_LAYOUT_AMB_ORDER1_ACN_N3D   | 0x100000000001   | 声道排序为ACN_N3D(根据ITU标准)的一阶FOA文件。  |
488| CH_LAYOUT_AMB_ORDER1_ACN_SN3D  | 0x100000001001   | 声道排序为ACN_SN3D(根据ITU标准)的一阶FOA文件。 |
489| CH_LAYOUT_AMB_ORDER1_FUMA      | 0x100000000101   | 声道排序为FUMA(根据ITU标准)的一阶FOA文件。     |
490| CH_LAYOUT_4POINT1              | 0x10F            | 声道布局为4.1                                  |
491| CH_LAYOUT_5POINT0              | 0x607            | 声道布局为5.0。                                |
492| CH_LAYOUT_5POINT0_BACK         | 0x37             | 声道布局为5.0-BACK。                           |
493| CH_LAYOUT_2POINT1POINT2        | 0x300000000B     | 声道布局为2.1.2。                              |
494| CH_LAYOUT_3POINT0POINT2        | 0x3000000007     | 声道布局为3.0.2。                              |
495| CH_LAYOUT_5POINT1              | 0x60F            | 声道布局为5.1。                                |
496| CH_LAYOUT_5POINT1_BACK         | 0x3F             | 声道布局为5.1-BACK。                           |
497| CH_LAYOUT_6POINT0              | 0x707            | 声道布局为6.0。                                |
498| CH_LAYOUT_HEXAGONAL            | 0x137            | 声道布局为HEXAGONAL。                          |
499| CH_LAYOUT_3POINT1POINT2        | 0x500F           | 声道布局为3.1.2。                              |
500| CH_LAYOUT_6POINT0_FRONT        | 0x6C3            | 声道布局为6.0-FRONT。                          |
501| CH_LAYOUT_6POINT1              | 0x70F            | 声道布局为6.1。                                |
502| CH_LAYOUT_6POINT1_BACK         | 0x13F            | 声道布局为6.1-BACK。                           |
503| CH_LAYOUT_6POINT1_FRONT        | 0x6CB            | 声道布局为6.1-FRONT。                          |
504| CH_LAYOUT_7POINT0              | 0x637            | 声道布局为7.0。                                |
505| CH_LAYOUT_7POINT0_FRONT        | 0x6C7            | 声道布局为7.0-FRONT。                          |
506| CH_LAYOUT_7POINT1              | 0x63F            | 声道布局为7.1。                                |
507| CH_LAYOUT_OCTAGONAL            | 0x737            | 声道布局为OCTAGONAL。                          |
508| CH_LAYOUT_5POINT1POINT2        | 0x300000060F     | 声道布局为5.1.2。                              |
509| CH_LAYOUT_7POINT1_WIDE         | 0x6CF            | 声道布局为7.1-WIDE。                           |
510| CH_LAYOUT_7POINT1_WIDE_BACK    | 0xFF             | 声道布局为7.1-WIDE-BACK。                      |
511| CH_LAYOUT_AMB_ORDER2_ACN_N3D   | 0x100000000002   | 声道排序为ACN_N3D(根据ITU标准)的二阶HOA文件。  |
512| CH_LAYOUT_AMB_ORDER2_ACN_SN3D  | 0x100000001002   | 声道排序为ACN_SN3D(根据ITU标准)的二阶HOA文件。 |
513| CH_LAYOUT_AMB_ORDER2_FUMA      | 0x100000000102   | 声道排序为FUMA(根据ITU标准)的二阶HOA文件。     |
514| CH_LAYOUT_5POINT1POINT4        | 0x2D60F          | 声道布局为5.1.4。                              |
515| CH_LAYOUT_7POINT1POINT2        | 0x300000063F     | 声道布局为7.1.2。                              |
516| CH_LAYOUT_7POINT1POINT4        | 0x2D63F          | 声道布局为7.1.4。                              |
517| CH_LAYOUT_10POINT2             | 0x180005737      | 声道布局为10.2。                               |
518| CH_LAYOUT_9POINT1POINT4        | 0x18002D63F      | 声道布局为9.1.4。                              |
519| CH_LAYOUT_9POINT1POINT6        | 0x318002D63F     | 声道布局为9.1.6。                              |
520| CH_LAYOUT_HEXADECAGONAL        | 0x18003F737      | 声道布局为HEXADECAGONAL。                      |
521| CH_LAYOUT_AMB_ORDER3_ACN_N3D   | 0x100000000003   | 声道排序为ACN_N3D(根据ITU标准)的三阶HOA文件。  |
522| CH_LAYOUT_AMB_ORDER3_ACN_SN3D  | 0x100000001003   | 声道排序为ACN_SN3D(根据ITU标准)的三阶HOA文件。 |
523| CH_LAYOUT_AMB_ORDER3_FUMA      | 0x100000000103   | 声道排序为FUMA(根据ITU标准)的三阶HOA文件。     |
524
525## ContentType<sup>(deprecated)</sup>
526
527枚举,音频内容类型。
528
529> **说明:**
530> 从 API version 7 开始支持,从 API version 10 开始废弃。建议使用[StreamUsage](#streamusage)声明音频流使用类型即可。
531
532**系统能力:** SystemCapability.Multimedia.Audio.Core
533
534| 名称                               |  值    | 说明       |
535| ---------------------------------- | ------ | ---------- |
536| CONTENT_TYPE_UNKNOWN               | 0      | 未知类型。 |
537| CONTENT_TYPE_SPEECH                | 1      | 语音。     |
538| CONTENT_TYPE_MUSIC                 | 2      | 音乐。     |
539| CONTENT_TYPE_MOVIE                 | 3      | 电影。     |
540| CONTENT_TYPE_SONIFICATION          | 4      | 通知音。   |
541| CONTENT_TYPE_RINGTONE<sup>8+</sup> | 5      | 铃声。     |
542
543## StreamUsage
544
545枚举,音频流使用类型。
546
547**系统能力:** SystemCapability.Multimedia.Audio.Core
548
549| 名称                                      |  值    | 说明                                                                                                                                          |
550| ------------------------------------------| ------ |---------------------------------------------------------------------------------------------------------------------------------------------|
551| STREAM_USAGE_UNKNOWN                      | 0      | 未知类型。  <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                                                     |
552| STREAM_USAGE_MEDIA<sup>(deprecated)</sup>                        | 1      | 媒体。<br/> 从API version 7开始支持,从API version 10 开始废弃。建议使用该枚举中的STREAM_USAGE_MUSIC、STREAM_USAGE_MOVIE、STREAM_USAGE_GAME或STREAM_USAGE_AUDIOBOOK替代。 |
553| STREAM_USAGE_MUSIC<sup>10+</sup>          | 1      | 音乐。   <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                                                      |
554| STREAM_USAGE_VOICE_COMMUNICATION          | 2      | VoIP语音通话。                                                                                                                                       <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
555| STREAM_USAGE_VOICE_ASSISTANT<sup>9+</sup> | 3      | 语音播报。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                                                      |
556| STREAM_USAGE_ALARM<sup>10+</sup>          | 4      | 闹钟。   <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                                                      |
557| STREAM_USAGE_VOICE_MESSAGE<sup>10+</sup>  | 5      | 语音消息。  <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                                                     |
558| STREAM_USAGE_NOTIFICATION_RINGTONE<sup>(deprecated)</sup>        | 6      | 通知铃声。<br/> 从 API version 10 开始废弃。建议使用该枚举中的STREAM_USAGE_RINGTONE替代。                                                                          |
559| STREAM_USAGE_RINGTONE<sup>10+</sup>       | 6      | 铃声。    <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                                                     |
560| STREAM_USAGE_NOTIFICATION<sup>10+</sup>   | 7      | 通知。  <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                                                       |
561| STREAM_USAGE_ACCESSIBILITY<sup>10+</sup>  | 8      | 无障碍。    <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                                                    |
562| STREAM_USAGE_MOVIE<sup>10+</sup>          | 10     | 电影或视频。   <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                                                   |
563| STREAM_USAGE_GAME<sup>10+</sup>           | 11     | 游戏。  <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                                                     |
564| STREAM_USAGE_AUDIOBOOK<sup>10+</sup>      | 12     | 有声读物(包括听书、相声、评书)、听新闻、播客等。   <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                                                    |
565| STREAM_USAGE_NAVIGATION<sup>10+</sup>     | 13     | 导航。   <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                                                      |
566| STREAM_USAGE_VIDEO_COMMUNICATION<sup>12+</sup>     | 17     | VoIP视频通话。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                                                        |
567
568## AudioState<sup>8+</sup>
569
570枚举,音频状态。
571
572**系统能力:** SystemCapability.Multimedia.Audio.Core
573
574| 名称           | 值     | 说明             |
575| -------------- | ------ | ---------------- |
576| STATE_INVALID  | -1     | 无效状态。       |
577| STATE_NEW      | 0      | 创建新实例状态。 |
578| STATE_PREPARED | 1      | 准备状态。       |
579| STATE_RUNNING  | 2      | 运行状态。 |
580| STATE_STOPPED  | 3      | 停止状态。       |
581| STATE_RELEASED | 4      | 释放状态。       |
582| STATE_PAUSED   | 5      | 暂停状态。       |
583
584## AudioEffectMode<sup>10+</sup>
585
586枚举,音效模式。
587
588**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
589
590**系统能力:** SystemCapability.Multimedia.Audio.Renderer
591
592| 名称               | 值     | 说明       |
593| ------------------ | ------ | ---------- |
594| EFFECT_NONE        | 0      | 关闭音效。 |
595| EFFECT_DEFAULT     | 1      | 默认音效。 |
596
597## AudioRendererRate<sup>8+</sup>
598
599枚举,音频渲染速度。
600
601**系统能力:** SystemCapability.Multimedia.Audio.Renderer
602
603| 名称               | 值     | 说明       |
604| ------------------ | ------ | ---------- |
605| RENDER_RATE_NORMAL | 0      | 正常速度。 |
606| RENDER_RATE_DOUBLE | 1      | 2倍速。    |
607| RENDER_RATE_HALF   | 2      | 0.5倍数。  |
608
609## InterruptType
610
611枚举,中断类型。
612
613**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
614
615**系统能力:** SystemCapability.Multimedia.Audio.Renderer
616
617| 名称                 |  值     | 说明                   |
618| -------------------- | ------ | ---------------------- |
619| INTERRUPT_TYPE_BEGIN | 1      | 音频播放中断事件开始。 |
620| INTERRUPT_TYPE_END   | 2      | 音频播放中断事件结束。 |
621
622## InterruptForceType<sup>9+</sup>
623
624枚举,音频打断类型。
625
626当用户监听到音频中断(即收到[InterruptEvent](#interruptevent9)事件)时,将获取此信息。
627
628此类型表示本次音频打断的操作是否已由系统强制执行,具体操作信息(如音频暂停、停止等)可通过[InterruptHint](#interrupthint)获取。关于音频打断策略的详细说明可参考文档[处理音频焦点事件](../../media/audio/audio-playback-concurrency.md)。
629
630**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
631
632**系统能力:** SystemCapability.Multimedia.Audio.Renderer
633
634| 名称            |  值    | 说明                                 |
635| --------------- | ------ | ------------------------------------ |
636| INTERRUPT_FORCE | 0      | 强制打断类型,即具体操作已由系统强制执行。   |
637| INTERRUPT_SHARE | 1      | 共享打断类型,即系统不执行具体操作,通过[InterruptHint](#interrupthint)提示并建议应用操作,应用可自行决策下一步处理方式。 |
638
639## InterruptHint
640
641枚举,中断提示。
642
643当用户监听到音频中断(即收到[InterruptEvent](#interruptevent9)事件)时,将获取此信息。
644
645此类型表示根据焦点策略,当前需要对音频流的具体操作(如暂停、调整音量等)。
646
647可以结合InterruptEvent中的[InterruptForceType](#interruptforcetype9)信息,判断该操作是否已由系统强制执行。关于音频打断策略的详细说明可参考文档[处理音频焦点事件](../../media/audio/audio-playback-concurrency.md)。
648
649**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
650
651**系统能力:** SystemCapability.Multimedia.Audio.Renderer
652
653| 名称                               |  值     | 说明                                         |
654| ---------------------------------- | ------ | -------------------------------------------- |
655| INTERRUPT_HINT_NONE<sup>8+</sup>   | 0      | 无提示。                                      |
656| INTERRUPT_HINT_RESUME              | 1      | 提示音频恢复,应用可主动触发开始渲染或开始采集的相关操作。<br>此操作无法由系统强制执行,其对应的[InterruptForceType](#interruptforcetype9)一定为INTERRUPT_SHARE类型。 |
657| INTERRUPT_HINT_PAUSE               | 2      | 提示音频暂停,暂时失去音频焦点。<br>后续待焦点可用时,会出现INTERRUPT_HINT_RESUME事件。  |
658| INTERRUPT_HINT_STOP                | 3      | 提示音频停止,彻底失去音频焦点。                |
659| INTERRUPT_HINT_DUCK                | 4      | 提示音频躲避开始,音频降低音量播放,而不会停止。 |
660| INTERRUPT_HINT_UNDUCK<sup>8+</sup> | 5      | 提示音量躲避结束,音频恢复正常音量。            |
661
662## AudioStreamInfo<sup>8+</sup>
663
664音频流信息。
665
666**系统能力:** SystemCapability.Multimedia.Audio.Core
667
668| 名称         | 类型                                               | 必填 | 说明               |
669| ------------ | ------------------------------------------------- | ---- | ------------------ |
670| samplingRate | [AudioSamplingRate](#audiosamplingrate8)          | 是   | 音频文件的采样率。 |
671| channels     | [AudioChannel](#audiochannel8)                    | 是   | 音频文件的通道数。 |
672| sampleFormat | [AudioSampleFormat](#audiosampleformat8)          | 是   | 音频采样格式。     |
673| encodingType | [AudioEncodingType](#audioencodingtype8)          | 是   | 音频编码格式。     |
674| channelLayout<sup>11+</sup> | [AudioChannelLayout](#audiochannellayout11)  | 否   | 音频声道布局,默认值为0x0。 |
675
676## AudioRendererInfo<sup>8+</sup>
677
678音频渲染器信息。
679
680**系统能力:** SystemCapability.Multimedia.Audio.Core
681
682| 名称          | 类型                        | 必填  | 说明             |
683| ------------- | --------------------------- | ---- | ---------------- |
684| content       | [ContentType](#contenttypedeprecated) | 否   | 音频内容类型。<br>API version 8、9为必填参数,从API version 10开始,变更为可选参数,默认值为CONTENT_TYPE_UNKNOWN。同时,[ContentType](#contenttypedeprecated)废弃,建议直接使用[StreamUsage](#streamusage)声明音频流使用类型即可。 |
685| usage         | [StreamUsage](#streamusage) | 是   | 音频流使用类型。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
686| rendererFlags | number                      | 是   | 音频渲染器标志。<br>0代表音频渲染器。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
687
688## AudioRendererOptions<sup>8+</sup>
689
690音频渲染器选项信息。
691
692| 名称         | 类型                                     | 必填  | 说明             |
693| ------------ | ---------------------------------------- | ---- | ---------------- |
694| streamInfo   | [AudioStreamInfo](#audiostreaminfo8)     | 是   | 表示音频流信息。<br/>**系统能力:** SystemCapability.Multimedia.Audio.Renderer |
695| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | 是   | 表示渲染器信息。<br/>**系统能力:** SystemCapability.Multimedia.Audio.Renderer |
696| privacyType<sup>10+</sup> | [AudioPrivacyType](#audioprivacytype10) | 否 | 表示音频流是否可以被其他应用录制,默认值为0。<br/>**系统能力:** SystemCapability.Multimedia.Audio.PlaybackCapture |
697
698## AudioPrivacyType<sup>10+</sup>
699
700枚举类型,用于标识对应播放音频流是否支持被其他应用录制。
701
702**系统能力:** SystemCapability.Multimedia.Audio.PlaybackCapture
703
704| 名称                 | 值   | 说明                             |
705| -------------------- | ---- | -------------------------------- |
706| PRIVACY_TYPE_PUBLIC  | 0    | 表示音频流可以被其他应用录制。   |
707| PRIVACY_TYPE_PRIVATE | 1    | 表示音频流不可以被其他应用录制。 |
708
709## InterruptEvent<sup>9+</sup>
710
711播放中断时,应用接收的中断事件。
712
713**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
714
715**系统能力:** SystemCapability.Multimedia.Audio.Renderer
716
717| 名称      | 类型                                       |必填   | 说明                                 |
718| --------- | ------------------------------------------ | ---- | ------------------------------------ |
719| eventType | [InterruptType](#interrupttype)            | 是   | 中断事件类型,开始或是结束。         |
720| forceType | [InterruptForceType](#interruptforcetype9) | 是   | 操作是由系统执行或是由应用程序执行。 |
721| hintType  | [InterruptHint](#interrupthint)            | 是   | 中断提示。                           |
722
723## VolumeEvent<sup>9+</sup>
724
725音量改变时,应用接收的事件。
726
727**系统能力:** SystemCapability.Multimedia.Audio.Volume
728
729| 名称       | 类型                                | 必填   | 说明                                        |
730| ---------- | ----------------------------------- | ---- |-------------------------------------------|
731| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                    |
732| volume     | number                              | 是   | 音量等级,可设置范围通过getMinVolume和getMaxVolume获取。  |
733| updateUi   | boolean                             | 是   | 在UI中显示音量变化,true为显示,false为不显示。             |
734
735## MicStateChangeEvent<sup>9+</sup>
736
737麦克风状态变化时,应用接收的事件。
738
739**系统能力:** SystemCapability.Multimedia.Audio.Device
740
741| 名称       | 类型                                | 必填 | 说明                                                     |
742| ---------- | ----------------------------------- | ---- |-------------------------------------------------------- |
743| mute | boolean | 是   | 回调返回系统麦克风静音状态,true为静音,false为非静音。          |
744
745## DeviceChangeAction
746
747描述设备连接状态变化和设备信息。
748
749**系统能力:** SystemCapability.Multimedia.Audio.Device
750
751| 名称              | 类型                                              | 必填 | 说明               |
752| :---------------- | :------------------------------------------------ | :--- | :----------------- |
753| type              | [DeviceChangeType](#devicechangetype)             | 是   | 设备连接状态变化。 |
754| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | 是   | 设备信息。         |
755
756## DeviceBlockStatusInfo<sup>13+</sup>
757
758描述音频设备被堵塞状态和设备信息。
759
760**系统能力:** SystemCapability.Multimedia.Audio.Device
761
762| 名称              | 类型                                              | 必填 | 说明               |
763| :---------------- | :------------------------------------------------ | :--- | :----------------- |
764| blockStatus       | [DeviceBlockStatus](#deviceblockstatus13)           | 是   | 音频设备堵塞状态。 |
765| devices | [AudioDeviceDescriptors](#audiodevicedescriptors) | 是   | 设备信息。         |
766
767## ChannelBlendMode<sup>11+</sup>
768
769枚举,声道混合模式类型。
770
771**系统能力:** SystemCapability.Multimedia.Audio.Core
772
773| 名称                                         |  值     | 说明                   |
774| :------------------------------------------- | :----- | :--------------------- |
775| MODE_DEFAULT | 0     | 无声道混合。  |
776| MODE_BLEND_LR | 1      | 混合左右声道。 |
777| MODE_ALL_LEFT | 2      | 从左声道拷贝覆盖到右声道混合。  |
778| MODE_ALL_RIGHT | 3 | 从右声道拷贝覆盖到左声道混合。 |
779
780## AudioStreamDeviceChangeReason<sup>11+</sup>
781
782枚举,流设备变更原因。
783
784**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
785
786**系统能力:** SystemCapability.Multimedia.Audio.Device
787
788| 名称                                        |  值     | 说明              |
789|:------------------------------------------| :----- |:----------------|
790| REASON_UNKNOWN | 0 | 未知原因。           |
791| REASON_NEW_DEVICE_AVAILABLE | 1 | 新设备可用。         |
792| REASON_OLD_DEVICE_UNAVAILABLE | 2 | 旧设备不可用。当报告此原因时,应用程序应考虑暂停音频播放。 |
793| REASON_OVERRODE | 3 | 强选。 |
794
795## AudioStreamDeviceChangeInfo<sup>11+</sup>
796
797流设备变更时,应用接收的事件。
798
799**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
800
801**系统能力:** SystemCapability.Multimedia.Audio.Device
802
803| 名称              | 类型                                                                | 必填 | 说明               |
804| :---------------- |:------------------------------------------------------------------| :--- | :----------------- |
805| devices              | [AudioDeviceDescriptors](#audiodevicedescriptors)                 | 是   | 设备信息。 |
806| changeReason | [AudioStreamDeviceChangeReason](#audiostreamdevicechangereason11) | 是   | 流设备变更原因。 |
807
808## DeviceChangeType
809
810枚举,设备连接状态变化。
811
812**系统能力:** SystemCapability.Multimedia.Audio.Device
813
814| 名称       | 值   | 说明           |
815| :--------- | :--- | :------------- |
816| CONNECT    | 0    | 设备连接。     |
817| DISCONNECT | 1    | 断开设备连接。 |
818
819## DeviceBlockStatus<sup>13+</sup>
820
821枚举,表示音频设备是否被堵塞。
822
823**系统能力:** SystemCapability.Multimedia.Audio.Device
824
825| 名称       | 值   | 说明           |
826| :--------- | :--- | :------------- |
827| UNBLOCKED  | 0    | 音频设备正常。    |
828| BLOCKED    | 1    | 音频设备被堵塞。 |
829
830## AudioCapturerOptions<sup>8+</sup>
831
832音频采集器选项信息。
833
834| 名称                                | 类型                                                      | 必填 | 说明                                                         |
835| ----------------------------------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ |
836| streamInfo                          | [AudioStreamInfo](#audiostreaminfo8)                      | 是   | 表示音频流信息。 <br/>**系统能力:** SystemCapability.Multimedia.Audio.Capturer   |
837| capturerInfo                        | [AudioCapturerInfo](#audiocapturerinfo8)                   | 是   | 表示采集器信息。 <br/>**系统能力:** SystemCapability.Multimedia.Audio.Capturer        |
838| playbackCaptureConfig<sup>(deprecated)</sup> | [AudioPlaybackCaptureConfig](#audioplaybackcaptureconfigdeprecated) | 否   | 音频内录的配置信息。<br/>**系统能力:** SystemCapability.Multimedia.Audio.PlaybackCapture。<br/> 从API version 10 开始支持,从 API version 12 开始废弃。Audio不再提供内录接口,请通过[录屏接口AVScreenCapture](../apis-media-kit/_a_v_screen_capture.md)进行内录。 |
839
840## AudioCapturerInfo<sup>8+</sup>
841
842描述音频采集器信息。
843
844**系统能力:** SystemCapability.Multimedia.Audio.Core
845
846| 名称          | 类型                      | 必填 | 说明             |
847| :------------ | :------------------------ | :--- | :--------------- |
848| source        | [SourceType](#sourcetype8) | 是   | 音源类型。       |
849| capturerFlags | number                    | 是   | 音频采集器标志。<br>0代表音频采集器。 |
850
851## SourceType<sup>8+</sup>
852
853枚举,音源类型。
854
855| 名称                                         |  值     | 说明                   |
856| :------------------------------------------- | :----- | :--------------------- |
857| SOURCE_TYPE_INVALID                          | -1     | 无效的音频源。<br/>**系统能力:** SystemCapability.Multimedia.Audio.Core  |
858| SOURCE_TYPE_MIC                              | 0      | Mic音频源。<br/>**系统能力:** SystemCapability.Multimedia.Audio.Core |
859| SOURCE_TYPE_VOICE_RECOGNITION<sup>9+</sup>   | 1      | 语音识别源。<br/>**系统能力:** SystemCapability.Multimedia.Audio.Core  |
860| SOURCE_TYPE_PLAYBACK_CAPTURE<sup>(deprecated)</sup>   | 2 | 播放音频流(内录)录制音频源。<br/>**系统能力:** SystemCapability.Multimedia.Audio.PlaybackCapture。<br/> 从API version 10 开始支持,从 API version 12 开始废弃。Audio不再提供内录接口,请通过[录屏接口AVScreenCapture](../apis-media-kit/_a_v_screen_capture.md)进行内录。 |
861| SOURCE_TYPE_VOICE_COMMUNICATION              | 7      | 语音通话场景的音频源。<br/>**系统能力:** SystemCapability.Multimedia.Audio.Core |
862| SOURCE_TYPE_VOICE_MESSAGE<sup>12+</sup>      | 10     | 短语音消息的音频源。<br/>**系统能力:** SystemCapability.Multimedia.Audio.Core |
863| SOURCE_TYPE_CAMCORDER<sup>13+</sup>          | 13     | 录像的音频源。<br/>**系统能力:** SystemCapability.Multimedia.Audio.Core |
864| SOURCE_TYPE_UNPROCESSED<sup>14+</sup>  | 14 | 麦克风纯净录音的音频源(系统不做任何算法处理)。<br/>**系统能力:** SystemCapability.Multimedia.Audio.Core |
865
866## AudioPlaybackCaptureConfig<sup>(deprecated)</sup>
867
868播放音频流录制(内录)的配置信息。
869
870> **说明:**
871> 从 API version 10 开始支持,从 API version 12 开始废弃。Audio不再提供内录接口,请通过[录屏接口AVScreenCapture](../apis-media-kit/_a_v_screen_capture.md)进行内录。
872
873**系统能力:** SystemCapability.Multimedia.Audio.PlaybackCapture
874
875| 名称          | 类型                                          | 必填 | 说明                             |
876| ------------- | --------------------------------------------- | ---- | -------------------------------- |
877| filterOptions | [CaptureFilterOptions](#capturefilteroptionsdeprecated) | 是   | 需要录制的播放音频流的筛选信息。 |
878
879## CaptureFilterOptions<sup>(deprecated)</sup>
880
881待录制的播放音频流的筛选信息。
882
883> **说明:**
884> 从 API version 10 开始支持,从 API version 12 开始废弃。Audio不再提供内录接口,请通过[录屏接口AVScreenCapture](../apis-media-kit/_a_v_screen_capture.md)进行内录。
885
886**需要权限:** ohos.permission.CAPTURE_VOICE_DOWNLINK_AUDIO,具体请参考以下说明。
887
888- 在API version 10时,CaptureFilterOptions支持使用StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,使用时需要申请权限ohos.permission.CAPTURE_VOICE_DOWNLINK_AUDIO,该权限仅系统应用可申请。
889
890- 从API version 11开始,CaptureFilterOptions不再支持使用StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,所以当前接口不再涉及此权限。
891
892**系统能力:** SystemCapability.Multimedia.Audio.PlaybackCapture
893
894| 名称   | 类型                               | 必填 | 说明                                                         |
895| ------ | ---------------------------------- | ---- | ------------------------------------------------------------ |
896| usages | Array<[StreamUsage](#streamusage)> | 是   | 指定需要录制的音频播放流的StreamUsage类型。可同时指定0个或多个StreamUsage。Array为空时,默认录制StreamUsage为STREAM_USAGE_MUSIC、STREAM_USAGE_MOVIE、STREAM_USAGE_GAME和STREAM_USAGE_AUDIOBOOK的音频播放流。 |
897
898## AudioScene<sup>8+</sup>
899
900枚举,音频场景。
901
902**系统能力:** SystemCapability.Multimedia.Audio.Communication
903
904| 名称                   |  值     | 说明                                          |
905| :--------------------- | :----- | :-------------------------------------------- |
906| AUDIO_SCENE_DEFAULT                  | 0      | 默认音频场景。                                |
907| AUDIO_SCENE_RINGING<sup>12+</sup>    | 1      | 响铃模式。 |
908| AUDIO_SCENE_PHONE_CALL<sup>12+</sup> | 2      | 电话模式。 |
909| AUDIO_SCENE_VOICE_CHAT               | 3      | 语音聊天模式。                                |
910
911## AudioConcurrencyMode<sup>12+</sup>
912
913枚举,音频并发模式。
914
915**系统能力:** SystemCapability.Multimedia.Audio.Core
916
917| 名称                   | 值 | 说明      |
918| :--------------------- |:--|:--------|
919| CONCURRENCY_DEFAULT | 0 | 默认使用系统策略。     |
920| CONCURRENCY_MIX_WITH_OTHERS | 1 | 和其它音频并发。     |
921| CONCURRENCY_DUCK_OTHERS | 2 | 压低其他音频的音量。 |
922| CONCURRENCY_PAUSE_OTHERS | 3 | 暂停其他音频。 |
923
924## AudioSessionDeactivatedReason<sup>12+</sup>
925
926枚举,音频会话停用原因。
927
928**系统能力:** SystemCapability.Multimedia.Audio.Core
929
930| 名称                   | 值 | 说明     |
931| :--------------------- |:--|:-------|
932| DEACTIVATED_LOWER_PRIORITY | 0 | 应用焦点被抢占。 |
933| DEACTIVATED_TIMEOUT | 1 | 音频会话等待超时。    |
934
935## AudioSessionStrategy<sup>12+</sup>
936
937音频会话策略。
938
939**系统能力:** SystemCapability.Multimedia.Audio.Core
940
941| 名称          | 类型                                              | 必填 | 说明             |
942| :------------ |:------------------------------------------------| :--- | :--------------- |
943| concurrencyMode        | [AudioConcurrencyMode](#audioconcurrencymode12) | 是   | 音频并发模式。       |
944
945## AudioSessionDeactivatedEvent<sup>12+</sup>
946
947音频会话已停用事件。
948
949**系统能力:** SystemCapability.Multimedia.Audio.Core
950
951| 名称          | 类型                                                                | 必填 | 说明             |
952| :------------ |:------------------------------------------------------------------| :--- | :--------------- |
953| reason        | [AudioSessionDeactivatedReason](#audiosessiondeactivatedreason12) | 是   | 音频会话停用原因。       |
954
955## AudioManager
956
957管理音频音量和音频设备。在调用AudioManager的接口前,需要先通过[getAudioManager](#audiogetaudiomanager)创建实例。
958
959### setAudioParameter<sup>(deprecated)</sup>
960
961setAudioParameter(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
962
963音频参数设置,使用callback方式异步返回结果。
964
965接口用于为根据硬件设备支持能力扩展音频配置。支持的参数与产品、设备强相关,非通用参数,示例代码内使用样例参数。
966
967> **说明:**
968> 从 API version 7 开始支持,从 API version 11 开始废弃。替代接口仅面向系统应用开放。
969
970**需要权限:** ohos.permission.MODIFY_AUDIO_SETTINGS
971
972**系统能力:** SystemCapability.Multimedia.Audio.Core
973
974**参数:**
975
976| 参数名   | 类型                      | 必填 | 说明                     |
977| -------- | ------------------------- | ---- | ------------------------ |
978| key      | string                    | 是   | 被设置的音频参数的键。   |
979| value    | string                    | 是   | 被设置的音频参数的值。   |
980| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。当音频参数设置成功,err为undefined,否则为错误对象。 |
981
982**示例:**
983
984```ts
985import { BusinessError } from '@kit.BasicServicesKit';
986
987audioManager.setAudioParameter('key_example', 'value_example', (err: BusinessError) => {
988  if (err) {
989    console.error(`Failed to set the audio parameter. ${err}`);
990    return;
991  }
992  console.info('Callback invoked to indicate a successful setting of the audio parameter.');
993});
994```
995
996### setAudioParameter<sup>(deprecated)</sup>
997
998setAudioParameter(key: string, value: string): Promise&lt;void&gt;
999
1000音频参数设置,使用Promise方式异步返回结果。
1001
1002接口用于为根据硬件设备支持能力扩展音频配置。支持的参数与产品、设备强相关,非通用参数,示例代码内使用样例参数。
1003
1004> **说明:**
1005> 从 API version 7 开始支持,从 API version 11 开始废弃。替代接口仅面向系统应用开放。
1006
1007**需要权限:** ohos.permission.MODIFY_AUDIO_SETTINGS
1008
1009**系统能力:** SystemCapability.Multimedia.Audio.Core
1010
1011**参数:**
1012
1013| 参数名 | 类型   | 必填 | 说明                   |
1014| ------ | ------ | ---- | ---------------------- |
1015| key    | string | 是   | 被设置的音频参数的键。 |
1016| value  | string | 是   | 被设置的音频参数的值。 |
1017
1018**返回值:**
1019
1020| 类型                | 说明                            |
1021| ------------------- | ------------------------------- |
1022| Promise&lt;void&gt; | Promise对象,无返回结果。 |
1023
1024**示例:**
1025
1026```ts
1027audioManager.setAudioParameter('key_example', 'value_example').then(() => {
1028  console.info('Promise returned to indicate a successful setting of the audio parameter.');
1029});
1030```
1031
1032### getAudioParameter<sup>(deprecated)</sup>
1033
1034getAudioParameter(key: string, callback: AsyncCallback&lt;string&gt;): void
1035
1036获取指定音频参数值,使用callback方式异步返回结果。
1037
1038本接口的使用场景为根据硬件设备支持能力扩展音频配置。在不同的设备平台上,所支持的音频参数会存在差异。示例代码内使用样例参数,实际支持的音频配置参数见具体设备平台的资料描述。
1039
1040> **说明:**
1041> 从 API version 7 开始支持,从 API version 11 开始废弃。替代接口仅面向系统应用开放。
1042
1043**系统能力:** SystemCapability.Multimedia.Audio.Core
1044
1045**参数:**
1046
1047| 参数名   | 类型                        | 必填 | 说明                         |
1048| -------- | --------------------------- | ---- | ---------------------------- |
1049| key      | string                      | 是   | 待获取的音频参数的键。       |
1050| callback | AsyncCallback&lt;string&gt; | 是   | 回调函数。当获取指定音频参数值成功,err为undefined,data为获取到的指定音频参数值;否则为错误对象。 |
1051
1052**示例:**
1053
1054```ts
1055import { BusinessError } from '@kit.BasicServicesKit';
1056
1057audioManager.getAudioParameter('key_example', (err: BusinessError, value: string) => {
1058  if (err) {
1059    console.error(`Failed to obtain the value of the audio parameter. ${err}`);
1060    return;
1061  }
1062  console.info(`Callback invoked to indicate that the value of the audio parameter is obtained ${value}.`);
1063});
1064```
1065
1066### getAudioParameter<sup>(deprecated)</sup>
1067
1068getAudioParameter(key: string): Promise&lt;string&gt;
1069
1070获取指定音频参数值,使用Promise方式异步返回结果。
1071
1072本接口的使用场景为根据硬件设备支持能力扩展音频配置。在不同的设备平台上,所支持的音频参数会存在差异。示例代码内使用样例参数,实际支持的音频配置参数见具体设备平台的资料描述。
1073
1074> **说明:**
1075> 从 API version 7 开始支持,从 API version 11 开始废弃。替代接口仅面向系统应用开放。
1076
1077**系统能力:** SystemCapability.Multimedia.Audio.Core
1078
1079**参数:**
1080
1081| 参数名 | 类型   | 必填 | 说明                   |
1082| ------ | ------ | ---- | ---------------------- |
1083| key    | string | 是   | 待获取的音频参数的键。 |
1084
1085**返回值:**
1086
1087| 类型                  | 说明                                |
1088| --------------------- | ----------------------------------- |
1089| Promise&lt;string&gt; | Promise对象,返回获取的音频参数的值。 |
1090
1091**示例:**
1092
1093```ts
1094audioManager.getAudioParameter('key_example').then((value: string) => {
1095  console.info(`Promise returned to indicate that the value of the audio parameter is obtained ${value}.`);
1096});
1097```
1098
1099### getAudioScene<sup>8+</sup>
1100
1101getAudioScene\(callback: AsyncCallback<AudioScene\>\): void
1102
1103获取音频场景模式,使用callback方式返回异步结果。
1104
1105**系统能力:** SystemCapability.Multimedia.Audio.Communication
1106
1107**参数:**
1108
1109| 参数名   | 类型                                                | 必填 | 说明                         |
1110| :------- | :-------------------------------------------------- | :--- | :--------------------------- |
1111| callback | AsyncCallback<[AudioScene](#audioscene8)> | 是   | 回调函数。当获取音频场景模式成功,err为undefined,data为获取到的音频场景模式;否则为错误对象。 |
1112
1113**示例:**
1114
1115```ts
1116import { BusinessError } from '@kit.BasicServicesKit';
1117
1118audioManager.getAudioScene((err: BusinessError, value: audio.AudioScene) => {
1119  if (err) {
1120    console.error(`Failed to obtain the audio scene mode. ${err}`);
1121    return;
1122  }
1123  console.info(`Callback invoked to indicate that the audio scene mode is obtained ${value}.`);
1124});
1125```
1126
1127### getAudioScene<sup>8+</sup>
1128
1129getAudioScene\(\): Promise<AudioScene\>
1130
1131获取音频场景模式,使用Promise方式返回异步结果。
1132
1133**系统能力:** SystemCapability.Multimedia.Audio.Communication
1134
1135**返回值:**
1136
1137| 类型                                          | 说明                         |
1138| :-------------------------------------------- | :--------------------------- |
1139| Promise<[AudioScene](#audioscene8)> | Promise对象,返回音频场景模式。 |
1140
1141**示例:**
1142
1143```ts
1144import { BusinessError } from '@kit.BasicServicesKit';
1145
1146audioManager.getAudioScene().then((value: audio.AudioScene) => {
1147  console.info(`Promise returned to indicate that the audio scene mode is obtained ${value}.`);
1148}).catch ((err: BusinessError) => {
1149  console.error(`Failed to obtain the audio scene mode ${err}`);
1150});
1151```
1152
1153### getAudioSceneSync<sup>10+</sup>
1154
1155getAudioSceneSync\(\): AudioScene
1156
1157获取音频场景模式,同步返回结果。
1158
1159**系统能力:** SystemCapability.Multimedia.Audio.Communication
1160
1161**返回值:**
1162
1163| 类型                                          | 说明                         |
1164| :-------------------------------------------- | :--------------------------- |
1165| [AudioScene](#audioscene8) | 音频场景模式。 |
1166
1167**示例:**
1168
1169```ts
1170import { BusinessError } from '@kit.BasicServicesKit';
1171
1172try {
1173  let value: audio.AudioScene = audioManager.getAudioSceneSync();
1174  console.info(`indicate that the audio scene mode is obtained ${value}.`);
1175} catch (err) {
1176  let error = err as BusinessError;
1177  console.error(`Failed to obtain the audio scene mode ${error}`);
1178}
1179```
1180
1181### getVolumeManager<sup>9+</sup>
1182
1183getVolumeManager(): AudioVolumeManager
1184
1185获取音频音量管理器。
1186
1187**系统能力:** SystemCapability.Multimedia.Audio.Volume
1188
1189**返回值:**
1190
1191| 类型                                      | 说明                          |
1192|-----------------------------------------| ----------------------------- |
1193| [AudioVolumeManager](#audiovolumemanager9) | AudioVolumeManager实例 |
1194
1195**示例:**
1196
1197```ts
1198import { audio } from '@kit.AudioKit';
1199
1200let audioVolumeManager: audio.AudioVolumeManager = audioManager.getVolumeManager();
1201```
1202
1203### getStreamManager<sup>9+</sup>
1204
1205getStreamManager(): AudioStreamManager
1206
1207获取音频流管理器。
1208
1209**系统能力:** SystemCapability.Multimedia.Audio.Core
1210
1211**返回值:**
1212
1213| 类型                                         | 说明                          |
1214|--------------------------------------------| ----------------------------- |
1215| [AudioStreamManager](#audiostreammanager9) | AudioStreamManager实例 |
1216
1217**示例:**
1218
1219```ts
1220import { audio } from '@kit.AudioKit';
1221
1222let audioStreamManager: audio.AudioStreamManager = audioManager.getStreamManager();
1223```
1224
1225### getRoutingManager<sup>9+</sup>
1226
1227getRoutingManager(): AudioRoutingManager
1228
1229获取音频路由设备管理器。
1230
1231**系统能力:** SystemCapability.Multimedia.Audio.Device
1232
1233**返回值:**
1234
1235| 类型                                       | 说明                          |
1236|------------------------------------------| ----------------------------- |
1237| [AudioRoutingManager](#audioroutingmanager9) | AudioRoutingManager实例 |
1238
1239**示例:**
1240
1241```ts
1242import { audio } from '@kit.AudioKit';
1243
1244let audioRoutingManager: audio.AudioRoutingManager = audioManager.getRoutingManager();
1245```
1246
1247### getSessionManager<sup>12+</sup>
1248
1249getSessionManager(): AudioSessionManager
1250
1251获取音频会话管理器。
1252
1253**系统能力:** SystemCapability.Multimedia.Audio.Core
1254
1255**返回值:**
1256
1257| 类型                                           | 说明                          |
1258|----------------------------------------------| ----------------------------- |
1259| [AudioSessionManager](#audiosessionmanager12) | AudioSessionManager实例 |
1260
1261**示例:**
1262
1263```ts
1264import { audio } from '@kit.AudioKit';
1265
1266let audioSessionManager: audio.AudioSessionManager = audioManager.getSessionManager();
1267```
1268
1269### setVolume<sup>(deprecated)</sup>
1270
1271setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&lt;void&gt;): void
1272
1273设置指定流的音量,使用callback方式异步返回结果。
1274
1275> **说明:**
1276>
1277> 从 API version 7 开始支持,从 API version 9 开始废弃。替代接口仅面向系统应用开放。
1278>
1279> 应用无法直接调节系统音量,建议应用通过系统音量面板组件,让用户通过界面操作来调节音量。当用户通过应用内音量面板调节音量时,系统会展示音量提示界面,显性地提示用户系统音量发生改变。具体样例和介绍请查看[AVVolumePanel参考文档](ohos-multimedia-avvolumepanel.md)。
1280
1281**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
1282
1283仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
1284
1285**系统能力:** SystemCapability.Multimedia.Audio.Volume
1286
1287**参数:**
1288
1289| 参数名     | 类型                                | 必填 | 说明                                                     |
1290| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
1291| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
1292| volume     | number                              | 是   | 音量等级,可设置范围通过[getMinVolume](#getminvolumedeprecated)和[getMaxVolume](#getmaxvolumedeprecated)获取。 |
1293| callback   | AsyncCallback&lt;void&gt;           | 是   | 回调函数。当设置指定流的音量成功,err为undefined,否则为错误对象。 |
1294
1295**示例:**
1296
1297```ts
1298import { BusinessError } from '@kit.BasicServicesKit';
1299
1300audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err: BusinessError) => {
1301  if (err) {
1302    console.error(`Failed to set the volume. ${err}`);
1303    return;
1304  }
1305  console.info('Callback invoked to indicate a successful volume setting.');
1306});
1307```
1308
1309### setVolume<sup>(deprecated)</sup>
1310
1311setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
1312
1313设置指定流的音量,使用Promise方式异步返回结果。
1314
1315> **说明:**
1316>
1317> 从 API version 7 开始支持,从 API version 9 开始废弃。替代接口仅面向系统应用开放。
1318>
1319> 应用无法直接调节系统音量,建议应用通过系统音量面板组件,让用户通过界面操作来调节音量。当用户通过应用内音量面板调节音量时,系统会展示音量提示界面,显性地提示用户系统音量发生改变。具体样例和介绍请查看[AVVolumePanel参考文档](ohos-multimedia-avvolumepanel.md)。
1320
1321**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
1322
1323仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
1324
1325**系统能力:** SystemCapability.Multimedia.Audio.Volume
1326
1327**参数:**
1328
1329| 参数名     | 类型                                | 必填 | 说明                                                     |
1330| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
1331| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
1332| volume     | number                              | 是   | 音量等级,可设置范围通过[getMinVolume](#getminvolumedeprecated)和[getMaxVolume](#getmaxvolumedeprecated)获取。 |
1333
1334**返回值:**
1335
1336| 类型                | 说明                          |
1337| ------------------- | ----------------------------- |
1338| Promise&lt;void&gt; | Promise对象,无返回结果。 |
1339
1340**示例:**
1341
1342```ts
1343audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
1344  console.info('Promise returned to indicate a successful volume setting.');
1345});
1346```
1347
1348### getVolume<sup>(deprecated)</sup>
1349
1350getVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
1351
1352获取指定流的音量,使用callback方式异步返回结果。
1353
1354> **说明:**
1355> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getVolume](#getvolume9)替代。
1356
1357**系统能力:** SystemCapability.Multimedia.Audio.Volume
1358
1359**参数:**
1360
1361| 参数名     | 类型                                | 必填 | 说明               |
1362| ---------- | ----------------------------------- | ---- | ------------------ |
1363| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。       |
1364| callback   | AsyncCallback&lt;number&gt;         | 是   | 回调函数。当获取指定流的音量成功,err为undefined,data为获取到的指定流的音量;否则为错误对象。指定流的音量等级范围可通过[getMinVolume](#getminvolumedeprecated)和[getMaxVolume](#getmaxvolumedeprecated)获取。 |
1365
1366**示例:**
1367
1368```ts
1369import { BusinessError } from '@kit.BasicServicesKit';
1370
1371audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
1372  if (err) {
1373    console.error(`Failed to obtain the volume. ${err}`);
1374    return;
1375  }
1376  console.info('Callback invoked to indicate that the volume is obtained.');
1377});
1378```
1379
1380### getVolume<sup>(deprecated)</sup>
1381
1382getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
1383
1384获取指定流的音量,使用Promise方式异步返回结果。
1385
1386> **说明:**
1387> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getVolume](#getvolume9)替代。
1388
1389**系统能力:** SystemCapability.Multimedia.Audio.Volume
1390
1391**参数:**
1392
1393| 参数名     | 类型                                | 必填 | 说明         |
1394| ---------- | ----------------------------------- | ---- | ------------ |
1395| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
1396
1397**返回值:**
1398
1399| 类型                  | 说明                      |
1400| --------------------- | ------------------------- |
1401| Promise&lt;number&gt; | Promise对象,返回指定流的音量。指定流的音量等级范围可通过[getMinVolume](#getminvolumedeprecated)和[getMaxVolume](#getmaxvolumedeprecated)获取。 |
1402
1403**示例:**
1404
1405```ts
1406audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value: number) => {
1407  console.info(`Promise returned to indicate that the volume is obtained ${value} .`);
1408});
1409```
1410
1411### getMinVolume<sup>(deprecated)</sup>
1412
1413getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
1414
1415获取指定流的最小音量,使用callback方式异步返回结果。
1416
1417> **说明:**
1418> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getMinVolume](#getminvolume9)替代。
1419
1420**系统能力:** SystemCapability.Multimedia.Audio.Volume
1421
1422**参数:**
1423
1424| 参数名     | 类型                                | 必填 | 说明               |
1425| ---------- | ----------------------------------- | ---- | ------------------ |
1426| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。       |
1427| callback   | AsyncCallback&lt;number&gt;         | 是   | 回调函数。当获取指定流的最小音量成功,err为undefined,data为获取到的指定流的最小音量;否则为错误对象。 |
1428
1429**示例:**
1430
1431```ts
1432import { BusinessError } from '@kit.BasicServicesKit';
1433
1434audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
1435  if (err) {
1436    console.error(`Failed to obtain the minimum volume. ${err}`);
1437    return;
1438  }
1439  console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
1440});
1441```
1442
1443### getMinVolume<sup>(deprecated)</sup>
1444
1445getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
1446
1447获取指定流的最小音量,使用Promise方式异步返回结果。
1448
1449> **说明:**
1450> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getMinVolume](#getminvolume9)替代。
1451
1452**系统能力:** SystemCapability.Multimedia.Audio.Volume
1453
1454**参数:**
1455
1456| 参数名     | 类型                                | 必填 | 说明         |
1457| ---------- | ----------------------------------- | ---- | ------------ |
1458| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
1459
1460**返回值:**
1461
1462| 类型                  | 说明                      |
1463| --------------------- | ------------------------- |
1464| Promise&lt;number&gt; | Promise对象,返回最小音量。 |
1465
1466**示例:**
1467
1468```ts
1469audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value: number) => {
1470  console.info(`Promised returned to indicate that the minimum volume is obtained. ${value}`);
1471});
1472```
1473
1474### getMaxVolume<sup>(deprecated)</sup>
1475
1476getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
1477
1478获取指定流的最大音量,使用callback方式异步返回结果。
1479
1480> **说明:**
1481> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getMaxVolume](#getmaxvolume9)替代。
1482
1483**系统能力:** SystemCapability.Multimedia.Audio.Volume
1484
1485**参数:**
1486
1487| 参数名     | 类型                                | 必填 | 说明                   |
1488| ---------- | ----------------------------------- | ---- | ---------------------- |
1489| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。           |
1490| callback   | AsyncCallback&lt;number&gt;         | 是   | 回调函数。当获取指定流的最大音量成功,err为undefined,data为获取到的指定流的最大音量;否则为错误对象。 |
1491
1492**示例:**
1493
1494```ts
1495import { BusinessError } from '@kit.BasicServicesKit';
1496
1497audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
1498  if (err) {
1499    console.error(`Failed to obtain the maximum volume. ${err}`);
1500    return;
1501  }
1502  console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`);
1503});
1504```
1505
1506### getMaxVolume<sup>(deprecated)</sup>
1507
1508getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
1509
1510获取指定流的最大音量,使用Promise方式异步返回结果。
1511
1512> **说明:**
1513> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getMaxVolume](#getmaxvolume9)替代。
1514
1515**系统能力:** SystemCapability.Multimedia.Audio.Volume
1516
1517**参数:**
1518
1519| 参数名     | 类型                                | 必填 | 说明         |
1520| ---------- | ----------------------------------- | ---- | ------------ |
1521| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
1522
1523**返回值:**
1524
1525| 类型                  | 说明                          |
1526| --------------------- | ----------------------------- |
1527| Promise&lt;number&gt; | Promise对象,返回最大音量。 |
1528
1529**示例:**
1530
1531```ts
1532audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data: number) => {
1533  console.info('Promised returned to indicate that the maximum volume is obtained.');
1534});
1535```
1536
1537### mute<sup>(deprecated)</sup>
1538
1539mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
1540
1541设置指定音量流静音,使用callback方式异步返回结果。
1542
1543当该音量流可设置的最小音量不能为0时,不支持静音操作,例如:闹钟、通话。
1544
1545> **说明:**
1546> 从 API version 7 开始支持,从 API version 9 开始废弃。替代接口仅面向系统应用开放。
1547
1548**系统能力:** SystemCapability.Multimedia.Audio.Volume
1549
1550**参数:**
1551
1552| 参数名     | 类型                                | 必填 | 说明                                  |
1553| ---------- | ----------------------------------- | ---- | ------------------------------------- |
1554| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                          |
1555| mute       | boolean                             | 是   | 静音状态,true为静音,false为非静音。 |
1556| callback   | AsyncCallback&lt;void&gt;           | 是   | 回调函数。当设置指定音量流静音成功,err为undefined,否则为错误对象。 |
1557
1558**示例:**
1559
1560```ts
1561import { BusinessError } from '@kit.BasicServicesKit';
1562
1563audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err: BusinessError) => {
1564  if (err) {
1565    console.error(`Failed to mute the stream. ${err}`);
1566    return;
1567  }
1568  console.info('Callback invoked to indicate that the stream is muted.');
1569});
1570```
1571
1572### mute<sup>(deprecated)</sup>
1573
1574mute(volumeType: AudioVolumeType, mute: boolean): Promise&lt;void&gt;
1575
1576设置指定音量流静音,使用Promise方式异步返回结果。
1577
1578当该音量流可设置的最小音量不能为0时,不支持静音操作,例如:闹钟、通话。
1579
1580> **说明:**
1581> 从 API version 7 开始支持,从 API version 9 开始废弃。替代接口仅面向系统应用开放。
1582
1583**系统能力:** SystemCapability.Multimedia.Audio.Volume
1584
1585**参数:**
1586
1587| 参数名     | 类型                                | 必填 | 说明                                  |
1588| ---------- | ----------------------------------- | ---- | ------------------------------------- |
1589| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                          |
1590| mute       | boolean                             | 是   | 静音状态,true为静音,false为非静音。 |
1591
1592**返回值:**
1593
1594| 类型                | 说明                          |
1595| ------------------- | ----------------------------- |
1596| Promise&lt;void&gt; | Promise对象,无返回结果。 |
1597
1598**示例:**
1599
1600
1601```ts
1602audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
1603  console.info('Promise returned to indicate that the stream is muted.');
1604});
1605```
1606
1607### isMute<sup>(deprecated)</sup>
1608
1609isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
1610
1611获取指定音量流是否被静音,使用callback方式异步返回结果。
1612
1613> **说明:**
1614> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[isMute](#ismute9)替代。
1615
1616**系统能力:** SystemCapability.Multimedia.Audio.Volume
1617
1618**参数:**
1619
1620| 参数名     | 类型                                | 必填 | 说明                                            |
1621| ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
1622| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                    |
1623| callback   | AsyncCallback&lt;boolean&gt;        | 是   | 回调函数。当获取指定音量流是否被静音成功,err为undefined,data为true为静音,false为非静音;否则为错误对象。 |
1624
1625**示例:**
1626
1627```ts
1628import { BusinessError } from '@kit.BasicServicesKit';
1629
1630audioManager.isMute(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => {
1631  if (err) {
1632    console.error(`Failed to obtain the mute status. ${err}`);
1633    return;
1634  }
1635  console.info(`Callback invoked to indicate that the mute status of the stream is obtained. ${value}`);
1636});
1637```
1638
1639### isMute<sup>(deprecated)</sup>
1640
1641isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
1642
1643获取指定音量流是否被静音,使用Promise方式异步返回结果。
1644
1645> **说明:**
1646> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[isMute](#ismute9)替代。
1647
1648**系统能力:** SystemCapability.Multimedia.Audio.Volume
1649
1650**参数:**
1651
1652| 参数名     | 类型                                | 必填 | 说明         |
1653| ---------- | ----------------------------------- | ---- | ------------ |
1654| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
1655
1656**返回值:**
1657
1658| 类型                   | 说明                                                   |
1659| ---------------------- | ------------------------------------------------------ |
1660| Promise&lt;boolean&gt; | Promise对象,返回流静音状态,true为静音,false为非静音。 |
1661
1662**示例:**
1663
1664```ts
1665audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value: boolean) => {
1666  console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`);
1667});
1668```
1669
1670### isActive<sup>(deprecated)</sup>
1671
1672isActive(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
1673
1674获取指定音量流是否为活跃状态,使用callback方式异步返回结果。
1675
1676> **说明:**
1677> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioStreamManager中的[isActive](#isactive9)替代。
1678
1679**系统能力:** SystemCapability.Multimedia.Audio.Volume
1680
1681**参数:**
1682
1683| 参数名     | 类型                                | 必填 | 说明                                              |
1684| ---------- | ----------------------------------- | ---- | ------------------------------------------------- |
1685| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                      |
1686| callback   | AsyncCallback&lt;boolean&gt;        | 是   | 回调函数。当获取指定音量流是否为活跃状态成功,err为undefined,data为true为活跃,false为不活跃;否则为错误对象。 |
1687
1688**示例:**
1689
1690```ts
1691import { BusinessError } from '@kit.BasicServicesKit';
1692
1693audioManager.isActive(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => {
1694  if (err) {
1695    console.error(`Failed to obtain the active status of the stream. ${err}`);
1696    return;
1697  }
1698  console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`);
1699});
1700```
1701
1702### isActive<sup>(deprecated)</sup>
1703
1704isActive(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
1705
1706获取指定音量流是否为活跃状态,使用Promise方式异步返回结果。
1707
1708> **说明:**
1709> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioStreamManager中的[isActive](#isactive9)替代。
1710
1711**系统能力:** SystemCapability.Multimedia.Audio.Volume
1712
1713**参数:**
1714
1715| 参数名     | 类型                                | 必填 | 说明         |
1716| ---------- | ----------------------------------- | ---- | ------------ |
1717| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
1718
1719**返回值:**
1720
1721| 类型                   | 说明                                                     |
1722| ---------------------- | -------------------------------------------------------- |
1723| Promise&lt;boolean&gt; | Promise对象,返回流的活跃状态,true为活跃,false为不活跃。 |
1724
1725**示例:**
1726
1727```ts
1728audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value: boolean) => {
1729  console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`);
1730});
1731```
1732
1733### setRingerMode<sup>(deprecated)</sup>
1734
1735setRingerMode(mode: AudioRingMode, callback: AsyncCallback&lt;void&gt;): void
1736
1737设置铃声模式,使用callback方式异步返回结果。
1738
1739> **说明:**
1740> 从 API version 7 开始支持,从 API version 9 开始废弃。替代接口仅面向系统应用开放。
1741
1742**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
1743
1744仅在静音和非静音状态切换时需要该权限。
1745
1746**系统能力:** SystemCapability.Multimedia.Audio.Communication
1747
1748**参数:**
1749
1750| 参数名   | 类型                            | 必填 | 说明                     |
1751| -------- | ------------------------------- | ---- | ------------------------ |
1752| mode     | [AudioRingMode](#audioringmode) | 是   | 音频铃声模式。           |
1753| callback | AsyncCallback&lt;void&gt;       | 是   | 回调函数。当设置铃声模式成功,err为undefined,否则为错误对象。 |
1754
1755**示例:**
1756
1757```ts
1758import { BusinessError } from '@kit.BasicServicesKit';
1759
1760audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err: BusinessError) => {
1761  if (err) {
1762    console.error(`Failed to set the ringer mode. ${err}`);
1763    return;
1764  }
1765  console.info('Callback invoked to indicate a successful setting of the ringer mode.');
1766});
1767```
1768
1769### setRingerMode<sup>(deprecated)</sup>
1770
1771setRingerMode(mode: AudioRingMode): Promise&lt;void&gt;
1772
1773设置铃声模式,使用Promise方式异步返回结果。
1774
1775> **说明:**
1776> 从 API version 7 开始支持,从 API version 9 开始废弃。替代接口仅面向系统应用开放。
1777
1778
1779**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
1780
1781仅在静音和非静音状态切换时需要该权限。
1782
1783**系统能力:** SystemCapability.Multimedia.Audio.Communication
1784
1785**参数:**
1786
1787| 参数名 | 类型                            | 必填 | 说明           |
1788| ------ | ------------------------------- | ---- | -------------- |
1789| mode   | [AudioRingMode](#audioringmode) | 是   | 音频铃声模式。 |
1790
1791**返回值:**
1792
1793| 类型                | 说明                            |
1794| ------------------- | ------------------------------- |
1795| Promise&lt;void&gt; | Promise对象,无返回结果。 |
1796
1797**示例:**
1798
1799```ts
1800audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
1801  console.info('Promise returned to indicate a successful setting of the ringer mode.');
1802});
1803```
1804
1805### getRingerMode<sup>(deprecated)</sup>
1806
1807getRingerMode(callback: AsyncCallback&lt;AudioRingMode&gt;): void
1808
1809获取铃声模式,使用callback方式异步返回结果。
1810
1811> **说明:**
1812> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getRingerMode](#getringermode9)替代。
1813
1814**系统能力:** SystemCapability.Multimedia.Audio.Communication
1815
1816**参数:**
1817
1818| 参数名   | 类型                                                 | 必填 | 说明                     |
1819| -------- | ---------------------------------------------------- | ---- | ------------------------ |
1820| callback | AsyncCallback&lt;[AudioRingMode](#audioringmode)&gt; | 是   | 回调函数。当获取铃声模式成功,err为undefined,data为获取到的铃声模式;否则为错误对象。 |
1821
1822**示例:**
1823
1824```ts
1825import { BusinessError } from '@kit.BasicServicesKit';
1826
1827audioManager.getRingerMode((err: BusinessError, value: audio.AudioRingMode) => {
1828  if (err) {
1829    console.error(`Failed to obtain the ringer mode. ${err}`);
1830    return;
1831  }
1832  console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`);
1833});
1834```
1835
1836### getRingerMode<sup>(deprecated)</sup>
1837
1838getRingerMode(): Promise&lt;AudioRingMode&gt;
1839
1840获取铃声模式,使用Promise方式异步返回结果。
1841
1842> **说明:**
1843> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getRingerMode](#getringermode9)替代。
1844
1845**系统能力:** SystemCapability.Multimedia.Audio.Communication
1846
1847**返回值:**
1848
1849| 类型                                           | 说明                            |
1850| ---------------------------------------------- | ------------------------------- |
1851| Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise对象,返回系统的铃声模式。 |
1852
1853**示例:**
1854
1855```ts
1856audioManager.getRingerMode().then((value: audio.AudioRingMode) => {
1857  console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`);
1858});
1859```
1860
1861### getDevices<sup>(deprecated)</sup>
1862
1863getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
1864
1865获取音频设备列表,使用callback方式异步返回结果。
1866
1867> **说明:**
1868> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[getDevices](#getdevices9)替代。
1869
1870**系统能力:** SystemCapability.Multimedia.Audio.Device
1871
1872**参数:**
1873
1874| 参数名     | 类型                                                         | 必填 | 说明                 |
1875| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
1876| deviceFlag | [DeviceFlag](#deviceflag)                                    | 是   | 设备类型的flag。     |
1877| callback   | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | 是   | 回调函数。当获取音频设备列表成功,err为undefined,data为获取到的音频设备列表;否则为错误对象。 |
1878
1879**示例:**
1880```ts
1881import { BusinessError } from '@kit.BasicServicesKit';
1882
1883audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err: BusinessError, value: audio.AudioDeviceDescriptors) => {
1884  if (err) {
1885    console.error(`Failed to obtain the device list. ${err}`);
1886    return;
1887  }
1888  console.info('Callback invoked to indicate that the device list is obtained.');
1889});
1890```
1891
1892### getDevices<sup>(deprecated)</sup>
1893
1894getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
1895
1896获取音频设备列表,使用Promise方式异步返回结果。
1897
1898> **说明:**
1899> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[getDevices](#getdevices9)替代。
1900
1901**系统能力:** SystemCapability.Multimedia.Audio.Device
1902
1903**参数:**
1904
1905| 参数名     | 类型                      | 必填 | 说明             |
1906| ---------- | ------------------------- | ---- | ---------------- |
1907| deviceFlag | [DeviceFlag](#deviceflag) | 是   | 设备类型的flag。 |
1908
1909**返回值:**
1910
1911| 类型                                                         | 说明                      |
1912| ------------------------------------------------------------ | ------------------------- |
1913| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise对象,返回设备列表。 |
1914
1915**示例:**
1916
1917```ts
1918audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data: audio.AudioDeviceDescriptors) => {
1919  console.info('Promise returned to indicate that the device list is obtained.');
1920});
1921```
1922
1923### setDeviceActive<sup>(deprecated)</sup>
1924
1925setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
1926
1927设置设备激活状态,使用callback方式异步返回结果。
1928
1929> **说明:**
1930> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[setCommunicationDevice](#setcommunicationdevice9)替代。
1931
1932**系统能力:** SystemCapability.Multimedia.Audio.Device
1933
1934**参数:**
1935
1936| 参数名     | 类型                                  | 必填 | 说明          |
1937| ---------- | ------------------------------------- | ---- |-------------|
1938| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | 是   | 活跃音频设备类型。   |
1939| active     | boolean                               | 是   | 设备激活状态。     |
1940| callback   | AsyncCallback&lt;void&gt;             | 是   | 回调函数。当设置设备激活状态成功,err为undefined,否则为错误对象。 |
1941
1942**示例:**
1943
1944```ts
1945import { BusinessError } from '@kit.BasicServicesKit';
1946
1947audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err: BusinessError) => {
1948  if (err) {
1949    console.error(`Failed to set the active status of the device. ${err}`);
1950    return;
1951  }
1952  console.info('Callback invoked to indicate that the device is set to the active status.');
1953});
1954```
1955
1956### setDeviceActive<sup>(deprecated)</sup>
1957
1958setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise&lt;void&gt;
1959
1960设置设备激活状态,使用Promise方式异步返回结果。
1961
1962> **说明:**
1963> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[setCommunicationDevice](#setcommunicationdevice9)替代。
1964
1965**系统能力:** SystemCapability.Multimedia.Audio.Device
1966
1967**参数:**
1968
1969| 参数名     | 类型                                  | 必填 | 说明               |
1970| ---------- | ------------------------------------- | ---- | ------------------ |
1971| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | 是   | 活跃音频设备类型。 |
1972| active     | boolean                               | 是   | 设备激活状态。     |
1973
1974**返回值:**
1975
1976| 类型                | 说明                            |
1977| ------------------- | ------------------------------- |
1978| Promise&lt;void&gt; | Promise对象,无返回结果。 |
1979
1980**示例:**
1981
1982
1983```ts
1984audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => {
1985  console.info('Promise returned to indicate that the device is set to the active status.');
1986});
1987```
1988
1989### isDeviceActive<sup>(deprecated)</sup>
1990
1991isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
1992
1993获取指定设备的激活状态,使用callback方式异步返回结果。
1994
1995> **说明:**
1996> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[isCommunicationDeviceActive](#iscommunicationdeviceactive9)替代。
1997
1998**系统能力:** SystemCapability.Multimedia.Audio.Device
1999
2000**参数:**
2001
2002| 参数名     | 类型                                  | 必填 | 说明                     |
2003| ---------- | ------------------------------------- | ---- | ------------------------ |
2004| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | 是   | 活跃音频设备类型。       |
2005| callback   | AsyncCallback&lt;boolean&gt;          | 是   | 回调函数。当获取指定设备的激活状态成功,err为undefined,data为true为激活,false为未激活;否则为错误对象。 |
2006
2007**示例:**
2008
2009```ts
2010import { BusinessError } from '@kit.BasicServicesKit';
2011
2012audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err: BusinessError, value: boolean) => {
2013  if (err) {
2014    console.error(`Failed to obtain the active status of the device. ${err}`);
2015    return;
2016  }
2017  console.info('Callback invoked to indicate that the active status of the device is obtained.');
2018});
2019```
2020
2021### isDeviceActive<sup>(deprecated)</sup>
2022
2023isDeviceActive(deviceType: ActiveDeviceType): Promise&lt;boolean&gt;
2024
2025获取指定设备的激活状态,使用Promise方式异步返回结果。
2026
2027> **说明:**
2028> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[isCommunicationDeviceActive](#iscommunicationdeviceactive9)替代。
2029
2030**系统能力:** SystemCapability.Multimedia.Audio.Device
2031
2032**参数:**
2033
2034| 参数名     | 类型                                  | 必填 | 说明               |
2035| ---------- | ------------------------------------- | ---- | ------------------ |
2036| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | 是   | 活跃音频设备类型。 |
2037
2038**返回值:**
2039
2040| Type                   | Description                           |
2041| ---------------------- |---------------------------------------|
2042| Promise&lt;boolean&gt; | Promise对象,返回设备的激活状态,true激活,false未激活。  |
2043
2044**示例:**
2045
2046```ts
2047audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value: boolean) => {
2048  console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
2049});
2050```
2051
2052### setMicrophoneMute<sup>(deprecated)</sup>
2053
2054setMicrophoneMute(mute: boolean, callback: AsyncCallback&lt;void&gt;): void
2055
2056设置麦克风静音状态,使用callback方式异步返回结果。
2057
2058> **说明:**
2059> 从 API version 7 开始支持,从 API version 9 开始废弃。替代接口仅面向系统应用开放。
2060
2061**需要权限:** ohos.permission.MICROPHONE
2062
2063**系统能力:** SystemCapability.Multimedia.Audio.Device
2064
2065**参数:**
2066
2067| 参数名   | 类型                      | 必填 | 说明                                          |
2068| -------- | ------------------------- | ---- | --------------------------------------------- |
2069| mute     | boolean                   | 是   | 待设置的静音状态,true为静音,false为非静音。 |
2070| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。当设置麦克风静音状态成功,err为undefined,否则为错误对象。 |
2071
2072**示例:**
2073
2074```ts
2075import { BusinessError } from '@kit.BasicServicesKit';
2076
2077audioManager.setMicrophoneMute(true, (err: BusinessError) => {
2078  if (err) {
2079    console.error(`Failed to mute the microphone. ${err}`);
2080    return;
2081  }
2082  console.info('Callback invoked to indicate that the microphone is muted.');
2083});
2084```
2085
2086### setMicrophoneMute<sup>(deprecated)</sup>
2087
2088setMicrophoneMute(mute: boolean): Promise&lt;void&gt;
2089
2090设置麦克风静音状态,使用Promise方式异步返回结果。
2091
2092> **说明:**
2093> 从 API version 7 开始支持,从 API version 9 开始废弃。替代接口仅面向系统应用开放。
2094
2095**需要权限:** ohos.permission.MICROPHONE
2096
2097**系统能力:** SystemCapability.Multimedia.Audio.Device
2098
2099**参数:**
2100
2101| 参数名 | 类型    | 必填 | 说明                                          |
2102| ------ | ------- | ---- | --------------------------------------------- |
2103| mute   | boolean | 是   | 待设置的静音状态,true为静音,false为非静音。 |
2104
2105**返回值:**
2106
2107| 类型                | 说明                            |
2108| ------------------- | ------------------------------- |
2109| Promise&lt;void&gt; | Promise对象,无返回结果。 |
2110
2111**示例:**
2112
2113```ts
2114audioManager.setMicrophoneMute(true).then(() => {
2115  console.info('Promise returned to indicate that the microphone is muted.');
2116});
2117```
2118
2119### isMicrophoneMute<sup>(deprecated)</sup>
2120
2121isMicrophoneMute(callback: AsyncCallback&lt;boolean&gt;): void
2122
2123获取麦克风静音状态,使用callback方式异步返回结果。
2124
2125> **说明:**
2126> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[isMicrophoneMute](#ismicrophonemute9)替代。
2127
2128**需要权限:** ohos.permission.MICROPHONE
2129
2130**系统能力:** SystemCapability.Multimedia.Audio.Device
2131
2132**参数:**
2133
2134| 参数名   | 类型                         | 必填 | 说明                                                    |
2135| -------- | ---------------------------- | ---- | ------------------------------------------------------- |
2136| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。当获取麦克风静音状态成功,err为undefined,data为true为静音,false为非静音;否则为错误对象。 |
2137
2138**示例:**
2139
2140```ts
2141import { BusinessError } from '@kit.BasicServicesKit';
2142
2143audioManager.isMicrophoneMute((err: BusinessError, value: boolean) => {
2144  if (err) {
2145    console.error(`Failed to obtain the mute status of the microphone. ${err}`);
2146    return;
2147  }
2148  console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`);
2149});
2150```
2151
2152### isMicrophoneMute<sup>(deprecated)</sup>
2153
2154isMicrophoneMute(): Promise&lt;boolean&gt;
2155
2156获取麦克风静音状态,使用Promise方式异步返回结果。
2157
2158> **说明:**
2159> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[isMicrophoneMute](#ismicrophonemute9)替代。
2160
2161**需要权限:** ohos.permission.MICROPHONE
2162
2163**系统能力:** SystemCapability.Multimedia.Audio.Device
2164
2165**返回值:**
2166
2167| 类型                   | 说明                                                         |
2168| ---------------------- | ------------------------------------------------------------ |
2169| Promise&lt;boolean&gt; | Promise对象,返回系统麦克风静音状态,true为静音,false为非静音。 |
2170
2171**示例:**
2172
2173```ts
2174audioManager.isMicrophoneMute().then((value: boolean) => {
2175  console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`);
2176});
2177```
2178
2179### on('deviceChange')<sup>(deprecated)</sup>
2180
2181on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void
2182
2183监听音频设备连接变化事件(当音频设备连接状态发生变化时触发),使用callback方式返回结果。
2184
2185> **说明:**
2186> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[on('deviceChange')](#ondevicechange9)替代。
2187
2188**系统能力:** SystemCapability.Multimedia.Audio.Device
2189
2190**参数:**
2191
2192| 参数名   | 类型                                                 | 必填 | 说明                                       |
2193| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
2194| type     | string                                               | 是   | 监听事件,固定为:'deviceChange'。 |
2195| callback | Callback<[DeviceChangeAction](#devicechangeaction)\> | 是   | 回调函数,返回设备更新详情。 |
2196
2197**示例:**
2198
2199```ts
2200audioManager.on('deviceChange', (deviceChanged: audio.DeviceChangeAction) => {
2201  console.info(`device change type : ${deviceChanged.type} `);
2202  console.info(`device descriptor size : ${deviceChanged.deviceDescriptors.length} `);
2203  console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceRole} `);
2204  console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceType} `);
2205});
2206```
2207
2208### off('deviceChange')<sup>(deprecated)</sup>
2209
2210off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void
2211
2212取消监听音频设备连接变化事件,使用callback方式返回结果。
2213
2214> **说明:**
2215> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[off('deviceChange')](#offdevicechange9)替代。
2216
2217**系统能力:** SystemCapability.Multimedia.Audio.Device
2218
2219**参数:**
2220
2221| 参数名   | 类型                                                | 必填 | 说明                                       |
2222| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
2223| type     | string                                              | 是   | 监听事件,固定为:'deviceChange'。 |
2224| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | 否   | 回调函数,返回设备更新详情。 |
2225
2226**示例:**
2227
2228```ts
2229// 取消该事件的所有监听
2230audioManager.off('deviceChange');
2231
2232// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
2233let deviceChangeCallback = (deviceChanged: audio.DeviceChangeAction) => {
2234  console.info(`device change type : ${deviceChanged.type} `);
2235  console.info(`device descriptor size : ${deviceChanged.deviceDescriptors.length} `);
2236  console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceRole} `);
2237  console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceType} `);
2238};
2239
2240audioManager.on('deviceChange', deviceChangeCallback);
2241
2242audioManager.off('deviceChange', deviceChangeCallback);
2243```
2244
2245### on('interrupt')<sup>(deprecated)</sup>
2246
2247on(type: 'interrupt', interrupt: AudioInterrupt, callback: Callback\<InterruptAction>): void
2248
2249监听音频打断事件(当应用程序的音频被另一个播放事件中断时触发,回调通知此应用程序),使用callback方式返回结果。
2250
2251与[on('audioInterrupt')](#onaudiointerrupt9)作用一致,均用于监听焦点变化。为无音频流的场景(未曾创建AudioRenderer对象),比如FM、语音唤醒等提供焦点变化监听功能。
2252
2253> **说明:**
2254> 从 API version 7 开始支持,从 API version 11 开始废弃,建议使用AudioCapturer中的[on('audioInterrupt')](#onaudiointerrupt10)替代。
2255
2256**系统能力:** SystemCapability.Multimedia.Audio.Renderer
2257
2258**参数:**
2259
2260| 参数名    | 类型                                                      | 必填 | 说明                                                         |
2261| --------- |---------------------------------------------------------| ---- | ------------------------------------------------------------ |
2262| type      | string                                                  | 是   | 监听事件,固定为:'interrupt'。 |
2263| interrupt | [AudioInterrupt](#audiointerruptdeprecated)             | 是   | 音频打断事件类型的参数。                                     |
2264| callback  | Callback<[InterruptAction](#interruptactiondeprecated)> | 是   | 回调函数,返回音频打断时,应用接收的中断事件信息。 |
2265
2266**示例:**
2267
2268```ts
2269import { audio } from '@kit.AudioKit';
2270
2271let interAudioInterrupt: audio.AudioInterrupt = {
2272  streamUsage:2,
2273  contentType:0,
2274  pauseWhenDucked:true
2275};
2276
2277audioManager.on('interrupt', interAudioInterrupt, (interruptAction: audio.InterruptAction) => {
2278  if (interruptAction.actionType === 0) {
2279    console.info('An event to gain the audio focus starts.');
2280    console.info(`Focus gain event: ${interruptAction} `);
2281  }
2282  if (interruptAction.actionType === 1) {
2283    console.info('An audio interruption event starts.');
2284    console.info(`Audio interruption event: ${interruptAction} `);
2285  }
2286});
2287```
2288
2289### off('interrupt')<sup>(deprecated)</sup>
2290
2291off(type: 'interrupt', interrupt: AudioInterrupt, callback?: Callback\<InterruptAction>): void
2292
2293取消监听音频打断事件,使用callback方式返回结果。
2294
2295> **说明:**
2296> 从 API version 7 开始支持,从 API version 11 开始废弃,建议使用AudioCapturer中的[off('audioInterrupt')](#offaudiointerrupt10)替代。
2297
2298**系统能力:** SystemCapability.Multimedia.Audio.Renderer
2299
2300**参数:**
2301
2302| 参数名    | 类型                                                      | 必填 | 说明                                                         |
2303| --------- |---------------------------------------------------------| ---- | ------------------------------------------------------------ |
2304| type      | string                                                  | 是   | 监听事件,固定为:'interrupt'。 |
2305| interrupt | [AudioInterrupt](#audiointerruptdeprecated)                       | 是   | 音频打断事件类型的参数。                                     |
2306| callback  | Callback<[InterruptAction](#interruptactiondeprecated)> | 否   | 回调函数,返回删除监听事件,取消打断时,应用接收的中断事件信息。 |
2307
2308**示例:**
2309
2310```ts
2311import { audio } from '@kit.AudioKit';
2312
2313let interAudioInterrupt: audio.AudioInterrupt = {
2314  streamUsage:2,
2315  contentType:0,
2316  pauseWhenDucked:true
2317};
2318
2319// 取消该事件的所有监听
2320audioManager.off('interrupt', interAudioInterrupt);
2321
2322// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
2323let interruptCallback = (interruptAction: audio.InterruptAction) => {
2324  if (interruptAction.actionType === 0) {
2325    console.info('An event to gain the audio focus starts.');
2326    console.info(`Focus gain event: ${interruptAction} `);
2327  }
2328  if (interruptAction.actionType === 1) {
2329    console.info('An audio interruption event starts.');
2330    console.info(`Audio interruption event: ${interruptAction} `);
2331  }
2332};
2333
2334audioManager.on('interrupt', interAudioInterrupt, interruptCallback);
2335
2336audioManager.off('interrupt', interAudioInterrupt, interruptCallback);
2337```
2338
2339## AudioVolumeManager<sup>9+</sup>
2340
2341音量管理。在使用AudioVolumeManager的接口前,需要使用[getVolumeManager](#getvolumemanager9)获取AudioVolumeManager实例。
2342
2343### getVolumeGroupManager<sup>9+</sup>
2344
2345getVolumeGroupManager(groupId: number, callback: AsyncCallback<AudioVolumeGroupManager\>\): void
2346
2347获取音频组管理器,使用callback方式异步返回结果。
2348
2349**系统能力:** SystemCapability.Multimedia.Audio.Volume
2350
2351**参数:**
2352
2353| 参数名     | 类型                                                         | 必填 | 说明                                                        |
2354| ---------- | ------------------------------------------------------------ | ---- |-----------------------------------------------------------|
2355| groupId    | number                                    | 是   | 音量组id,默认使用LOCAL_VOLUME_GROUP_ID。                          |
2356| callback   | AsyncCallback&lt;[AudioVolumeGroupManager](#audiovolumegroupmanager9)&gt; | 是   | 回调函数。当获取音频组管理器成功,err为undefined,data为获取到的音频组管理器对象;否则为错误对象。 |
2357
2358**示例:**
2359
2360```ts
2361import { BusinessError } from '@kit.BasicServicesKit';
2362
2363let groupId: number = audio.DEFAULT_VOLUME_GROUP_ID;
2364
2365audioVolumeManager.getVolumeGroupManager(groupId, (err: BusinessError, value: audio.AudioVolumeGroupManager) => {
2366  if (err) {
2367    console.error(`Failed to obtain the volume group infos list. ${err}`);
2368    return;
2369  }
2370  console.info('Callback invoked to indicate that the volume group infos list is obtained.');
2371});
2372
2373```
2374
2375### getVolumeGroupManager<sup>9+</sup>
2376
2377getVolumeGroupManager(groupId: number\): Promise<AudioVolumeGroupManager\>
2378
2379获取音频组管理器,使用Promise方式异步返回结果。
2380
2381**系统能力:** SystemCapability.Multimedia.Audio.Volume
2382
2383**参数:**
2384
2385| 参数名     | 类型                                      | 必填 | 说明                               |
2386| ---------- | ---------------------------------------- | ---- |----------------------------------|
2387| groupId    | number                                   | 是   | 音量组id,默认使用LOCAL_VOLUME_GROUP_ID。 |
2388
2389**返回值:**
2390
2391| 类型                | 说明                          |
2392| ------------------- | ----------------------------- |
2393| Promise&lt; [AudioVolumeGroupManager](#audiovolumegroupmanager9) &gt; | Promise对象,返回音量组实例。 |
2394
2395**示例:**
2396
2397```ts
2398import { audio } from '@kit.AudioKit';
2399
2400let groupId: number = audio.DEFAULT_VOLUME_GROUP_ID;
2401let audioVolumeGroupManager: audio.AudioVolumeGroupManager | undefined = undefined;
2402
2403async function getVolumeGroupManager(){
2404  audioVolumeGroupManager = await audioVolumeManager.getVolumeGroupManager(groupId);
2405  console.info('Promise returned to indicate that the volume group infos list is obtained.');
2406}
2407```
2408
2409### getVolumeGroupManagerSync<sup>10+</sup>
2410
2411getVolumeGroupManagerSync(groupId: number\): AudioVolumeGroupManager
2412
2413获取音频组管理器,同步返回结果。
2414
2415**系统能力:** SystemCapability.Multimedia.Audio.Volume
2416
2417**参数:**
2418
2419| 参数名     | 类型                                      | 必填 | 说明                               |
2420| ---------- | ---------------------------------------- | ---- |----------------------------------|
2421| groupId    | number                                   | 是   | 音量组id,默认使用LOCAL_VOLUME_GROUP_ID。 |
2422
2423**返回值:**
2424
2425| 类型                | 说明                          |
2426| ------------------- | ----------------------------- |
2427| [AudioVolumeGroupManager](#audiovolumegroupmanager9) | 音量组实例。 |
2428
2429**错误码:**
2430
2431以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2432
2433| 错误码ID | 错误信息 |
2434| ------- | --------------------------------------------|
2435| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2436| 6800101 | Parameter verification failed. |
2437
2438**示例:**
2439
2440```ts
2441import { BusinessError } from '@kit.BasicServicesKit';
2442
2443try {
2444  let audioVolumeGroupManager: audio.AudioVolumeGroupManager = audioVolumeManager.getVolumeGroupManagerSync(audio.DEFAULT_VOLUME_GROUP_ID);
2445  console.info(`Get audioVolumeGroupManager success.`);
2446} catch (err) {
2447  let error = err as BusinessError;
2448  console.error(`Failed to get audioVolumeGroupManager, error: ${error}`);
2449}
2450```
2451
2452### on('volumeChange')<sup>9+</sup>
2453
2454on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
2455
2456监听系统音量变化事件(当系统音量发生变化时触发),使用callback方式返回结果。
2457
2458**系统能力:** SystemCapability.Multimedia.Audio.Volume
2459
2460**参数:**
2461
2462| 参数名   | 类型                                   | 必填 | 说明                                                         |
2463| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
2464| type     | string                                 | 是   | 监听事件,固定为:'volumeChange'。 |
2465| callback | Callback<[VolumeEvent](#volumeevent9)> | 是   | 回调函数,返回变化后的音量信息。 |
2466
2467**错误码:**
2468
2469以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2470
2471| 错误码ID | 错误信息 |
2472| ------- | --------------------------------------------|
2473| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2474| 6800101 | Parameter verification failed. |
2475
2476**示例:**
2477
2478```ts
2479audioVolumeManager.on('volumeChange', (volumeEvent: audio.VolumeEvent) => {
2480  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
2481  console.info(`Volume level: ${volumeEvent.volume} `);
2482  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
2483});
2484```
2485
2486### off('volumeChange')<sup>12+</sup>
2487
2488off(type: 'volumeChange', callback?: Callback\<VolumeEvent>): void
2489
2490取消监听系统音量变化事件,使用callback方式返回结果。
2491
2492**系统能力:** SystemCapability.Multimedia.Audio.Volume
2493
2494**参数:**
2495
2496| 参数名   | 类型                                   | 必填 | 说明                                                         |
2497| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
2498| type     | string                                 | 是   | 监听事件,固定为:'volumeChange'。 |
2499| callback | Callback<[VolumeEvent](#volumeevent9)> | 否   | 回调函数,返回变化后的音量信息。 |
2500
2501**错误码:**
2502
2503以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2504
2505| 错误码ID | 错误信息 |
2506| ------- | --------------------------------------------|
2507| 401 | Parameter error. Possible causes: 1.Mandatory parameters missing; 2.Incorrect parameter types. |
2508| 6800101 | Parameter verification failed. |
2509
2510**示例:**
2511
2512```ts
2513// 取消该事件的所有监听
2514audioVolumeManager.off('volumeChange');
2515
2516// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
2517let volumeChangeCallback = (volumeEvent: audio.VolumeEvent) => {
2518  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
2519  console.info(`Volume level: ${volumeEvent.volume} `);
2520  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
2521};
2522
2523audioVolumeManager.on('volumeChange', volumeChangeCallback);
2524
2525audioVolumeManager.off('volumeChange', volumeChangeCallback);
2526```
2527
2528## AudioVolumeGroupManager<sup>9+</sup>
2529
2530管理音频组音量。在调用AudioVolumeGroupManager的接口前,需要先通过 [getVolumeGroupManager](#getvolumegroupmanager9) 创建实例。
2531
2532### getVolume<sup>9+</sup>
2533
2534getVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
2535
2536获取指定流的音量,使用callback方式异步返回结果。
2537
2538**系统能力:** SystemCapability.Multimedia.Audio.Volume
2539
2540**参数:**
2541
2542| 参数名     | 类型                                | 必填 | 说明               |
2543| ---------- | ----------------------------------- | ---- | ------------------ |
2544| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。       |
2545| callback   | AsyncCallback&lt;number&gt;         | 是   | 回调函数。当获取指定流的音量成功,err为undefined,data为获取到的指定流的音量;否则为错误对象。指定流的音量等级范围可通过[getMinVolume](#getminvolume9)和[getMaxVolume](#getmaxvolume9)获取。 |
2546
2547**示例:**
2548
2549```ts
2550import { BusinessError } from '@kit.BasicServicesKit';
2551
2552audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
2553  if (err) {
2554    console.error(`Failed to obtain the volume. ${err}`);
2555    return;
2556  }
2557  console.info('Callback invoked to indicate that the volume is obtained.');
2558});
2559```
2560
2561### getVolume<sup>9+</sup>
2562
2563getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
2564
2565获取指定流的音量,使用Promise方式异步返回结果。
2566
2567**系统能力:** SystemCapability.Multimedia.Audio.Volume
2568
2569**参数:**
2570
2571| 参数名     | 类型                                | 必填 | 说明         |
2572| ---------- | ----------------------------------- | ---- | ------------ |
2573| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
2574
2575**返回值:**
2576
2577| 类型                  | 说明                      |
2578| --------------------- | ------------------------- |
2579| Promise&lt;number&gt; | Promise对象,返回指定流的音量。指定流的音量等级范围可通过[getMinVolume](#getminvolume9)和[getMaxVolume](#getmaxvolume9)获取。 |
2580
2581**示例:**
2582
2583```ts
2584audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA).then((value: number) => {
2585  console.info(`Promise returned to indicate that the volume is obtained ${value}.`);
2586});
2587```
2588
2589### getVolumeSync<sup>10+</sup>
2590
2591getVolumeSync(volumeType: AudioVolumeType): number;
2592
2593获取指定流的音量,同步返回结果。
2594
2595**系统能力:** SystemCapability.Multimedia.Audio.Volume
2596
2597**参数:**
2598
2599| 参数名     | 类型                                | 必填 | 说明         |
2600| ---------- | ----------------------------------- | ---- | ------------ |
2601| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
2602
2603**返回值:**
2604
2605| 类型                  | 说明                      |
2606| --------------------- | ------------------------- |
2607| number | 返回指定流的音量。指定流的音量等级范围可通过[getMinVolume](#getminvolume9)和[getMaxVolume](#getmaxvolume9)获取。 |
2608
2609**错误码:**
2610
2611以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2612
2613| 错误码ID | 错误信息 |
2614| ------- | --------------------------------------------|
2615| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2616| 6800101 | Parameter verification failed. |
2617
2618**示例:**
2619
2620```ts
2621import { BusinessError } from '@kit.BasicServicesKit';
2622
2623try {
2624  let value: number = audioVolumeGroupManager.getVolumeSync(audio.AudioVolumeType.MEDIA);
2625  console.info(`Indicate that the volume is obtained ${value}.`);
2626} catch (err) {
2627  let error = err as BusinessError;
2628  console.error(`Failed to obtain the volume, error ${error}.`);
2629}
2630```
2631
2632### getMinVolume<sup>9+</sup>
2633
2634getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
2635
2636获取指定流的最小音量,使用callback方式异步返回结果。
2637
2638**系统能力:** SystemCapability.Multimedia.Audio.Volume
2639
2640**参数:**
2641
2642| 参数名     | 类型                                | 必填 | 说明               |
2643| ---------- | ----------------------------------- | ---- | ------------------ |
2644| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。       |
2645| callback   | AsyncCallback&lt;number&gt;         | 是   | 回调函数。当获取指定流的最小音量成功,err为undefined,data为获取到的指定流的最小音量;否则为错误对象。 |
2646
2647**示例:**
2648
2649```ts
2650import { BusinessError } from '@kit.BasicServicesKit';
2651
2652audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
2653  if (err) {
2654    console.error(`Failed to obtain the minimum volume. ${err}`);
2655    return;
2656  }
2657  console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
2658});
2659```
2660
2661### getMinVolume<sup>9+</sup>
2662
2663getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
2664
2665获取指定流的最小音量,使用Promise方式异步返回结果。
2666
2667**系统能力:** SystemCapability.Multimedia.Audio.Volume
2668
2669**参数:**
2670
2671| 参数名     | 类型                                | 必填 | 说明         |
2672| ---------- | ----------------------------------- | ---- | ------------ |
2673| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
2674
2675**返回值:**
2676
2677| 类型                  | 说明                      |
2678| --------------------- | ------------------------- |
2679| Promise&lt;number&gt; | Promise对象,返回最小音量。 |
2680
2681**示例:**
2682
2683```ts
2684audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value: number) => {
2685  console.info(`Promised returned to indicate that the minimum volume is obtained ${value}.`);
2686});
2687```
2688
2689### getMinVolumeSync<sup>10+</sup>
2690
2691getMinVolumeSync(volumeType: AudioVolumeType): number;
2692
2693获取指定流的最小音量,同步返回结果。
2694
2695**系统能力:** SystemCapability.Multimedia.Audio.Volume
2696
2697**参数:**
2698
2699| 参数名     | 类型                                | 必填 | 说明         |
2700| ---------- | ----------------------------------- | ---- | ------------ |
2701| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
2702
2703**返回值:**
2704
2705| 类型                  | 说明                      |
2706| --------------------- | ------------------------- |
2707| number | 返回最小音量。 |
2708
2709**错误码:**
2710
2711以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2712
2713| 错误码ID | 错误信息 |
2714| ------- | --------------------------------------------|
2715| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2716| 6800101 | Parameter verification failed. |
2717
2718**示例:**
2719
2720```ts
2721import { BusinessError } from '@kit.BasicServicesKit';
2722
2723try {
2724  let value: number = audioVolumeGroupManager.getMinVolumeSync(audio.AudioVolumeType.MEDIA);
2725  console.info(`Indicate that the minimum volume is obtained ${value}.`);
2726} catch (err) {
2727  let error = err as BusinessError;
2728  console.error(`Failed to obtain the minimum volume, error ${error}.`);
2729}
2730```
2731
2732### getMaxVolume<sup>9+</sup>
2733
2734getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
2735
2736获取指定流的最大音量,使用callback方式异步返回结果。
2737
2738**系统能力:** SystemCapability.Multimedia.Audio.Volume
2739
2740**参数:**
2741
2742| 参数名     | 类型                                | 必填 | 说明                   |
2743| ---------- | ----------------------------------- | ---- | ---------------------- |
2744| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。           |
2745| callback   | AsyncCallback&lt;number&gt;         | 是   | 回调函数。当获取指定流的最大音量成功,err为undefined,data为获取到的指定流的最大音量;否则为错误对象。 |
2746
2747**示例:**
2748
2749```ts
2750import { BusinessError } from '@kit.BasicServicesKit';
2751
2752audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
2753  if (err) {
2754    console.error(`Failed to obtain the maximum volume. ${err}`);
2755    return;
2756  }
2757  console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`);
2758});
2759```
2760
2761### getMaxVolume<sup>9+</sup>
2762
2763getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
2764
2765获取指定流的最大音量,使用Promise方式异步返回结果。
2766
2767**系统能力:** SystemCapability.Multimedia.Audio.Volume
2768
2769**参数:**
2770
2771| 参数名     | 类型                                | 必填 | 说明         |
2772| ---------- | ----------------------------------- | ---- | ------------ |
2773| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
2774
2775**返回值:**
2776
2777| 类型                  | 说明                          |
2778| --------------------- | ----------------------------- |
2779| Promise&lt;number&gt; | Promise对象,返回最大音量大小。 |
2780
2781**示例:**
2782
2783```ts
2784audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data: number) => {
2785  console.info('Promised returned to indicate that the maximum volume is obtained.');
2786});
2787```
2788
2789### getMaxVolumeSync<sup>10+</sup>
2790
2791getMaxVolumeSync(volumeType: AudioVolumeType): number;
2792
2793获取指定流的最大音量,同步返回结果。
2794
2795**系统能力:** SystemCapability.Multimedia.Audio.Volume
2796
2797**参数:**
2798
2799| 参数名     | 类型                                | 必填 | 说明         |
2800| ---------- | ----------------------------------- | ---- | ------------ |
2801| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
2802
2803**返回值:**
2804
2805| 类型                  | 说明                          |
2806| --------------------- | ----------------------------- |
2807| number | 返回最大音量大小。 |
2808
2809**错误码:**
2810
2811以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2812
2813| 错误码ID | 错误信息 |
2814| ------- | --------------------------------------------|
2815| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2816| 6800101 | Parameter verification failed. |
2817
2818**示例:**
2819
2820```ts
2821import { BusinessError } from '@kit.BasicServicesKit';
2822
2823try {
2824  let value: number = audioVolumeGroupManager.getMaxVolumeSync(audio.AudioVolumeType.MEDIA);
2825  console.info(`Indicate that the maximum volume is obtained. ${value}`);
2826} catch (err) {
2827  let error = err as BusinessError;
2828  console.error(`Failed to obtain the maximum volume, error ${error}.`);
2829}
2830```
2831
2832### isMute<sup>9+</sup>
2833
2834isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
2835
2836获取指定音量流是否被静音,使用callback方式异步返回结果。
2837
2838**系统能力:** SystemCapability.Multimedia.Audio.Volume
2839
2840**参数:**
2841
2842| 参数名     | 类型                                | 必填 | 说明                                            |
2843| ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
2844| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                    |
2845| callback   | AsyncCallback&lt;boolean&gt;        | 是   | 回调函数。当获取指定音量流是否被静音成功,err为undefined,data为true为静音,false为非静音;否则为错误对象。 |
2846
2847**示例:**
2848
2849```ts
2850import { BusinessError } from '@kit.BasicServicesKit';
2851
2852audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => {
2853  if (err) {
2854    console.error(`Failed to obtain the mute status. ${err}`);
2855    return;
2856  }
2857  console.info(`Callback invoked to indicate that the mute status of the stream is obtained ${value}.`);
2858});
2859```
2860
2861### isMute<sup>9+</sup>
2862
2863isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
2864
2865获取指定音量流是否被静音,使用Promise方式异步返回结果。
2866
2867**系统能力:** SystemCapability.Multimedia.Audio.Volume
2868
2869**参数:**
2870
2871| 参数名     | 类型                                | 必填 | 说明         |
2872| ---------- | ----------------------------------- | ---- | ------------ |
2873| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
2874
2875**返回值:**
2876
2877| 类型                   | 说明                                                   |
2878| ---------------------- | ------------------------------------------------------ |
2879| Promise&lt;boolean&gt; | Promise对象,返回流静音状态,true为静音,false为非静音。 |
2880
2881**示例:**
2882
2883```ts
2884audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA).then((value: boolean) => {
2885  console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`);
2886});
2887```
2888
2889### isMuteSync<sup>10+</sup>
2890
2891isMuteSync(volumeType: AudioVolumeType): boolean
2892
2893获取指定音量流是否被静音,同步返回结果。
2894
2895**系统能力:** SystemCapability.Multimedia.Audio.Volume
2896
2897**参数:**
2898
2899| 参数名     | 类型                                | 必填 | 说明         |
2900| ---------- | ----------------------------------- | ---- | ------------ |
2901| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
2902
2903**返回值:**
2904
2905| 类型                   | 说明                                                   |
2906| ---------------------- | ------------------------------------------------------ |
2907| boolean | 返回流静音状态,true为静音,false为非静音。 |
2908
2909**错误码:**
2910
2911以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2912
2913| 错误码ID | 错误信息 |
2914| ------- | --------------------------------------------|
2915| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2916| 6800101 | Parameter verification failed. |
2917
2918**示例:**
2919
2920```ts
2921import { BusinessError } from '@kit.BasicServicesKit';
2922
2923try {
2924  let value: boolean = audioVolumeGroupManager.isMuteSync(audio.AudioVolumeType.MEDIA);
2925  console.info(`Indicate that the mute status of the stream is obtained ${value}.`);
2926} catch (err) {
2927  let error = err as BusinessError;
2928  console.error(`Failed to obtain the mute status of the stream, error ${error}.`);
2929}
2930```
2931
2932### getRingerMode<sup>9+</sup>
2933
2934getRingerMode(callback: AsyncCallback&lt;AudioRingMode&gt;): void
2935
2936获取铃声模式,使用callback方式异步返回结果。
2937
2938**系统能力:** SystemCapability.Multimedia.Audio.Volume
2939
2940**参数:**
2941
2942| 参数名   | 类型                                                 | 必填 | 说明                     |
2943| -------- | ---------------------------------------------------- | ---- | ------------------------ |
2944| callback | AsyncCallback&lt;[AudioRingMode](#audioringmode)&gt; | 是   | 回调函数。当获取铃声模式成功,err为undefined,data为获取到的铃声模式;否则为错误对象。 |
2945
2946**示例:**
2947
2948```ts
2949import { BusinessError } from '@kit.BasicServicesKit';
2950
2951audioVolumeGroupManager.getRingerMode((err: BusinessError, value: audio.AudioRingMode) => {
2952  if (err) {
2953    console.error(`Failed to obtain the ringer mode. ${err}`);
2954    return;
2955  }
2956  console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`);
2957});
2958```
2959
2960### getRingerMode<sup>9+</sup>
2961
2962getRingerMode(): Promise&lt;AudioRingMode&gt;
2963
2964获取铃声模式,使用Promise方式异步返回结果。
2965
2966**系统能力:** SystemCapability.Multimedia.Audio.Volume
2967
2968**返回值:**
2969
2970| 类型                                           | 说明                            |
2971| ---------------------------------------------- | ------------------------------- |
2972| Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise对象,返回系统的铃声模式。 |
2973
2974**示例:**
2975
2976```ts
2977audioVolumeGroupManager.getRingerMode().then((value: audio.AudioRingMode) => {
2978  console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`);
2979});
2980```
2981
2982### getRingerModeSync<sup>10+</sup>
2983
2984getRingerModeSync(): AudioRingMode
2985
2986获取铃声模式,同步返回结果。
2987
2988**系统能力:** SystemCapability.Multimedia.Audio.Volume
2989
2990**返回值:**
2991
2992| 类型                                           | 说明                            |
2993| ---------------------------------------------- | ------------------------------- |
2994| [AudioRingMode](#audioringmode) | 返回系统的铃声模式。 |
2995
2996**示例:**
2997
2998```ts
2999import { BusinessError } from '@kit.BasicServicesKit';
3000
3001try {
3002  let value: audio.AudioRingMode = audioVolumeGroupManager.getRingerModeSync();
3003  console.info(`Indicate that the ringer mode is obtained ${value}.`);
3004} catch (err) {
3005  let error = err as BusinessError;
3006  console.error(`Failed to obtain the ringer mode, error ${error}.`);
3007}
3008```
3009
3010### on('ringerModeChange')<sup>9+</sup>
3011
3012on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void
3013
3014监听铃声模式变化事件(当[铃声模式](#audioringmode)发生变化时触发),使用callback方式返回结果。
3015
3016**系统能力:** SystemCapability.Multimedia.Audio.Volume
3017
3018**参数:**
3019
3020| 参数名   | 类型                                      | 必填 | 说明                                                         |
3021| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
3022| type     | string                                    | 是   | 监听事件,固定为:'ringerModeChange'。 |
3023| callback | Callback<[AudioRingMode](#audioringmode)> | 是   | 回调函数,返回变化后的铃音模式。 |
3024
3025**错误码:**
3026
3027以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3028
3029| 错误码ID | 错误信息 |
3030| ------- | --------------------------------------------|
3031| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3032| 6800101 | Parameter verification failed. |
3033
3034**示例:**
3035
3036```ts
3037audioVolumeGroupManager.on('ringerModeChange', (ringerMode: audio.AudioRingMode) => {
3038  console.info(`Updated ringermode: ${ringerMode}`);
3039});
3040```
3041
3042### setMicrophoneMute<sup>(deprecated)</sup>
3043
3044setMicrophoneMute(mute: boolean, callback: AsyncCallback&lt;void&gt;): void
3045
3046设置麦克风静音状态,使用callback方式异步返回结果。
3047
3048> **说明:**
3049>
3050> 从 API version 9开始支持,从API version 11 开始废弃。替代接口仅面向系统应用开放。
3051
3052**需要权限:** ohos.permission.MANAGE_AUDIO_CONFIG,该权限仅系统应用可申请。
3053
3054**系统能力:** SystemCapability.Multimedia.Audio.Volume
3055
3056**参数:**
3057
3058| 参数名   | 类型                      | 必填 | 说明                                          |
3059| -------- | ------------------------- | ---- | --------------------------------------------- |
3060| mute     | boolean                   | 是   | 待设置的静音状态,true为静音,false为非静音。 |
3061| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。当设置麦克风静音状态成功,err为undefined,否则为错误对象。 |
3062
3063**示例:**
3064
3065```ts
3066import { BusinessError } from '@kit.BasicServicesKit';
3067
3068audioVolumeGroupManager.setMicrophoneMute(true, (err: BusinessError) => {
3069  if (err) {
3070    console.error(`Failed to mute the microphone. ${err}`);
3071    return;
3072  }
3073  console.info('Callback invoked to indicate that the microphone is muted.');
3074});
3075```
3076
3077### setMicrophoneMute<sup>(deprecated)</sup>
3078
3079setMicrophoneMute(mute: boolean): Promise&lt;void&gt;
3080
3081设置麦克风静音状态,使用Promise方式异步返回结果。
3082
3083> **说明:**
3084>
3085> 从 API version 9开始支持,从API version 11 开始废弃。替代接口仅面向系统应用开放。
3086
3087**需要权限:** ohos.permission.MANAGE_AUDIO_CONFIG,该权限仅系统应用可申请。
3088
3089**系统能力:** SystemCapability.Multimedia.Audio.Volume
3090
3091**参数:**
3092
3093| 参数名 | 类型    | 必填 | 说明                                          |
3094| ------ | ------- | ---- | --------------------------------------------- |
3095| mute   | boolean | 是   | 待设置的静音状态,true为静音,false为非静音。 |
3096
3097**返回值:**
3098
3099| 类型                | 说明                            |
3100| ------------------- | ------------------------------- |
3101| Promise&lt;void&gt; | Promise对象,无返回结果。 |
3102
3103**示例:**
3104
3105```ts
3106audioVolumeGroupManager.setMicrophoneMute(true).then(() => {
3107  console.info('Promise returned to indicate that the microphone is muted.');
3108});
3109```
3110
3111### isMicrophoneMute<sup>9+</sup>
3112
3113isMicrophoneMute(callback: AsyncCallback&lt;boolean&gt;): void
3114
3115获取麦克风静音状态,使用callback方式异步返回结果。
3116
3117**系统能力:** SystemCapability.Multimedia.Audio.Volume
3118
3119**参数:**
3120
3121| 参数名   | 类型                         | 必填 | 说明                                                    |
3122| -------- | ---------------------------- | ---- | ------------------------------------------------------- |
3123| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。当获取麦克风静音状态成功,err为undefined,data为true为静音,false为非静音;否则为错误对象。 |
3124
3125**示例:**
3126
3127```ts
3128import { BusinessError } from '@kit.BasicServicesKit';
3129
3130audioVolumeGroupManager.isMicrophoneMute((err: BusinessError, value: boolean) => {
3131  if (err) {
3132    console.error(`Failed to obtain the mute status of the microphone. ${err}`);
3133    return;
3134  }
3135  console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`);
3136});
3137```
3138
3139### isMicrophoneMute<sup>9+</sup>
3140
3141isMicrophoneMute(): Promise&lt;boolean&gt;
3142
3143获取麦克风静音状态,使用Promise方式异步返回结果。
3144
3145**系统能力:** SystemCapability.Multimedia.Audio.Volume
3146
3147**返回值:**
3148
3149| 类型                   | 说明                                                         |
3150| ---------------------- | ------------------------------------------------------------ |
3151| Promise&lt;boolean&gt; | Promise对象,返回系统麦克风静音状态,true为静音,false为非静音。 |
3152
3153**示例:**
3154
3155```ts
3156audioVolumeGroupManager.isMicrophoneMute().then((value: boolean) => {
3157  console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`);
3158});
3159```
3160
3161### isMicrophoneMuteSync<sup>10+</sup>
3162
3163isMicrophoneMuteSync(): boolean
3164
3165获取麦克风静音状态,同步返回结果。
3166
3167**系统能力:** SystemCapability.Multimedia.Audio.Volume
3168
3169**返回值:**
3170
3171| 类型                   | 说明                                                         |
3172| ---------------------- | ------------------------------------------------------------ |
3173| boolean | 返回系统麦克风静音状态,true为静音,false为非静音。 |
3174
3175**示例:**
3176
3177```ts
3178import { BusinessError } from '@kit.BasicServicesKit';
3179
3180try {
3181  let value: boolean = audioVolumeGroupManager.isMicrophoneMuteSync();
3182  console.info(`Indicate that the mute status of the microphone is obtained ${value}.`);
3183} catch (err) {
3184  let error = err as BusinessError;
3185  console.error(`Failed to obtain the mute status of the microphone, error ${error}.`);
3186}
3187```
3188
3189### on('micStateChange')<sup>9+</sup>
3190
3191on(type: 'micStateChange', callback: Callback&lt;MicStateChangeEvent&gt;): void
3192
3193监听系统麦克风状态更改事件(当检测到系统麦克风状态发生改变时触发),使用callback方式返回结果。
3194
3195目前此订阅接口在单进程多AudioManager实例的使用场景下,仅最后一个实例的订阅生效,其他实例的订阅会被覆盖(即使最后一个实例没有进行订阅),因此推荐使用单一AudioManager实例进行开发。
3196
3197**系统能力:** SystemCapability.Multimedia.Audio.Volume
3198
3199**参数:**
3200
3201| 参数名   | 类型                                   | 必填 | 说明                                                         |
3202| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
3203| type     | string                                 | 是   | 监听事件,固定为:'micStateChange'。 |
3204| callback | Callback<[MicStateChangeEvent](#micstatechangeevent9)> | 是   | 回调函数,返回变更后的麦克风状态。 |
3205
3206**错误码:**
3207
3208以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3209
3210| 错误码ID | 错误信息 |
3211| ------- | --------------------------------------------|
3212| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3213| 6800101 | Parameter verification failed. |
3214
3215**示例:**
3216
3217```ts
3218audioVolumeGroupManager.on('micStateChange', (micStateChange: audio.MicStateChangeEvent) => {
3219  console.info(`Current microphone status is: ${micStateChange.mute} `);
3220});
3221```
3222
3223### off('micStateChange')<sup>12+</sup>
3224
3225off(type: 'micStateChange', callback?: Callback&lt;MicStateChangeEvent&gt;): void
3226
3227取消监听系统麦克风状态更改事件,使用callback方式返回结果。
3228
3229**系统能力:** SystemCapability.Multimedia.Audio.Volume
3230
3231**参数:**
3232
3233| 参数名   | 类型                                   | 必填 | 说明                                                         |
3234| -------- | -------------------------------------- |----| ------------------------------------------------------------ |
3235| type     | string                                 | 是  | 监听事件,固定为:'micStateChange'。 |
3236| callback | Callback<[MicStateChangeEvent](#micstatechangeevent9)> | 否  | 回调函数,返回变更后的麦克风状态。 |
3237
3238**错误码:**
3239
3240以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3241
3242| 错误码ID | 错误信息 |
3243| ------- | --------------------------------------------|
3244| 401 | Parameter error. Possible causes: 1.Mandatory parameters missing; 2.Incorrect parameter types. |
3245| 6800101 | Parameter verification failed. |
3246
3247**示例:**
3248
3249```ts
3250// 取消该事件的所有监听
3251audioVolumeGroupManager.off('micStateChange');
3252
3253// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
3254let micStateChangeCallback = (micStateChange: audio.MicStateChangeEvent) => {
3255  console.info(`Current microphone status is: ${micStateChange.mute} `);
3256});
3257
3258audioVolumeGroupManager.on('micStateChange', micStateChangeCallback);
3259
3260audioVolumeGroupManager.off('micStateChange', micStateChangeCallback);
3261```
3262
3263### isVolumeUnadjustable<sup>10+</sup>
3264
3265isVolumeUnadjustable(): boolean
3266
3267获取固定音量模式开关状态,打开时进入固定音量模式,此时音量固定无法被调节,使用同步方式返回结果。
3268
3269**系统能力:** SystemCapability.Multimedia.Audio.Volume
3270
3271**返回值:**
3272
3273| 类型                   | 说明                                                   |
3274| ---------------------- | ------------------------------------------------------ |
3275| boolean            | 同步接口,返回固定音量模式开关状态,true为固定音量模式,false为非固定音量模式。 |
3276
3277**示例:**
3278
3279```ts
3280let volumeAdjustSwitch: boolean = audioVolumeGroupManager.isVolumeUnadjustable();
3281console.info(`Whether it is volume unadjustable: ${volumeAdjustSwitch}.`);
3282```
3283
3284### getSystemVolumeInDb<sup>10+</sup>
3285
3286getSystemVolumeInDb(volumeType: AudioVolumeType, volumeLevel: number, device: DeviceType, callback: AsyncCallback&lt;number&gt;): void
3287
3288获取音量增益dB值,使用callback方式异步返回结果。
3289
3290**系统能力:** SystemCapability.Multimedia.Audio.Volume
3291
3292**参数:**
3293
3294| 参数名     | 类型                                | 必填 | 说明                                                     |
3295| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3296| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
3297| volumeLevel | number                         | 是   | 音量等级。                                               |
3298| device     | [DeviceType](#devicetype)           | 是   | 设备类型。                                               |
3299| callback   | AsyncCallback&lt;number&gt;           | 是   | 回调函数。当获取音量增益dB值成功,err为undefined,data为获取到的音量增益dB值;否则为错误对象。 |
3300
3301**错误码:**
3302
3303以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3304
3305| 错误码ID | 错误信息 |
3306| ------- | --------------------------------------------|
3307| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3308| 6800101 | Parameter verification failed. Return by callback.                     |
3309| 6800301 | System error. Return by callback.                                |
3310
3311**示例:**
3312
3313```ts
3314import { BusinessError } from '@kit.BasicServicesKit';
3315
3316audioVolumeGroupManager.getSystemVolumeInDb(audio.AudioVolumeType.MEDIA, 3, audio.DeviceType.SPEAKER, (err: BusinessError, dB: number) => {
3317  if (err) {
3318    console.error(`Failed to get the volume DB. ${err}`);
3319  } else {
3320    console.info(`Success to get the volume DB. ${dB}`);
3321  }
3322});
3323```
3324### getSystemVolumeInDb<sup>10+</sup>
3325
3326getSystemVolumeInDb(volumeType: AudioVolumeType, volumeLevel: number, device: DeviceType): Promise&lt;number&gt;
3327
3328获取音量增益dB值,使用Promise方式异步返回结果。
3329
3330**系统能力:** SystemCapability.Multimedia.Audio.Volume
3331
3332**参数:**
3333
3334| 参数名     | 类型                                | 必填 | 说明                                                     |
3335| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3336| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
3337| volumeLevel | number                              | 是   | 音量等级。                                             |
3338| device     | [DeviceType](#devicetype)           | 是   | 设备类型。                                               |
3339
3340**返回值:**
3341
3342| 类型                  | 说明                               |
3343| --------------------- | ---------------------------------- |
3344| Promise&lt;number&gt; | Promise对象,返回对应的音量增益dB值。 |
3345
3346**错误码:**
3347
3348以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3349
3350| 错误码ID | 错误信息 |
3351| ------- | --------------------------------------------|
3352| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3353| 6800101 | Parameter verification failed. Return by promise.                     |
3354| 6800301 | System error. Return by promise.                                |
3355
3356**示例:**
3357
3358```ts
3359import { BusinessError } from '@kit.BasicServicesKit';
3360
3361audioVolumeGroupManager.getSystemVolumeInDb(audio.AudioVolumeType.MEDIA, 3, audio.DeviceType.SPEAKER).then((value: number) => {
3362  console.info(`Success to get the volume DB. ${value}`);
3363}).catch((error: BusinessError) => {
3364  console.error(`Fail to adjust the system volume by step. ${error}`);
3365});
3366```
3367
3368### getSystemVolumeInDbSync<sup>10+</sup>
3369
3370getSystemVolumeInDbSync(volumeType: AudioVolumeType, volumeLevel: number, device: DeviceType): number
3371
3372获取音量增益dB值,同步返回结果。
3373
3374**系统能力:** SystemCapability.Multimedia.Audio.Volume
3375
3376**参数:**
3377
3378| 参数名     | 类型                                | 必填 | 说明                                                     |
3379| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3380| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
3381| volumeLevel | number                              | 是   | 音量等级。                                             |
3382| device     | [DeviceType](#devicetype)           | 是   | 设备类型。                                               |
3383
3384**返回值:**
3385
3386| 类型                  | 说明                               |
3387| --------------------- | ---------------------------------- |
3388| number | 返回对应的音量增益dB值。 |
3389
3390**错误码:**
3391
3392以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3393
3394| 错误码ID | 错误信息 |
3395| ------- | --------------------------------------------|
3396| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3397| 6800101 | Parameter verification failed. |
3398
3399**示例:**
3400
3401```ts
3402import { BusinessError } from '@kit.BasicServicesKit';
3403
3404try {
3405  let value: number = audioVolumeGroupManager.getSystemVolumeInDbSync(audio.AudioVolumeType.MEDIA, 3, audio.DeviceType.SPEAKER);
3406  console.info(`Success to get the volume DB. ${value}`);
3407} catch (err) {
3408  let error = err as BusinessError;
3409  console.error(`Fail to adjust the system volume by step. ${error}`);
3410}
3411```
3412
3413### getMaxAmplitudeForInputDevice<sup>12+</sup>
3414
3415getMaxAmplitudeForInputDevice(inputDevice: AudioDeviceDescriptor): Promise&lt;number&gt;
3416
3417获取输入设备音频流的最大电平值,大小取值在0-1之间,最小为0,使用Promise方式异步返回结果。
3418
3419**系统能力:** SystemCapability.Multimedia.Audio.Volume
3420
3421**参数:**
3422
3423| 参数名     | 类型                                | 必填 | 说明                                                     |
3424| ----------- | ------------------------------------- | ---- | --------------------------------------------------- |
3425| inputDevice | [AudioDeviceDescriptor](#audiodevicedescriptor) | 是   | 获取最大电平值的设备信息。                                 |
3426
3427**返回值:**
3428
3429| 类型                  | 说明                               |
3430| --------------------- | ---------------------------------- |
3431| Promise&lt;number&gt; | Promise对象,返回对应设备的电平值,大小在0-1之间。 |
3432
3433**错误码:**
3434
3435以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3436
3437| 错误码ID | 错误信息 |
3438| ------- | --------------------------------------------|
3439| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3440| 6800101 | Parameter verification failed. Return by promise. |
3441| 6800301 | System error. Return by promise. |
3442
3443**示例:**
3444
3445```ts
3446import { BusinessError } from '@kit.BasicServicesKit';
3447
3448let capturerInfo: audio.AudioCapturerInfo = {
3449  source: audio.SourceType.SOURCE_TYPE_MIC,
3450  capturerFlags: 0
3451};
3452
3453audio.getAudioManager().getRoutingManager().getPreferredInputDeviceForCapturerInfo(capturerInfo).then((data) => {
3454  audioVolumeGroupManager.getMaxAmplitudeForInputDevice(data[0]).then((value) => {
3455    console.info(`mic volatileume amplitude is: ${value}`);
3456  }).catch((err: BusinessError) => {
3457    console.error("getMaxAmplitudeForInputDevice error" + JSON.stringify(err));
3458  })
3459}).catch((err: BusinessError) => {
3460  console.error("get outputDeviceId error" + JSON.stringify(err));
3461})
3462```
3463
3464### getMaxAmplitudeForOutputDevice<sup>12+</sup>
3465
3466getMaxAmplitudeForOutputDevice(outputDevice: AudioDeviceDescriptor): Promise&lt;number&gt;
3467
3468获取输出设备音频流的最大电平值,大小取值在0-1之间,最小为0,使用Promise方式异步返回结果。
3469
3470**系统能力:** SystemCapability.Multimedia.Audio.Volume
3471
3472**参数:**
3473
3474| 参数名     | 类型                                | 必填 | 说明                                                     |
3475| ------------ | --------------------------------------- | ---- | -------------------------------------------------------- |
3476| outputDevice | [AudioDeviceDescriptor](#audiodevicedescriptor) | 是   | 获取最大电平值的设备信息。                                             |
3477
3478**返回值:**
3479
3480| 类型                  | 说明                               |
3481| --------------------- | ---------------------------------- |
3482| Promise&lt;number&gt; | Promise对象,返回对应设备的电平值,大小在0-1之间。 |
3483
3484**错误码:**
3485
3486以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3487
3488| 错误码ID | 错误信息 |
3489| ------- | --------------------------------------------|
3490| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3491| 6800101 | Parameter verification failed. Return by promise. |
3492| 6800301 | System error. Return by promise. |
3493
3494**示例:**
3495
3496```ts
3497import { BusinessError } from '@kit.BasicServicesKit';
3498
3499let rendererInfo: audio.AudioRendererInfo = {
3500  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
3501  rendererFlags : 0
3502};
3503
3504audio.getAudioManager().getRoutingManager().getPreferOutputDeviceForRendererInfo(rendererInfo).then((data) => {
3505  audioVolumeGroupManager.getMaxAmplitudeForOutputDevice(data[0]).then((value) => {
3506    console.info(`mic volatileume amplitude is: ${value}`);
3507  }).catch((err: BusinessError) => {
3508    console.error("getMaxAmplitudeForOutputDevice error" + JSON.stringify(err));
3509  })
3510}).catch((err: BusinessError) => {
3511  console.error("getPreferOutputDeviceForRendererInfo error" + JSON.stringify(err));
3512})
3513```
3514
3515## AudioStreamManager<sup>9+</sup>
3516
3517管理音频流。在使用AudioStreamManager的API前,需要使用[getStreamManager](#getstreammanager9)获取AudioStreamManager实例。
3518
3519### getCurrentAudioRendererInfoArray<sup>9+</sup>
3520
3521getCurrentAudioRendererInfoArray(callback: AsyncCallback&lt;AudioRendererChangeInfoArray&gt;): void
3522
3523获取当前音频渲染器的信息。使用callback异步回调。
3524
3525**系统能力**: SystemCapability.Multimedia.Audio.Renderer
3526
3527**参数:**
3528
3529| 参数名     | 类型                                 | 必填     | 说明                         |
3530| -------- | ----------------------------------- | -------- | --------------------------- |
3531| callback | AsyncCallback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | 是     | 回调函数。当获取当前音频渲染器的信息成功,err为undefined,data为获取到的当前音频渲染器的信息;否则为错误对象。 |
3532
3533**示例:**
3534
3535```ts
3536import { BusinessError } from '@kit.BasicServicesKit';
3537
3538audioStreamManager.getCurrentAudioRendererInfoArray(async (err: BusinessError, AudioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray) => {
3539  console.info('getCurrentAudioRendererInfoArray **** Get Callback Called ****');
3540  if (err) {
3541    console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`);
3542  } else {
3543    if (AudioRendererChangeInfoArray != null) {
3544      for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
3545        let AudioRendererChangeInfo: audio.AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
3546        console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
3547        console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
3548        console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
3549        console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
3550        for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
3551          console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
3552          console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
3553          console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
3554          console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
3555          console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
3556          console.info(`SampleRate: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
3557          console.info(`ChannelCount: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
3558          console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
3559        }
3560      }
3561    }
3562  }
3563});
3564```
3565
3566### getCurrentAudioRendererInfoArray<sup>9+</sup>
3567
3568getCurrentAudioRendererInfoArray(): Promise&lt;AudioRendererChangeInfoArray&gt;
3569
3570获取当前音频渲染器的信息。使用Promise异步回调。
3571
3572**系统能力:** SystemCapability.Multimedia.Audio.Renderer
3573
3574**返回值:**
3575
3576| 类型                                                                              | 说明                                    |
3577| ---------------------------------------------------------------------------------| --------------------------------------- |
3578| Promise<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)>          | Promise对象,返回当前音频渲染器信息。      |
3579
3580**示例:**
3581
3582```ts
3583import { BusinessError } from '@kit.BasicServicesKit';
3584
3585async function getCurrentAudioRendererInfoArray(){
3586  await audioStreamManager.getCurrentAudioRendererInfoArray().then((AudioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray) => {
3587    console.info(`getCurrentAudioRendererInfoArray ######### Get Promise is called ##########`);
3588    if (AudioRendererChangeInfoArray != null) {
3589      for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
3590        let AudioRendererChangeInfo: audio.AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
3591        console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
3592        console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
3593        console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
3594        console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
3595        for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
3596          console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
3597          console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
3598          console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
3599          console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
3600          console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
3601          console.info(`SampleRate: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
3602          console.info(`ChannelCount: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
3603          console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
3604        }
3605      }
3606    }
3607  }).catch((err: BusinessError) => {
3608    console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`);
3609  });
3610}
3611```
3612### getCurrentAudioRendererInfoArraySync<sup>10+</sup>
3613
3614getCurrentAudioRendererInfoArraySync(): AudioRendererChangeInfoArray
3615
3616获取当前音频渲染器的信息,同步返回结果。
3617
3618**系统能力:** SystemCapability.Multimedia.Audio.Renderer
3619
3620**返回值:**
3621
3622| 类型                                                                              | 说明                                    |
3623| ---------------------------------------------------------------------------------| --------------------------------------- |
3624| [AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)          | 返回当前音频渲染器信息。      |
3625
3626**示例:**
3627
3628```ts
3629import { BusinessError } from '@kit.BasicServicesKit';
3630
3631try {
3632  let audioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray = audioStreamManager.getCurrentAudioRendererInfoArraySync();
3633  console.info(`getCurrentAudioRendererInfoArraySync success.`);
3634  if (audioRendererChangeInfoArray != null) {
3635    for (let i = 0; i < audioRendererChangeInfoArray.length; i++) {
3636      let AudioRendererChangeInfo: audio.AudioRendererChangeInfo = audioRendererChangeInfoArray[i];
3637      console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
3638      console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
3639      console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
3640      console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
3641      for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
3642        console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
3643        console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
3644        console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
3645        console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
3646        console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
3647        console.info(`SampleRate: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
3648        console.info(`ChannelCount: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
3649        console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
3650      }
3651    }
3652  }
3653} catch (err) {
3654  let error = err as BusinessError;
3655  console.error(`getCurrentAudioRendererInfoArraySync :ERROR: ${error}`);
3656}
3657```
3658
3659### getCurrentAudioCapturerInfoArray<sup>9+</sup>
3660
3661getCurrentAudioCapturerInfoArray(callback: AsyncCallback&lt;AudioCapturerChangeInfoArray&gt;): void
3662
3663获取当前音频采集器的信息。使用callback异步回调。
3664
3665**系统能力:** SystemCapability.Multimedia.Audio.Renderer
3666
3667**参数:**
3668
3669| 参数名        | 类型                                 | 必填      | 说明                                                      |
3670| ---------- | ----------------------------------- | --------- | -------------------------------------------------------- |
3671| callback   | AsyncCallback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | 是    | 回调函数。当获取当前音频采集器的信息成功,err为undefined,data为获取到的当前音频采集器的信息;否则为错误对象。 |
3672
3673**示例:**
3674
3675```ts
3676import { BusinessError } from '@kit.BasicServicesKit';
3677
3678audioStreamManager.getCurrentAudioCapturerInfoArray(async (err: BusinessError, AudioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray) => {
3679  console.info('getCurrentAudioCapturerInfoArray **** Get Callback Called ****');
3680  if (err) {
3681    console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
3682  } else {
3683    if (AudioCapturerChangeInfoArray != null) {
3684      for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
3685        console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
3686        console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
3687        console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
3688        for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
3689          console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
3690          console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
3691          console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
3692          console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
3693          console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
3694          console.info(`SampleRate: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
3695          console.info(`ChannelCount: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
3696          console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
3697        }
3698      }
3699    }
3700  }
3701});
3702```
3703
3704### getCurrentAudioCapturerInfoArray<sup>9+</sup>
3705
3706getCurrentAudioCapturerInfoArray(): Promise&lt;AudioCapturerChangeInfoArray&gt;
3707
3708获取当前音频采集器的信息。使用Promise异步回调。
3709
3710**系统能力:** SystemCapability.Multimedia.Audio.Renderer
3711
3712**返回值:**
3713
3714| 类型                                                                         | 说明                                 |
3715| -----------------------------------------------------------------------------| ----------------------------------- |
3716| Promise<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)>      | Promise对象,返回当前音频采集器信息。  |
3717
3718**示例:**
3719
3720```ts
3721import { BusinessError } from '@kit.BasicServicesKit';
3722
3723async function getCurrentAudioCapturerInfoArray(){
3724  await audioStreamManager.getCurrentAudioCapturerInfoArray().then((AudioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray) => {
3725    console.info('getCurrentAudioCapturerInfoArray **** Get Promise Called ****');
3726    if (AudioCapturerChangeInfoArray != null) {
3727      for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
3728        console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
3729        console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
3730        console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
3731        for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
3732          console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
3733          console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
3734          console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
3735          console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
3736          console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
3737          console.info(`SampleRate: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
3738          console.info(`ChannelCount: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
3739          console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
3740        }
3741      }
3742    }
3743  }).catch((err: BusinessError) => {
3744    console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
3745  });
3746}
3747```
3748### getCurrentAudioCapturerInfoArraySync<sup>10+</sup>
3749
3750getCurrentAudioCapturerInfoArraySync(): AudioCapturerChangeInfoArray
3751
3752获取当前音频采集器的信息,同步返回结果。
3753
3754**系统能力:** SystemCapability.Multimedia.Audio.Capturer
3755
3756**返回值:**
3757
3758| 类型                                                                         | 说明                                 |
3759| -----------------------------------------------------------------------------| ----------------------------------- |
3760| [AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)      | 返回当前音频采集器信息。  |
3761
3762**示例:**
3763
3764```ts
3765import { BusinessError } from '@kit.BasicServicesKit';
3766
3767try {
3768  let audioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray = audioStreamManager.getCurrentAudioCapturerInfoArraySync();
3769  console.info('getCurrentAudioCapturerInfoArraySync success.');
3770  if (audioCapturerChangeInfoArray != null) {
3771    for (let i = 0; i < audioCapturerChangeInfoArray.length; i++) {
3772      console.info(`StreamId for ${i} is: ${audioCapturerChangeInfoArray[i].streamId}`);
3773      console.info(`Source for ${i} is: ${audioCapturerChangeInfoArray[i].capturerInfo.source}`);
3774      console.info(`Flag  ${i} is: ${audioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
3775      for (let j = 0; j < audioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
3776        console.info(`Id: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
3777        console.info(`Type: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
3778        console.info(`Role: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
3779        console.info(`Name: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
3780        console.info(`Address: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
3781        console.info(`SampleRate: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
3782        console.info(`ChannelCount: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
3783        console.info(`ChannelMask: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
3784      }
3785    }
3786  }
3787} catch (err) {
3788  let error = err as BusinessError;
3789  console.error(`getCurrentAudioCapturerInfoArraySync ERROR: ${error}`);
3790}
3791```
3792
3793### on('audioRendererChange')<sup>9+</sup>
3794
3795on(type: 'audioRendererChange', callback: Callback&lt;AudioRendererChangeInfoArray&gt;): void
3796
3797监听音频渲染器更改事件(当音频播放流状态变化、设备变化时触发),使用callback方式返回结果。
3798
3799**系统能力:** SystemCapability.Multimedia.Audio.Renderer
3800
3801**参数:**
3802
3803| 参数名      | 类型        | 必填      | 说明                                                                     |
3804| -------- | ---------- | --------- | ------------------------------------------------------------------------ |
3805| type     | string     | 是        | 监听事件,固定为:'audioRendererChange'。     |
3806| callback | Callback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | 是  |  回调函数,返回当前音频渲染器信息。 |
3807
3808**错误码:**
3809
3810以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3811
3812| 错误码ID | 错误信息 |
3813| ------- | --------------------------------------------|
3814| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3815| 6800101 | Parameter verification failed. |
3816
3817**示例:**
3818
3819```ts
3820audioStreamManager.on('audioRendererChange',  (audioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray) => {
3821  for (let i = 0; i < audioRendererChangeInfoArray.length; i++) {
3822    let audioRendererChangeInfo: audio.AudioRendererChangeInfo = audioRendererChangeInfoArray[i];
3823    console.info(`## RendererChange on is called for ${i} ##`);
3824    console.info(`StreamId for ${i} is: ${audioRendererChangeInfo.streamId}`);
3825    console.info(`Content ${i} is: ${audioRendererChangeInfo.rendererInfo.content}`);
3826    console.info(`Stream ${i} is: ${audioRendererChangeInfo.rendererInfo.usage}`);
3827    console.info(`Flag ${i} is: ${audioRendererChangeInfo.rendererInfo.rendererFlags}`);
3828    for (let j = 0;j < audioRendererChangeInfo.deviceDescriptors.length; j++) {
3829      console.info(`Id: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].id}`);
3830      console.info(`Type: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
3831      console.info(`Role: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
3832      console.info(`Name: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].name}`);
3833      console.info(`Address: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].address}`);
3834      console.info(`SampleRate: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
3835      console.info(`ChannelCount: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
3836      console.info(`ChannelMask: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
3837    }
3838  }
3839});
3840```
3841
3842### off('audioRendererChange')<sup>9+</sup>
3843
3844off(type: 'audioRendererChange'): void
3845
3846取消监听音频渲染器更改事件。
3847
3848**系统能力:** SystemCapability.Multimedia.Audio.Renderer
3849
3850**参数:**
3851
3852| 参数名     | 类型     | 必填 | 说明              |
3853| -------- | ------- | ---- | ---------------- |
3854| type     | string  | 是   | 监听事件,固定为:'audioRendererChange'。 |
3855
3856**错误码:**
3857
3858以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3859
3860| 错误码ID | 错误信息                     |
3861| ------- |--------------------------|
3862| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3863| 6800101 | Parameter verification failed. |
3864
3865**示例:**
3866
3867```ts
3868audioStreamManager.off('audioRendererChange');
3869```
3870
3871### on('audioCapturerChange')<sup>9+</sup>
3872
3873on(type: 'audioCapturerChange', callback: Callback&lt;AudioCapturerChangeInfoArray&gt;): void
3874
3875监听音频采集器更改事件(当音频录制流状态变化、设备变化时触发),使用callback方式返回结果。
3876
3877**系统能力:** SystemCapability.Multimedia.Audio.Capturer
3878
3879**参数:**
3880
3881| 参数名     | 类型     | 必填      | 说明                                                                                          |
3882| -------- | ------- | --------- | ---------------------------------------------------------------------- |
3883| type     | string  | 是        | 监听事件,固定为:'audioCapturerChange'。     |
3884| callback | Callback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | 是     | 回调函数,返回当前音频采集器信息。 |
3885
3886**错误码:**
3887
3888以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3889
3890| 错误码ID | 错误信息 |
3891| ------- | --------------------------------------------|
3892| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3893| 6800101 | Parameter verification failed. |
3894
3895**示例:**
3896
3897```ts
3898audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray) =>  {
3899  for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
3900    console.info(`## CapChange on is called for element ${i} ##`);
3901    console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
3902    console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
3903    console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
3904    for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
3905      console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
3906      console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
3907      console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
3908      console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
3909      console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
3910      console.info(`SampleRate: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
3911      console.info(`ChannelCount: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
3912      console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
3913    }
3914  }
3915});
3916```
3917
3918### off('audioCapturerChange')<sup>9+</sup>
3919
3920off(type: 'audioCapturerChange'): void
3921
3922取消监听音频采集器更改事件。
3923
3924**系统能力:** SystemCapability.Multimedia.Audio.Capturer
3925
3926**参数:**
3927
3928| 参数名       | 类型     | 必填 | 说明                                                          |
3929| -------- | -------- | --- | ------------------------------------------------------------- |
3930| type     | string   |是   | 监听事件,固定为:'audioCapturerChange'。 |
3931
3932**错误码:**
3933
3934以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3935
3936| 错误码ID | 错误信息 |
3937| ------- | --------------------------------------------|
3938| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3939| 6800101 | Parameter verification failed. |
3940
3941**示例:**
3942
3943```ts
3944audioStreamManager.off('audioCapturerChange');
3945```
3946
3947### isActive<sup>9+</sup>
3948
3949isActive(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
3950
3951获取指定音频流是否为活跃状态,使用callback方式异步返回结果。
3952
3953**系统能力:** SystemCapability.Multimedia.Audio.Renderer
3954
3955**参数:**
3956
3957| 参数名     | 类型                                | 必填 | 说明                                              |
3958| ---------- | ----------------------------------- | ---- | ------------------------------------------------- |
3959| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音频流类型。                                      |
3960| callback   | AsyncCallback&lt;boolean&gt;        | 是   | 回调函数。当获取指定音频流是否为活跃状态成功,err为undefined,data为true为活跃,false为不活跃;否则为错误对象。 |
3961
3962**示例:**
3963
3964```ts
3965import { BusinessError } from '@kit.BasicServicesKit';
3966
3967audioStreamManager.isActive(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => {
3968if (err) {
3969  console.error(`Failed to obtain the active status of the stream. ${err}`);
3970  return;
3971}
3972  console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`);
3973});
3974```
3975
3976### isActive<sup>9+</sup>
3977
3978isActive(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
3979
3980获取指定音频流是否为活跃状态,使用Promise方式异步返回结果。
3981
3982**系统能力:** SystemCapability.Multimedia.Audio.Renderer
3983
3984**参数:**
3985
3986| 参数名     | 类型                                | 必填 | 说明         |
3987| ---------- | ----------------------------------- | ---- | ------------ |
3988| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音频流类型。 |
3989
3990**返回值:**
3991
3992| 类型                   | 说明                                                     |
3993| ---------------------- | -------------------------------------------------------- |
3994| Promise&lt;boolean&gt; | Promise对象,返回流的活跃状态,true为活跃,false为不活跃。 |
3995
3996**示例:**
3997
3998```ts
3999audioStreamManager.isActive(audio.AudioVolumeType.MEDIA).then((value: boolean) => {
4000  console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`);
4001});
4002```
4003
4004### isActiveSync<sup>10+</sup>
4005
4006isActiveSync(volumeType: AudioVolumeType): boolean
4007
4008获取指定音频流是否为活跃状态,同步返回结果。
4009
4010**系统能力:** SystemCapability.Multimedia.Audio.Renderer
4011
4012**参数:**
4013
4014| 参数名     | 类型                                | 必填 | 说明         |
4015| ---------- | ----------------------------------- | ---- | ------------ |
4016| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音频流类型。 |
4017
4018**返回值:**
4019
4020| 类型                   | 说明                                                     |
4021| ---------------------- | -------------------------------------------------------- |
4022| boolean | 返回流的活跃状态,true为活跃,false为不活跃。 |
4023
4024**错误码:**
4025
4026以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4027
4028| 错误码ID | 错误信息 |
4029| ------- | --------------------------------------------|
4030| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4031| 6800101 | Parameter verification failed. |
4032
4033**示例:**
4034
4035```ts
4036import { BusinessError } from '@kit.BasicServicesKit';
4037
4038try {
4039  let value: boolean = audioStreamManager.isActiveSync(audio.AudioVolumeType.MEDIA);
4040  console.info(`Indicate that the active status of the stream is obtained ${value}.`);
4041} catch (err) {
4042  let error = err as BusinessError;
4043  console.error(`Failed to obtain the active status of the stream ${error}.`);
4044}
4045```
4046
4047### getAudioEffectInfoArray<sup>10+</sup>
4048
4049getAudioEffectInfoArray(usage: StreamUsage, callback: AsyncCallback&lt;AudioEffectInfoArray&gt;): void
4050
4051获取当前音效模式的信息。使用callback异步回调。
4052
4053**系统能力**: SystemCapability.Multimedia.Audio.Renderer
4054
4055**参数:**
4056
4057| 参数名    | 类型                                | 必填     | 说明                         |
4058| -------- | ----------------------------------- | -------- | --------------------------- |
4059| usage    | [StreamUsage](#streamusage)                                    | 是     |  音频流使用类型。                |
4060| callback | AsyncCallback<[AudioEffectInfoArray](#audioeffectinfoarray10)> | 是     | 回调函数。当获取当前音效模式的信息成功,err为undefined,data为获取到的当前音效模式的信息;否则为错误对象。|
4061
4062**错误码:**
4063
4064以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4065
4066| 错误码ID | 错误信息 |
4067| ------- | --------------------------------------------|
4068| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4069| 6800101 | Parameter verification failed. Return by callback.|
4070
4071**示例:**
4072
4073```ts
4074import { BusinessError } from '@kit.BasicServicesKit';
4075
4076audioStreamManager.getAudioEffectInfoArray(audio.StreamUsage.STREAM_USAGE_MUSIC, async (err: BusinessError, audioEffectInfoArray: audio.AudioEffectInfoArray) => {
4077  console.info('getAudioEffectInfoArray **** Get Callback Called ****');
4078  if (err) {
4079    console.error(`getAudioEffectInfoArray :ERROR: ${err}`);
4080    return;
4081  } else {
4082    console.info(`The effect modes are: ${audioEffectInfoArray}`);
4083  }
4084});
4085```
4086
4087### getAudioEffectInfoArray<sup>10+</sup>
4088
4089getAudioEffectInfoArray(usage: StreamUsage): Promise&lt;AudioEffectInfoArray&gt;
4090
4091获取当前音效模式的信息。使用Promise异步回调。
4092
4093**系统能力:** SystemCapability.Multimedia.Audio.Renderer
4094
4095**参数:**
4096
4097| 参数名    | 类型                                | 必填     | 说明                         |
4098| -------- | ----------------------------------- | -------- | --------------------------- |
4099| usage    | [StreamUsage](#streamusage)         | 是     |  音频流使用类型。               |
4100
4101**返回值:**
4102
4103| 类型                                                                      | 说明                                    |
4104| --------------------------------------------------------------------------| --------------------------------------- |
4105| Promise<[AudioEffectInfoArray](#audioeffectinfoarray10)>                  | Promise对象,返回当前音效模式的信息。      |
4106
4107**错误码:**
4108
4109以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4110
4111| 错误码ID | 错误信息 |
4112| ------- | --------------------------------------------|
4113| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4114| 6800101 | Parameter verification failed. Return by promise. |
4115
4116**示例:**
4117
4118```ts
4119import { BusinessError } from '@kit.BasicServicesKit';
4120
4121audioStreamManager.getAudioEffectInfoArray(audio.StreamUsage.STREAM_USAGE_MUSIC).then((audioEffectInfoArray: audio.AudioEffectInfoArray) => {
4122  console.info('getAudioEffectInfoArray ######### Get Promise is called ##########');
4123  console.info(`The effect modes are: ${audioEffectInfoArray}`);
4124}).catch((err: BusinessError) => {
4125  console.error(`getAudioEffectInfoArray :ERROR: ${err}`);
4126});
4127```
4128
4129### getAudioEffectInfoArraySync<sup>10+</sup>
4130
4131getAudioEffectInfoArraySync(usage: StreamUsage): AudioEffectInfoArray
4132
4133获取当前音效模式的信息,同步返回结果。
4134
4135**系统能力:** SystemCapability.Multimedia.Audio.Renderer
4136
4137**参数:**
4138
4139| 参数名    | 类型                                | 必填     | 说明                         |
4140| -------- | ----------------------------------- | -------- | --------------------------- |
4141| usage    | [StreamUsage](#streamusage)         | 是     |  音频流使用类型。               |
4142
4143**返回值:**
4144
4145| 类型                                                                      | 说明                                    |
4146| --------------------------------------------------------------------------| --------------------------------------- |
4147| [AudioEffectInfoArray](#audioeffectinfoarray10)                  | 返回当前音效模式的信息。      |
4148
4149**错误码:**
4150
4151以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4152
4153| 错误码ID | 错误信息 |
4154| ------- | --------------------------------------------|
4155| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4156| 6800101 | Parameter verification failed. |
4157
4158**示例:**
4159
4160```ts
4161import { BusinessError } from '@kit.BasicServicesKit';
4162
4163try {
4164  let audioEffectInfoArray: audio.AudioEffectInfoArray = audioStreamManager.getAudioEffectInfoArraySync(audio.StreamUsage.STREAM_USAGE_MUSIC);
4165  console.info(`The effect modes are: ${audioEffectInfoArray}`);
4166} catch (err) {
4167  let error = err as BusinessError;
4168  console.error(`getAudioEffectInfoArraySync ERROR: ${error}`);
4169}
4170```
4171
4172## AudioRoutingManager<sup>9+</sup>
4173
4174音频路由管理。在使用AudioRoutingManager的接口前,需要使用[getRoutingManager](#getroutingmanager9)获取AudioRoutingManager实例。
4175
4176### getDevices<sup>9+</sup>
4177
4178getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
4179
4180获取音频设备列表,使用callback方式异步返回结果。
4181
4182**系统能力:** SystemCapability.Multimedia.Audio.Device
4183
4184**参数:**
4185
4186| 参数名     | 类型                                                         | 必填 | 说明                 |
4187| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
4188| deviceFlag | [DeviceFlag](#deviceflag)                                    | 是   | 设备类型的flag。     |
4189| callback   | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | 是   | 回调函数。当获取音频设备列表成功,err为undefined,data为获取到的音频设备列表;否则为错误对象。 |
4190
4191**示例:**
4192
4193```ts
4194import { BusinessError } from '@kit.BasicServicesKit';
4195
4196audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err: BusinessError, value: audio.AudioDeviceDescriptors) => {
4197  if (err) {
4198    console.error(`Failed to obtain the device list. ${err}`);
4199    return;
4200  }
4201  console.info('Callback invoked to indicate that the device list is obtained.');
4202});
4203```
4204
4205### getDevices<sup>9+</sup>
4206
4207getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
4208
4209获取音频设备列表,使用Promise方式异步返回结果。
4210
4211**系统能力:** SystemCapability.Multimedia.Audio.Device
4212
4213**参数:**
4214
4215| 参数名     | 类型                      | 必填 | 说明             |
4216| ---------- | ------------------------- | ---- | ---------------- |
4217| deviceFlag | [DeviceFlag](#deviceflag) | 是   | 设备类型的flag。 |
4218
4219**返回值:**
4220
4221| 类型                                                         | 说明                      |
4222| ------------------------------------------------------------ | ------------------------- |
4223| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise对象,返回设备列表。 |
4224
4225**示例:**
4226
4227```ts
4228audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data: audio.AudioDeviceDescriptors) => {
4229  console.info('Promise returned to indicate that the device list is obtained.');
4230});
4231```
4232
4233### getDevicesSync<sup>10+</sup>
4234
4235getDevicesSync(deviceFlag: DeviceFlag): AudioDeviceDescriptors
4236
4237获取音频设备列表,同步返回结果。
4238
4239**系统能力:** SystemCapability.Multimedia.Audio.Device
4240
4241**参数:**
4242
4243| 参数名     | 类型                      | 必填 | 说明             |
4244| ---------- | ------------------------- | ---- | ---------------- |
4245| deviceFlag | [DeviceFlag](#deviceflag) | 是   | 设备类型的flag。 |
4246
4247**返回值:**
4248
4249| 类型                                                         | 说明                      |
4250| ------------------------------------------------------------ | ------------------------- |
4251| [AudioDeviceDescriptors](#audiodevicedescriptors) | 返回设备列表。 |
4252
4253**错误码:**
4254
4255以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4256
4257| 错误码ID | 错误信息 |
4258| ------- | --------------------------------------------|
4259| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4260| 6800101 | Parameter verification failed. |
4261
4262**示例:**
4263
4264```ts
4265import { BusinessError } from '@kit.BasicServicesKit';
4266
4267try {
4268  let data: audio.AudioDeviceDescriptors = audioRoutingManager.getDevicesSync(audio.DeviceFlag.OUTPUT_DEVICES_FLAG);
4269  console.info(`Indicate that the device list is obtained ${data}`);
4270} catch (err) {
4271  let error = err as BusinessError;
4272  console.error(`Failed to obtain the device list. ${error}`);
4273}
4274```
4275
4276### isMicBlockDetectionSupported<sup>13+</sup>
4277
4278isMicBlockDetectionSupported(): Promise&lt;boolean&gt;
4279
4280获取当前设备是否支持麦克风状态检测,使用Promise方式异步返回结果。
4281
4282**系统能力:** SystemCapability.Multimedia.Audio.Device
4283
4284**返回值:**
4285
4286| 类型                   | 说明                                                         |
4287| ---------------------- | ------------------------------------------------------------ |
4288| Promise&lt;boolean&gt; | Promise对象,返回当前设备是否支持堵麦回调注册状态,true为支持,false为不支持。 |
4289
4290**示例:**
4291
4292```ts
4293audioRoutingManager.isMicBlockDetectionSupported().then((value: boolean) => {
4294  console.info(`Query whether microphone block detection is supported on current device result is ${value}.`);
4295});
4296```
4297
4298### on('micBlockStatusChanged')<sup>13+</sup>
4299
4300on(type: 'micBlockStatusChanged', callback: Callback<DeviceBlockStatusInfo\>): void
4301
4302监听音频麦克风是否被堵塞变化事件。在使用此功能之前,用户应查询当前设备是否支持检测,应用只有在使用麦克风录音时,并且所使用的麦克风的堵塞状态发生改变,
4303才会收到回调,目前此检测功能仅支持麦克风位于本地设备上,使用callback方式返回结果。
4304
4305**系统能力:** SystemCapability.Multimedia.Audio.Device
4306
4307**参数:**
4308
4309| 参数名   | 类型                                                 | 必填 | 说明                                       |
4310| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
4311| type     | string                                               | 是   | 监听事件,固定为:'micBlockStatusChanged'。 |
4312| callback | Callback<[DeviceBlockStatusInfo](#deviceblockstatusinfo13)\> | 是   | 回调函数,返回设备麦克风是否被堵塞状态更新详情。 |
4313
4314**错误码:**
4315
4316以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4317
4318| 错误码ID | 错误信息 |
4319| ------- | --------------------------------------------|
4320| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4321| 6800101 | Parameter verification failed. |
4322
4323**示例:**
4324
4325```ts
4326// 在使用此功能之前,应先查询当前设备是否支持检测
4327audioRoutingManager.isMicBlockDetectionSupported().then((value: boolean) => {
4328  console.info(`Query whether microphone block detection is supported on current device result is ${value}.`);
4329  if (value) {
4330    audioRoutingManager.on('micBlockStatusChanged', (micBlockStatusChanged: audio.DeviceBlockStatusInfo) => {
4331      console.info(`block status : ${micBlockStatusChanged.blockStatus} `);
4332    });
4333  }
4334});
4335```
4336
4337### off('micBlockStatusChanged')<sup>13+</sup>
4338
4339off(type: 'micBlockStatusChanged', callback?: Callback<DeviceBlockStatusInfo\>): void
4340
4341取消监听音频麦克风是否被堵塞变化事件,使用callback方式返回结果。
4342
4343**系统能力:** SystemCapability.Multimedia.Audio.Device
4344
4345**参数:**
4346
4347| 参数名   | 类型                                                | 必填 | 说明                                       |
4348| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
4349| type     | string                                              | 是   | 监听事件,固定为:'micBlockStatusChanged'。 |
4350| callback | Callback<[DeviceBlockStatusInfo](#deviceblockstatusinfo13)\> | 否   | 回调函数,返回设备麦克风是否被堵塞状态更新详情。|
4351
4352**错误码:**
4353
4354以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4355
4356| 错误码ID | 错误信息 |
4357| ------- | --------------------------------------------|
4358| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4359| 6800101 | Parameter verification failed. |
4360
4361**示例:**
4362
4363```ts
4364// 取消该事件的所有监听
4365audioRoutingManager.off('micBlockStatusChanged');
4366
4367// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
4368let micBlockStatusCallback = (micBlockStatusChanged: audio.DeviceBlockStatusInfo) => {
4369  console.info(`block status : ${micBlockStatusChanged.blockStatus} `);
4370};
4371
4372audioRoutingManager.on('micBlockStatusChanged', micBlockStatusCallback);
4373
4374audioRoutingManager.off('micBlockStatusChanged', micBlockStatusCallback);
4375```
4376
4377### on('deviceChange')<sup>9+</sup>
4378
4379on(type: 'deviceChange', deviceFlag: DeviceFlag, callback: Callback<DeviceChangeAction\>): void
4380
4381监听音频设备连接变化事件(当音频设备连接状态发生变化时触发),使用callback方式返回结果。
4382
4383**系统能力:** SystemCapability.Multimedia.Audio.Device
4384
4385**参数:**
4386
4387| 参数名   | 类型                                                 | 必填 | 说明                      |
4388| :------- | :--------------------------------------------------- | :--- |:------------------------|
4389| type     | string                                               | 是   | 监听事件,固定为:'deviceChange'。 |
4390| deviceFlag | [DeviceFlag](#deviceflag)                                    | 是   | 设备类型的flag。              |
4391| callback | Callback<[DeviceChangeAction](#devicechangeaction)\> | 是   | 回调函数,返回设备更新详情。          |
4392
4393**错误码:**
4394
4395以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4396
4397| 错误码ID | 错误信息 |
4398| ------- | --------------------------------------------|
4399| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4400| 6800101 | Parameter verification failed. |
4401
4402**示例:**
4403
4404```ts
4405audioRoutingManager.on('deviceChange', audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (deviceChanged: audio.DeviceChangeAction) => {
4406  console.info('device change type : ' + deviceChanged.type);
4407  console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
4408  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole);
4409  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType);
4410});
4411```
4412
4413### off('deviceChange')<sup>9+</sup>
4414
4415off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void
4416
4417取消监听音频设备连接变化事件,使用callback方式返回结果。
4418
4419**系统能力:** SystemCapability.Multimedia.Audio.Device
4420
4421**参数:**
4422
4423| 参数名   | 类型                                                | 必填 | 说明                                       |
4424| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
4425| type     | string                                              | 是   | 监听事件,固定为:'deviceChange'。 |
4426| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | 否   | 回调函数,返回设备更新详情。 |
4427
4428**错误码:**
4429
4430以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4431
4432| 错误码ID | 错误信息 |
4433| ------- | --------------------------------------------|
4434| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4435| 6800101 | Parameter verification failed. |
4436
4437**示例:**
4438
4439```ts
4440// 取消该事件的所有监听
4441audioRoutingManager.off('deviceChange');
4442
4443// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
4444let deviceChangeCallback = (deviceChanged: audio.DeviceChangeAction) => {
4445  console.info('device change type : ' + deviceChanged.type);
4446  console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
4447  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole);
4448  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType);
4449};
4450
4451audioRoutingManager.on('deviceChange', audio.DeviceFlag.OUTPUT_DEVICES_FLAG, deviceChangeCallback);
4452
4453audioRoutingManager.off('deviceChange', deviceChangeCallback);
4454```
4455
4456### setCommunicationDevice<sup>9+</sup>
4457
4458setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
4459
4460设置通信设备激活状态,使用callback方式异步返回结果。
4461
4462该接口由于功能设计变化,将在后续版本废弃,不建议开发者使用。
4463
4464推荐开发者使用AVSession提供的[设备切换组件](../../media/avsession/using-switch-call-devices.md),实现通话设备切换。
4465
4466**系统能力:** SystemCapability.Multimedia.Audio.Communication
4467
4468**参数:**
4469
4470| 参数名     | 类型                                  | 必填 | 说明                      |
4471| ---------- | ------------------------------------- | ---- |-------------------------|
4472| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | 是   | 音频设备类型。                 |
4473| active     | boolean                               | 是   | 设备激活状态,true激活,false未激活。 |
4474| callback   | AsyncCallback&lt;void&gt;             | 是   | 回调函数。当设置通信设备激活状态成功,err为undefined,否则为错误对象。 |
4475
4476**示例:**
4477
4478```ts
4479import { BusinessError } from '@kit.BasicServicesKit';
4480
4481audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true, (err: BusinessError) => {
4482  if (err) {
4483    console.error(`Failed to set the active status of the device. ${err}`);
4484    return;
4485  }
4486  console.info('Callback invoked to indicate that the device is set to the active status.');
4487});
4488```
4489
4490### getAvailableDevices<sup>12+</sup>
4491
4492getAvailableDevices(deviceUsage: DeviceUsage): AudioDeviceDescriptors
4493
4494获取音频可选设备列表,同步返回结果。
4495
4496**系统能力:** SystemCapability.Multimedia.Audio.Device
4497
4498**参数:**
4499
4500| 参数名     | 类型                      | 必填 | 说明             |
4501| ---------- | ------------------------- | ---- | ---------------- |
4502| deviceUsage| [DeviceUsage](#deviceusage12) | 是   | 设备的usage。 |
4503
4504**返回值:**
4505
4506| 类型                                                         | 说明                      |
4507| ------------------------------------------------------------ | ------------------------- |
4508| [AudioDeviceDescriptors](js-apis-audio.md#audiodevicedescriptors) | 返回设备列表。 |
4509
4510**错误码:**
4511
4512以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4513
4514| 错误码ID | 错误信息 |
4515| ------- | --------------------------------------------|
4516| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4517| 6800101 | Parameter verification failed. |
4518
4519**示例:**
4520
4521```ts
4522import { BusinessError } from '@kit.BasicServicesKit';
4523
4524try {
4525  let data: audio.AudioDeviceDescriptors = audioRoutingManager.getAvailableDevices(audio.DeviceUsage.MEDIA_OUTPUT_DEVICES);
4526  console.info(`Indicate that the device list is obtained ${data}`);
4527} catch (err) {
4528  let error = err as BusinessError;
4529  console.error(`Failed to obtain the device list. ${error}`);
4530}
4531```
4532
4533### on('availableDeviceChange')<sup>12+</sup>
4534
4535on(type: 'availableDeviceChange', deviceUsage: DeviceUsage, callback: Callback<DeviceChangeAction\>): void
4536
4537监听音频可选设备连接变化事件(当音频可选设备连接状态发生变化时触发),使用callback方式返回结果。
4538
4539**系统能力:** SystemCapability.Multimedia.Audio.Device
4540
4541**参数:**
4542
4543| 参数名   | 类型                                                 | 必填 | 说明                                       |
4544| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
4545| type     | string                                               | 是   | 监听事件,固定为:'availableDeviceChange'。 |
4546| deviceUsage | [DeviceUsage](#deviceusage12)                       | 是   | 设备的usage。     |
4547| callback | Callback<[DeviceChangeAction](js-apis-audio.md#devicechangeaction)\> | 是   | 回调函数,返回设备更新详情。 |
4548
4549**错误码:**
4550
4551以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4552
4553| 错误码ID | 错误信息 |
4554| ------- | --------------------------------------------|
4555| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4556| 6800101 | Parameter verification failed. |
4557
4558**示例:**
4559
4560```ts
4561audioRoutingManager.on('availableDeviceChange', audio.DeviceUsage.MEDIA_OUTPUT_DEVICES, (deviceChanged: audio.DeviceChangeAction) => {
4562  console.info('device change type : ' + deviceChanged.type);
4563  console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
4564  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole);
4565  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType);
4566});
4567```
4568
4569### off('availableDeviceChange')<sup>12+</sup>
4570
4571off(type: 'availableDeviceChange', callback?: Callback<DeviceChangeAction\>): void
4572
4573取消监听音频可选设备连接变化事件,使用callback方式返回结果。
4574
4575**系统能力:** SystemCapability.Multimedia.Audio.Device
4576
4577**参数:**
4578
4579| 参数名   | 类型                                                | 必填 | 说明                                       |
4580| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
4581| type     | string                                              | 是   | 监听事件,固定为:'availableDeviceChange'。 |
4582| callback | Callback<[DeviceChangeAction](js-apis-audio.md#devicechangeaction)> | 否   | 回调函数,返回可选设备更新详情。 |
4583
4584**错误码:**
4585
4586以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4587
4588| 错误码ID | 错误信息 |
4589| ------- | --------------------------------------------|
4590| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4591| 6800101 | Parameter verification failed. |
4592
4593**示例:**
4594
4595```ts
4596// 取消该事件的所有监听
4597audioRoutingManager.off('availableDeviceChange');
4598
4599// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
4600let availableDeviceChangeCallback = (deviceChanged: audio.DeviceChangeAction) => {
4601  console.info('device change type : ' + deviceChanged.type);
4602  console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
4603  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole);
4604  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType);
4605};
4606
4607audioRoutingManager.on('availableDeviceChange', audio.DeviceUsage.MEDIA_OUTPUT_DEVICES, availableDeviceChangeCallback);
4608
4609audioRoutingManager.off('availableDeviceChange', availableDeviceChangeCallback);
4610```
4611
4612### setCommunicationDevice<sup>9+</sup>
4613
4614setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean): Promise&lt;void&gt;
4615
4616设置通信设备激活状态,使用Promise方式异步返回结果。
4617
4618该接口由于功能设计变化,将在后续版本废弃,不建议开发者使用。
4619
4620推荐开发者使用AVSession提供的[设备切换组件](../../media/avsession/using-switch-call-devices.md),实现通话设备切换。
4621
4622**系统能力:** SystemCapability.Multimedia.Audio.Communication
4623
4624**参数:**
4625
4626| 参数名     | 类型                                                   | 必填 | 说明               |
4627| ---------- | ----------------------------------------------------- | ---- | ------------------ |
4628| deviceType | [CommunicationDeviceType](#communicationdevicetype9)  | 是   | 活跃音频设备类型。 |
4629| active     | boolean                                               | 是   | 设备激活状态,true激活,false未激活。     |
4630
4631**返回值:**
4632
4633| 类型                | 说明                            |
4634| ------------------- | ------------------------------- |
4635| Promise&lt;void&gt; | Promise对象,无返回结果。 |
4636
4637**示例:**
4638
4639```ts
4640audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true).then(() => {
4641  console.info('Promise returned to indicate that the device is set to the active status.');
4642});
4643```
4644
4645### isCommunicationDeviceActive<sup>9+</sup>
4646
4647isCommunicationDeviceActive(deviceType: CommunicationDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
4648
4649获取指定通信设备的激活状态,使用callback方式异步返回结果。
4650
4651**系统能力:** SystemCapability.Multimedia.Audio.Communication
4652
4653**参数:**
4654
4655| 参数名     | 类型                                                  | 必填 | 说明                     |
4656| ---------- | ---------------------------------------------------- | ---- | ------------------------ |
4657| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | 是   | 活跃音频设备类型。       |
4658| callback   | AsyncCallback&lt;boolean&gt;                         | 是   | 回调函数。当获取指定通信设备的激活状态成功,err为undefined,data为true为激活,false为未激活;否则为错误对象。 |
4659
4660**示例:**
4661
4662```ts
4663import { BusinessError } from '@kit.BasicServicesKit';
4664
4665audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER, (err: BusinessError, value: boolean) => {
4666  if (err) {
4667    console.error(`Failed to obtain the active status of the device. ${err}`);
4668    return;
4669  }
4670  console.info('Callback invoked to indicate that the active status of the device is obtained.');
4671});
4672```
4673
4674### isCommunicationDeviceActive<sup>9+</sup>
4675
4676isCommunicationDeviceActive(deviceType: CommunicationDeviceType): Promise&lt;boolean&gt;
4677
4678获取指定通信设备的激活状态,使用Promise方式异步返回结果。
4679
4680**系统能力:** SystemCapability.Multimedia.Audio.Communication
4681
4682**参数:**
4683
4684| 参数名     | 类型                                                  | 必填 | 说明               |
4685| ---------- | ---------------------------------------------------- | ---- | ------------------ |
4686| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | 是   | 活跃音频设备类型。 |
4687
4688**返回值:**
4689
4690| Type                   | Description                     |
4691| ---------------------- | ------------------------------- |
4692| Promise&lt;boolean&gt; | Promise对象,返回设备的激活状态,true激活,false未激活。 |
4693
4694**示例:**
4695
4696```ts
4697audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER).then((value: boolean) => {
4698  console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
4699});
4700```
4701
4702### isCommunicationDeviceActiveSync<sup>10+</sup>
4703
4704isCommunicationDeviceActiveSync(deviceType: CommunicationDeviceType): boolean
4705
4706获取指定通信设备的激活状态,同步返回结果。
4707
4708**系统能力:** SystemCapability.Multimedia.Audio.Communication
4709
4710**参数:**
4711
4712| 参数名     | 类型                                                  | 必填 | 说明               |
4713| ---------- | ---------------------------------------------------- | ---- | ------------------ |
4714| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | 是   | 活跃音频设备类型。 |
4715
4716**返回值:**
4717
4718| Type                   | Description                     |
4719| ---------------------- | ------------------------------- |
4720| boolean | 返回设备的激活状态,true激活,false未激活。 |
4721
4722**错误码:**
4723
4724以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4725
4726| 错误码ID | 错误信息 |
4727| ------- | --------------------------------------------|
4728| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4729| 6800101 | Parameter verification failed. |
4730
4731**示例:**
4732
4733```ts
4734import { BusinessError } from '@kit.BasicServicesKit';
4735
4736try {
4737  let value: boolean = audioRoutingManager.isCommunicationDeviceActiveSync(audio.CommunicationDeviceType.SPEAKER);
4738  console.info(`Indicate that the active status of the device is obtained ${value}.`);
4739} catch (err) {
4740  let error = err as BusinessError;
4741  console.error(`Failed to obtain the active status of the device ${error}.`);
4742}
4743```
4744
4745### getPreferOutputDeviceForRendererInfo<sup>10+</sup>
4746
4747getPreferOutputDeviceForRendererInfo(rendererInfo: AudioRendererInfo, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
4748
4749根据音频信息,返回优先级最高的输出设备,使用callback方式异步返回结果。
4750
4751**系统能力:** SystemCapability.Multimedia.Audio.Device
4752
4753**参数:**
4754
4755| 参数名                       | 类型                                                         | 必填 | 说明                      |
4756| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
4757| rendererInfo                | [AudioRendererInfo](#audiorendererinfo8)                     | 是   | 表示渲染器信息。             |
4758| callback                    | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt;  | 是   | 回调函数。当获取优先级最高的输出设备成功,err为undefined,data为获取到的优先级最高的输出设备信息;否则为错误对象。 |
4759
4760**错误码:**
4761
4762以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4763
4764| 错误码ID | 错误信息                                           |
4765| ------- |--------------------------------------------------|
4766| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4767| 6800101 | Parameter verification failed. Return by callback. |
4768| 6800301 | System error. Return by callback.                |
4769
4770**示例:**
4771```ts
4772import { audio } from '@kit.AudioKit';
4773import { BusinessError } from '@kit.BasicServicesKit';
4774
4775let rendererInfo: audio.AudioRendererInfo = {
4776  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
4777  rendererFlags : 0
4778};
4779
4780async function getPreferOutputDevice() {
4781  audioRoutingManager.getPreferOutputDeviceForRendererInfo(rendererInfo, (err: BusinessError, desc: audio.AudioDeviceDescriptors) => {
4782    if (err) {
4783      console.error(`Result ERROR: ${err}`);
4784    } else {
4785      console.info(`device descriptor: ${desc}`);
4786    }
4787  });
4788}
4789```
4790
4791### getPreferOutputDeviceForRendererInfo<sup>10+</sup>
4792getPreferOutputDeviceForRendererInfo(rendererInfo: AudioRendererInfo): Promise&lt;AudioDeviceDescriptors&gt;
4793
4794根据音频信息,返回优先级最高的输出设备,使用Promise方式异步返回结果。
4795
4796**系统能力:** SystemCapability.Multimedia.Audio.Device
4797
4798**参数:**
4799
4800| 参数名                 | 类型                                                         | 必填 | 说明                      |
4801| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
4802| rendererInfo          | [AudioRendererInfo](#audiorendererinfo8)                     | 是   | 表示渲染器信息。            |
4803
4804**返回值:**
4805
4806| 类型                  | 说明                         |
4807| --------------------- | --------------------------- |
4808| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt;   | Promise对象,返回优先级最高的输出设备信息。 |
4809
4810**错误码:**
4811
4812以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4813
4814| 错误码ID | 错误信息                                          |
4815| ------- |-------------------------------------------------|
4816| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4817| 6800101 | Parameter verification failed. Return by promise. |
4818| 6800301 | System error. Return by promise.                |
4819
4820**示例:**
4821
4822```ts
4823import { audio } from '@kit.AudioKit';
4824import { BusinessError } from '@kit.BasicServicesKit';
4825
4826let rendererInfo: audio.AudioRendererInfo = {
4827  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
4828  rendererFlags : 0
4829};
4830
4831async function getPreferOutputDevice() {
4832  audioRoutingManager.getPreferOutputDeviceForRendererInfo(rendererInfo).then((desc: audio.AudioDeviceDescriptors) => {
4833    console.info(`device descriptor: ${desc}`);
4834  }).catch((err: BusinessError) => {
4835    console.error(`Result ERROR: ${err}`);
4836  })
4837}
4838```
4839
4840### getPreferredOutputDeviceForRendererInfoSync<sup>10+</sup>
4841getPreferredOutputDeviceForRendererInfoSync(rendererInfo: AudioRendererInfo): AudioDeviceDescriptors
4842
4843根据音频信息,返回优先级最高的输出设备,同步返回结果。
4844
4845**系统能力:** SystemCapability.Multimedia.Audio.Device
4846
4847**参数:**
4848
4849| 参数名                 | 类型                                                         | 必填 | 说明                      |
4850| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
4851| rendererInfo          | [AudioRendererInfo](#audiorendererinfo8)                     | 是   | 表示渲染器信息。            |
4852
4853**返回值:**
4854
4855| 类型                  | 说明                         |
4856| --------------------- | --------------------------- |
4857| [AudioDeviceDescriptors](#audiodevicedescriptors)   | 返回优先级最高的输出设备信息。 |
4858
4859**错误码:**
4860
4861以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4862
4863| 错误码ID | 错误信息                     |
4864| ------- |--------------------------|
4865| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4866| 6800101 | Parameter verification failed. |
4867
4868**示例:**
4869
4870```ts
4871import { audio } from '@kit.AudioKit';
4872import { BusinessError } from '@kit.BasicServicesKit';
4873
4874let rendererInfo: audio.AudioRendererInfo = {
4875  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
4876  rendererFlags : 0
4877};
4878
4879try {
4880  let desc: audio.AudioDeviceDescriptors = audioRoutingManager.getPreferredOutputDeviceForRendererInfoSync(rendererInfo);
4881  console.info(`device descriptor: ${desc}`);
4882} catch (err) {
4883  let error = err as BusinessError;
4884  console.error(`Result ERROR: ${error}`);
4885}
4886```
4887
4888### on('preferOutputDeviceChangeForRendererInfo')<sup>10+</sup>
4889
4890on(type: 'preferOutputDeviceChangeForRendererInfo', rendererInfo: AudioRendererInfo, callback: Callback<AudioDeviceDescriptors\>): void
4891
4892监听最高优先级输出设备变化事件(当最高优先级输出设备发生变化时触发),使用callback方式返回结果。
4893
4894**系统能力:** SystemCapability.Multimedia.Audio.Device
4895
4896**参数:**
4897
4898| 参数名   | 类型                                                 | 必填 | 说明                                                      |
4899| :------- | :--------------------------------------------------- | :--- |:--------------------------------------------------------|
4900| type     | string                                               | 是   | 监听事件,固定为:'preferOutputDeviceChangeForRendererInfo' |
4901| rendererInfo  | [AudioRendererInfo](#audiorendererinfo8)        | 是   | 表示渲染器信息。                                                |
4902| callback | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)\> | 是   | 回调函数,返回优先级最高的输出设备信息。 |
4903
4904**错误码:**
4905
4906以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4907
4908| 错误码ID | 错误信息 |
4909| ------- | --------------------------------------------|
4910| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4911| 6800101 | Parameter verification failed. |
4912
4913**示例:**
4914
4915```ts
4916import { audio } from '@kit.AudioKit';
4917
4918let rendererInfo: audio.AudioRendererInfo = {
4919  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
4920  rendererFlags : 0
4921};
4922
4923audioRoutingManager.on('preferOutputDeviceChangeForRendererInfo', rendererInfo, (desc: audio.AudioDeviceDescriptors) => {
4924  console.info(`device descriptor: ${desc}`);
4925});
4926```
4927
4928### off('preferOutputDeviceChangeForRendererInfo')<sup>10+</sup>
4929
4930off(type: 'preferOutputDeviceChangeForRendererInfo', callback?: Callback<AudioDeviceDescriptors\>): void
4931
4932取消监听最高优先级输出音频设备变化事件,使用callback方式返回结果。
4933
4934**系统能力:** SystemCapability.Multimedia.Audio.Device
4935
4936**参数:**
4937
4938| 参数名   | 类型                                                | 必填 | 说明                                       |
4939| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
4940| type     | string                                              | 是   | 监听事件,固定为:'preferOutputDeviceChangeForRendererInfo'。 |
4941| callback | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 否   | 回调函数,返回优先级最高的输出设备信息。 |
4942
4943**错误码:**
4944
4945以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4946
4947| 错误码ID | 错误信息 |
4948| ------- | --------------------------------------------|
4949| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4950| 6800101 | Parameter verification failed. |
4951
4952**示例:**
4953
4954```ts
4955// 取消该事件的所有监听
4956audioRoutingManager.off('preferOutputDeviceChangeForRendererInfo');
4957
4958// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
4959let preferOutputDeviceChangeForRendererInfoCallback = (desc: audio.AudioDeviceDescriptors) => {
4960  console.info(`device descriptor: ${desc}`);
4961};
4962let rendererInfo: audio.AudioRendererInfo = {
4963  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
4964  rendererFlags : 0
4965};
4966
4967audioRoutingManager.on('preferOutputDeviceChangeForRendererInfo', rendererInfo, preferOutputDeviceChangeForRendererInfoCallback);
4968
4969audioRoutingManager.off('preferOutputDeviceChangeForRendererInfo', preferOutputDeviceChangeForRendererInfoCallback);
4970```
4971
4972### getPreferredInputDeviceForCapturerInfo<sup>10+</sup>
4973
4974getPreferredInputDeviceForCapturerInfo(capturerInfo: AudioCapturerInfo, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
4975
4976根据音频信息,返回优先级最高的输入设备,使用callback方式异步返回结果。
4977
4978**系统能力:** SystemCapability.Multimedia.Audio.Device
4979
4980**参数:**
4981
4982| 参数名                       | 类型                                                         | 必填 | 说明                      |
4983| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
4984| capturerInfo                | [AudioCapturerInfo](#audiocapturerinfo8)                     | 是   | 表示采集器信息。             |
4985| callback                    | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt;  | 是   | 回调函数。当获取优先级最高的输入设备成功,err为undefined,data为获取到的优先级最高的输入设备信息;否则为错误对象。 |
4986
4987**错误码:**
4988
4989以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4990
4991| 错误码ID | 错误信息 |
4992| ------- | --------------------------------------------|
4993| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4994| 6800101 | Parameter verification failed. Return by callback.|
4995| 6800301 | System error. Return by callback. |
4996
4997**示例:**
4998```ts
4999import { audio } from '@kit.AudioKit';
5000import { BusinessError } from '@kit.BasicServicesKit';
5001
5002let capturerInfo: audio.AudioCapturerInfo = {
5003  source: audio.SourceType.SOURCE_TYPE_MIC,
5004  capturerFlags: 0
5005};
5006
5007audioRoutingManager.getPreferredInputDeviceForCapturerInfo(capturerInfo, (err: BusinessError, desc: audio.AudioDeviceDescriptors) => {
5008  if (err) {
5009    console.error(`Result ERROR: ${err}`);
5010  } else {
5011    console.info(`device descriptor: ${desc}`);
5012  }
5013});
5014```
5015
5016### getPreferredInputDeviceForCapturerInfo<sup>10+</sup>
5017
5018getPreferredInputDeviceForCapturerInfo(capturerInfo: AudioCapturerInfo): Promise&lt;AudioDeviceDescriptors&gt;
5019
5020根据音频信息,返回优先级最高的输入设备,使用Promise方式异步返回结果。
5021
5022**系统能力:** SystemCapability.Multimedia.Audio.Device
5023
5024**参数:**
5025
5026| 参数名                 | 类型                                                         | 必填 | 说明                      |
5027| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
5028| capturerInfo          | [AudioCapturerInfo](#audiocapturerinfo8)                     | 是   | 表示采集器信息。            |
5029
5030**返回值:**
5031
5032| 类型                  | 说明                         |
5033| --------------------- | --------------------------- |
5034| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt;   | Promise对象,返回优先级最高的输入设备信息。 |
5035
5036**错误码:**
5037
5038以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
5039
5040| 错误码ID | 错误信息 |
5041| ------- | --------------------------------------------|
5042| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
5043| 6800101 | Parameter verification failed. Return by promise. |
5044| 6800301 | System error. Return by promise. |
5045
5046**示例:**
5047
5048```ts
5049import { audio } from '@kit.AudioKit';
5050import { BusinessError } from '@kit.BasicServicesKit';
5051
5052let capturerInfo: audio.AudioCapturerInfo = {
5053  source: audio.SourceType.SOURCE_TYPE_MIC,
5054  capturerFlags: 0
5055};
5056
5057audioRoutingManager.getPreferredInputDeviceForCapturerInfo(capturerInfo).then((desc: audio.AudioDeviceDescriptors) => {
5058  console.info(`device descriptor: ${desc}`);
5059}).catch((err: BusinessError) => {
5060  console.error(`Result ERROR: ${err}`);
5061});
5062```
5063
5064### getPreferredInputDeviceForCapturerInfoSync<sup>10+</sup>
5065
5066getPreferredInputDeviceForCapturerInfoSync(capturerInfo: AudioCapturerInfo): AudioDeviceDescriptors
5067
5068根据音频信息,返回优先级最高的输入设备,同步返回结果。
5069
5070**系统能力:** SystemCapability.Multimedia.Audio.Device
5071
5072**参数:**
5073
5074| 参数名                 | 类型                                                         | 必填 | 说明                      |
5075| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
5076| capturerInfo          | [AudioCapturerInfo](#audiocapturerinfo8)                     | 是   | 表示采集器信息。            |
5077
5078**返回值:**
5079
5080| 类型                  | 说明                         |
5081| --------------------- | --------------------------- |
5082| [AudioDeviceDescriptors](#audiodevicedescriptors)   | 返回优先级最高的输入设备信息。 |
5083
5084**错误码:**
5085
5086以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
5087
5088| 错误码ID | 错误信息 |
5089| ------- | --------------------------------------------|
5090| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
5091| 6800101 | Parameter verification failed. |
5092
5093**示例:**
5094
5095```ts
5096import { audio } from '@kit.AudioKit';
5097import { BusinessError } from '@kit.BasicServicesKit';
5098
5099let capturerInfo: audio.AudioCapturerInfo = {
5100  source: audio.SourceType.SOURCE_TYPE_MIC,
5101  capturerFlags: 0
5102};
5103
5104try {
5105  let desc: audio.AudioDeviceDescriptors = audioRoutingManager.getPreferredInputDeviceForCapturerInfoSync(capturerInfo);
5106  console.info(`device descriptor: ${desc}`);
5107} catch (err) {
5108  let error = err as BusinessError;
5109  console.error(`Result ERROR: ${error}`);
5110}
5111```
5112
5113### on('preferredInputDeviceChangeForCapturerInfo')<sup>10+</sup>
5114
5115on(type: 'preferredInputDeviceChangeForCapturerInfo', capturerInfo: AudioCapturerInfo, callback: Callback<AudioDeviceDescriptors\>): void
5116
5117监听最高优先级输入设备变化事件(当最高优先级输入设备发生变化时触发),使用callback方式返回结果。
5118
5119**系统能力:** SystemCapability.Multimedia.Audio.Device
5120
5121**参数:**
5122
5123| 参数名   | 类型                                                 | 必填 | 说明                                       |
5124| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
5125| type     | string                                               | 是   | 监听事件,固定为:'preferredInputDeviceChangeForCapturerInfo' |
5126| capturerInfo  | [AudioCapturerInfo](#audiocapturerinfo8)        | 是   | 表示采集器信息。              |
5127| callback | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)\> | 是   | 回调函数,返回优先级最高的输入设备信息。 |
5128
5129**错误码:**
5130
5131以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
5132
5133| 错误码ID | 错误信息 |
5134| ------- | --------------------------------------------|
5135| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
5136| 6800101 | Parameter verification failed. |
5137
5138**示例:**
5139
5140```ts
5141import { audio } from '@kit.AudioKit';
5142
5143let capturerInfo: audio.AudioCapturerInfo = {
5144  source: audio.SourceType.SOURCE_TYPE_MIC,
5145  capturerFlags: 0
5146};
5147
5148audioRoutingManager.on('preferredInputDeviceChangeForCapturerInfo', capturerInfo, (desc: audio.AudioDeviceDescriptors) => {
5149  console.info(`device descriptor: ${desc}`);
5150});
5151```
5152
5153### off('preferredInputDeviceChangeForCapturerInfo')<sup>10+</sup>
5154
5155off(type: 'preferredInputDeviceChangeForCapturerInfo', callback?: Callback<AudioDeviceDescriptors\>): void
5156
5157取消监听最高优先级输入音频设备变化事件,使用callback方式返回结果。
5158
5159**系统能力:** SystemCapability.Multimedia.Audio.Device
5160
5161**参数:**
5162
5163| 参数名   | 类型                                                | 必填 | 说明                                       |
5164| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
5165| type     | string                                              | 是   | 监听事件,固定为:'preferredInputDeviceChangeForCapturerInfo' |
5166| callback | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 否   | 回调函数,返回优先级最高的输入设备信息。 |
5167
5168**错误码:**
5169
5170以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
5171
5172| 错误码ID | 错误信息 |
5173| ------- | --------------------------------------------|
5174| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
5175| 6800101 | Parameter verification failed. |
5176
5177**示例:**
5178
5179```ts
5180// 取消该事件的所有监听
5181audioRoutingManager.off('preferredInputDeviceChangeForCapturerInfo');
5182
5183// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
5184let preferredInputDeviceChangeForCapturerInfoCallback = (desc: audio.AudioDeviceDescriptors) => {
5185  console.info(`device descriptor: ${desc}`);
5186};
5187let capturerInfo: audio.AudioCapturerInfo = {
5188  source: audio.SourceType.SOURCE_TYPE_MIC,
5189  capturerFlags: 0
5190};
5191
5192audioRoutingManager.on('preferredInputDeviceChangeForCapturerInfo', capturerInfo, preferredInputDeviceChangeForCapturerInfoCallback);
5193
5194audioRoutingManager.off('preferredInputDeviceChangeForCapturerInfo', preferredInputDeviceChangeForCapturerInfoCallback);
5195```
5196
5197## AudioSessionManager<sup>12+</sup>
5198
5199音频会话管理。在使用AudioSessionManager的接口前,需要使用[getSessionManager](#getsessionmanager12)获取AudioSessionManager实例。
5200
5201### activateAudioSession<sup>12+</sup>
5202
5203activateAudioSession(strategy: AudioSessionStrategy): Promise\<void>
5204
5205激活音频会话。使用Promise方式异步返回结果。
5206
5207**系统能力:** SystemCapability.Multimedia.Audio.Core
5208
5209**参数:**
5210
5211| 参数名 | 类型                                              | 必填 | 说明         |
5212| ------ |-------------------------------------------------| ---- | ------------ |
5213| strategy | [AudioSessionStrategy](#audiosessionstrategy12) | 是   | 音频会话策略。 |
5214
5215**返回值:**
5216
5217| 类型           | 说明                      |
5218| -------------- | ------------------------- |
5219| Promise\<void> | Promise对象,无返回结果。 |
5220
5221**错误码:**
5222
5223以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
5224
5225| 错误码ID | 错误信息 |
5226| ------- | ---------------------------------------------|
5227| 401 | Parameter error. Possible causes: 1.Mandatory parameters unspecified. 2.Incorrect parameter types. |
5228| 6800101 | Parameter verification failed.|
5229| 6800301 | System error. Returned by promise. |
5230
5231**示例:**
5232
5233```ts
5234import { BusinessError } from '@kit.BasicServicesKit';
5235
5236let strategy: audio.AudioSessionStrategy = {
5237  concurrencyMode: audio.AudioConcurrencyMode.CONCURRENCY_MIX_WITH_OTHERS
5238};
5239
5240audioSessionManager.activateAudioSession(strategy).then(() => {
5241  console.info('activateAudioSession SUCCESS');
5242}).catch((err: BusinessError) => {
5243  console.error(`ERROR: ${err}`);
5244});
5245```
5246
5247### deactivateAudioSession<sup>12+</sup>
5248
5249deactivateAudioSession(): Promise\<void>
5250
5251停用音频会话。使用Promise方式异步返回结果。
5252
5253**系统能力:** SystemCapability.Multimedia.Audio.Core
5254
5255**返回值:**
5256
5257| 类型           | 说明                      |
5258| -------------- | ------------------------- |
5259| Promise\<void> | Promise对象,无返回结果。 |
5260
5261**错误码:**
5262
5263以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
5264
5265| 错误码ID | 错误信息 |
5266| ------- | ---------------------------------------------|
5267| 6800301 | System error. Returned by promise. |
5268
5269**示例:**
5270
5271```ts
5272import { BusinessError } from '@kit.BasicServicesKit';
5273
5274audioSessionManager.deactivateAudioSession().then(() => {
5275  console.info('deactivateAudioSession SUCCESS');
5276}).catch((err: BusinessError) => {
5277  console.error(`ERROR: ${err}`);
5278});
5279```
5280
5281### isAudioSessionActivated<sup>12+</sup>
5282
5283isAudioSessionActivated(): boolean
5284
5285检查音频会话是否已激活。
5286
5287**系统能力:** SystemCapability.Multimedia.Audio.Core
5288
5289**返回值:**
5290
5291| 类型                                              | 说明                                    |
5292| ------------------------------------------------- |---------------------------------------|
5293| boolean | 返回当前pid应用程序的音频会话是否已激活,true表示已激活,false表示已停用。 |
5294
5295**示例:**
5296
5297```ts
5298let isActivated = audioSessionManager.isAudioSessionActivated();
5299```
5300
5301### on('audioSessionDeactivated')<sup>12+</sup>
5302
5303on(type: 'audioSessionDeactivated', callback: Callback\<AudioSessionDeactivatedEvent>): void
5304
5305监听音频会话停用事件(当音频会话停用时触发),使用callback方式返回结果。
5306
5307**系统能力:** SystemCapability.Multimedia.Audio.Core
5308
5309**参数:**
5310
5311| 参数名   | 类型                                                                        | 必填 | 说明                                                         |
5312| -------- |---------------------------------------------------------------------------| ---- | ------------------------------------------------------------ |
5313| type     | string                                                                    | 是   | 监听事件,固定为:'audioSessionDeactivated'。 |
5314| callback | Callback<[AudioSessionDeactivatedEvent](#audiosessiondeactivatedevent12)> | 是   | 回调函数,返回音频会话停用原因。 |
5315
5316**错误码:**
5317
5318以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
5319
5320| 错误码ID | 错误信息 |
5321| ------- | --------------------------------------------|
5322| 401 | Parameter error. Possible causes: 1.Mandatory parameters unspecified. 2.Incorrect parameter types. |
5323| 6800101 | Parameter verification failed. |
5324
5325**示例:**
5326
5327```ts
5328audioSessionManager.on('audioSessionDeactivated', (audioSessionDeactivatedEvent: audio.AudioSessionDeactivatedEvent) => {
5329  console.info(`reason of audioSessionDeactivated: ${audioSessionDeactivatedEvent.reason} `);
5330});
5331```
5332
5333### off('audioSessionDeactivated')<sup>12+</sup>
5334
5335off(type: 'audioSessionDeactivated', callback?: Callback\<AudioSessionDeactivatedEvent>): void
5336
5337取消监听音频会话停用事件,使用callback方式返回结果。
5338
5339**系统能力:** SystemCapability.Multimedia.Audio.Core
5340
5341**参数:**
5342
5343| 参数名   | 类型                                   | 必填 | 说明                                                         |
5344| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
5345| type     | string                                 | 是   | 监听事件,固定为:'audioSessionDeactivated'。 |
5346| callback |Callback<[AudioSessionDeactivatedEvent](#audiosessiondeactivatedevent12)> | 否   | 回调函数,返回音频会话停用原因。 |
5347
5348**错误码:**
5349
5350以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
5351
5352| 错误码ID | 错误信息 |
5353| ------- | --------------------------------------------|
5354| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
5355| 6800101 | Parameter verification failed. |
5356
5357**示例:**
5358
5359```ts
5360// 取消该事件的所有监听
5361audioSessionManager.off('audioSessionDeactivated');
5362
5363// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
5364let audioSessionDeactivatedCallback = (audioSessionDeactivatedEvent: audio.AudioSessionDeactivatedEvent) => {
5365  console.info(`reason of audioSessionDeactivated: ${audioSessionDeactivatedEvent.reason} `);
5366};
5367
5368audioSessionManager.on('audioSessionDeactivated', audioSessionDeactivatedCallback);
5369
5370audioSessionManager.off('audioSessionDeactivated', audioSessionDeactivatedCallback);
5371```
5372
5373## AudioRendererChangeInfoArray<sup>9+</sup>
5374
5375type AudioRendererChangeInfoArray = Array&lt;Readonly&lt;AudioRendererChangeInfo&gt;&gt;
5376
5377数组类型,AudioRenderChangeInfo数组,只读。
5378
5379**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5380
5381| 类型      | 说明                                                            |
5382|---------|---------------------------------------------------------------|
5383| Array&lt;Readonly&lt;AudioRendererChangeInfo&gt;&gt; | 数组类型,[AudioRenderChangeInfo](#audiorendererchangeinfo9)数组,只读。 |
5384
5385## AudioRendererChangeInfo<sup>9+</sup>
5386
5387描述音频渲染器更改信息。
5388
5389**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5390
5391| 名称               | 类型                                       | 可读 | 可写 | 说明                          |
5392| -------------------| ----------------------------------------- | ---- | ---- | ---------------------------- |
5393| streamId           | number                                    | 是   | 否   | 音频流唯一id。                |
5394| rendererInfo       | [AudioRendererInfo](#audiorendererinfo8)  | 是   | 否   | 音频渲染器信息。               |
5395| deviceDescriptors  | [AudioDeviceDescriptors](#audiodevicedescriptors)      | 是   | 否   | 音频设备描述。|
5396
5397**示例:**
5398
5399```ts
5400import { audio } from '@kit.AudioKit';
5401
5402const audioManager = audio.getAudioManager();
5403let audioStreamManager = audioManager.getStreamManager();
5404
5405audioStreamManager.on('audioRendererChange',  (AudioRendererChangeInfoArray) => {
5406  for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
5407    console.info(`## RendererChange on is called for ${i} ##`);
5408    console.info(`StreamId for ${i} is: ${AudioRendererChangeInfoArray[i].streamId}`);
5409    console.info(`Content for ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.content}`);
5410    console.info(`Stream for ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.usage}`);
5411    console.info(`Flag ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.rendererFlags}`);
5412    let devDescriptor = AudioRendererChangeInfoArray[i].deviceDescriptors;
5413    for (let j = 0; j < AudioRendererChangeInfoArray[i].deviceDescriptors.length; j++) {
5414      console.info(`Id: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].id}`);
5415      console.info(`Type: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
5416      console.info(`Role: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
5417      console.info(`Name: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].name}`);
5418      console.info(`Addr: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].address}`);
5419      console.info(`SR: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
5420      console.info(`C ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
5421      console.info(`CM: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
5422    }
5423  }
5424});
5425```
5426
5427
5428## AudioCapturerChangeInfoArray<sup>9+</sup>
5429
5430type AudioCapturerChangeInfoArray = Array&lt;Readonly&lt;AudioCapturerChangeInfo&gt;&gt;
5431
5432数组类型,AudioCapturerChangeInfo数组,只读。
5433
5434**系统能力:** SystemCapability.Multimedia.Audio.Capturer
5435
5436| 类型      | 说明                                                              |
5437|---------|-----------------------------------------------------------------|
5438| Array&lt;Readonly&lt;AudioCapturerChangeInfo&gt;&gt; | 数组类型,[AudioCapturerChangeInfo](#audiocapturerchangeinfo9)数组,只读。 |
5439
5440## AudioCapturerChangeInfo<sup>9+</sup>
5441
5442描述音频采集器更改信息。
5443
5444**系统能力:** SystemCapability.Multimedia.Audio.Capturer
5445
5446| 名称               | 类型                                       | 可读 | 可写 | 说明                          |
5447| -------------------| ----------------------------------------- | ---- | ---- | ---------------------------- |
5448| streamId           | number                                    | 是   | 否   | 音频流唯一id。                |
5449| capturerInfo       | [AudioCapturerInfo](#audiocapturerinfo8)  | 是   | 否   | 音频采集器信息。               |
5450| deviceDescriptors  | [AudioDeviceDescriptors](#audiodevicedescriptors)      | 是   | 否   | 音频设备描述。|
5451| muted<sup>11+</sup>  | boolean    | 是   | 否   | 音频采集器静音状态。true表示音频采集器为静音状态,false表示音频采集器为非静音状态。|
5452
5453**示例:**
5454
5455```ts
5456import { audio } from '@kit.AudioKit';
5457
5458const audioManager = audio.getAudioManager();
5459let audioStreamManager = audioManager.getStreamManager();
5460
5461audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) =>  {
5462  for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
5463    console.info(`## CapChange on is called for element ${i} ##`);
5464    console.info(`StrId for  ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
5465    console.info(`Src for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
5466    console.info(`Flag ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
5467    let devDescriptor = AudioCapturerChangeInfoArray[i].deviceDescriptors;
5468    for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
5469      console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
5470      console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
5471      console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
5472      console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
5473      console.info(`Addr: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
5474      console.info(`SR: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
5475      console.info(`C ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
5476      console.info(`CM ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
5477    }
5478  }
5479});
5480```
5481
5482## AudioEffectInfoArray<sup>10+</sup>
5483
5484type AudioEffectInfoArray = Array&lt;Readonly&lt;AudioEffectMode&gt;&gt;
5485
5486待查询ContentType和StreamUsage组合场景下的音效模式数组类型,[AudioEffectMode](#audioeffectmode10)数组,只读。
5487
5488**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5489
5490| 类型      | 说明                                                            |
5491|---------|---------------------------------------------------------------|
5492| Array&lt;Readonly&lt;AudioEffectMode&gt;&gt; | 待查询ContentType和StreamUsage组合场景下的音效模式数组类型,[AudioEffectMode](#audioeffectmode10)数组,只读。 |
5493
5494## AudioDeviceDescriptors
5495
5496type AudioDeviceDescriptors = Array&lt;Readonly&lt;AudioDeviceDescriptor&gt;&gt;
5497
5498设备属性数组类型,为[AudioDeviceDescriptor](#audiodevicedescriptor)的数组,只读。
5499
5500**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5501
5502**系统能力:** SystemCapability.Multimedia.Audio.Device
5503
5504| 类型      | 说明                                                            |
5505|---------|---------------------------------------------------------------|
5506| Array&lt;Readonly&lt;AudioDeviceDescriptor&gt;&gt; | 设备属性数组类型,为[AudioDeviceDescriptor](#audiodevicedescriptor)的数组,只读。 |
5507
5508## AudioDeviceDescriptor
5509
5510描述音频设备。
5511
5512**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5513
5514| 名称                          | 类型                       | 可读 | 可写 | 说明       |
5515| ----------------------------- | -------------------------- | ---- | ---- | ---------- |
5516| deviceRole                    | [DeviceRole](#devicerole)  | 是   | 否   | 设备角色。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
5517| deviceType                    | [DeviceType](#devicetype)  | 是   | 否   | 设备类型。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
5518| id<sup>9+</sup>               | number                     | 是   | 否   | 设备id,唯一。  <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
5519| name<sup>9+</sup>             | string                     | 是   | 否   | 设备名称。<br>如果是蓝牙设备,需要申请权限ohos.permission.USE_BLUETOOTH。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
5520| address<sup>9+</sup>          | string                     | 是   | 否   | 设备地址。<br>如果是蓝牙设备,需要申请权限ohos.permission.USE_BLUETOOTH。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
5521| sampleRates<sup>9+</sup>      | Array&lt;number&gt;        | 是   | 否   | 支持的采样率。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
5522| channelCounts<sup>9+</sup>    | Array&lt;number&gt;        | 是   | 否   | 支持的通道数。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
5523| channelMasks<sup>9+</sup>     | Array&lt;number&gt;        | 是   | 否   | 支持的通道掩码。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
5524| displayName<sup>10+</sup>     | string                     | 是   | 否   | 设备显示名。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
5525| encodingTypes<sup>11+</sup>    | Array&lt;[AudioEncodingType](#audioencodingtype8)&gt;                     | 是   | 否   | 支持的编码类型。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Core|
5526
5527**示例:**
5528
5529```ts
5530import { audio } from '@kit.AudioKit';
5531
5532function displayDeviceProp(value: audio.AudioDeviceDescriptor) {
5533  deviceRoleValue = value.deviceRole;
5534  deviceTypeValue = value.deviceType;
5535}
5536
5537let deviceRoleValue: audio.DeviceRole | undefined = undefined;
5538let deviceTypeValue: audio.DeviceType | undefined = undefined;
5539audio.getAudioManager().getRoutingManager().getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((value: audio.AudioDeviceDescriptors) => {
5540  console.info('AudioFrameworkTest: Promise: getDevices OUTPUT_DEVICES_FLAG');
5541  value.forEach(displayDeviceProp);
5542  if (deviceTypeValue != undefined && deviceRoleValue != undefined){
5543    console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  PASS');
5544  } else {
5545    console.error('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  FAIL');
5546  }
5547});
5548```
5549## AudioDataCallbackResult<sup>12+</sup>
5550
5551枚举,表示音频数据回调的结果。
5552
5553**系统能力:** SystemCapability.Multimedia.Audio.Core
5554
5555| 名称                 | 值      | 说明         |
5556| ---------------------| --------| ----------------- |
5557| INVALID  | -1 | 表示该回调数据无效。      |
5558| VALID      | 0 | 表示该回调数据有效。     |
5559
5560## AudioRendererWriteDataCallback<sup>12+</sup>
5561
5562type AudioRendererWriteDataCallback = (data: ArrayBuffer) => AudioDataCallbackResult | void
5563
5564回调函数类型,用于音频渲染器的数据写入,回调函数结束后,音频服务会把data指针数据放入队列里等待播放,因此请勿在回调外再次更改data指向的数据, 且务必保证往data填满待播放数据, 否则会导致音频服务播放杂音。
5565
5566**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5567
5568**参数:**
5569
5570| 参数名          | 类型      |必填   | 说明         |
5571| :--------------| :--------| :----- | :------------ |
5572| data           | ArrayBuffer  | 是 | 待写入缓冲区的数据。 |
5573
5574**返回值:**
5575
5576| 类型                                                           | 说明                                                                                                          |
5577|--------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
5578| [AudioDataCallbackResult](#audiodatacallbackresult12) \| void | 如果返回 void 或 AudioDataCallbackResult.VALID:表示数据有效,将播放音频数据;如果返回 AudioDataCallbackResult.INVALID:表示数据无效,且音频数据不播放。 |
5579
5580## AudioRenderer<sup>8+</sup>
5581
5582提供音频渲染的相关接口。在调用AudioRenderer的接口前,需要先通过[createAudioRenderer](#audiocreateaudiorenderer8)创建实例。
5583
5584### 属性
5585
5586**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5587
5588| 名称  | 类型                     | 可读 | 可写 | 说明               |
5589| ----- | -------------------------- | ---- | ---- | ------------------ |
5590| state<sup>8+</sup> | [AudioState](#audiostate8) | 是   | 否   | 音频渲染器的状态。 |
5591
5592**示例:**
5593
5594```ts
5595import { audio } from '@kit.AudioKit';
5596
5597let state: audio.AudioState = audioRenderer.state;
5598```
5599
5600### getRendererInfo<sup>8+</sup>
5601
5602getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void
5603
5604获取当前被创建的音频渲染器的信息,使用callback方式异步返回结果。
5605
5606**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5607
5608**参数:**
5609
5610| 参数名   | 类型                                                     | 必填 | 说明                   |
5611| :------- | :------------------------------------------------------- | :--- | :--------------------- |
5612| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | 是   | 回调函数。当获取音频渲染器的信息成功,err为undefined,data为获取到的音频渲染器的信息;否则为错误对象。 |
5613
5614**示例:**
5615
5616```ts
5617import { BusinessError } from '@kit.BasicServicesKit';
5618
5619audioRenderer.getRendererInfo((err: BusinessError, rendererInfo: audio.AudioRendererInfo) => {
5620  console.info('Renderer GetRendererInfo:');
5621  console.info(`Renderer content: ${rendererInfo.content}`);
5622  console.info(`Renderer usage: ${rendererInfo.usage}`);
5623  console.info(`Renderer flags: ${rendererInfo.rendererFlags}`);
5624});
5625```
5626
5627### getRendererInfo<sup>8+</sup>
5628
5629getRendererInfo(): Promise<AudioRendererInfo\>
5630
5631获取当前被创建的音频渲染器的信息,使用Promise方式异步返回结果。
5632
5633**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5634
5635**返回值:**
5636
5637| 类型                                               | 说明                            |
5638| -------------------------------------------------- | ------------------------------- |
5639| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise对象,返回音频渲染器信息。 |
5640
5641**示例:**
5642
5643```ts
5644import { BusinessError } from '@kit.BasicServicesKit';
5645
5646audioRenderer.getRendererInfo().then((rendererInfo: audio.AudioRendererInfo) => {
5647  console.info('Renderer GetRendererInfo:');
5648  console.info(`Renderer content: ${rendererInfo.content}`);
5649  console.info(`Renderer usage: ${rendererInfo.usage}`);
5650  console.info(`Renderer flags: ${rendererInfo.rendererFlags}`)
5651}).catch((err: BusinessError) => {
5652  console.error(`AudioFrameworkRenderLog: RendererInfo :ERROR: ${err}`);
5653});
5654```
5655
5656### getRendererInfoSync<sup>10+</sup>
5657
5658getRendererInfoSync(): AudioRendererInfo
5659
5660获取当前被创建的音频渲染器的信息,同步返回结果。
5661
5662**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5663
5664**返回值:**
5665
5666| 类型                                               | 说明                            |
5667| -------------------------------------------------- | ------------------------------- |
5668| [AudioRendererInfo](#audiorendererinfo8) | 返回音频渲染器信息。 |
5669
5670**示例:**
5671
5672```ts
5673import { BusinessError } from '@kit.BasicServicesKit';
5674
5675try {
5676  let rendererInfo: audio.AudioRendererInfo = audioRenderer.getRendererInfoSync();
5677  console.info(`Renderer content: ${rendererInfo.content}`);
5678  console.info(`Renderer usage: ${rendererInfo.usage}`);
5679  console.info(`Renderer flags: ${rendererInfo.rendererFlags}`)
5680} catch (err) {
5681  let error = err as BusinessError;
5682  console.error(`AudioFrameworkRenderLog: RendererInfo :ERROR: ${error}`);
5683}
5684```
5685
5686### getStreamInfo<sup>8+</sup>
5687
5688getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
5689
5690获取音频流信息,使用callback方式异步返回结果。
5691
5692**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5693
5694**参数:**
5695
5696| 参数名   | 类型                                                 | 必填 | 说明                 |
5697| :------- | :--------------------------------------------------- | :--- | :------------------- |
5698| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | 是   | 回调函数。当获取音频流信息成功,err为undefined,data为获取到的音频流信息;否则为错误对象。 |
5699
5700**示例:**
5701
5702```ts
5703import { BusinessError } from '@kit.BasicServicesKit';
5704
5705audioRenderer.getStreamInfo((err: BusinessError, streamInfo: audio.AudioStreamInfo) => {
5706  console.info('Renderer GetStreamInfo:');
5707  console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
5708  console.info(`Renderer channel: ${streamInfo.channels}`);
5709  console.info(`Renderer format: ${streamInfo.sampleFormat}`);
5710  console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
5711});
5712```
5713
5714### getStreamInfo<sup>8+</sup>
5715
5716getStreamInfo(): Promise<AudioStreamInfo\>
5717
5718获取音频流信息,使用Promise方式异步返回结果。
5719
5720**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5721
5722**返回值:**
5723
5724| 类型                                           | 说明                   |
5725| :--------------------------------------------- | :--------------------- |
5726| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise对象,返回音频流信息. |
5727
5728**示例:**
5729
5730```ts
5731import { BusinessError } from '@kit.BasicServicesKit';
5732
5733audioRenderer.getStreamInfo().then((streamInfo: audio.AudioStreamInfo) => {
5734  console.info('Renderer GetStreamInfo:');
5735  console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
5736  console.info(`Renderer channel: ${streamInfo.channels}`);
5737  console.info(`Renderer format: ${streamInfo.sampleFormat}`);
5738  console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
5739}).catch((err: BusinessError) => {
5740  console.error(`ERROR: ${err}`);
5741});
5742```
5743
5744### getStreamInfoSync<sup>10+</sup>
5745
5746getStreamInfoSync(): AudioStreamInfo
5747
5748获取音频流信息,同步返回结果。
5749
5750**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5751
5752**返回值:**
5753
5754| 类型                                           | 说明                   |
5755| :--------------------------------------------- | :--------------------- |
5756| [AudioStreamInfo](#audiostreaminfo8) | 返回音频流信息. |
5757
5758**示例:**
5759
5760```ts
5761import { BusinessError } from '@kit.BasicServicesKit';
5762
5763try {
5764  let streamInfo: audio.AudioStreamInfo = audioRenderer.getStreamInfoSync();
5765  console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
5766  console.info(`Renderer channel: ${streamInfo.channels}`);
5767  console.info(`Renderer format: ${streamInfo.sampleFormat}`);
5768  console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
5769} catch (err) {
5770  let error = err as BusinessError;
5771  console.error(`ERROR: ${error}`);
5772}
5773```
5774
5775### getAudioStreamId<sup>9+</sup>
5776
5777getAudioStreamId(callback: AsyncCallback<number\>): void
5778
5779获取音频流id,使用callback方式异步返回结果。
5780
5781**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5782
5783**参数:**
5784
5785| 参数名   | 类型                                                 | 必填 | 说明                 |
5786| :------- | :--------------------------------------------------- | :--- | :------------------- |
5787| callback | AsyncCallback<number\> | 是   | 回调函数。当获取音频流id成功,err为undefined,data为获取到的音频流id;否则为错误对象。 |
5788
5789**示例:**
5790
5791```ts
5792import { BusinessError } from '@kit.BasicServicesKit';
5793
5794audioRenderer.getAudioStreamId((err: BusinessError, streamId: number) => {
5795  console.info(`Renderer GetStreamId: ${streamId}`);
5796});
5797```
5798
5799### getAudioStreamId<sup>9+</sup>
5800
5801getAudioStreamId(): Promise<number\>
5802
5803获取音频流id,使用Promise方式异步返回结果。
5804
5805**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5806
5807**返回值:**
5808
5809| 类型                                           | 说明                   |
5810| :--------------------------------------------- | :--------------------- |
5811| Promise<number\> | Promise对象,返回音频流id。 |
5812
5813**示例:**
5814
5815```ts
5816import { BusinessError } from '@kit.BasicServicesKit';
5817
5818audioRenderer.getAudioStreamId().then((streamId: number) => {
5819  console.info(`Renderer getAudioStreamId: ${streamId}`);
5820}).catch((err: BusinessError) => {
5821  console.error(`ERROR: ${err}`);
5822});
5823```
5824
5825### getAudioStreamIdSync<sup>10+</sup>
5826
5827getAudioStreamIdSync(): number
5828
5829获取音频流id,同步返回结果。
5830
5831**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5832
5833**返回值:**
5834
5835| 类型                                           | 说明                   |
5836| :--------------------------------------------- | :--------------------- |
5837| number | 返回音频流id。 |
5838
5839**示例:**
5840
5841```ts
5842import { BusinessError } from '@kit.BasicServicesKit';
5843
5844try {
5845  let streamId: number = audioRenderer.getAudioStreamIdSync();
5846  console.info(`Renderer getAudioStreamIdSync: ${streamId}`);
5847} catch (err) {
5848  let error = err as BusinessError;
5849  console.error(`ERROR: ${error}`);
5850}
5851```
5852
5853### setAudioEffectMode<sup>10+</sup>
5854
5855setAudioEffectMode(mode: AudioEffectMode, callback: AsyncCallback\<void>): void
5856
5857设置当前音效模式。使用callback方式异步返回结果。
5858
5859**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5860
5861**参数:**
5862
5863| 参数名   | 类型                                     | 必填 | 说明                     |
5864| -------- | ---------------------------------------- | ---- | ------------------------ |
5865| mode     | [AudioEffectMode](#audioeffectmode10)    | 是   | 音效模式。               |
5866| callback | AsyncCallback\<void>                     | 是   | 回调函数。当设置当前音效模式成功,err为undefined,否则为错误对象。 |
5867
5868**错误码:**
5869
5870以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
5871
5872| 错误码ID | 错误信息 |
5873| ------- | ----------------------------------------------|
5874| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
5875| 6800101 | Parameter verification failed. Return by callback.  |
5876
5877**示例:**
5878
5879```ts
5880import { BusinessError } from '@kit.BasicServicesKit';
5881
5882audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_DEFAULT, (err: BusinessError) => {
5883  if (err) {
5884    console.error('Failed to set params');
5885  } else {
5886    console.info('Callback invoked to indicate a successful audio effect mode setting.');
5887  }
5888});
5889```
5890
5891### setAudioEffectMode<sup>10+</sup>
5892
5893setAudioEffectMode(mode: AudioEffectMode): Promise\<void>
5894
5895设置当前音效模式。使用Promise方式异步返回结果。
5896
5897**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5898
5899**参数:**
5900
5901| 参数名 | 类型                                     | 必填 | 说明         |
5902| ------ | ---------------------------------------- | ---- | ------------ |
5903| mode   | [AudioEffectMode](#audioeffectmode10)   | 是   | 音效模式。 |
5904
5905**返回值:**
5906
5907| 类型           | 说明                      |
5908| -------------- | ------------------------- |
5909| Promise\<void> | Promise对象,无返回结果。 |
5910
5911**错误码:**
5912
5913以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
5914
5915| 错误码ID | 错误信息 |
5916| ------- | ---------------------------------------------|
5917| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
5918| 6800101 | Parameter verification failed. Return by promise. |
5919
5920**示例:**
5921
5922```ts
5923import { BusinessError } from '@kit.BasicServicesKit';
5924
5925audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_DEFAULT).then(() => {
5926  console.info('setAudioEffectMode SUCCESS');
5927}).catch((err: BusinessError) => {
5928  console.error(`ERROR: ${err}`);
5929});
5930```
5931
5932### getAudioEffectMode<sup>10+</sup>
5933
5934getAudioEffectMode(callback: AsyncCallback\<AudioEffectMode>): void
5935
5936获取当前音效模式。使用callback方式异步返回结果。
5937
5938**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5939
5940**参数:**
5941
5942| 参数名   | 类型                                                    | 必填 | 说明               |
5943| -------- | ------------------------------------------------------- | ---- | ------------------ |
5944| callback | AsyncCallback<[AudioEffectMode](#audioeffectmode10)> | 是   | 回调函数。当获取当前音效模式成功,err为undefined,data为获取到的当前音效模式;否则为错误对象。 |
5945
5946**示例:**
5947
5948```ts
5949import { BusinessError } from '@kit.BasicServicesKit';
5950
5951audioRenderer.getAudioEffectMode((err: BusinessError, effectMode: audio.AudioEffectMode) => {
5952  if (err) {
5953    console.error('Failed to get params');
5954  } else {
5955    console.info(`getAudioEffectMode: ${effectMode}`);
5956  }
5957});
5958```
5959
5960### getAudioEffectMode<sup>10+</sup>
5961
5962getAudioEffectMode(): Promise\<AudioEffectMode>
5963
5964获取当前音效模式。使用Promise方式异步返回结果。
5965
5966**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5967
5968**返回值:**
5969
5970| 类型                                              | 说明                      |
5971| ------------------------------------------------- | ------------------------- |
5972| Promise<[AudioEffectMode](#audioeffectmode10)> | Promise对象,返回当前音效模式。 |
5973
5974**示例:**
5975
5976```ts
5977import { BusinessError } from '@kit.BasicServicesKit';
5978
5979audioRenderer.getAudioEffectMode().then((effectMode: audio.AudioEffectMode) => {
5980  console.info(`getAudioEffectMode: ${effectMode}`);
5981}).catch((err: BusinessError) => {
5982  console.error(`ERROR: ${err}`);
5983});
5984```
5985
5986### start<sup>8+</sup>
5987
5988start(callback: AsyncCallback<void\>): void
5989
5990启动音频渲染器。使用callback方式异步返回结果。
5991
5992**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5993
5994**参数:**
5995
5996| 参数名   | 类型                 | 必填 | 说明       |
5997| -------- | -------------------- | ---- | ---------- |
5998| callback | AsyncCallback\<void> | 是   | Callback对象,成功表示启动音频采集器成功,异常将返回error对象:<br>错误码6800301,表示包含状态检查异常、焦点抢占失败、系统处理异常(具体错误查看系统日志)。 |
5999
6000**示例:**
6001
6002```ts
6003import { BusinessError } from '@kit.BasicServicesKit';
6004
6005audioRenderer.start((err: BusinessError) => {
6006  if (err) {
6007    console.error('Renderer start failed.');
6008  } else {
6009    console.info('Renderer start success.');
6010  }
6011});
6012```
6013
6014### start<sup>8+</sup>
6015
6016start(): Promise<void\>
6017
6018启动音频渲染器。使用Promise方式异步返回结果。
6019
6020**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6021
6022**返回值:**
6023
6024| 类型           | 说明                      |
6025| -------------- | ------------------------- |
6026| Promise\<void> | Promise对象,成功表示启动音频采集器成功,异常将返回error对象:<br>错误码6800301,表示包含状态检查异常、焦点抢占失败、系统处理异常(具体错误查看系统日志)。 |
6027
6028**示例:**
6029
6030```ts
6031import { BusinessError } from '@kit.BasicServicesKit';
6032
6033audioRenderer.start().then(() => {
6034  console.info('Renderer started');
6035}).catch((err: BusinessError) => {
6036  console.error(`ERROR: ${err}`);
6037});
6038```
6039
6040### pause<sup>8+</sup>
6041
6042pause(callback: AsyncCallback\<void>): void
6043
6044暂停渲染。使用callback方式异步返回结果。
6045
6046**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6047
6048**参数:**
6049
6050| 参数名   | 类型                 | 必填 | 说明             |
6051| -------- | -------------------- | ---- | ---------------- |
6052| callback | AsyncCallback\<void> | 是   | 回调函数。当暂停渲染成功,err为undefined,否则为错误对象。 |
6053
6054**示例:**
6055
6056```ts
6057import { BusinessError } from '@kit.BasicServicesKit';
6058
6059audioRenderer.pause((err: BusinessError) => {
6060  if (err) {
6061    console.error('Renderer pause failed');
6062  } else {
6063    console.info('Renderer paused.');
6064  }
6065});
6066```
6067
6068### pause<sup>8+</sup>
6069
6070pause(): Promise\<void>
6071
6072暂停渲染。使用Promise方式异步返回结果。
6073
6074**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6075
6076**返回值:**
6077
6078| 类型           | 说明                      |
6079| -------------- | ------------------------- |
6080| Promise\<void> | Promise对象,无返回结果。 |
6081
6082**示例:**
6083
6084```ts
6085import { BusinessError } from '@kit.BasicServicesKit';
6086
6087audioRenderer.pause().then(() => {
6088  console.info('Renderer paused');
6089}).catch((err: BusinessError) => {
6090  console.error(`ERROR: ${err}`);
6091});
6092```
6093
6094### drain<sup>8+</sup>
6095
6096drain(callback: AsyncCallback\<void>): void
6097
6098检查缓冲区是否已被耗尽。使用callback方式异步返回结果。
6099
6100**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6101
6102**参数:**
6103
6104| 参数名   | 类型                 | 必填 | 说明             |
6105| -------- | -------------------- | ---- | ---------------- |
6106| callback | AsyncCallback\<void> | 是   | 回调函数。当检查缓冲区是否已被耗尽成功,err为undefined,否则为错误对象。 |
6107
6108**示例:**
6109
6110```ts
6111import { BusinessError } from '@kit.BasicServicesKit';
6112
6113audioRenderer.drain((err: BusinessError) => {
6114  if (err) {
6115    console.error('Renderer drain failed');
6116  } else {
6117    console.info('Renderer drained.');
6118  }
6119});
6120```
6121
6122### drain<sup>8+</sup>
6123
6124drain(): Promise\<void>
6125
6126检查缓冲区是否已被耗尽。使用Promise方式异步返回结果。
6127
6128**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6129
6130**返回值:**
6131
6132| 类型           | 说明                      |
6133| -------------- | ------------------------- |
6134| Promise\<void> | Promise对象,无返回结果。 |
6135
6136**示例:**
6137
6138```ts
6139import { BusinessError } from '@kit.BasicServicesKit';
6140
6141audioRenderer.drain().then(() => {
6142  console.info('Renderer drained successfully');
6143}).catch((err: BusinessError) => {
6144  console.error(`ERROR: ${err}`);
6145});
6146```
6147
6148### flush<sup>11+</sup>
6149
6150flush(): Promise\<void>
6151
6152清空缓冲区([AudioState](#audiostate8)为STATE_RUNNING、STATE_PAUSED、STATE_STOPPED状态下可用)。使用Promise方式异步返回结果。
6153
6154**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6155
6156**返回值:**
6157
6158| 类型           | 说明                      |
6159| -------------- | ------------------------- |
6160| Promise\<void> | Promise对象,无返回结果。 |
6161
6162**错误码:**
6163
6164以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
6165
6166| 错误码ID | 错误信息 |
6167| ------- | --------------------------------------------|
6168| 6800103 | Operation not permit at current state. Return by promise. |
6169
6170**示例:**
6171
6172```ts
6173import { BusinessError } from '@kit.BasicServicesKit';
6174
6175audioRenderer.flush().then(() => {
6176  console.info('Renderer flushed successfully');
6177}).catch((err: BusinessError) => {
6178  console.error(`ERROR: ${err}`);
6179});
6180```
6181
6182### stop<sup>8+</sup>
6183
6184stop(callback: AsyncCallback\<void>): void
6185
6186停止渲染。使用callback方式异步返回结果。
6187
6188**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6189
6190**参数:**
6191
6192| 参数名   | 类型                 | 必填 | 说明             |
6193| -------- | -------------------- | ---- | ---------------- |
6194| callback | AsyncCallback\<void> | 是   | 回调函数。当停止渲染成功,err为undefined,否则为错误对象。 |
6195
6196**示例:**
6197
6198```ts
6199import { BusinessError } from '@kit.BasicServicesKit';
6200
6201audioRenderer.stop((err: BusinessError) => {
6202  if (err) {
6203    console.error('Renderer stop failed');
6204  } else {
6205    console.info('Renderer stopped.');
6206  }
6207});
6208```
6209
6210### stop<sup>8+</sup>
6211
6212stop(): Promise\<void>
6213
6214停止渲染。使用Promise方式异步返回结果。
6215
6216**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6217
6218**返回值:**
6219
6220| 类型           | 说明                      |
6221| -------------- | ------------------------- |
6222| Promise\<void> | Promise对象,无返回结果。 |
6223
6224**示例:**
6225
6226```ts
6227import { BusinessError } from '@kit.BasicServicesKit';
6228
6229audioRenderer.stop().then(() => {
6230  console.info('Renderer stopped successfully');
6231}).catch((err: BusinessError) => {
6232  console.error(`ERROR: ${err}`);
6233});
6234```
6235
6236### release<sup>8+</sup>
6237
6238release(callback: AsyncCallback\<void>): void
6239
6240释放音频渲染器。使用callback方式异步返回结果。
6241
6242**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6243
6244**参数:**
6245
6246| 参数名   | 类型                 | 必填 | 说明             |
6247| -------- | -------------------- | ---- | ---------------- |
6248| callback | AsyncCallback\<void> | 是   | 回调函数。当释放音频渲染器成功,err为undefined,否则为错误对象。 |
6249
6250**示例:**
6251
6252```ts
6253import { BusinessError } from '@kit.BasicServicesKit';
6254
6255audioRenderer.release((err: BusinessError) => {
6256  if (err) {
6257    console.error('Renderer release failed');
6258  } else {
6259    console.info('Renderer released.');
6260  }
6261});
6262```
6263
6264### release<sup>8+</sup>
6265
6266release(): Promise\<void>
6267
6268释放渲染器。使用Promise方式异步返回结果。
6269
6270**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6271
6272**返回值:**
6273
6274| 类型           | 说明                      |
6275| -------------- | ------------------------- |
6276| Promise\<void> | Promise对象,无返回结果。 |
6277
6278**示例:**
6279
6280```ts
6281import { BusinessError } from '@kit.BasicServicesKit';
6282
6283audioRenderer.release().then(() => {
6284  console.info('Renderer released successfully');
6285}).catch((err: BusinessError) => {
6286  console.error(`ERROR: ${err}`);
6287});
6288```
6289
6290### write<sup>8+(deprecated)</sup>
6291
6292write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void
6293
6294写入缓冲区。使用callback方式异步返回结果。
6295
6296> **说明:**
6297> 从 API version 8 开始支持,从 API version 11 开始废弃,建议使用AudioRenderer中的[on('writeData')](#onwritedata11)替代。
6298
6299**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6300
6301**参数:**
6302
6303| 参数名   | 类型                   | 必填 | 说明                                                |
6304| -------- | ---------------------- | ---- | --------------------------------------------------- |
6305| buffer   | ArrayBuffer            | 是   | 要写入缓冲区的数据。                                |
6306| callback | AsyncCallback\<number> | 是   | 回调函数。当写入缓冲区成功,err为undefined,data为获取到的写入的字节数;否则为错误对象。 |
6307
6308**示例:**
6309
6310```ts
6311import { BusinessError } from '@kit.BasicServicesKit';
6312import { fileIo as fs } from '@kit.CoreFileKit';
6313
6314let bufferSize: number;
6315class Options {
6316  offset?: number;
6317  length?: number;
6318}
6319audioRenderer.getBufferSize().then((data: number)=> {
6320  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
6321  bufferSize = data;
6322  console.info(`Buffer size: ${bufferSize}`);
6323  let path = getContext().cacheDir;
6324  let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
6325  let file: fs.File = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
6326  fs.stat(filePath).then(async (stat: fs.Stat) => {
6327    let buf = new ArrayBuffer(bufferSize);
6328    let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1);
6329    for (let i = 0;i < len; i++) {
6330      let options: Options = {
6331        offset: i * bufferSize,
6332        length: bufferSize
6333      };
6334      let readSize: number = await fs.read(file.fd, buf, options);
6335      let writeSize: number = await new Promise((resolve,reject)=>{
6336        audioRenderer.write(buf,(err: BusinessError, writeSize: number)=>{
6337          if(err){
6338            reject(err)
6339          }else{
6340            resolve(writeSize)
6341          }
6342        })
6343      })
6344    }
6345  });
6346  }).catch((err: BusinessError) => {
6347    console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
6348});
6349```
6350
6351### write<sup>8+(deprecated)</sup>
6352
6353write(buffer: ArrayBuffer): Promise\<number>
6354
6355写入缓冲区。使用Promise方式异步返回结果。
6356
6357> **说明:**
6358> 从 API version 8 开始支持,从 API version 11 开始废弃,建议使用AudioRenderer中的[on('writeData')](#onwritedata11)替代。
6359
6360**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6361
6362**参数:**
6363
6364| 参数名   | 类型                   | 必填 | 说明                                                |
6365| -------- | ---------------------- | ---- | --------------------------------------------------- |
6366| buffer   | ArrayBuffer            | 是   | 要写入缓冲区的数据。                                |
6367
6368**返回值:**
6369
6370| 类型             | 说明                                                         |
6371| ---------------- | ------------------------------------------------------------ |
6372| Promise\<number> | Promise对象,返回写入的字节数。 |
6373
6374**示例:**
6375
6376```ts
6377import { BusinessError } from '@kit.BasicServicesKit';
6378import { fileIo as fs } from '@kit.CoreFileKit';
6379
6380let bufferSize: number;
6381class Options {
6382  offset?: number;
6383  length?: number;
6384}
6385audioRenderer.getBufferSize().then((data: number) => {
6386  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
6387  bufferSize = data;
6388  console.info(`BufferSize: ${bufferSize}`);
6389  let path = getContext().cacheDir;
6390  let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
6391  let file: fs.File = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
6392  fs.stat(filePath).then(async (stat: fs.Stat) => {
6393    let buf = new ArrayBuffer(bufferSize);
6394    let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1);
6395    for (let i = 0;i < len; i++) {
6396      let options: Options = {
6397        offset: i * bufferSize,
6398        length: bufferSize
6399      };
6400      let readSize: number = await fs.read(file.fd, buf, options);
6401      try{
6402        let writeSize: number = await audioRenderer.write(buf);
6403      } catch(err) {
6404        let error = err as BusinessError;
6405        console.error(`audioRenderer.write err: ${error}`);
6406      }
6407    }
6408  });
6409}).catch((err: BusinessError) => {
6410  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
6411});
6412```
6413
6414### getAudioTime<sup>8+</sup>
6415
6416getAudioTime(callback: AsyncCallback\<number>): void
6417
6418获取播放到当前位置时的时间戳(从 1970 年 1 月 1 日开始),单位为纳秒。使用callback方式异步返回结果。
6419
6420**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6421
6422**参数:**
6423
6424| 参数名   | 类型                   | 必填 | 说明             |
6425| -------- | ---------------------- | ---- | ---------------- |
6426| callback | AsyncCallback\<number> | 是   | 回调函数。当获取时间戳成功,err为undefined,data为获取到的时间戳;否则为错误对象。 |
6427
6428**示例:**
6429
6430```ts
6431import { BusinessError } from '@kit.BasicServicesKit';
6432
6433audioRenderer.getAudioTime((err: BusinessError, timestamp: number) => {
6434  console.info(`Current timestamp: ${timestamp}`);
6435});
6436```
6437
6438### getAudioTime<sup>8+</sup>
6439
6440getAudioTime(): Promise\<number>
6441
6442获取播放到当前位置时的时间戳(从 1970 年 1 月 1 日开始),单位为纳秒。使用Promise方式异步返回结果。
6443
6444**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6445
6446**返回值:**
6447
6448| 类型             | 描述                    |
6449| ---------------- | ----------------------- |
6450| Promise\<number> | Promise对象,返回时间戳。 |
6451
6452**示例:**
6453
6454```ts
6455import { BusinessError } from '@kit.BasicServicesKit';
6456
6457audioRenderer.getAudioTime().then((timestamp: number) => {
6458  console.info(`Current timestamp: ${timestamp}`);
6459}).catch((err: BusinessError) => {
6460  console.error(`ERROR: ${err}`);
6461});
6462```
6463
6464### getAudioTimeSync<sup>10+</sup>
6465
6466getAudioTimeSync(): number
6467
6468获取播放到当前位置时的时间戳(从 1970 年 1 月 1 日开始),单位为纳秒。同步返回结果。
6469
6470**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6471
6472**返回值:**
6473
6474| 类型             | 描述                    |
6475| ---------------- | ----------------------- |
6476| number | 返回时间戳。 |
6477
6478**示例:**
6479
6480```ts
6481import { BusinessError } from '@kit.BasicServicesKit';
6482
6483try {
6484  let timestamp: number = audioRenderer.getAudioTimeSync();
6485  console.info(`Current timestamp: ${timestamp}`);
6486} catch (err) {
6487  let error = err as BusinessError;
6488  console.error(`ERROR: ${error}`);
6489}
6490```
6491
6492### getBufferSize<sup>8+</sup>
6493
6494getBufferSize(callback: AsyncCallback\<number>): void
6495
6496获取音频渲染器的最小缓冲区大小。使用callback方式异步返回结果。
6497
6498**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6499
6500**参数:**
6501
6502| 参数名   | 类型                   | 必填 | 说明                 |
6503| -------- | ---------------------- | ---- | -------------------- |
6504| callback | AsyncCallback\<number> | 是   | 回调函数。当获取音频渲染器的最小缓冲区大小成功,err为undefined,data为获取到的最小缓冲区大小;否则为错误对象。 |
6505
6506**示例:**
6507
6508```ts
6509import { BusinessError } from '@kit.BasicServicesKit';
6510
6511let bufferSize: number;
6512
6513audioRenderer.getBufferSize((err: BusinessError, data: number) => {
6514  if (err) {
6515    console.error('getBufferSize error');
6516  } else {
6517    console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
6518    bufferSize = data;
6519  }
6520});
6521```
6522
6523### getBufferSize<sup>8+</sup>
6524
6525getBufferSize(): Promise\<number>
6526
6527获取音频渲染器的最小缓冲区大小。使用Promise方式异步返回结果。
6528
6529**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6530
6531**返回值:**
6532
6533| 类型             | 说明                        |
6534| ---------------- | --------------------------- |
6535| Promise\<number> | Promise对象,返回缓冲区大小。 |
6536
6537**示例:**
6538
6539```ts
6540import { BusinessError } from '@kit.BasicServicesKit';
6541
6542let bufferSize: number;
6543
6544audioRenderer.getBufferSize().then((data: number) => {
6545  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
6546  bufferSize = data;
6547}).catch((err: BusinessError) => {
6548  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
6549});
6550```
6551
6552### getBufferSizeSync<sup>10+</sup>
6553
6554getBufferSizeSync(): number
6555
6556获取音频渲染器的最小缓冲区大小,同步返回结果。
6557
6558**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6559
6560**返回值:**
6561
6562| 类型             | 说明                        |
6563| ---------------- | --------------------------- |
6564| number | 返回缓冲区大小。 |
6565
6566**示例:**
6567
6568```ts
6569import { BusinessError } from '@kit.BasicServicesKit';
6570
6571let bufferSize: number = 0;
6572
6573try {
6574  bufferSize = audioRenderer.getBufferSizeSync();
6575  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${bufferSize}`);
6576} catch (err) {
6577  let error = err as BusinessError;
6578  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${error}`);
6579}
6580```
6581
6582### setRenderRate<sup>8+(deprecated)</sup>
6583
6584setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\<void>): void
6585
6586设置音频渲染速率。使用callback方式异步返回结果。
6587
6588> **说明:**
6589> 从 API version 8 开始支持,从 API version 11 开始废弃。建议使用AudioRenderer中的[setSpeed](#setspeed11)替代。
6590
6591**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6592
6593**参数:**
6594
6595| 参数名   | 类型                                     | 必填 | 说明                     |
6596| -------- | ---------------------------------------- | ---- | ------------------------ |
6597| rate     | [AudioRendererRate](#audiorendererrate8) | 是   | 渲染的速率。             |
6598| callback | AsyncCallback\<void>                     | 是   | 回调函数。当设置音频渲染速率成功,err为undefined,否则为错误对象。 |
6599
6600**示例:**
6601
6602```ts
6603import { BusinessError } from '@kit.BasicServicesKit';
6604
6605audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err: BusinessError) => {
6606  if (err) {
6607    console.error('Failed to set params');
6608  } else {
6609    console.info('Callback invoked to indicate a successful render rate setting.');
6610  }
6611});
6612```
6613
6614### setRenderRate<sup>8+(deprecated)</sup>
6615
6616setRenderRate(rate: AudioRendererRate): Promise\<void>
6617
6618设置音频渲染速率。使用Promise方式异步返回结果。
6619
6620> **说明:**
6621> 从 API version 8 开始支持,从 API version 11 开始废弃。建议使用AudioRenderer中的[setSpeed](#setspeed11)替代。
6622
6623**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6624
6625**参数:**
6626
6627| 参数名 | 类型                                     | 必填 | 说明         |
6628| ------ | ---------------------------------------- | ---- | ------------ |
6629| rate   | [AudioRendererRate](#audiorendererrate8) | 是   | 渲染的速率。 |
6630
6631**返回值:**
6632
6633| 类型           | 说明                      |
6634| -------------- | ------------------------- |
6635| Promise\<void> | Promise对象,无返回结果。 |
6636
6637**示例:**
6638
6639```ts
6640import { BusinessError } from '@kit.BasicServicesKit';
6641
6642audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
6643  console.info('setRenderRate SUCCESS');
6644}).catch((err: BusinessError) => {
6645  console.error(`ERROR: ${err}`);
6646});
6647```
6648
6649### setSpeed<sup>11+</sup>
6650
6651setSpeed(speed: number): void
6652
6653设置播放倍速。
6654
6655**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6656
6657**参数:**
6658
6659| 参数名 | 类型                                     | 必填 | 说明                   |
6660| ------ | ---------------------------------------- | ---- |----------------------|
6661| speed | number | 是   | 设置播放的倍速值(倍速范围:0.125-4.0)。 |
6662
6663**错误码:**
6664
6665以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
6666
6667| 错误码ID | 错误信息 |
6668| ------- | --------------------------------------------|
6669| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
6670| 6800101 | Parameter verification failed. |
6671
6672**示例:**
6673
6674```ts
6675audioRenderer.setSpeed(1.5);
6676```
6677
6678### getRenderRate<sup>8+(deprecated)</sup>
6679
6680getRenderRate(callback: AsyncCallback\<AudioRendererRate>): void
6681
6682获取当前渲染速率。使用callback方式异步返回结果。
6683
6684> **说明:**
6685> 从 API version 8 开始支持,从 API version 11 开始废弃。建议使用AudioRenderer中的[getSpeed](#getspeed11)替代。
6686
6687**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6688
6689**参数:**
6690
6691| 参数名   | 类型                                                    | 必填 | 说明               |
6692| -------- | ------------------------------------------------------- | ---- | ------------------ |
6693| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | 是   | 回调函数。当获取当前渲染速率成功,err为undefined,data为获取到的当前渲染速率;否则为错误对象。 |
6694
6695**示例:**
6696
6697```ts
6698import { BusinessError } from '@kit.BasicServicesKit';
6699
6700audioRenderer.getRenderRate((err: BusinessError, renderRate: audio.AudioRendererRate) => {
6701  console.info(`getRenderRate: ${renderRate}`);
6702});
6703```
6704
6705### getRenderRate<sup>8+(deprecated)</sup>
6706
6707getRenderRate(): Promise\<AudioRendererRate>
6708
6709获取当前渲染速率。使用Promise方式异步返回结果。
6710
6711> **说明:**
6712> 从 API version 8 开始支持,从 API version 11 开始废弃。建议使用AudioRenderer中的[getSpeed](#getspeed11)替代。
6713
6714**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6715
6716**返回值:**
6717
6718| 类型                                              | 说明                      |
6719| ------------------------------------------------- | ------------------------- |
6720| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise对象,返回渲染速率。 |
6721
6722**示例:**
6723
6724```ts
6725import { BusinessError } from '@kit.BasicServicesKit';
6726
6727audioRenderer.getRenderRate().then((renderRate: audio.AudioRendererRate) => {
6728  console.info(`getRenderRate: ${renderRate}`);
6729}).catch((err: BusinessError) => {
6730  console.error(`ERROR: ${err}`);
6731});
6732```
6733
6734### getRenderRateSync<sup>10+(deprecated)</sup>
6735
6736getRenderRateSync(): AudioRendererRate
6737
6738获取当前渲染速率,同步返回结果。
6739
6740> **说明:**
6741> 从 API version 10 开始支持,从 API version 11 开始废弃。建议使用AudioRenderer中的[getSpeed](#getspeed11)替代。
6742
6743**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6744
6745**返回值:**
6746
6747| 类型                                              | 说明                      |
6748| ------------------------------------------------- | ------------------------- |
6749| [AudioRendererRate](#audiorendererrate8) | 返回渲染速率。 |
6750
6751**示例:**
6752
6753```ts
6754import { BusinessError } from '@kit.BasicServicesKit';
6755
6756try {
6757  let renderRate: audio.AudioRendererRate = audioRenderer.getRenderRateSync();
6758  console.info(`getRenderRate: ${renderRate}`);
6759} catch (err) {
6760  let error = err as BusinessError;
6761  console.error(`ERROR: ${error}`);
6762}
6763```
6764
6765### getSpeed<sup>11+</sup>
6766
6767getSpeed(): number
6768
6769获取播放倍速。
6770
6771**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6772
6773**返回值:**
6774
6775| 类型                                              | 说明        |
6776| ------------------------------------------------- |-----------|
6777| number | 返回播放的倍速值。 |
6778
6779**示例:**
6780
6781```ts
6782let speed = audioRenderer.getSpeed();
6783```
6784
6785### setInterruptMode<sup>9+</sup>
6786
6787setInterruptMode(mode: InterruptMode): Promise&lt;void&gt;
6788
6789设置应用的焦点模型。使用Promise异步回调。
6790
6791**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
6792
6793**参数:**
6794
6795| 参数名     | 类型                                | 必填   | 说明        |
6796| ---------- | ---------------------------------- | ------ | ---------- |
6797| mode       | [InterruptMode](#interruptmode9)    | 是     | 焦点模型。  |
6798
6799**返回值:**
6800
6801| 类型                | 说明                          |
6802| ------------------- | ----------------------------- |
6803| Promise&lt;void&gt; | Promise对象,无返回结果。 |
6804
6805**示例:**
6806
6807```ts
6808import { BusinessError } from '@kit.BasicServicesKit';
6809
6810let mode = 0;
6811
6812audioRenderer.setInterruptMode(mode).then(() => {
6813  console.info('setInterruptMode Success!');
6814}).catch((err: BusinessError) => {
6815  console.error(`setInterruptMode Fail: ${err}`);
6816});
6817```
6818### setInterruptMode<sup>9+</sup>
6819
6820setInterruptMode(mode: InterruptMode, callback: AsyncCallback\<void>): void
6821
6822设置应用的焦点模型。使用Callback回调返回执行结果。
6823
6824**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
6825
6826**参数:**
6827
6828| 参数名   | 类型                                | 必填   | 说明            |
6829| ------- | ----------------------------------- | ------ | -------------- |
6830|mode     | [InterruptMode](#interruptmode9)     | 是     | 焦点模型。|
6831|callback | AsyncCallback\<void>                 | 是     |回调函数。当设置应用的焦点模型成功,err为undefined,否则为错误对象。|
6832
6833**示例:**
6834
6835```ts
6836import { BusinessError } from '@kit.BasicServicesKit';
6837
6838let mode = 1;
6839
6840audioRenderer.setInterruptMode(mode, (err: BusinessError) => {
6841  if(err){
6842    console.error(`setInterruptMode Fail: ${err}`);
6843  }
6844  console.info('setInterruptMode Success!');
6845});
6846```
6847
6848### setInterruptModeSync<sup>10+</sup>
6849
6850setInterruptModeSync(mode: InterruptMode): void
6851
6852设置应用的焦点模型,同步设置。
6853
6854**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
6855
6856**参数:**
6857
6858| 参数名     | 类型                                | 必填   | 说明        |
6859| ---------- | ---------------------------------- | ------ | ---------- |
6860| mode       | [InterruptMode](#interruptmode9)    | 是     | 焦点模型。  |
6861
6862**错误码:**
6863
6864以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
6865
6866| 错误码ID | 错误信息 |
6867| ------- | --------------------------------------------|
6868| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
6869| 6800101 | Parameter verification failed. |
6870
6871**示例:**
6872
6873```ts
6874import { BusinessError } from '@kit.BasicServicesKit';
6875
6876try {
6877  audioRenderer.setInterruptModeSync(0);
6878  console.info('setInterruptMode Success!');
6879} catch (err) {
6880  let error = err as BusinessError;
6881  console.error(`setInterruptMode Fail: ${error}`);
6882}
6883```
6884
6885### setVolume<sup>9+</sup>
6886
6887setVolume(volume: number): Promise&lt;void&gt;
6888
6889设置应用的音量。使用Promise异步回调。
6890
6891**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6892
6893**参数:**
6894
6895| 参数名     | 类型    | 必填   | 说明                 |
6896| ---------- | ------- | ------ | ------------------- |
6897| volume     | number  | 是     | 音量值范围为0.0-1.0。 |
6898
6899**返回值:**
6900
6901| 类型                | 说明                          |
6902| ------------------- | ----------------------------- |
6903| Promise&lt;void&gt; | Promise对象,无返回结果。 |
6904
6905**示例:**
6906
6907```ts
6908import { BusinessError } from '@kit.BasicServicesKit';
6909
6910audioRenderer.setVolume(0.5).then(() => {
6911  console.info('setVolume Success!');
6912}).catch((err: BusinessError) => {
6913  console.error(`setVolume Fail: ${err}`);
6914});
6915```
6916### setVolume<sup>9+</sup>
6917
6918setVolume(volume: number, callback: AsyncCallback\<void>): void
6919
6920设置应用的音量。使用Callback回调返回执行结果。
6921
6922**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6923
6924**参数:**
6925
6926| 参数名  | 类型       | 必填   | 说明                 |
6927| ------- | -----------| ------ | ------------------- |
6928|volume   | number     | 是     | 音量值范围为0.0-1.0。 |
6929|callback | AsyncCallback\<void> | 是     |回调函数。当设置应用的音量成功,err为undefined,否则为错误对象。|
6930
6931**示例:**
6932
6933```ts
6934import { BusinessError } from '@kit.BasicServicesKit';
6935
6936audioRenderer.setVolume(0.5, (err: BusinessError) => {
6937  if(err){
6938    console.error(`setVolume Fail: ${err}`);
6939    return;
6940  }
6941  console.info('setVolume Success!');
6942});
6943```
6944### getVolume<sup>12+</sup>
6945
6946getVolume(): number
6947
6948获取音频渲染器的当前音量值,同步返回结果。
6949
6950**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6951
6952**返回值:**
6953
6954| 类型             | 说明                        |
6955| ---------------- | --------------------------- |
6956| number | 返回音量大小,音量范围[0.0-1.0]。 |
6957
6958**示例:**
6959
6960```ts
6961import { BusinessError } from '@kit.BasicServicesKit';
6962
6963try {
6964  let value: number = audioRenderer.getVolume();
6965  console.info(`Indicate that the volume is obtained ${value}.`);
6966} catch (err) {
6967  let error = err as BusinessError;
6968  console.error(`Failed to obtain the volume, error ${error}.`);
6969}
6970```
6971
6972### getMinStreamVolume<sup>10+</sup>
6973
6974getMinStreamVolume(callback: AsyncCallback&lt;number&gt;): void
6975
6976获取应用基于音频流的最小音量。使用Callback回调返回。
6977
6978**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6979
6980**参数:**
6981
6982| 参数名  | 类型       | 必填   | 说明                 |
6983| ------- | -----------| ------ | ------------------- |
6984|callback |AsyncCallback&lt;number&gt; | 是     |回调函数。当获取应用基于音频流的最小音量成功,err为undefined,data为获取到的应用基于音频流的最小音量(音量范围0-1);否则为错误对象。|
6985
6986**示例:**
6987
6988```ts
6989import { BusinessError } from '@kit.BasicServicesKit';
6990
6991audioRenderer.getMinStreamVolume((err: BusinessError, minVolume: number) => {
6992  if (err) {
6993    console.error(`getMinStreamVolume error: ${err}`);
6994  } else {
6995    console.info(`getMinStreamVolume Success! ${minVolume}`);
6996  }
6997});
6998```
6999### getMinStreamVolume<sup>10+</sup>
7000
7001getMinStreamVolume(): Promise&lt;number&gt;
7002
7003获取应用基于音频流的最小音量。使用Promise异步回调。
7004
7005**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7006
7007**返回值:**
7008
7009| 类型                | 说明                          |
7010| ------------------- | ----------------------------- |
7011| Promise&lt;number&gt;| Promise对象,返回音频流最小音量(音量范围0-1)。|
7012
7013**示例:**
7014
7015```ts
7016import { BusinessError } from '@kit.BasicServicesKit';
7017
7018audioRenderer.getMinStreamVolume().then((value: number) => {
7019  console.info(`Get min stream volume Success! ${value}`);
7020}).catch((err: BusinessError) => {
7021  console.error(`Get min stream volume Fail: ${err}`);
7022});
7023```
7024
7025### getMinStreamVolumeSync<sup>10+</sup>
7026
7027getMinStreamVolumeSync(): number
7028
7029获取应用基于音频流的最小音量,同步返回结果。
7030
7031**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7032
7033**返回值:**
7034
7035| 类型                | 说明                          |
7036| ------------------- | ----------------------------- |
7037| number| 返回音频流最小音量(音量范围0-1)。|
7038
7039**示例:**
7040
7041```ts
7042import { BusinessError } from '@kit.BasicServicesKit';
7043
7044try {
7045  let value: number = audioRenderer.getMinStreamVolumeSync();
7046  console.info(`Get min stream volume Success! ${value}`);
7047} catch (err) {
7048  let error = err as BusinessError;
7049  console.error(`Get min stream volume Fail: ${error}`);
7050}
7051```
7052
7053### getMaxStreamVolume<sup>10+</sup>
7054
7055getMaxStreamVolume(callback: AsyncCallback&lt;number&gt;): void
7056
7057获取应用基于音频流的最大音量。使用Callback回调返回。
7058
7059**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7060
7061**参数:**
7062
7063| 参数名  | 类型       | 必填   | 说明                 |
7064| ------- | -----------| ------ | ------------------- |
7065|callback | AsyncCallback&lt;number&gt; | 是     |回调函数。当获取应用基于音频流的最大音量成功,err为undefined,data为获取到的应用基于音频流的最大音量(音量范围0-1);否则为错误对象。|
7066
7067**示例:**
7068
7069```ts
7070import { BusinessError } from '@kit.BasicServicesKit';
7071
7072audioRenderer.getMaxStreamVolume((err: BusinessError, maxVolume: number) => {
7073  if (err) {
7074    console.error(`getMaxStreamVolume Fail: ${err}`);
7075  } else {
7076    console.info(`getMaxStreamVolume Success! ${maxVolume}`);
7077  }
7078});
7079```
7080### getMaxStreamVolume<sup>10+</sup>
7081
7082getMaxStreamVolume(): Promise&lt;number&gt;
7083
7084获取应用基于音频流的最大音量。使用Promise异步回调。
7085
7086**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7087
7088**返回值:**
7089
7090| 类型                | 说明                          |
7091| ------------------- | ----------------------------- |
7092| Promise&lt;number&gt;| Promise对象,返回音频流最大音量(音量范围0-1)。|
7093
7094**示例:**
7095
7096```ts
7097import { BusinessError } from '@kit.BasicServicesKit';
7098
7099audioRenderer.getMaxStreamVolume().then((value: number) => {
7100  console.info(`Get max stream volume Success! ${value}`);
7101}).catch((err: BusinessError) => {
7102  console.error(`Get max stream volume Fail: ${err}`);
7103});
7104```
7105
7106### getMaxStreamVolumeSync<sup>10+</sup>
7107
7108getMaxStreamVolumeSync(): number
7109
7110获取应用基于音频流的最大音量,同步返回结果。
7111
7112**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7113
7114**返回值:**
7115
7116| 类型                | 说明                          |
7117| ------------------- | ----------------------------- |
7118| number| 返回音频流最大音量(音量范围0-1)。|
7119
7120**示例:**
7121
7122```ts
7123import { BusinessError } from '@kit.BasicServicesKit';
7124
7125try {
7126  let value: number = audioRenderer.getMaxStreamVolumeSync();
7127  console.info(`Get max stream volume Success! ${value}`);
7128} catch (err) {
7129  let error = err as BusinessError;
7130  console.error(`Get max stream volume Fail: ${error}`);
7131}
7132```
7133
7134### getUnderflowCount<sup>10+</sup>
7135
7136getUnderflowCount(callback: AsyncCallback&lt;number&gt;): void
7137
7138获取当前播放音频流的欠载音频帧数量。使用Callback回调返回。
7139
7140**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7141
7142**参数:**
7143
7144| 参数名  | 类型       | 必填   | 说明                 |
7145| ------- | -----------| ------ | ------------------- |
7146|callback | AsyncCallback&lt;number&gt; | 是     |回调函数。当获取当前播放音频流的欠载音频帧数量成功,err为undefined,data为获取到的当前播放音频流的欠载音频帧数量;否则为错误对象。|
7147
7148**示例:**
7149
7150```ts
7151import { BusinessError } from '@kit.BasicServicesKit';
7152
7153audioRenderer.getUnderflowCount((err: BusinessError, underflowCount: number) => {
7154  if (err) {
7155    console.error(`getUnderflowCount Fail: ${err}`);
7156  } else {
7157    console.info(`getUnderflowCount Success! ${underflowCount}`);
7158  }
7159});
7160```
7161### getUnderflowCount<sup>10+</sup>
7162
7163getUnderflowCount(): Promise&lt;number&gt;
7164
7165获取当前播放音频流的欠载音频帧数量。使用Promise异步回调。
7166
7167**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7168
7169**返回值:**
7170
7171| 类型                | 说明                          |
7172| ------------------- | ----------------------------- |
7173| Promise&lt;number&gt;| Promise对象,返回音频流的欠载音频帧数量。|
7174
7175**示例:**
7176
7177```ts
7178import { BusinessError } from '@kit.BasicServicesKit';
7179
7180audioRenderer.getUnderflowCount().then((value: number) => {
7181  console.info(`Get underflow count Success! ${value}`);
7182}).catch((err: BusinessError) => {
7183  console.error(`Get underflow count Fail: ${err}`);
7184});
7185```
7186
7187### getUnderflowCountSync<sup>10+</sup>
7188
7189getUnderflowCountSync(): number
7190
7191获取当前播放音频流的欠载音频帧数量,同步返回数据。
7192
7193**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7194
7195**返回值:**
7196
7197| 类型                | 说明                          |
7198| ------------------- | ----------------------------- |
7199| number| 返回音频流的欠载音频帧数量。|
7200
7201**示例:**
7202
7203```ts
7204import { BusinessError } from '@kit.BasicServicesKit';
7205
7206try {
7207  let value: number = audioRenderer.getUnderflowCountSync();
7208  console.info(`Get underflow count Success! ${value}`);
7209} catch (err) {
7210  let error = err as BusinessError;
7211  console.error(`Get underflow count Fail: ${error}`);
7212}
7213```
7214
7215### getCurrentOutputDevices<sup>10+</sup>
7216
7217getCurrentOutputDevices(callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
7218
7219获取音频流输出设备描述符。使用Callback回调返回。
7220
7221**系统能力:** SystemCapability.Multimedia.Audio.Device
7222
7223**参数:**
7224
7225| 参数名  | 类型       | 必填   | 说明                 |
7226| ------- | -----------| ------ | ------------------- |
7227|callback | AsyncCallback\<[AudioDeviceDescriptors](#audiodevicedescriptors)>| 是     |回调函数。当获取音频流输出设备描述符成功,err为undefined,data为获取到的音频流输出设备描述符;否则为错误对象。|
7228
7229**示例:**
7230
7231```ts
7232import { BusinessError } from '@kit.BasicServicesKit';
7233
7234audioRenderer.getCurrentOutputDevices((err: BusinessError, deviceInfo: audio.AudioDeviceDescriptors) => {
7235  if (err) {
7236    console.error(`getCurrentOutputDevices Fail: ${err}`);
7237  } else {
7238    for (let i = 0; i < deviceInfo.length; i++) {
7239      console.info(`DeviceInfo id: ${deviceInfo[i].id}`);
7240      console.info(`DeviceInfo type: ${deviceInfo[i].deviceType}`);
7241      console.info(`DeviceInfo role: ${deviceInfo[i].deviceRole}`);
7242      console.info(`DeviceInfo name: ${deviceInfo[i].name}`);
7243      console.info(`DeviceInfo address: ${deviceInfo[i].address}`);
7244      console.info(`DeviceInfo samplerate: ${deviceInfo[i].sampleRates[0]}`);
7245      console.info(`DeviceInfo channelcount: ${deviceInfo[i].channelCounts[0]}`);
7246      console.info(`DeviceInfo channelmask: ${deviceInfo[i].channelMasks[0]}`);
7247    }
7248  }
7249});
7250```
7251### getCurrentOutputDevices<sup>10+</sup>
7252
7253getCurrentOutputDevices(): Promise&lt;AudioDeviceDescriptors&gt;
7254
7255获取音频流输出设备描述符。使用Promise异步回调。
7256
7257**系统能力:** SystemCapability.Multimedia.Audio.Device
7258
7259**返回值:**
7260
7261| 类型                | 说明                          |
7262| ------------------- | ----------------------------- |
7263| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt;| Promise对象,返回音频流的输出设备描述信息 |
7264
7265**示例:**
7266
7267```ts
7268import { BusinessError } from '@kit.BasicServicesKit';
7269
7270audioRenderer.getCurrentOutputDevices().then((deviceInfo: audio.AudioDeviceDescriptors) => {
7271  for (let i = 0; i < deviceInfo.length; i++) {
7272    console.info(`DeviceInfo id: ${deviceInfo[i].id}`);
7273    console.info(`DeviceInfo type: ${deviceInfo[i].deviceType}`);
7274    console.info(`DeviceInfo role: ${deviceInfo[i].deviceRole}`);
7275    console.info(`DeviceInfo name: ${deviceInfo[i].name}`);
7276    console.info(`DeviceInfo address: ${deviceInfo[i].address}`);
7277    console.info(`DeviceInfo samplerate: ${deviceInfo[i].sampleRates[0]}`);
7278    console.info(`DeviceInfo channelcount: ${deviceInfo[i].channelCounts[0]}`);
7279    console.info(`DeviceInfo channelmask: ${deviceInfo[i].channelMasks[0]}`);
7280  }
7281}).catch((err: BusinessError) => {
7282  console.error(`Get current output devices Fail: ${err}`);
7283});
7284```
7285
7286### getCurrentOutputDevicesSync<sup>10+</sup>
7287
7288getCurrentOutputDevicesSync(): AudioDeviceDescriptors
7289
7290获取音频流输出设备描述符,同步返回结果。
7291
7292**系统能力:** SystemCapability.Multimedia.Audio.Device
7293
7294**返回值:**
7295
7296| 类型                | 说明                          |
7297| ------------------- | ----------------------------- |
7298| [AudioDeviceDescriptors](#audiodevicedescriptors) | 返回音频流的输出设备描述信息 |
7299
7300**示例:**
7301
7302```ts
7303import { BusinessError } from '@kit.BasicServicesKit';
7304
7305try {
7306  let deviceInfo: audio.AudioDeviceDescriptors = audioRenderer.getCurrentOutputDevicesSync();
7307  for (let i = 0; i < deviceInfo.length; i++) {
7308    console.info(`DeviceInfo id: ${deviceInfo[i].id}`);
7309    console.info(`DeviceInfo type: ${deviceInfo[i].deviceType}`);
7310    console.info(`DeviceInfo role: ${deviceInfo[i].deviceRole}`);
7311    console.info(`DeviceInfo name: ${deviceInfo[i].name}`);
7312    console.info(`DeviceInfo address: ${deviceInfo[i].address}`);
7313    console.info(`DeviceInfo samplerate: ${deviceInfo[i].sampleRates[0]}`);
7314    console.info(`DeviceInfo channelcount: ${deviceInfo[i].channelCounts[0]}`);
7315    console.info(`DeviceInfo channelmask: ${deviceInfo[i].channelMasks[0]}`);
7316  }
7317} catch (err) {
7318  let error = err as BusinessError;
7319  console.error(`Get current output devices Fail: ${error}`);
7320}
7321```
7322### setChannelBlendMode<sup>11+</sup>
7323
7324setChannelBlendMode(mode: ChannelBlendMode): void
7325
7326设置单双声道混合模式。使用同步方式返回结果。
7327
7328**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7329
7330**参数:**
7331
7332| 参数名     | 类型                                | 必填 | 说明                                                     |
7333| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
7334| mode | [ChannelBlendMode](#channelblendmode11) | 是   | 声道混合模式类型。                                             |
7335
7336**错误码:**
7337
7338以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
7339
7340| 错误码ID | 错误信息 |
7341| ------- | --------------------------------------------|
7342| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
7343| 6800101 | Parameter verification failed. |
7344| 6800103 | Operation not permit at current state.    |
7345
7346**示例:**
7347
7348```ts
7349let mode = audio.ChannelBlendMode.MODE_DEFAULT;
7350
7351audioRenderer.setChannelBlendMode(mode);
7352console.info(`BlendMode: ${mode}`);
7353```
7354### setVolumeWithRamp<sup>11+</sup>
7355
7356setVolumeWithRamp(volume: number, duration: number): void
7357
7358设置音量渐变模式。使用同步方式返回结果。
7359
7360**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7361
7362**参数:**
7363
7364| 参数名     | 类型                                | 必填 | 说明                                                     |
7365| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
7366| volume     | number | 是   | 渐变目标音量值,音量范围为[0.0, 1.0]。                                             |
7367| duration     | number | 是   | 渐变持续时间,单位为ms。                                             |
7368
7369**错误码:**
7370
7371以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
7372
7373| 错误码ID | 错误信息 |
7374| ------- | --------------------------------------------|
7375| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
7376| 6800101 | Parameter verification failed. |
7377
7378**示例:**
7379
7380```ts
7381let volume = 0.5;
7382let duration = 1000;
7383
7384audioRenderer.setVolumeWithRamp(volume, duration);
7385console.info(`setVolumeWithRamp: ${volume}`);
7386```
7387
7388### setSilentModeAndMixWithOthers<sup>12+</sup>
7389
7390setSilentModeAndMixWithOthers(on: boolean): void
7391
7392设置静音并发播放模式。
7393
7394当设置为true,打开静音并发播放模式,系统将让此音频流静音播放,并且不会打断其它音频流。设置为false,将关闭静音并发播放,音频流可根据系统焦点策略抢占焦点。
7395
7396**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7397
7398**参数:**
7399
7400| 参数名 | 类型                                     | 必填 | 说明                   |
7401| ------ | ---------------------------------------- | ---- |----------------------|
7402| on | boolean | 是   | 打开/关闭静音并发播放模式,true打开,false关闭。 |
7403
7404**示例:**
7405
7406```ts
7407audioRenderer.setSilentModeAndMixWithOthers(true);
7408```
7409
7410### getSilentModeAndMixWithOthers<sup>12+</sup>
7411
7412getSilentModeAndMixWithOthers(): boolean
7413
7414获取静音并发播放模式。
7415
7416**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7417
7418**返回值:**
7419
7420| 类型                                              | 说明        |
7421| ------------------------------------------------- |-----------|
7422| boolean | 返回静音并发播放模式状态,true打开,false关闭。 |
7423
7424**示例:**
7425
7426```ts
7427let on = audioRenderer.getSilentModeAndMixWithOthers();
7428```
7429
7430### setDefaultOutputDevice<sup>12+</sup>
7431
7432setDefaultOutputDevice(deviceType: DeviceType): Promise&lt;void&gt;
7433
7434设置默认本机内置发声设备。使用Promise方式异步返回结果。
7435
7436本接口仅适用于[音频流类型](#streamusage)为语音消息、VoIP语音通话或者VoIP视频通话的场景使用,以及可选的设备类型为听筒、扬声器和系统默认设备。
7437
7438本接口允许在AudioRenderer创建以后的任何时间被调用,系统会记录应用设置的默认本机内置发声设备。在应用启动播放时,若有外接设备如蓝牙耳机/有线耳机接入,系统优先从外接设备发声;否则系统遵循应用设置的默认本机内置发声设备发声。
7439
7440**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7441
7442**参数:**
7443
7444| 参数名     | 类型             | 必填   | 说明                                                      |
7445| ---------- |----------------| ------ |---------------------------------------------------------|
7446| deviceType | [DeviceType](#devicetype) | 是     | 设备类型。<br>只支持:EARPIECE(听筒)、SPEAKER(扬声器)和DEFAULT(系统默认设备)。 |
7447
7448**返回值:**
7449
7450| 类型                | 说明                          |
7451| ------------------- | ----------------------------- |
7452| Promise&lt;void&gt; | Promise对象,无返回结果。 |
7453
7454**错误码:**
7455
7456以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
7457
7458| 错误码ID | 错误信息 |
7459| ------- | --------------------------------------------|
7460| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
7461| 6800101 | Parameter verification failed. |
7462| 6800103 | Operation not permit at current state.    |
7463
7464**示例:**
7465
7466```ts
7467import { BusinessError } from '@kit.BasicServicesKit';
7468
7469// 本接口允许在AudioRenderer创建以后的任何时间被调用。
7470// 未播放时调用,系统会记录应用设置的默认本机内置发声设备,当应用启动播放时从设置的默认本机内置发声设备发声。
7471// 正在播放时调用,在没有外接设备如蓝牙耳机/有线耳机,系统会立即切换到设置的默认本机内置发声设备发声;否则系统会先记录应用设置的默认本机内置发声设备,等外接设备移除后再切换到设置的默认本机内置发声设备发声。
7472audioRenderer.setDefaultOutputDevice(audio.DeviceType.SPEAKER).then(() => {
7473  console.info('setDefaultOutputDevice Success!');
7474}).catch((err: BusinessError) => {
7475  console.error(`setDefaultOutputDevice Fail: ${err}`);
7476});
7477```
7478
7479### on('audioInterrupt')<sup>9+</sup>
7480
7481on(type: 'audioInterrupt', callback: Callback\<InterruptEvent>): void
7482
7483监听音频中断事件(当音频焦点发生变化时触发),使用callback方式返回结果。
7484
7485AudioRenderer对象在start事件发生时会主动获取焦点,在pause、stop等事件发生时会主动释放焦点,不需要开发者主动发起获取焦点或释放焦点的申请。
7486
7487调用此方法,在AudioRenderer对象获取焦点失败或发生中断事件(如被其他音频打断等)时,会收到[InterruptEvent](#interruptevent9)。建议应用可根据InterruptEvent的信息完成进一步处理,更多信息可参考文档[处理音频焦点事件](../../media/audio/audio-playback-concurrency.md)。
7488
7489**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
7490
7491**参数:**
7492
7493| 参数名   | 类型                                         | 必填 | 说明                                                        |
7494| -------- | -------------------------------------------- | ---- | ----------------------------------------------------------- |
7495| type     | string                                       | 是   | 监听事件,固定为:'audioInterrupt'。 |
7496| callback | Callback\<[InterruptEvent](#interruptevent9)\> | 是   | 回调函数,返回播放中断时,应用接收的中断事件信息。 |
7497
7498**错误码:**
7499
7500以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
7501
7502| 错误码ID | 错误信息 |
7503| ------- | --------------------------------------------|
7504| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
7505| 6800101 | Parameter verification failed. |
7506
7507**示例:**
7508
7509```ts
7510import { audio } from '@kit.AudioKit';
7511
7512let isPlaying: boolean; // 标识符,表示是否正在渲染
7513let isDucked: boolean; // 标识符,表示是否被降低音量
7514onAudioInterrupt();
7515
7516async function onAudioInterrupt(){
7517  audioRenderer.on('audioInterrupt', (interruptEvent: audio.InterruptEvent) => {
7518    // 在发生音频打断事件时,audioRenderer收到interruptEvent回调,此处根据其内容做相应处理。
7519    // 1、可选:读取interruptEvent.forceType的类型,判断系统是否已强制执行相应操作。
7520    // 注:默认焦点策略下,INTERRUPT_HINT_RESUME为INTERRUPT_SHARE类型,其余hintType均为INTERRUPT_FORCE类型。因此对forceType可不做判断。
7521    // 2、必选:读取interruptEvent.hintType的类型,做出相应的处理。
7522    if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
7523      // 音频焦点事件已由系统强制执行,应用需更新自身状态及显示内容等
7524      switch (interruptEvent.hintType) {
7525        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
7526          // 音频流已被暂停,临时失去焦点,待可重获焦点时会收到resume对应的interruptEvent
7527          console.info('Force paused. Update playing status and stop writing');
7528          isPlaying = false; // 简化处理,代表应用切换至暂停状态的若干操作
7529          break;
7530        case audio.InterruptHint.INTERRUPT_HINT_STOP:
7531          // 音频流已被停止,永久失去焦点,若想恢复渲染,需用户主动触发
7532          console.info('Force stopped. Update playing status and stop writing');
7533          isPlaying = false; // 简化处理,代表应用切换至暂停状态的若干操作
7534          break;
7535        case audio.InterruptHint.INTERRUPT_HINT_DUCK:
7536          // 音频流已被降低音量渲染
7537          console.info('Force ducked. Update volume status');
7538          isDucked = true; // 简化处理,代表应用更新音量状态的若干操作
7539          break;
7540        case audio.InterruptHint.INTERRUPT_HINT_UNDUCK:
7541          // 音频流已被恢复正常音量渲染
7542          console.info('Force ducked. Update volume status');
7543          isDucked = false; // 简化处理,代表应用更新音量状态的若干操作
7544          break;
7545        default:
7546          console.info('Invalid interruptEvent');
7547          break;
7548      }
7549    } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
7550      // 音频焦点事件需由应用进行操作,应用可以自主选择如何处理该事件,建议应用遵从InterruptHint提示处理
7551      switch (interruptEvent.hintType) {
7552        case audio.InterruptHint.INTERRUPT_HINT_RESUME:
7553          // 建议应用继续渲染(说明音频流此前被强制暂停,临时失去焦点,现在可以恢复渲染)
7554          // 由于INTERRUPT_HINT_RESUME操作需要应用主动执行,系统无法强制,故INTERRUPT_HINT_RESUME事件一定为INTERRUPT_SHARE类型
7555          console.info('Resume force paused renderer or ignore');
7556          // 若选择继续渲染,需在此处主动执行开始渲染的若干操作
7557          break;
7558        default:
7559          console.info('Invalid interruptEvent');
7560          break;
7561      }
7562    }
7563  });
7564}
7565```
7566
7567### on('markReach')<sup>8+</sup>
7568
7569on(type: 'markReach', frame: number, callback: Callback&lt;number&gt;): void
7570
7571监听到达标记事件(当渲染的帧数到达frame参数的值时触发,仅调用一次),使用callback方式返回结果。
7572
7573举例说明,如果frame设置为100,当渲染帧数到达第100帧时,将上报信息。
7574
7575**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7576
7577**参数:**
7578
7579| 参数名   | 类型                     | 必填 | 说明                                      |
7580| :------- | :----------------------- | :--- | :---------------------------------------- |
7581| type     | string                   | 是   | 监听事件,固定为:'markReach'。 |
7582| frame    | number                   | 是   | 触发事件的帧数。该值必须大于0。         |
7583| callback | Callback\<number>         | 是   | 回调函数,返回frame参数的值。 |
7584
7585**示例:**
7586
7587```ts
7588audioRenderer.on('markReach', 1000, (position: number) => {
7589  if (position == 1000) {
7590    console.info('ON Triggered successfully');
7591  }
7592});
7593```
7594
7595
7596### off('markReach')<sup>8+</sup>
7597
7598off(type: 'markReach'): void
7599
7600取消监听到达标记事件。
7601
7602**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7603
7604**参数:**
7605
7606| 参数名 | 类型   | 必填 | 说明                                              |
7607| :----- | :----- | :--- | :------------------------------------------------ |
7608| type   | string | 是   | 监听事件,固定为:'markReach'。 |
7609
7610**示例:**
7611
7612```ts
7613audioRenderer.off('markReach');
7614```
7615
7616### on('periodReach')<sup>8+</sup>
7617
7618on(type: 'periodReach', frame: number, callback: Callback&lt;number&gt;): void
7619
7620监听到达标记事件(每当渲染的帧数达到frame参数的值时触发,即按周期上报信息),使用callback方式返回结果。
7621
7622举例说明,如果frame设置为10,每当渲染10帧数据时将上报信息,例如在第10帧、20帧、30帧,均会上报信息。
7623
7624**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7625
7626**参数:**
7627
7628| 参数名   | 类型                     | 必填 | 说明                                        |
7629| :------- | :----------------------- | :--- | :------------------------------------------ |
7630| type     | string                   | 是   | 监听事件,固定为:'periodReach'。 |
7631| frame    | number                   | 是   | 触发事件的帧数。该值必须大于 0。           |
7632| callback | Callback\<number>         | 是   | 回调函数,返回frame参数的值。 |
7633
7634**示例:**
7635
7636```ts
7637audioRenderer.on('periodReach', 1000, (position: number) => {
7638  if (position == 1000) {
7639    console.info('ON Triggered successfully');
7640  }
7641});
7642```
7643
7644### off('periodReach')<sup>8+</sup>
7645
7646off(type: 'periodReach'): void
7647
7648取消监听到达标记事件。
7649
7650**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7651
7652**参数:**
7653
7654| 参数名 | 类型   | 必填 | 说明                                                |
7655| :----- | :----- | :--- | :-------------------------------------------------- |
7656| type   | string | 是   | 监听事件,固定为:'periodReach'。 |
7657
7658**示例:**
7659
7660```ts
7661audioRenderer.off('periodReach');
7662```
7663
7664### on('stateChange')<sup>8+</sup>
7665
7666on(type: 'stateChange', callback: Callback<AudioState\>): void
7667
7668监听状态变化事件(当AudioRenderer的状态发生变化时触发),使用callback方式返回结果。
7669
7670**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7671
7672**参数:**
7673
7674| 参数名   | 类型                       | 必填 | 说明                                        |
7675| :------- | :------------------------- | :--- | :------------------------------------------ |
7676| type     | string                     | 是   | 监听事件,固定为:'stateChange'。 |
7677| callback | Callback\<[AudioState](#audiostate8)> | 是   | 回调函数,返回当前音频的状态。 |
7678
7679**示例:**
7680
7681```ts
7682audioRenderer.on('stateChange', (state: audio.AudioState) => {
7683  if (state == 1) {
7684    console.info('audio renderer state is: STATE_PREPARED');
7685  }
7686  if (state == 2) {
7687    console.info('audio renderer state is: STATE_RUNNING');
7688  }
7689});
7690```
7691
7692### on('outputDeviceChange')<sup>10+</sup>
7693
7694on(type: 'outputDeviceChange', callback: Callback\<AudioDeviceDescriptors>): void
7695
7696监听音频输出设备变化事件(当音频输出设备发生变化时触发),使用callback方式返回结果。
7697
7698**系统能力:** SystemCapability.Multimedia.Audio.Device
7699
7700**参数:**
7701
7702| 参数名   | 类型                       | 必填 | 说明                                        |
7703| :------- | :------------------------- | :--- | :------------------------------------------ |
7704| type     | string                     | 是   | 监听事件,固定为:'outputDeviceChange'。 |
7705| callback | Callback\<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 是   | 回调函数,返回当前音频流的输出设备描述信息。 |
7706
7707**错误码:**
7708
7709以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
7710
7711| 错误码ID | 错误信息 |
7712| ------- | --------------------------------------------|
7713| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
7714| 6800101 | Parameter verification failed. |
7715
7716**示例:**
7717
7718```ts
7719audioRenderer.on('outputDeviceChange', (deviceInfo: audio.AudioDeviceDescriptors) => {
7720  console.info(`DeviceInfo id: ${deviceInfo[0].id}`);
7721  console.info(`DeviceInfo name: ${deviceInfo[0].name}`);
7722  console.info(`DeviceInfo address: ${deviceInfo[0].address}`);
7723});
7724```
7725
7726### off('outputDeviceChange')<sup>10+</sup>
7727
7728off(type: 'outputDeviceChange', callback?: Callback\<AudioDeviceDescriptors>): void
7729
7730取消监听音频输出设备变化事件,使用callback方式返回结果。
7731
7732**系统能力:** SystemCapability.Multimedia.Audio.Device
7733
7734**参数:**
7735
7736| 参数名   | 类型                       | 必填 | 说明                                        |
7737| :------- | :------------------------- | :--- | :------------------------------------------ |
7738| type     | string                     | 是   | 监听事件,固定为:'outputDeviceChange'。 |
7739| callback | Callback\<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 否   | 回调函数,返回当前音频流的输出设备描述信息。 |
7740
7741**错误码:**
7742
7743以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
7744
7745| 错误码ID | 错误信息 |
7746| ------- | --------------------------------------------|
7747| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
7748| 6800101 | Parameter verification failed. |
7749
7750**示例:**
7751
7752```ts
7753// 取消该事件的所有监听
7754audioRenderer.off('outputDeviceChange');
7755
7756// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
7757let outputDeviceChangeCallback = (deviceInfo: audio.AudioDeviceDescriptors) => {
7758  console.info(`DeviceInfo id: ${deviceInfo[0].id}`);
7759  console.info(`DeviceInfo name: ${deviceInfo[0].name}`);
7760  console.info(`DeviceInfo address: ${deviceInfo[0].address}`);
7761};
7762
7763audioRenderer.on('outputDeviceChange', outputDeviceChangeCallback);
7764
7765audioRenderer.off('outputDeviceChange', outputDeviceChangeCallback);
7766```
7767
7768### on('outputDeviceChangeWithInfo')<sup>11+</sup>
7769
7770on(type: 'outputDeviceChangeWithInfo', callback: Callback\<AudioStreamDeviceChangeInfo>): void
7771
7772监听音频流输出设备变化及原因事件(当音频输出设备发生变化时触发),使用callback方式返回结果。
7773
7774**系统能力:** SystemCapability.Multimedia.Audio.Device
7775
7776**参数:**
7777
7778| 参数名   | 类型                                                                       | 必填 | 说明                                          |
7779| :------- |:-------------------------------------------------------------------------| :--- |:--------------------------------------------|
7780| type     | string                                                                   | 是   | 监听事件,固定为:'outputDeviceChangeWithInfo'。 |
7781| callback | Callback\<[AudioStreamDeviceChangeInfo](#audiostreamdevicechangeinfo11)> | 是   | 回调函数,返回当前音频流的输出设备描述信息及变化原因。 |
7782
7783**错误码:**
7784
7785以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
7786
7787| 错误码ID | 错误信息 |
7788| ------- | --------------------------------------------|
7789| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
7790| 6800101 | Parameter verification failed. |
7791
7792**示例:**
7793
7794```ts
7795audioRenderer.on('outputDeviceChangeWithInfo', (deviceChangeInfo: audio.AudioStreamDeviceChangeInfo) => {
7796  console.info(`DeviceInfo id: ${deviceChangeInfo.devices[0].id}`);
7797  console.info(`DeviceInfo name: ${deviceChangeInfo.devices[0].name}`);
7798  console.info(`DeviceInfo address: ${deviceChangeInfo.devices[0].address}`);
7799  console.info(`Device change reason: ${deviceChangeInfo.changeReason}`);
7800});
7801```
7802
7803### off('outputDeviceChangeWithInfo')<sup>11+</sup>
7804
7805off(type: 'outputDeviceChangeWithInfo', callback?: Callback\<AudioStreamDeviceChangeInfo>): void
7806
7807取消监听音频流输出设备变化及原因事件,使用callback方式返回结果。
7808
7809**系统能力:** SystemCapability.Multimedia.Audio.Device
7810
7811**参数:**
7812
7813| 参数名   | 类型                                                                       | 必填 | 说明                                          |
7814| :------- |:-------------------------------------------------------------------------| :--- |:--------------------------------------------|
7815| type     | string                                                                   | 是   | 监听事件,固定为:'outputDeviceChangeWithInfo'。 |
7816| callback | Callback\<[AudioStreamDeviceChangeInfo](#audiostreamdevicechangeinfo11)> | 否   | 回调函数,返回当前音频流的输出设备描述信息及变化原因。 |
7817
7818**错误码:**
7819
7820以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
7821
7822| 错误码ID | 错误信息 |
7823| ------- | --------------------------------------------|
7824| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
7825| 6800101 | Parameter verification failed. |
7826
7827**示例:**
7828
7829```ts
7830// 取消该事件的所有监听
7831audioRenderer.off('outputDeviceChangeWithInfo');
7832
7833// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
7834let outputDeviceChangeWithInfoCallback = (deviceChangeInfo: audio.AudioStreamDeviceChangeInfo) => {
7835  console.info(`DeviceInfo id: ${deviceChangeInfo.devices[0].id}`);
7836  console.info(`DeviceInfo name: ${deviceChangeInfo.devices[0].name}`);
7837  console.info(`DeviceInfo address: ${deviceChangeInfo.devices[0].address}`);
7838  console.info(`Device change reason: ${deviceChangeInfo.changeReason}`);
7839};
7840
7841audioRenderer.on('outputDeviceChangeWithInfo', outputDeviceChangeWithInfoCallback);
7842
7843audioRenderer.off('outputDeviceChangeWithInfo', outputDeviceChangeWithInfoCallback);
7844```
7845
7846### on('writeData')<sup>11+</sup>
7847
7848on(type: 'writeData', callback: AudioRendererWriteDataCallback): void
7849
7850监听音频数据写入回调事件(当需要写入音频数据时触发),使用 callback 方式返回结果。
7851
7852回调函数仅用来写入音频数据,请勿在回调函数中调用AudioRenderer相关接口。
7853
7854**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7855
7856**参数:**
7857
7858| 参数名   | 类型                             | 必填 | 说明                                  |
7859| :------- |:--------------------------------| :--- |:--------------------------------------|
7860| type     | string                           | 是   | 监听事件,固定为:'writeData'。 |
7861| callback | [AudioRendererWriteDataCallback](#audiorendererwritedatacallback12)   | 是   | 回调函数,入参代表应用接收待写入的数据缓冲区。<br>API version 11 不支持返回回调结果,从 API version 12 开始支持返回回调结果[AudioDataCallbackResult](#audiodatacallbackresult12)。        |
7862
7863**错误码:**
7864
7865以下错误码的详细介绍请参见 [Audio错误码](errorcode-audio.md)。
7866
7867| 错误码ID | 错误信息 |
7868| ------- | --------------------------------------------|
7869| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
7870| 6800101 | Parameter verification failed. |
7871
7872**示例:**
7873
7874```ts
7875import { BusinessError } from '@kit.BasicServicesKit';
7876import {fileIo as fs} from '@kit.CoreFileKit';
7877
7878class Options {
7879  offset?: number;
7880  length?: number;
7881}
7882
7883let bufferSize: number = 0;
7884let path = getContext().cacheDir;
7885// 确保该沙箱路径下存在该资源
7886let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
7887let file: fs.File = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
7888let writeDataCallback = (buffer: ArrayBuffer) => {
7889  let options: Options = {
7890    offset: bufferSize,
7891    length: buffer.byteLength
7892  };
7893
7894  try {
7895    fs.readSync(file.fd, buffer, options);
7896    bufferSize += buffer.byteLength;
7897    // API version 11 不支持返回回调结果,从 API version 12 开始支持返回回调结果
7898    return audio.AudioDataCallbackResult.VALID;
7899  } catch (error) {
7900    console.error('Error reading file:', error);
7901    // API version 11 不支持返回回调结果,从 API version 12 开始支持返回回调结果
7902    return audio.AudioDataCallbackResult.INVALID;
7903  }
7904};
7905
7906audioRenderer.on('writeData', writeDataCallback);
7907audioRenderer.start().then(() => {
7908  console.info('Renderer started');
7909}).catch((err: BusinessError) => {
7910  console.error(`ERROR: ${err}`);
7911});
7912```
7913
7914### off('writeData')<sup>11+</sup>
7915
7916off(type: 'writeData', callback?: AudioRendererWriteDataCallback): void
7917
7918取消监听音频数据写入回调事件,使用 callback 方式返回结果。
7919
7920**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7921
7922**参数:**
7923
7924| 参数名   | 类型                             | 必填 | 说明                                  |
7925| :------- |:--------------------------------| :--- |:--------------------------------------|
7926| type     | string                           | 是   | 监听事件,固定为:'writeData'。 |
7927| callback | [AudioRendererWriteDataCallback](#audiorendererwritedatacallback12)   | 否   | 回调函数,入参代表应用接收待写入的数据缓冲区。<br>API version 11 不支持返回回调结果,从 API version 12 开始支持返回回调结果[AudioDataCallbackResult](#audiodatacallbackresult12)。 |
7928
7929**错误码:**
7930
7931以下错误码的详细介绍请参见 [Audio错误码](errorcode-audio.md)。
7932
7933| 错误码ID | 错误信息 |
7934| ------- | --------------------------------------------|
7935| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7936| 6800101 | Parameter verification failed. |
7937
7938**示例:**
7939
7940```ts
7941// 取消该事件的所有监听
7942audioRenderer.off('writeData');
7943
7944// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
7945let writeDataCallback = (data: ArrayBuffer) => {
7946    console.info(`write data: ${data}`);
7947};
7948
7949audioRenderer.on('writeData', writeDataCallback);
7950
7951audioRenderer.off('writeData', writeDataCallback);
7952```
7953
7954## AudioCapturer<sup>8+</sup>
7955
7956提供音频采集的相关接口。在调用AudioCapturer的接口前,需要先通过[createAudioCapturer](#audiocreateaudiocapturer8)创建实例。
7957
7958### 属性
7959
7960**系统能力:** SystemCapability.Multimedia.Audio.Capturer
7961
7962| 名称  | 类型                     | 可读 | 可写 | 说明             |
7963| :---- | :------------------------- | :--- | :--- | :--------------- |
7964| state<sup>8+</sup>  | [AudioState](#audiostate8) | 是 | 否   | 音频采集器状态。 |
7965
7966**示例:**
7967
7968```ts
7969import { audio } from '@kit.AudioKit';
7970
7971let state: audio.AudioState = audioCapturer.state;
7972```
7973
7974### getCapturerInfo<sup>8+</sup>
7975
7976getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void
7977
7978获取采集器信息。使用callback方式异步返回结果。
7979
7980**系统能力:** SystemCapability.Multimedia.Audio.Capturer
7981
7982**参数:**
7983
7984| 参数名   | 类型                              | 必填 | 说明                                 |
7985| :------- | :-------------------------------- | :--- | :----------------------------------- |
7986| callback | AsyncCallback<[AudioCapturerInfo](#audiocapturerinfo8)\> | 是   | 回调函数。当获取采集器信息成功,err为undefined,data为获取到的采集器信息;否则为错误对象。 |
7987
7988**示例:**
7989
7990```ts
7991import { BusinessError } from '@kit.BasicServicesKit';
7992
7993audioCapturer.getCapturerInfo((err: BusinessError, capturerInfo: audio.AudioCapturerInfo) => {
7994  if (err) {
7995    console.error('Failed to get capture info');
7996  } else {
7997    console.info('Capturer getCapturerInfo:');
7998    console.info(`Capturer source: ${capturerInfo.source}`);
7999    console.info(`Capturer flags: ${capturerInfo.capturerFlags}`);
8000  }
8001});
8002```
8003
8004
8005### getCapturerInfo<sup>8+</sup>
8006
8007getCapturerInfo(): Promise<AudioCapturerInfo\>
8008
8009获取采集器信息。使用Promise方式异步返回结果。
8010
8011**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8012
8013**返回值:**
8014
8015| 类型                                              | 说明                                |
8016| :------------------------------------------------ | :---------------------------------- |
8017| Promise<[AudioCapturerInfo](#audiocapturerinfo8)\> | Promise对象,返回采集器信息。 |
8018
8019**示例:**
8020
8021```ts
8022import { BusinessError } from '@kit.BasicServicesKit';
8023
8024audioCapturer.getCapturerInfo().then((audioParamsGet: audio.AudioCapturerInfo) => {
8025  if (audioParamsGet != undefined) {
8026    console.info('AudioFrameworkRecLog: Capturer CapturerInfo:');
8027    console.info(`AudioFrameworkRecLog: Capturer SourceType: ${audioParamsGet.source}`);
8028    console.info(`AudioFrameworkRecLog: Capturer capturerFlags: ${audioParamsGet.capturerFlags}`);
8029  } else {
8030    console.info(`AudioFrameworkRecLog: audioParamsGet is : ${audioParamsGet}`);
8031    console.info('AudioFrameworkRecLog: audioParams getCapturerInfo are incorrect');
8032  }
8033}).catch((err: BusinessError) => {
8034  console.error(`AudioFrameworkRecLog: CapturerInfo :ERROR: ${err}`);
8035})
8036```
8037
8038### getCapturerInfoSync<sup>10+</sup>
8039
8040getCapturerInfoSync(): AudioCapturerInfo
8041
8042获取采集器信息,同步返回结果。
8043
8044**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8045
8046**返回值:**
8047
8048| 类型                                              | 说明                                |
8049| :------------------------------------------------ | :---------------------------------- |
8050| [AudioCapturerInfo](#audiocapturerinfo8) | 返回采集器信息。 |
8051
8052**示例:**
8053
8054```ts
8055import { BusinessError } from '@kit.BasicServicesKit';
8056
8057try {
8058  let audioParamsGet: audio.AudioCapturerInfo = audioCapturer.getCapturerInfoSync();
8059  console.info(`AudioFrameworkRecLog: Capturer SourceType: ${audioParamsGet.source}`);
8060  console.info(`AudioFrameworkRecLog: Capturer capturerFlags: ${audioParamsGet.capturerFlags}`);
8061} catch (err) {
8062  let error = err as BusinessError;
8063  console.error(`AudioFrameworkRecLog: CapturerInfo :ERROR: ${error}`);
8064}
8065```
8066
8067### getStreamInfo<sup>8+</sup>
8068
8069getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
8070
8071获取采集器流信息。使用callback方式异步返回结果。
8072
8073**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8074
8075**参数:**
8076
8077| 参数名   | 类型                                                 | 必填 | 说明                             |
8078| :------- | :--------------------------------------------------- | :--- | :------------------------------- |
8079| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | 是   | 回调函数。当获取采集器流信息成功,err为undefined,data为获取到的采集器流信息;否则为错误对象。 |
8080
8081**示例:**
8082
8083```ts
8084import { BusinessError } from '@kit.BasicServicesKit';
8085
8086audioCapturer.getStreamInfo((err: BusinessError, streamInfo: audio.AudioStreamInfo) => {
8087  if (err) {
8088    console.error('Failed to get stream info');
8089  } else {
8090    console.info('Capturer GetStreamInfo:');
8091    console.info(`Capturer sampling rate: ${streamInfo.samplingRate}`);
8092    console.info(`Capturer channel: ${streamInfo.channels}`);
8093    console.info(`Capturer format: ${streamInfo.sampleFormat}`);
8094    console.info(`Capturer encoding type: ${streamInfo.encodingType}`);
8095  }
8096});
8097```
8098
8099### getStreamInfo<sup>8+</sup>
8100
8101getStreamInfo(): Promise<AudioStreamInfo\>
8102
8103获取采集器流信息。使用Promise方式异步返回结果。
8104
8105**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8106
8107**返回值:**
8108
8109| 类型                                           | 说明                            |
8110| :--------------------------------------------- | :------------------------------ |
8111| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise对象,返回流信息。 |
8112
8113**示例:**
8114
8115```ts
8116import { BusinessError } from '@kit.BasicServicesKit';
8117
8118audioCapturer.getStreamInfo().then((audioParamsGet: audio.AudioStreamInfo) => {
8119  console.info('getStreamInfo:');
8120  console.info(`sampleFormat: ${audioParamsGet.sampleFormat}`);
8121  console.info(`samplingRate: ${audioParamsGet.samplingRate}`);
8122  console.info(`channels: ${audioParamsGet.channels}`);
8123  console.info(`encodingType: ${audioParamsGet.encodingType}`);
8124}).catch((err: BusinessError) => {
8125  console.error(`getStreamInfo :ERROR: ${err}`);
8126});
8127```
8128
8129### getStreamInfoSync<sup>10+</sup>
8130
8131getStreamInfoSync(): AudioStreamInfo
8132
8133获取采集器流信息,同步返回结果。
8134
8135**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8136
8137**返回值:**
8138
8139| 类型                                           | 说明                            |
8140| :--------------------------------------------- | :------------------------------ |
8141| [AudioStreamInfo](#audiostreaminfo8) | 返回流信息。 |
8142
8143**示例:**
8144
8145```ts
8146import { BusinessError } from '@kit.BasicServicesKit';
8147
8148try {
8149  let audioParamsGet: audio.AudioStreamInfo = audioCapturer.getStreamInfoSync();
8150  console.info(`sampleFormat: ${audioParamsGet.sampleFormat}`);
8151  console.info(`samplingRate: ${audioParamsGet.samplingRate}`);
8152  console.info(`channels: ${audioParamsGet.channels}`);
8153  console.info(`encodingType: ${audioParamsGet.encodingType}`);
8154} catch (err) {
8155  let error = err as BusinessError;
8156  console.error(`getStreamInfo :ERROR: ${error}`);
8157}
8158```
8159
8160### getAudioStreamId<sup>9+</sup>
8161
8162getAudioStreamId(callback: AsyncCallback<number\>): void
8163
8164获取音频流id,使用callback方式异步返回结果。
8165
8166**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8167
8168**参数:**
8169
8170| 参数名   | 类型                                                 | 必填 | 说明                 |
8171| :------- | :--------------------------------------------------- | :--- | :------------------- |
8172| callback | AsyncCallback<number\> | 是   | 回调函数。当获取音频流id成功,err为undefined,data为获取到的音频流id;否则为错误对象。 |
8173
8174**示例:**
8175
8176```ts
8177import { BusinessError } from '@kit.BasicServicesKit';
8178
8179audioCapturer.getAudioStreamId((err: BusinessError, streamId: number) => {
8180  console.info(`audioCapturer GetStreamId: ${streamId}`);
8181});
8182```
8183
8184### getAudioStreamId<sup>9+</sup>
8185
8186getAudioStreamId(): Promise<number\>
8187
8188获取音频流id,使用Promise方式异步返回结果。
8189
8190**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8191
8192**返回值:**
8193
8194| 类型             | 说明                   |
8195| :----------------| :--------------------- |
8196| Promise<number\> | Promise对象,返回音频流id。 |
8197
8198**示例:**
8199
8200```ts
8201import { BusinessError } from '@kit.BasicServicesKit';
8202
8203audioCapturer.getAudioStreamId().then((streamId: number) => {
8204  console.info(`audioCapturer getAudioStreamId: ${streamId}`);
8205}).catch((err: BusinessError) => {
8206  console.error(`ERROR: ${err}`);
8207});
8208```
8209
8210### getAudioStreamIdSync<sup>10+</sup>
8211
8212getAudioStreamIdSync(): number
8213
8214获取音频流id,同步返回结果。
8215
8216**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8217
8218**返回值:**
8219
8220| 类型             | 说明                   |
8221| :----------------| :--------------------- |
8222| number | 返回音频流id。 |
8223
8224**示例:**
8225
8226```ts
8227import { BusinessError } from '@kit.BasicServicesKit';
8228
8229try {
8230  let streamId: number = audioCapturer.getAudioStreamIdSync();
8231  console.info(`audioCapturer getAudioStreamIdSync: ${streamId}`);
8232} catch (err) {
8233  let error = err as BusinessError;
8234  console.error(`ERROR: ${error}`);
8235}
8236```
8237
8238### start<sup>8+</sup>
8239
8240start(callback: AsyncCallback<void\>): void
8241
8242启动音频采集器。使用callback方式异步返回结果。
8243
8244**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8245
8246**参数:**
8247
8248| 参数名   | 类型                 | 必填 | 说明                           |
8249| :------- | :------------------- | :--- | :----------------------------- |
8250| callback | AsyncCallback<void\> | 是   | Callback对象,成功表示启动音频采集器成功,异常将返回error对象:<br>错误码6800301,表示包含状态检查异常、焦点抢占失败、系统处理异常(具体错误查看系统日志)。 |
8251
8252**示例:**
8253
8254```ts
8255import { BusinessError } from '@kit.BasicServicesKit';
8256
8257audioCapturer.start((err: BusinessError) => {
8258  if (err) {
8259    console.error('Capturer start failed.');
8260  } else {
8261    console.info('Capturer start success.');
8262  }
8263});
8264```
8265
8266
8267### start<sup>8+</sup>
8268
8269start(): Promise<void\>
8270
8271启动音频采集器。使用Promise方式异步返回结果。
8272
8273**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8274
8275**返回值:**
8276
8277| 类型           | 说明                          |
8278| :------------- | :---------------------------- |
8279| Promise<void\> | Promise对象,成功表示启动音频采集器成功,异常将返回error对象:<br>错误码6800301,表示包含状态检查异常、焦点抢占失败、系统处理异常(具体错误查看系统日志)。 |
8280
8281**示例:**
8282
8283```ts
8284import { BusinessError } from '@kit.BasicServicesKit';
8285
8286audioCapturer.start().then(() => {
8287  console.info('AudioFrameworkRecLog: ---------START---------');
8288  console.info('AudioFrameworkRecLog: Capturer started: SUCCESS');
8289  console.info(`AudioFrameworkRecLog: AudioCapturer: STATE: ${audioCapturer.state}`);
8290  console.info('AudioFrameworkRecLog: Capturer started: SUCCESS');
8291  if ((audioCapturer.state == audio.AudioState.STATE_RUNNING)) {
8292    console.info('AudioFrameworkRecLog: AudioCapturer is in Running State');
8293  }
8294}).catch((err: BusinessError) => {
8295  console.error(`AudioFrameworkRecLog: Capturer start :ERROR : ${err}`);
8296});
8297```
8298
8299### stop<sup>8+</sup>
8300
8301stop(callback: AsyncCallback<void\>): void
8302
8303停止采集。使用callback方式异步返回结果。
8304
8305**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8306
8307**参数:**
8308
8309| 参数名   | 类型                 | 必填 | 说明                           |
8310| :------- | :------------------- | :--- | :----------------------------- |
8311| callback | AsyncCallback<void\> | 是   | 回调函数。当停止采集成功,err为undefined,否则为错误对象。 |
8312
8313**示例:**
8314
8315```ts
8316import { BusinessError } from '@kit.BasicServicesKit';
8317
8318audioCapturer.stop((err: BusinessError) => {
8319  if (err) {
8320    console.error('Capturer stop failed');
8321  } else {
8322    console.info('Capturer stopped.');
8323  }
8324});
8325```
8326
8327
8328### stop<sup>8+</sup>
8329
8330stop(): Promise<void\>
8331
8332停止采集。使用Promise方式异步返回结果。
8333
8334**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8335
8336**返回值:**
8337
8338| 类型           | 说明                          |
8339| :------------- | :---------------------------- |
8340| Promise<void\> | Promise对象,无返回结果。 |
8341
8342**示例:**
8343
8344```ts
8345import { BusinessError } from '@kit.BasicServicesKit';
8346
8347audioCapturer.stop().then(() => {
8348  console.info('AudioFrameworkRecLog: ---------STOP RECORD---------');
8349  console.info('AudioFrameworkRecLog: Capturer stopped: SUCCESS');
8350  if ((audioCapturer.state == audio.AudioState.STATE_STOPPED)){
8351    console.info('AudioFrameworkRecLog: State is Stopped:');
8352  }
8353}).catch((err: BusinessError) => {
8354  console.error(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
8355});
8356```
8357
8358### release<sup>8+</sup>
8359
8360release(callback: AsyncCallback<void\>): void
8361
8362释放采集器。使用callback方式异步返回结果。
8363
8364**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8365
8366**参数:**
8367
8368| 参数名   | 类型                 | 必填 | 说明                                |
8369| :------- | :------------------- | :--- | :---------------------------------- |
8370| callback | AsyncCallback<void\> | 是   | 回调函数。当释放采集器成功,err为undefined,否则为错误对象。 |
8371
8372**示例:**
8373
8374```ts
8375import { BusinessError } from '@kit.BasicServicesKit';
8376
8377audioCapturer.release((err: BusinessError) => {
8378  if (err) {
8379    console.error('capturer release failed');
8380  } else {
8381    console.info('capturer released.');
8382  }
8383});
8384```
8385
8386
8387### release<sup>8+</sup>
8388
8389release(): Promise<void\>
8390
8391释放采集器。使用Promise方式异步返回结果。
8392
8393**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8394
8395**返回值:**
8396
8397| 类型           | 说明                          |
8398| :------------- | :---------------------------- |
8399| Promise<void\> | Promise对象,无返回结果。 |
8400
8401**示例:**
8402
8403```ts
8404import { BusinessError } from '@kit.BasicServicesKit';
8405
8406audioCapturer.release().then(() => {
8407  console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
8408  console.info('AudioFrameworkRecLog: Capturer release : SUCCESS');
8409  console.info(`AudioFrameworkRecLog: AudioCapturer : STATE : ${audioCapturer.state}`);
8410}).catch((err: BusinessError) => {
8411  console.error(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
8412});
8413```
8414
8415### read<sup>8+(deprecated)</sup>
8416
8417read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void
8418
8419读入缓冲区。使用callback方式异步返回结果。
8420
8421> **说明:**
8422> 从 API version 8 开始支持,从 API version 11 开始废弃,建议使用AudioCapturer中的[on('readData')](#onreaddata11)替代。
8423
8424**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8425
8426**参数:**
8427
8428| 参数名         | 类型                        | 必填 | 说明                             |
8429| :------------- | :-------------------------- | :--- | :------------------------------- |
8430| size           | number                      | 是   | 读入的字节数。                   |
8431| isBlockingRead | boolean                     | 是   | 是否阻塞读操作 ,true阻塞,false不阻塞。                 |
8432| callback       | AsyncCallback<ArrayBuffer\> | 是   | 回调函数。当读入缓冲区成功,err为undefined,data为获取到的缓冲区;否则为错误对象。 |
8433
8434**示例:**
8435
8436```ts
8437import { BusinessError } from '@kit.BasicServicesKit';
8438
8439let bufferSize: number = 0;
8440
8441audioCapturer.getBufferSize().then((data: number) => {
8442  console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ${data}`);
8443  bufferSize = data;
8444}).catch((err: BusinessError) => {
8445  console.error(`AudioFrameworkRecLog: getBufferSize: ERROR: ${err}`);
8446});
8447
8448audioCapturer.read(bufferSize, true, (err: BusinessError, buffer: ArrayBuffer) => {
8449  if (!err) {
8450    console.info('Success in reading the buffer data');
8451  }
8452});
8453```
8454
8455### read<sup>8+(deprecated)</sup>
8456
8457read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
8458
8459读入缓冲区。使用Promise方式异步返回结果。
8460
8461> **说明:**
8462> 从 API version 8 开始支持,从 API version 11 开始废弃,建议使用AudioCapturer中的[on('readData')](#onreaddata11)替代。
8463
8464**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8465
8466**参数:**
8467
8468| 参数名         | 类型    | 必填 | 说明             |
8469| :------------- | :------ | :--- | :--------------- |
8470| size           | number  | 是   | 读入的字节数。   |
8471| isBlockingRead | boolean | 是   | 是否阻塞读操作 ,true阻塞,false不阻塞。 |
8472
8473**返回值:**
8474
8475| 类型                  | 说明                                                   |
8476| :-------------------- | :----------------------------------------------------- |
8477| Promise<ArrayBuffer\> | Promise对象,返回读取的缓冲区数据。 |
8478
8479**示例:**
8480
8481```ts
8482import { BusinessError } from '@kit.BasicServicesKit';
8483
8484let bufferSize: number = 0;
8485
8486audioCapturer.getBufferSize().then((data: number) => {
8487  console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ${data}`);
8488  bufferSize = data;
8489}).catch((err: BusinessError) => {
8490  console.error(`AudioFrameworkRecLog: getBufferSize: ERROR ${err}`);
8491});
8492console.info(`Buffer size: ${bufferSize}`);
8493
8494audioCapturer.read(bufferSize, true).then((buffer: ArrayBuffer) => {
8495  console.info('buffer read successfully');
8496}).catch((err: BusinessError) => {
8497  console.error(`ERROR : ${err}`);
8498});
8499```
8500
8501### getAudioTime<sup>8+</sup>
8502
8503getAudioTime(callback: AsyncCallback<number\>): void
8504
8505获取录制到当前位置时的时间戳(从1970年1月1日开始),单位为纳秒。使用callback方式异步返回结果。
8506
8507**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8508
8509**参数:**
8510
8511| 参数名   | 类型                   | 必填 | 说明                           |
8512| :------- | :--------------------- | :--- | :----------------------------- |
8513| callback | AsyncCallback<number\> | 是   | 回调函数。当获取时间戳成功,err为undefined,data为获取到的时间戳;否则为错误对象。 |
8514
8515**示例:**
8516
8517```ts
8518import { BusinessError } from '@kit.BasicServicesKit';
8519
8520audioCapturer.getAudioTime((err: BusinessError, timestamp: number) => {
8521  console.info(`Current timestamp: ${timestamp}`);
8522});
8523```
8524
8525### getAudioTime<sup>8+</sup>
8526
8527getAudioTime(): Promise<number\>
8528
8529获取录制到当前位置时的时间戳(从1970年1月1日开始),单位为纳秒。使用Promise方式异步返回结果。
8530
8531**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8532
8533**返回值:**
8534
8535| 类型             | 说明                          |
8536| :--------------- | :---------------------------- |
8537| Promise<number\> | Promise对象,返回时间戳(从1970年1月1日开始),单位为纳秒。 |
8538
8539**示例:**
8540
8541```ts
8542import { BusinessError } from '@kit.BasicServicesKit';
8543
8544audioCapturer.getAudioTime().then((audioTime: number) => {
8545  console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTime : Success ${audioTime}`);
8546}).catch((err: BusinessError) => {
8547  console.error(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
8548});
8549```
8550
8551### getAudioTimeSync<sup>10+</sup>
8552
8553getAudioTimeSync(): number
8554
8555获取录制到当前位置时的时间戳(从1970年1月1日开始),单位为纳秒。同步返回结果。
8556
8557**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8558
8559**返回值:**
8560
8561| 类型             | 说明                          |
8562| :--------------- | :---------------------------- |
8563| number | 返回时间戳。 |
8564
8565**示例:**
8566
8567```ts
8568import { BusinessError } from '@kit.BasicServicesKit';
8569
8570try {
8571  let audioTime: number = audioCapturer.getAudioTimeSync();
8572  console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTimeSync : Success ${audioTime}`);
8573} catch (err) {
8574  let error = err as BusinessError;
8575  console.error(`AudioFrameworkRecLog: AudioCapturer getAudioTimeSync : ERROR : ${error}`);
8576}
8577```
8578
8579### getBufferSize<sup>8+</sup>
8580
8581getBufferSize(callback: AsyncCallback<number\>): void
8582
8583获取采集器合理的最小缓冲区大小。使用callback方式异步返回结果。
8584
8585**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8586
8587**参数:**
8588
8589| 参数名   | 类型                   | 必填 | 说明                                 |
8590| :------- | :--------------------- | :--- | :----------------------------------- |
8591| callback | AsyncCallback<number\> | 是   | 回调函数。当获取采集器合理的最小缓冲区大小成功,err为undefined,data为获取到的采集器合理的最小缓冲区大小;否则为错误对象。 |
8592
8593**示例:**
8594
8595```ts
8596import { BusinessError } from '@kit.BasicServicesKit';
8597
8598audioCapturer.getBufferSize((err: BusinessError, bufferSize: number) => {
8599  if (!err) {
8600    console.info(`BufferSize : ${bufferSize}`);
8601    audioCapturer.read(bufferSize, true).then((buffer: ArrayBuffer) => {
8602      console.info(`Buffer read is ${buffer.byteLength}`);
8603    }).catch((err: BusinessError) => {
8604      console.error(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
8605    });
8606  }
8607});
8608```
8609
8610### getBufferSize<sup>8+</sup>
8611
8612getBufferSize(): Promise<number\>
8613
8614获取采集器合理的最小缓冲区大小。使用Promise方式异步返回结果。
8615
8616**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8617
8618**返回值:**
8619
8620| 类型             | 说明                                |
8621| :--------------- | :---------------------------------- |
8622| Promise<number\> | Promise对象,返回缓冲区大小。 |
8623
8624**示例:**
8625
8626```ts
8627import { BusinessError } from '@kit.BasicServicesKit';
8628
8629let bufferSize: number = 0;
8630
8631audioCapturer.getBufferSize().then((data: number) => {
8632  console.info(`AudioFrameworkRecLog: getBufferSize :SUCCESS ${data}`);
8633  bufferSize = data;
8634}).catch((err: BusinessError) => {
8635  console.error(`AudioFrameworkRecLog: getBufferSize :ERROR : ${err}`);
8636});
8637```
8638
8639### getBufferSizeSync<sup>10+</sup>
8640
8641getBufferSizeSync(): number
8642
8643获取采集器合理的最小缓冲区大小,同步返回结果。
8644
8645**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8646
8647**返回值:**
8648
8649| 类型             | 说明                                |
8650| :--------------- | :---------------------------------- |
8651| number | 返回缓冲区大小。 |
8652
8653**示例:**
8654
8655```ts
8656import { BusinessError } from '@kit.BasicServicesKit';
8657
8658let bufferSize: number = 0;
8659
8660try {
8661  bufferSize = audioCapturer.getBufferSizeSync();
8662  console.info(`AudioFrameworkRecLog: getBufferSizeSync :SUCCESS ${bufferSize}`);
8663} catch (err) {
8664  let error = err as BusinessError;
8665  console.error(`AudioFrameworkRecLog: getBufferSizeSync :ERROR : ${error}`);
8666}
8667```
8668
8669### getCurrentInputDevices<sup>11+</sup>
8670
8671getCurrentInputDevices(): AudioDeviceDescriptors
8672
8673获取录音流输入设备描述符。使用同步方式返回结果。
8674
8675**系统能力:** SystemCapability.Multimedia.Audio.Device
8676
8677**返回值:**
8678
8679| 类型                   | 说明                                                   |
8680| ---------------------- | ------------------------------------------------------ |
8681| [AudioDeviceDescriptors](#audiodevicedescriptors)            | 同步接口,返回设备属性数组类型数据。 |
8682
8683**示例:**
8684
8685```ts
8686let deviceDescriptors: audio.AudioDeviceDescriptors = audioCapturer.getCurrentInputDevices();
8687console.info(`Device id: ${deviceDescriptors[0].id}`);
8688console.info(`Device type: ${deviceDescriptors[0].deviceType}`);
8689console.info(`Device role: ${deviceDescriptors[0].deviceRole}`);
8690console.info(`Device name: ${deviceDescriptors[0].name}`);
8691console.info(`Device address: ${deviceDescriptors[0].address}`);
8692console.info(`Device samplerates: ${deviceDescriptors[0].sampleRates[0]}`);
8693console.info(`Device channelcounts: ${deviceDescriptors[0].channelCounts[0]}`);
8694console.info(`Device channelmask: ${deviceDescriptors[0].channelMasks[0]}`);
8695if (deviceDescriptors[0].encodingTypes) {
8696  console.info(`Device encodingTypes: ${deviceDescriptors[0].encodingTypes[0]}`);
8697}
8698```
8699
8700### getCurrentAudioCapturerChangeInfo<sup>11+</sup>
8701
8702getCurrentAudioCapturerChangeInfo(): AudioCapturerChangeInfo
8703
8704获取录音流配置。使用同步方式返回结果。
8705
8706**系统能力:** SystemCapability.Multimedia.Audio.Device
8707
8708**返回值:**
8709
8710| 类型             | 说明                                |
8711| :--------------- | :---------------------------------- |
8712| [AudioCapturerChangeInfo](#audiocapturerchangeinfo9) | 同步接口,返回描述音频采集器更改信息。 |
8713
8714**示例:**
8715
8716```ts
8717let info: audio.AudioCapturerChangeInfo = audioCapturer.getCurrentAudioCapturerChangeInfo();
8718console.info(`Info streamId: ${info.streamId}`);
8719console.info(`Info source: ${info.capturerInfo.source}`);
8720console.info(`Info capturerFlags: ${info.capturerInfo.capturerFlags}`);
8721console.info(`Info muted: ${info.muted}`);
8722console.info(`Info type: ${info.deviceDescriptors[0].deviceType}`);
8723console.info(`Info role: ${info.deviceDescriptors[0].deviceRole}`);
8724console.info(`Info name: ${info.deviceDescriptors[0].name}`);
8725console.info(`Info address: ${info.deviceDescriptors[0].address}`);
8726console.info(`Info samplerates: ${info.deviceDescriptors[0].sampleRates[0]}`);
8727console.info(`Info channelcounts: ${info.deviceDescriptors[0].channelCounts[0]}`);
8728console.info(`Info channelmask: ${info.deviceDescriptors[0].channelMasks[0]}`);
8729if (info.deviceDescriptors[0].encodingTypes) {
8730  console.info(`Device encodingTypes: ${info.deviceDescriptors[0].encodingTypes[0]}`);
8731}
8732```
8733
8734### on('audioInterrupt')<sup>10+</sup>
8735
8736on(type: 'audioInterrupt', callback: Callback\<InterruptEvent>): void
8737
8738监听音频中断事件(当音频焦点发生变化时触发),使用callback方式返回结果。
8739
8740AudioCapturer对象在start事件发生时会主动获取焦点,在pause、stop等事件发生时会主动释放焦点,不需要开发者主动发起获取焦点或释放焦点的申请。
8741
8742调用此方法,在AudioCapturer对象获取焦点失败或发生中断事件(如被其他音频打断等)时,会收到[InterruptEvent](#interruptevent9)。建议应用可根据InterruptEvent的信息完成进一步处理,更多信息可参考文档[处理音频焦点事件](../../media/audio/audio-playback-concurrency.md)。
8743
8744**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
8745
8746**参数:**
8747
8748| 参数名   | 类型                                         | 必填 | 说明                                                         |
8749| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
8750| type     | string                                       | 是   | 监听事件,固定为:'audioInterrupt'。 |
8751| callback | Callback\<[InterruptEvent](#interruptevent9)\> | 是   | 回调函数,返回录制中断时,应用接收的中断事件信息。 |
8752
8753**错误码:**
8754
8755以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
8756
8757| 错误码ID | 错误信息 |
8758| ------- | --------------------------------------------|
8759| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
8760| 6800101 | Parameter verification failed. |
8761
8762**示例:**
8763
8764```ts
8765import { audio } from '@kit.AudioKit';
8766
8767let isCapturing: boolean; // 标识符,表示是否正在采集
8768onAudioInterrupt();
8769
8770async function onAudioInterrupt(){
8771  audioCapturer.on('audioInterrupt', (interruptEvent: audio.InterruptEvent) => {
8772    // 在发生音频打断事件时,audioCapturer收到interruptEvent回调,此处根据其内容做相应处理。
8773    // 1、可选:读取interruptEvent.forceType的类型,判断系统是否已强制执行相应操作。
8774    // 注:默认焦点策略下,INTERRUPT_HINT_RESUME为INTERRUPT_SHARE类型,其余hintType均为INTERRUPT_FORCE类型。因此对forceType可不做判断。
8775    // 2、必选:读取interruptEvent.hintType的类型,做出相应的处理。
8776    if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
8777      // 音频焦点事件已由系统强制执行,应用需更新自身状态及显示内容等
8778      switch (interruptEvent.hintType) {
8779        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
8780          // 音频流已被暂停,临时失去焦点,待可重获焦点时会收到resume对应的interruptEvent
8781          console.info('Force paused. Update capturing status and stop reading');
8782          isCapturing = false; // 简化处理,代表应用切换至暂停状态的若干操作
8783          break;
8784        case audio.InterruptHint.INTERRUPT_HINT_STOP:
8785          // 音频流已被停止,永久失去焦点,若想恢复采集,需用户主动触发
8786          console.info('Force stopped. Update capturing status and stop reading');
8787          isCapturing = false; // 简化处理,代表应用切换至暂停状态的若干操作
8788          break;
8789        default:
8790          console.info('Invalid interruptEvent');
8791          break;
8792      }
8793    } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
8794      // 音频焦点事件需由应用进行操作,应用可以自主选择如何处理该事件,建议应用遵从InterruptHint提示处理
8795      switch (interruptEvent.hintType) {
8796        case audio.InterruptHint.INTERRUPT_HINT_RESUME:
8797          // 建议应用继续采集(说明音频流此前被强制暂停,临时失去焦点,现在可以恢复采集)
8798          // 由于INTERRUPT_HINT_RESUME操作需要应用主动执行,系统无法强制,故INTERRUPT_HINT_RESUME事件一定为INTERRUPT_SHARE类型
8799          console.info('Resume force paused renderer or ignore');
8800          // 若选择继续采集,需在此处主动执行开始采集的若干操作
8801          break;
8802        default:
8803          console.info('Invalid interruptEvent');
8804          break;
8805      }
8806    }
8807  });
8808}
8809```
8810
8811### off('audioInterrupt')<sup>10+</sup>
8812
8813off(type: 'audioInterrupt'): void
8814
8815取消监听音频中断事件。
8816
8817**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
8818
8819**参数:**
8820
8821| 参数名   | 类型                                         | 必填 | 说明                                                         |
8822| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
8823| type     | string                                       | 是   | 监听事件,固定为:'audioInterrupt'。 |
8824
8825**错误码:**
8826
8827以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
8828
8829| 错误码ID | 错误信息 |
8830| ------- | --------------------------------------------|
8831| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
8832| 6800101 | Parameter verification failed. |
8833
8834**示例:**
8835
8836```ts
8837audioCapturer.off('audioInterrupt');
8838```
8839
8840### on('inputDeviceChange')<sup>11+</sup>
8841
8842on(type: 'inputDeviceChange', callback: Callback\<AudioDeviceDescriptors>): void
8843
8844监听音频输入设备变化事件(当音频输入设备发生变化时触发),使用callback方式返回结果。
8845
8846**系统能力:** SystemCapability.Multimedia.Audio.Device
8847
8848**参数:**
8849
8850| 参数名   | 类型                       | 必填 | 说明                                        |
8851| :------- | :------------------------- | :--- | :------------------------------------------ |
8852| type     | string                     | 是   | 监听事件,固定为:'inputDeviceChange'。 |
8853| callback | Callback\<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 是   | 回调函数,返回监听的音频输入设备变化(返回数据为切换后的设备信息)。 |
8854
8855**错误码:**
8856
8857以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
8858
8859| 错误码ID | 错误信息 |
8860| ------- | --------------------------------------------|
8861| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
8862| 6800101 | Parameter verification failed. |
8863
8864**示例:**
8865
8866```ts
8867audioCapturer.on('inputDeviceChange', (deviceChangeInfo: audio.AudioDeviceDescriptors) => {
8868  console.info(`inputDevice id: ${deviceChangeInfo[0].id}`);
8869  console.info(`inputDevice deviceRole: ${deviceChangeInfo[0].deviceRole}`);
8870  console.info(`inputDevice deviceType: ${deviceChangeInfo[0].deviceType}`);
8871});
8872```
8873### off('inputDeviceChange')<sup>11+</sup>
8874
8875off(type: 'inputDeviceChange', callback?: Callback\<AudioDeviceDescriptors>): void
8876
8877取消监听音频输入设备更改事件,使用callback方式返回结果。
8878
8879**系统能力:** SystemCapability.Multimedia.Audio.Device
8880
8881**参数:**
8882
8883| 参数名   | 类型                       | 必填 | 说明                                       |
8884| :------- | :------------------------- | :--- |:-----------------------------------------|
8885| type     | string                     | 是   | 监听事件,固定为:'inputDeviceChange'。       |
8886| callback | Callback\<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 否   | 回调函数,返回监听的音频输入设备信息。 |
8887
8888**错误码:**
8889
8890以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
8891
8892| 错误码ID | 错误信息 |
8893| ------- | --------------------------------------------|
8894| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
8895| 6800101 | Parameter verification failed. |
8896
8897**示例:**
8898
8899```ts
8900// 取消该事件的所有监听
8901audioCapturer.off('inputDeviceChange');
8902
8903// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
8904let inputDeviceChangeCallback = (deviceChangeInfo: audio.AudioDeviceDescriptors) => {
8905  console.info(`inputDevice id: ${deviceChangeInfo[0].id}`);
8906  console.info(`inputDevice deviceRole: ${deviceChangeInfo[0].deviceRole}`);
8907  console.info(`inputDevice deviceType: ${deviceChangeInfo[0].deviceType}`);
8908};
8909
8910audioCapturer.on('inputDeviceChange', inputDeviceChangeCallback);
8911
8912audioCapturer.off('inputDeviceChange', inputDeviceChangeCallback);
8913```
8914
8915### on('audioCapturerChange')<sup>11+</sup>
8916
8917on(type: 'audioCapturerChange', callback: Callback\<AudioCapturerChangeInfo>): void
8918
8919监听录音流配置变化事件(当音频录制流状态变化、设备变化时触发),使用callback方式返回结果。订阅内部是异步实现,是非精确回调,在录音流配置变化的同时注册回调,收到的返回结果存在变化可能性。
8920
8921**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8922
8923**参数:**
8924
8925| 参数名   | 类型                       | 必填 | 说明                                        |
8926| :------- | :------------------------- | :--- | :------------------------------------------ |
8927| type     | string                     | 是   | 监听事件,固定为:'audioCapturerChange'。 |
8928| callback | Callback\<[AudioCapturerChangeInfo](#audiocapturerchangeinfo9)> | 是   | 回调函数,录音流配置或状态变化时返回监听的录音流当前配置和状态信息。 |
8929
8930**错误码:**
8931
8932以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
8933
8934| 错误码ID | 错误信息 |
8935| ------- | --------------------------------------------|
8936| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
8937| 6800101 | Parameter verification failed. |
8938
8939**示例:**
8940
8941```ts
8942audioCapturer.on('audioCapturerChange', (capturerChangeInfo: audio.AudioCapturerChangeInfo) => {
8943  console.info(`audioCapturerChange id: ${capturerChangeInfo[0].id}`);
8944  console.info(`audioCapturerChange deviceRole: ${capturerChangeInfo[0].deviceRole}`);
8945  console.info(`audioCapturerChange deviceType: ${capturerChangeInfo[0].deviceType}`);
8946});
8947```
8948
8949### off('audioCapturerChange')<sup>11+</sup>
8950
8951off(type: 'audioCapturerChange', callback?: Callback\<AudioCapturerChangeInfo>): void
8952
8953取消监听录音流配置变化事件,使用callback方式返回结果。
8954
8955**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8956
8957**参数:**
8958
8959| 参数名   | 类型                       | 必填 | 说明                                        |
8960| :------- | :------------------------- | :--- | :------------------------------------------ |
8961| type     | string                     | 是   | 监听事件,固定为:'audioCapturerChange'。 |
8962| callback | Callback\<[AudioCapturerChangeInfo](#audiocapturerchangeinfo9)> | 否   | 回调函数,返回取消监听的录音流配置或状态变化。 |
8963
8964**错误码:**
8965
8966以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
8967
8968| 错误码ID | 错误信息 |
8969| ------- | --------------------------------------------|
8970| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
8971| 6800101 | Parameter verification failed. |
8972
8973**示例:**
8974
8975```ts
8976// 取消该事件的所有监听
8977audioCapturer.off('audioCapturerChange');
8978
8979// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
8980let audioCapturerChangeCallback = (capturerChangeInfo: audio.AudioCapturerChangeInfo) => {
8981  console.info(`audioCapturerChange id: ${capturerChangeInfo[0].id}`);
8982  console.info(`audioCapturerChange deviceRole: ${capturerChangeInfo[0].deviceRole}`);
8983  console.info(`audioCapturerChange deviceType: ${capturerChangeInfo[0].deviceType}`);
8984};
8985
8986audioCapturer.on('audioCapturerChange', audioCapturerChangeCallback);
8987
8988audioCapturer.off('audioCapturerChange', audioCapturerChangeCallback);
8989```
8990
8991### on('markReach')<sup>8+</sup>
8992
8993on(type: 'markReach', frame: number, callback: Callback&lt;number&gt;): void
8994
8995监听标记到达事件(当采集的帧数达到frame参数的值时触发,仅调用一次),使用callback方式返回结果。
8996
8997举例说明,如果frame设置为100,当采集帧数到达第100帧时,将上报信息。
8998
8999**系统能力:** SystemCapability.Multimedia.Audio.Capturer
9000
9001**参数:**
9002
9003| 参数名   | 类型                     | 必填 | 说明                                       |
9004| :------- | :----------------------  | :--- | :----------------------------------------- |
9005| type     | string                   | 是   | 监听事件,固定为:'markReach'。  |
9006| frame    | number                   | 是   | 触发事件的帧数。该值必须大于0。           |
9007| callback | Callback\<number>         | 是   | 回调函数,返回frame参数的值。 |
9008
9009**示例:**
9010
9011```ts
9012audioCapturer.on('markReach', 1000, (position: number) => {
9013  if (position == 1000) {
9014    console.info('ON Triggered successfully');
9015  }
9016});
9017```
9018
9019### off('markReach')<sup>8+</sup>
9020
9021off(type: 'markReach'): void
9022
9023取消监听标记到达事件。
9024
9025**系统能力:** SystemCapability.Multimedia.Audio.Capturer
9026
9027**参数:**
9028
9029| 参数名 | 类型   | 必填 | 说明                                          |
9030| :----- | :----- | :--- | :-------------------------------------------- |
9031| type   | string | 是   | 监听事件,固定为:'markReach'。 |
9032
9033**示例:**
9034
9035```ts
9036audioCapturer.off('markReach');
9037```
9038
9039### on('periodReach')<sup>8+</sup>
9040
9041on(type: 'periodReach', frame: number, callback: Callback&lt;number&gt;): void
9042
9043监听到达标记事件(当采集的帧数达到frame参数的值时触发,即按周期上报信息),使用callback方式返回结果。
9044
9045举例说明,如果frame设置为10,每当采集10帧数据时将上报信息,例如在第10帧、20帧、30帧,均会上报信息。
9046
9047**系统能力:** SystemCapability.Multimedia.Audio.Capturer
9048
9049**参数:**
9050
9051| 参数名   | 类型                     | 必填 | 说明                                        |
9052| :------- | :----------------------- | :--- | :------------------------------------------ |
9053| type     | string                   | 是   | 监听事件,固定为:'periodReach'。 |
9054| frame    | number                   | 是   | 触发事件的帧数。该值必须大于0。            |
9055| callback | Callback\<number>         | 是   |回调函数,返回frame参数的值。    |
9056
9057**示例:**
9058
9059```ts
9060audioCapturer.on('periodReach', 1000, (position: number) => {
9061  if (position == 1000) {
9062    console.info('ON Triggered successfully');
9063  }
9064});
9065```
9066
9067### off('periodReach')<sup>8+</sup>
9068
9069off(type: 'periodReach'): void
9070
9071取消监听标记到达事件。
9072
9073**系统能力:** SystemCapability.Multimedia.Audio.Capturer
9074
9075**参数:**
9076
9077| 参数名 | 类型   | 必填 | 说明                                            |
9078| :----- | :----- | :--- | :---------------------------------------------- |
9079| type   | string | 是  | 监听事件,固定为:'periodReach'。 |
9080
9081**示例:**
9082
9083```ts
9084audioCapturer.off('periodReach');
9085```
9086
9087### on('stateChange')<sup>8+</sup>
9088
9089on(type: 'stateChange', callback: Callback<AudioState\>): void
9090
9091监听状态变化事件(当AudioCapturer状态发生变化时触发),使用callback方式返回结果。
9092
9093**系统能力:** SystemCapability.Multimedia.Audio.Capturer
9094
9095**参数:**
9096
9097| 参数名   | 类型                       | 必填 | 说明                                        |
9098| :------- | :------------------------- | :--- | :------------------------------------------ |
9099| type     | string                     | 是   | 监听事件,固定为:'stateChange'。 |
9100| callback | Callback\<[AudioState](#audiostate8)> | 是   | 回调函数,返回当前音频的状态。 |
9101
9102**示例:**
9103
9104```ts
9105audioCapturer.on('stateChange', (state: audio.AudioState) => {
9106  if (state == 1) {
9107    console.info('audio capturer state is: STATE_PREPARED');
9108  }
9109  if (state == 2) {
9110    console.info('audio capturer state is: STATE_RUNNING');
9111  }
9112});
9113```
9114
9115### on('readData')<sup>11+</sup>
9116
9117on(type: 'readData', callback: Callback\<ArrayBuffer>): void
9118
9119监听音频数据读取回调事件(当需要读取音频流数据时触发),使用callback方式返回结果。
9120
9121回调函数仅用来读取音频数据,请勿在回调函数中调用AudioCapturer相关接口。
9122
9123**系统能力:** SystemCapability.Multimedia.Audio.Capturer
9124
9125**参数:**
9126
9127| 参数名   | 类型                     | 必填 | 说明                        |
9128| :------- |:-----------------------| :--- |:--------------------------|
9129| type     | string                 | 是   | 监听事件,固定为:'readData'。 |
9130| callback | Callback\<ArrayBuffer> | 是   | 回调函数,返回读到的数据缓冲区。            |
9131
9132**错误码:**
9133
9134以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
9135
9136| 错误码ID | 错误信息 |
9137| ------- | --------------------------------------------|
9138| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
9139| 6800101 | Parameter verification failed. |
9140
9141**示例:**
9142
9143```ts
9144import { BusinessError } from '@kit.BasicServicesKit';
9145import { fileIo as fs } from '@kit.CoreFileKit';
9146
9147class Options {
9148  offset?: number;
9149  length?: number;
9150}
9151
9152let bufferSize: number = 0;
9153let path = getContext().cacheDir;
9154// 确保该沙箱路径下存在该资源
9155let filePath = path + '/StarWars10s-2C-48000-4SW.pcm';
9156let file: fs.File = fs.openSync(filePath, fs.OpenMode.READ_WRITE);
9157let readDataCallback = (buffer: ArrayBuffer) => {
9158  let options: Options = {
9159    offset: bufferSize,
9160    length: buffer.byteLength
9161  };
9162  fs.writeSync(file.fd, buffer, options);
9163  bufferSize += buffer.byteLength;
9164}
9165
9166audioCapturer.on('readData', readDataCallback);
9167
9168audioCapturer.start((err: BusinessError) => {
9169  if (err) {
9170    console.error('Capturer start failed.');
9171  } else {
9172    console.info('Capturer start success.');
9173  }
9174});
9175```
9176
9177### off('readData')<sup>11+</sup>
9178
9179off(type: 'readData', callback?: Callback\<ArrayBuffer>): void
9180
9181取消监听音频数据读取回调事件,使用callback方式返回结果。
9182
9183**系统能力:** SystemCapability.Multimedia.Audio.Capturer
9184
9185**参数:**
9186
9187| 参数名   | 类型                     | 必填 | 说明                                         |
9188| :------- |:-----------------------| :--- |:-------------------------------------------|
9189| type     | string                 | 是   | 监听事件,固定为:'readData'。                 |
9190| callback | Callback\<ArrayBuffer> | 否   | 回调函数,返回读到的数据缓冲区。                            |
9191
9192**错误码:**
9193
9194以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
9195
9196| 错误码ID | 错误信息 |
9197| ------- | --------------------------------------------|
9198| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
9199| 6800101 | Parameter verification failed. |
9200
9201**示例:**
9202
9203```ts
9204// 取消该事件的所有监听
9205audioCapturer.off('readData');
9206
9207// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
9208let readDataCallback = (data: ArrayBuffer) => {
9209    console.info(`read data: ${data}`);
9210};
9211
9212audioCapturer.on('readData', readDataCallback);
9213
9214audioCapturer.off('readData', readDataCallback);
9215```
9216
9217### getOverflowCount<sup>12+</sup>
9218
9219getOverflowCount(): Promise&lt;number&gt;
9220
9221获取当前录制音频流的过载音频帧数量。使用Promise异步回调。
9222
9223**系统能力:** SystemCapability.Multimedia.Audio.Capturer
9224
9225**返回值:**
9226
9227| 类型                | 说明                          |
9228| ------------------- | ----------------------------- |
9229| Promise&lt;number&gt;| Promise对象,返回音频流的过载音频帧数量。|
9230
9231**示例:**
9232
9233```ts
9234import { BusinessError } from '@kit.BasicServicesKit';
9235
9236audioCapturer.getOverflowCount().then((value: number) => {
9237  console.info(`Get overflow count Success! ${value}`);
9238}).catch((err: BusinessError) => {
9239  console.error(`Get overflow count Fail: ${err}`);
9240});
9241```
9242
9243### getOverflowCountSync<sup>12+</sup>
9244
9245getOverflowCountSync(): number
9246
9247获取当前录制音频流的过载音频帧数量,同步返回数据。
9248
9249**系统能力:** SystemCapability.Multimedia.Audio.Capturer
9250
9251**返回值:**
9252
9253| 类型                | 说明                          |
9254| ------------------- | ----------------------------- |
9255| number| 返回音频流的过载音频帧数量。|
9256
9257**示例:**
9258
9259```ts
9260import { BusinessError } from '@kit.BasicServicesKit';
9261
9262try {
9263  let value: number = audioCapturer.getOverflowCountSync();
9264  console.info(`Get overflow count Success! ${value}`);
9265} catch (err) {
9266  let error = err as BusinessError;
9267  console.error(`Get overflow count Fail: ${error}`);
9268}
9269```
9270
9271## ActiveDeviceType<sup>(deprecated)</sup>
9272
9273枚举,活跃设备类型。
9274
9275> **说明:**
9276>
9277> 从 API version 9 开始废弃,建议使用[CommunicationDeviceType](#communicationdevicetype9)替代。
9278
9279**系统能力:** SystemCapability.Multimedia.Audio.Device
9280
9281| 名称          |  值     | 说明                                                 |
9282| ------------- | ------ | ---------------------------------------------------- |
9283| SPEAKER       | 2      | 扬声器。                                             |
9284| BLUETOOTH_SCO | 7      | 蓝牙设备SCO(Synchronous Connection Oriented)连接。 |
9285
9286## InterruptActionType<sup>(deprecated)</sup>
9287
9288枚举,中断事件返回类型。
9289
9290> **说明:**
9291>
9292> 从 API version 7 开始支持,从 API version 9 开始废弃。无替代接口,与中断事件配套使用。
9293
9294**系统能力:** SystemCapability.Multimedia.Audio.Renderer
9295
9296| 名称           |  值     | 说明               |
9297| -------------- | ------ | ------------------ |
9298| TYPE_ACTIVATED | 0      | 表示触发焦点事件。 |
9299| TYPE_INTERRUPT | 1      | 表示音频打断事件。 |
9300
9301## AudioInterrupt<sup>(deprecated)</sup>
9302
9303音频监听事件传入的参数。
9304
9305> **说明:**
9306>
9307> 从 API version 7 开始支持,从 API version 9 开始废弃。无替代接口,与中断事件配套使用。
9308
9309**系统能力:** SystemCapability.Multimedia.Audio.Renderer
9310
9311| 名称            | 类型                        | 必填 | 说明                                                         |
9312| --------------- | --------------------------- | ----| ------------------------------------------------------------ |
9313| streamUsage     | [StreamUsage](#streamusage) | 是  | 音频流使用类型。                                             |
9314| contentType     | [ContentType](#contenttypedeprecated) | 是  | 音频打断媒体类型。                                           |
9315| pauseWhenDucked | boolean                     | 是  | 音频打断时是否可以暂停音频播放(true表示音频播放可以在音频打断期间暂停,false表示相反)。 |
9316
9317## InterruptAction<sup>(deprecated)</sup>
9318
9319音频打断/获取焦点事件的回调方法。
9320
9321> **说明:**
9322>
9323> 从 API version 7 开始支持,从 API version 9 开始废弃。建议使用[InterruptEvent](#interruptevent9)替代。
9324
9325**系统能力:** SystemCapability.Multimedia.Audio.Renderer
9326
9327| 名称       | 类型                                        | 必填 | 说明                                                         |
9328| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
9329| actionType | [InterruptActionType](#interruptactiontypedeprecated) | 是   | 事件返回类型。TYPE_ACTIVATED为焦点触发事件,TYPE_INTERRUPT为音频打断事件。 |
9330| type       | [InterruptType](#interrupttype)             | 否   | 打断事件类型。                                               |
9331| hint       | [InterruptHint](#interrupthint)             | 否   | 打断事件提示。                                               |
9332| activated  | boolean                                     | 否   | 获得/释放焦点。true表示焦点获取/释放成功,false表示焦点获得/释放失败。 |
9333