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_44100,
79  channels: audio.AudioChannel.CHANNEL_1,
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_VOICE_COMMUNICATION,
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_44100,
132  channels: audio.AudioChannel.CHANNEL_1,
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_VOICE_COMMUNICATION,
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)时需要该权限。
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_44100,
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)时需要该权限。
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_44100,
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 | 0x1 << 0 | 单声道。 |
418| CHANNEL_2 | 0x1 << 1 | 双声道。 |
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## ChannelBlendMode<sup>11+</sup>
757
758枚举,声道混合模式类型。
759
760**系统能力:** SystemCapability.Multimedia.Audio.Core
761
762| 名称                                         |  值     | 说明                   |
763| :------------------------------------------- | :----- | :--------------------- |
764| MODE_DEFAULT | 0     | 无声道混合。  |
765| MODE_BLEND_LR | 1      | 混合左右声道。 |
766| MODE_ALL_LEFT | 2      | 从左声道拷贝覆盖到右声道混合。  |
767| MODE_ALL_RIGHT | 3 | 从右声道拷贝覆盖到左声道混合。 |
768
769## AudioStreamDeviceChangeReason<sup>11+</sup>
770
771枚举,流设备变更原因。
772
773**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
774
775**系统能力:** SystemCapability.Multimedia.Audio.Device
776
777| 名称                                        |  值     | 说明              |
778|:------------------------------------------| :----- |:----------------|
779| REASON_UNKNOWN | 0 | 未知原因。           |
780| REASON_NEW_DEVICE_AVAILABLE | 1 | 新设备可用。         |
781| REASON_OLD_DEVICE_UNAVAILABLE | 2 | 旧设备不可用。当报告此原因时,应用程序应考虑暂停音频播放。 |
782| REASON_OVERRODE | 3 | 强选。 |
783
784## AudioStreamDeviceChangeInfo<sup>11+</sup>
785
786流设备变更时,应用接收的事件。
787
788**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
789
790**系统能力:** SystemCapability.Multimedia.Audio.Device
791
792| 名称              | 类型                                                                | 必填 | 说明               |
793| :---------------- |:------------------------------------------------------------------| :--- | :----------------- |
794| devices              | [AudioDeviceDescriptors](#audiodevicedescriptors)                 | 是   | 设备信息。 |
795| changeReason | [AudioStreamDeviceChangeReason](#audiostreamdevicechangereason11) | 是   | 流设备变更原因。 |
796
797## DeviceChangeType
798
799枚举,设备连接状态变化。
800
801**系统能力:** SystemCapability.Multimedia.Audio.Device
802
803| 名称       | 值   | 说明           |
804| :--------- | :--- | :------------- |
805| CONNECT    | 0    | 设备连接。     |
806| DISCONNECT | 1    | 断开设备连接。 |
807
808## AudioCapturerOptions<sup>8+</sup>
809
810音频采集器选项信息。
811
812| 名称                                | 类型                                                      | 必填 | 说明                                                         |
813| ----------------------------------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ |
814| streamInfo                          | [AudioStreamInfo](#audiostreaminfo8)                      | 是   | 表示音频流信息。 <br/>**系统能力:** SystemCapability.Multimedia.Audio.Capturer   |
815| capturerInfo                        | [AudioCapturerInfo](#audiocapturerinfo8)                   | 是   | 表示采集器信息。 <br/>**系统能力:** SystemCapability.Multimedia.Audio.Capturer        |
816| 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)进行内录。 |
817
818## AudioCapturerInfo<sup>8+</sup>
819
820描述音频采集器信息。
821
822**系统能力:** SystemCapability.Multimedia.Audio.Core
823
824| 名称          | 类型                      | 必填 | 说明             |
825| :------------ | :------------------------ | :--- | :--------------- |
826| source        | [SourceType](#sourcetype8) | 是   | 音源类型。       |
827| capturerFlags | number                    | 是   | 音频采集器标志。<br>0代表音频采集器。 |
828
829## SourceType<sup>8+</sup>
830
831枚举,音源类型。
832
833| 名称                                         |  值     | 说明                   |
834| :------------------------------------------- | :----- | :--------------------- |
835| SOURCE_TYPE_INVALID                          | -1     | 无效的音频源。<br/>**系统能力:** SystemCapability.Multimedia.Audio.Core  |
836| SOURCE_TYPE_MIC                              | 0      | Mic音频源。<br/>**系统能力:** SystemCapability.Multimedia.Audio.Core |
837| SOURCE_TYPE_VOICE_RECOGNITION<sup>9+</sup>   | 1      | 语音识别源。<br/>**系统能力:** SystemCapability.Multimedia.Audio.Core  |
838| 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)进行内录。 |
839| SOURCE_TYPE_VOICE_COMMUNICATION              | 7      | 语音通话场景的音频源。<br/>**系统能力:** SystemCapability.Multimedia.Audio.Core |
840| SOURCE_TYPE_VOICE_MESSAGE<sup>12+</sup>      | 10     | 短语音消息的音频源。<br/>**系统能力:** SystemCapability.Multimedia.Audio.Core |
841
842## AudioPlaybackCaptureConfig<sup>(deprecated)</sup>
843
844播放音频流录制(内录)的配置信息。
845
846> **说明:**
847> 从 API version 10 开始支持,从 API version 12 开始废弃。Audio不再提供内录接口,请通过[录屏接口AVScreenCapture](../apis-media-kit/_a_v_screen_capture.md)进行内录。
848
849**系统能力:** SystemCapability.Multimedia.Audio.PlaybackCapture
850
851| 名称          | 类型                                          | 必填 | 说明                             |
852| ------------- | --------------------------------------------- | ---- | -------------------------------- |
853| filterOptions | [CaptureFilterOptions](#capturefilteroptionsdeprecated) | 是   | 需要录制的播放音频流的筛选信息。 |
854
855## CaptureFilterOptions<sup>(deprecated)</sup>
856
857待录制的播放音频流的筛选信息。
858
859> **说明:**
860> 从 API version 10 开始支持,从 API version 12 开始废弃。Audio不再提供内录接口,请通过[录屏接口AVScreenCapture](../apis-media-kit/_a_v_screen_capture.md)进行内录。
861
862**需要权限:** ohos.permission.CAPTURE_VOICE_DOWNLINK_AUDIO,具体请参考以下说明。
863
864- 在API version 10时,CaptureFilterOptions支持使用StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,使用时需要申请权限ohos.permission.CAPTURE_VOICE_DOWNLINK_AUDIO,该权限仅系统应用可申请。
865
866- 从API version 11开始,CaptureFilterOptions不再支持使用StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,所以当前接口不再涉及此权限。
867
868**系统能力:** SystemCapability.Multimedia.Audio.PlaybackCapture
869
870| 名称   | 类型                               | 必填 | 说明                                                         |
871| ------ | ---------------------------------- | ---- | ------------------------------------------------------------ |
872| usages | Array<[StreamUsage](#streamusage)> | 是   | 指定需要录制的音频播放流的StreamUsage类型。可同时指定0个或多个StreamUsage。Array为空时,默认录制StreamUsage为STREAM_USAGE_MUSIC、STREAM_USAGE_MOVIE、STREAM_USAGE_GAME和STREAM_USAGE_AUDIOBOOK的音频播放流。 |
873
874## AudioScene<sup>8+</sup>
875
876枚举,音频场景。
877
878**系统能力:** SystemCapability.Multimedia.Audio.Communication
879
880| 名称                   |  值     | 说明                                          |
881| :--------------------- | :----- | :-------------------------------------------- |
882| AUDIO_SCENE_DEFAULT                  | 0      | 默认音频场景。                                |
883| AUDIO_SCENE_RINGING<sup>12+</sup>    | 1      | 响铃模式。 |
884| AUDIO_SCENE_PHONE_CALL<sup>12+</sup> | 2      | 电话模式。 |
885| AUDIO_SCENE_VOICE_CHAT               | 3      | 语音聊天模式。                                |
886
887## AudioConcurrencyMode<sup>12+</sup>
888
889枚举,音频并发模式。
890
891**系统能力:** SystemCapability.Multimedia.Audio.Core
892
893| 名称                   | 值 | 说明      |
894| :--------------------- |:--|:--------|
895| CONCURRENCY_DEFAULT | 0 | 默认使用系统策略。     |
896| CONCURRENCY_MIX_WITH_OTHERS | 1 | 和其它音频并发。     |
897| CONCURRENCY_DUCK_OTHERS | 2 | 压低其他音频的音量。 |
898| CONCURRENCY_PAUSE_OTHERS | 3 | 暂停其他音频。 |
899
900## AudioSessionDeactivatedReason<sup>12+</sup>
901
902枚举,音频会话停用原因。
903
904**系统能力:** SystemCapability.Multimedia.Audio.Core
905
906| 名称                   | 值 | 说明     |
907| :--------------------- |:--|:-------|
908| DEACTIVATED_LOWER_PRIORITY | 0 | 应用焦点被抢占。 |
909| DEACTIVATED_TIMEOUT | 1 | 音频会话等待超时。    |
910
911## AudioSessionStrategy<sup>12+</sup>
912
913音频会话策略。
914
915**系统能力:** SystemCapability.Multimedia.Audio.Core
916
917| 名称          | 类型                                              | 必填 | 说明             |
918| :------------ |:------------------------------------------------| :--- | :--------------- |
919| concurrencyMode        | [AudioConcurrencyMode](#audioconcurrencymode12) | 是   | 音频并发模式。       |
920
921## AudioSessionDeactivatedEvent<sup>12+</sup>
922
923音频会话已停用事件。
924
925**系统能力:** SystemCapability.Multimedia.Audio.Core
926
927| 名称          | 类型                                                                | 必填 | 说明             |
928| :------------ |:------------------------------------------------------------------| :--- | :--------------- |
929| reason        | [AudioSessionDeactivatedReason](#audiosessiondeactivatedreason12) | 是   | 音频会话停用原因。       |
930
931## AudioManager
932
933管理音频音量和音频设备。在调用AudioManager的接口前,需要先通过[getAudioManager](#audiogetaudiomanager)创建实例。
934
935### setAudioParameter<sup>(deprecated)</sup>
936
937setAudioParameter(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
938
939音频参数设置,使用callback方式异步返回结果。
940
941接口用于为根据硬件设备支持能力扩展音频配置。支持的参数与产品、设备强相关,非通用参数,示例代码内使用样例参数。
942
943> **说明:**
944> 从 API version 7 开始支持,从 API version 11 开始废弃。替代接口仅面向系统应用开放。
945
946**需要权限:** ohos.permission.MODIFY_AUDIO_SETTINGS
947
948**系统能力:** SystemCapability.Multimedia.Audio.Core
949
950**参数:**
951
952| 参数名   | 类型                      | 必填 | 说明                     |
953| -------- | ------------------------- | ---- | ------------------------ |
954| key      | string                    | 是   | 被设置的音频参数的键。   |
955| value    | string                    | 是   | 被设置的音频参数的值。   |
956| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。当音频参数设置成功,err为undefined,否则为错误对象。 |
957
958**示例:**
959
960```ts
961import { BusinessError } from '@kit.BasicServicesKit';
962
963audioManager.setAudioParameter('key_example', 'value_example', (err: BusinessError) => {
964  if (err) {
965    console.error(`Failed to set the audio parameter. ${err}`);
966    return;
967  }
968  console.info('Callback invoked to indicate a successful setting of the audio parameter.');
969});
970```
971
972### setAudioParameter<sup>(deprecated)</sup>
973
974setAudioParameter(key: string, value: string): Promise&lt;void&gt;
975
976音频参数设置,使用Promise方式异步返回结果。
977
978接口用于为根据硬件设备支持能力扩展音频配置。支持的参数与产品、设备强相关,非通用参数,示例代码内使用样例参数。
979
980> **说明:**
981> 从 API version 7 开始支持,从 API version 11 开始废弃。替代接口仅面向系统应用开放。
982
983**需要权限:** ohos.permission.MODIFY_AUDIO_SETTINGS
984
985**系统能力:** SystemCapability.Multimedia.Audio.Core
986
987**参数:**
988
989| 参数名 | 类型   | 必填 | 说明                   |
990| ------ | ------ | ---- | ---------------------- |
991| key    | string | 是   | 被设置的音频参数的键。 |
992| value  | string | 是   | 被设置的音频参数的值。 |
993
994**返回值:**
995
996| 类型                | 说明                            |
997| ------------------- | ------------------------------- |
998| Promise&lt;void&gt; | Promise对象,无返回结果。 |
999
1000**示例:**
1001
1002```ts
1003audioManager.setAudioParameter('key_example', 'value_example').then(() => {
1004  console.info('Promise returned to indicate a successful setting of the audio parameter.');
1005});
1006```
1007
1008### getAudioParameter<sup>(deprecated)</sup>
1009
1010getAudioParameter(key: string, callback: AsyncCallback&lt;string&gt;): void
1011
1012获取指定音频参数值,使用callback方式异步返回结果。
1013
1014本接口的使用场景为根据硬件设备支持能力扩展音频配置。在不同的设备平台上,所支持的音频参数会存在差异。示例代码内使用样例参数,实际支持的音频配置参数见具体设备平台的资料描述。
1015
1016> **说明:**
1017> 从 API version 7 开始支持,从 API version 11 开始废弃。替代接口仅面向系统应用开放。
1018
1019**系统能力:** SystemCapability.Multimedia.Audio.Core
1020
1021**参数:**
1022
1023| 参数名   | 类型                        | 必填 | 说明                         |
1024| -------- | --------------------------- | ---- | ---------------------------- |
1025| key      | string                      | 是   | 待获取的音频参数的键。       |
1026| callback | AsyncCallback&lt;string&gt; | 是   | 回调函数。当获取指定音频参数值成功,err为undefined,data为获取到的指定音频参数值;否则为错误对象。 |
1027
1028**示例:**
1029
1030```ts
1031import { BusinessError } from '@kit.BasicServicesKit';
1032
1033audioManager.getAudioParameter('key_example', (err: BusinessError, value: string) => {
1034  if (err) {
1035    console.error(`Failed to obtain the value of the audio parameter. ${err}`);
1036    return;
1037  }
1038  console.info(`Callback invoked to indicate that the value of the audio parameter is obtained ${value}.`);
1039});
1040```
1041
1042### getAudioParameter<sup>(deprecated)</sup>
1043
1044getAudioParameter(key: string): Promise&lt;string&gt;
1045
1046获取指定音频参数值,使用Promise方式异步返回结果。
1047
1048本接口的使用场景为根据硬件设备支持能力扩展音频配置。在不同的设备平台上,所支持的音频参数会存在差异。示例代码内使用样例参数,实际支持的音频配置参数见具体设备平台的资料描述。
1049
1050> **说明:**
1051> 从 API version 7 开始支持,从 API version 11 开始废弃。替代接口仅面向系统应用开放。
1052
1053**系统能力:** SystemCapability.Multimedia.Audio.Core
1054
1055**参数:**
1056
1057| 参数名 | 类型   | 必填 | 说明                   |
1058| ------ | ------ | ---- | ---------------------- |
1059| key    | string | 是   | 待获取的音频参数的键。 |
1060
1061**返回值:**
1062
1063| 类型                  | 说明                                |
1064| --------------------- | ----------------------------------- |
1065| Promise&lt;string&gt; | Promise对象,返回获取的音频参数的值。 |
1066
1067**示例:**
1068
1069```ts
1070audioManager.getAudioParameter('key_example').then((value: string) => {
1071  console.info(`Promise returned to indicate that the value of the audio parameter is obtained ${value}.`);
1072});
1073```
1074
1075### getAudioScene<sup>8+</sup>
1076
1077getAudioScene\(callback: AsyncCallback<AudioScene\>\): void
1078
1079获取音频场景模式,使用callback方式返回异步结果。
1080
1081**系统能力:** SystemCapability.Multimedia.Audio.Communication
1082
1083**参数:**
1084
1085| 参数名   | 类型                                                | 必填 | 说明                         |
1086| :------- | :-------------------------------------------------- | :--- | :--------------------------- |
1087| callback | AsyncCallback<[AudioScene](#audioscene8)> | 是   | 回调函数。当获取音频场景模式成功,err为undefined,data为获取到的音频场景模式;否则为错误对象。 |
1088
1089**示例:**
1090
1091```ts
1092import { BusinessError } from '@kit.BasicServicesKit';
1093
1094audioManager.getAudioScene((err: BusinessError, value: audio.AudioScene) => {
1095  if (err) {
1096    console.error(`Failed to obtain the audio scene mode. ${err}`);
1097    return;
1098  }
1099  console.info(`Callback invoked to indicate that the audio scene mode is obtained ${value}.`);
1100});
1101```
1102
1103### getAudioScene<sup>8+</sup>
1104
1105getAudioScene\(\): Promise<AudioScene\>
1106
1107获取音频场景模式,使用Promise方式返回异步结果。
1108
1109**系统能力:** SystemCapability.Multimedia.Audio.Communication
1110
1111**返回值:**
1112
1113| 类型                                          | 说明                         |
1114| :-------------------------------------------- | :--------------------------- |
1115| Promise<[AudioScene](#audioscene8)> | Promise对象,返回音频场景模式。 |
1116
1117**示例:**
1118
1119```ts
1120import { BusinessError } from '@kit.BasicServicesKit';
1121
1122audioManager.getAudioScene().then((value: audio.AudioScene) => {
1123  console.info(`Promise returned to indicate that the audio scene mode is obtained ${value}.`);
1124}).catch ((err: BusinessError) => {
1125  console.error(`Failed to obtain the audio scene mode ${err}`);
1126});
1127```
1128
1129### getAudioSceneSync<sup>10+</sup>
1130
1131getAudioSceneSync\(\): AudioScene
1132
1133获取音频场景模式,同步返回结果。
1134
1135**系统能力:** SystemCapability.Multimedia.Audio.Communication
1136
1137**返回值:**
1138
1139| 类型                                          | 说明                         |
1140| :-------------------------------------------- | :--------------------------- |
1141| [AudioScene](#audioscene8) | 音频场景模式。 |
1142
1143**示例:**
1144
1145```ts
1146import { BusinessError } from '@kit.BasicServicesKit';
1147
1148try {
1149  let value: audio.AudioScene = audioManager.getAudioSceneSync();
1150  console.info(`indicate that the audio scene mode is obtained ${value}.`);
1151} catch (err) {
1152  let error = err as BusinessError;
1153  console.error(`Failed to obtain the audio scene mode ${error}`);
1154}
1155```
1156
1157### getVolumeManager<sup>9+</sup>
1158
1159getVolumeManager(): AudioVolumeManager
1160
1161获取音频音量管理器。
1162
1163**系统能力:** SystemCapability.Multimedia.Audio.Volume
1164
1165**返回值:**
1166
1167| 类型                                      | 说明                          |
1168|-----------------------------------------| ----------------------------- |
1169| [AudioVolumeManager](#audiovolumemanager9) | AudioVolumeManager实例 |
1170
1171**示例:**
1172
1173```ts
1174import { audio } from '@kit.AudioKit';
1175
1176let audioVolumeManager: audio.AudioVolumeManager = audioManager.getVolumeManager();
1177```
1178
1179### getStreamManager<sup>9+</sup>
1180
1181getStreamManager(): AudioStreamManager
1182
1183获取音频流管理器。
1184
1185**系统能力:** SystemCapability.Multimedia.Audio.Core
1186
1187**返回值:**
1188
1189| 类型                                         | 说明                          |
1190|--------------------------------------------| ----------------------------- |
1191| [AudioStreamManager](#audiostreammanager9) | AudioStreamManager实例 |
1192
1193**示例:**
1194
1195```ts
1196import { audio } from '@kit.AudioKit';
1197
1198let audioStreamManager: audio.AudioStreamManager = audioManager.getStreamManager();
1199```
1200
1201### getRoutingManager<sup>9+</sup>
1202
1203getRoutingManager(): AudioRoutingManager
1204
1205获取音频路由设备管理器。
1206
1207**系统能力:** SystemCapability.Multimedia.Audio.Device
1208
1209**返回值:**
1210
1211| 类型                                       | 说明                          |
1212|------------------------------------------| ----------------------------- |
1213| [AudioRoutingManager](#audioroutingmanager9) | AudioRoutingManager实例 |
1214
1215**示例:**
1216
1217```ts
1218import { audio } from '@kit.AudioKit';
1219
1220let audioRoutingManager: audio.AudioRoutingManager = audioManager.getRoutingManager();
1221```
1222
1223### getSessionManager<sup>12+</sup>
1224
1225getSessionManager(): AudioSessionManager
1226
1227获取音频会话管理器。
1228
1229**系统能力:** SystemCapability.Multimedia.Audio.Core
1230
1231**返回值:**
1232
1233| 类型                                           | 说明                          |
1234|----------------------------------------------| ----------------------------- |
1235| [AudioSessionManager](#audiosessionmanager12) | AudioSessionManager实例 |
1236
1237**示例:**
1238
1239```ts
1240import { audio } from '@kit.AudioKit';
1241
1242let audioSessionManager: audio.AudioSessionManager = audioManager.getSessionManager();
1243```
1244
1245### setVolume<sup>(deprecated)</sup>
1246
1247setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&lt;void&gt;): void
1248
1249设置指定流的音量,使用callback方式异步返回结果。
1250
1251> **说明:**
1252> 从 API version 7 开始支持,从 API version 9 开始废弃。建议使用AudioVolumeGroupManager中的[setVolume](#setvolume9)替代,替代接口能力仅对系统应用开放。
1253
1254**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
1255
1256仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
1257
1258**系统能力:** SystemCapability.Multimedia.Audio.Volume
1259
1260**参数:**
1261
1262| 参数名     | 类型                                | 必填 | 说明                                                     |
1263| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
1264| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
1265| volume     | number                              | 是   | 音量等级,可设置范围通过[getMinVolume](#getminvolumedeprecated)和[getMaxVolume](#getmaxvolumedeprecated)获取。 |
1266| callback   | AsyncCallback&lt;void&gt;           | 是   | 回调函数。当设置指定流的音量成功,err为undefined,否则为错误对象。 |
1267
1268**示例:**
1269
1270```ts
1271import { BusinessError } from '@kit.BasicServicesKit';
1272
1273audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err: BusinessError) => {
1274  if (err) {
1275    console.error(`Failed to set the volume. ${err}`);
1276    return;
1277  }
1278  console.info('Callback invoked to indicate a successful volume setting.');
1279});
1280```
1281
1282### setVolume<sup>(deprecated)</sup>
1283
1284setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
1285
1286设置指定流的音量,使用Promise方式异步返回结果。
1287
1288> **说明:**
1289> 从 API version 7 开始支持,从 API version 9 开始废弃。建议使用AudioVolumeGroupManager中的[setVolume](#setvolume9)替代,替代接口能力仅对系统应用开放。
1290
1291**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
1292
1293仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
1294
1295**系统能力:** SystemCapability.Multimedia.Audio.Volume
1296
1297**参数:**
1298
1299| 参数名     | 类型                                | 必填 | 说明                                                     |
1300| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
1301| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
1302| volume     | number                              | 是   | 音量等级,可设置范围通过[getMinVolume](#getminvolumedeprecated)和[getMaxVolume](#getmaxvolumedeprecated)获取。 |
1303
1304**返回值:**
1305
1306| 类型                | 说明                          |
1307| ------------------- | ----------------------------- |
1308| Promise&lt;void&gt; | Promise对象,无返回结果。 |
1309
1310**示例:**
1311
1312```ts
1313audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
1314  console.info('Promise returned to indicate a successful volume setting.');
1315});
1316```
1317
1318### getVolume<sup>(deprecated)</sup>
1319
1320getVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
1321
1322获取指定流的音量,使用callback方式异步返回结果。
1323
1324> **说明:**
1325> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getVolume](#getvolume9)替代。
1326
1327**系统能力:** SystemCapability.Multimedia.Audio.Volume
1328
1329**参数:**
1330
1331| 参数名     | 类型                                | 必填 | 说明               |
1332| ---------- | ----------------------------------- | ---- | ------------------ |
1333| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。       |
1334| callback   | AsyncCallback&lt;number&gt;         | 是   | 回调函数。当获取指定流的音量成功,err为undefined,data为获取到的指定流的音量;否则为错误对象。指定流的音量等级范围可通过[getMinVolume](#getminvolumedeprecated)和[getMaxVolume](#getmaxvolumedeprecated)获取。 |
1335
1336**示例:**
1337
1338```ts
1339import { BusinessError } from '@kit.BasicServicesKit';
1340
1341audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
1342  if (err) {
1343    console.error(`Failed to obtain the volume. ${err}`);
1344    return;
1345  }
1346  console.info('Callback invoked to indicate that the volume is obtained.');
1347});
1348```
1349
1350### getVolume<sup>(deprecated)</sup>
1351
1352getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
1353
1354获取指定流的音量,使用Promise方式异步返回结果。
1355
1356> **说明:**
1357> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getVolume](#getvolume9)替代。
1358
1359**系统能力:** SystemCapability.Multimedia.Audio.Volume
1360
1361**参数:**
1362
1363| 参数名     | 类型                                | 必填 | 说明         |
1364| ---------- | ----------------------------------- | ---- | ------------ |
1365| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
1366
1367**返回值:**
1368
1369| 类型                  | 说明                      |
1370| --------------------- | ------------------------- |
1371| Promise&lt;number&gt; | Promise对象,返回指定流的音量。指定流的音量等级范围可通过[getMinVolume](#getminvolumedeprecated)和[getMaxVolume](#getmaxvolumedeprecated)获取。 |
1372
1373**示例:**
1374
1375```ts
1376audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value: number) => {
1377  console.info(`Promise returned to indicate that the volume is obtained ${value} .`);
1378});
1379```
1380
1381### getMinVolume<sup>(deprecated)</sup>
1382
1383getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
1384
1385获取指定流的最小音量,使用callback方式异步返回结果。
1386
1387> **说明:**
1388> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getMinVolume](#getminvolume9)替代。
1389
1390**系统能力:** SystemCapability.Multimedia.Audio.Volume
1391
1392**参数:**
1393
1394| 参数名     | 类型                                | 必填 | 说明               |
1395| ---------- | ----------------------------------- | ---- | ------------------ |
1396| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。       |
1397| callback   | AsyncCallback&lt;number&gt;         | 是   | 回调函数。当获取指定流的最小音量成功,err为undefined,data为获取到的指定流的最小音量;否则为错误对象。 |
1398
1399**示例:**
1400
1401```ts
1402import { BusinessError } from '@kit.BasicServicesKit';
1403
1404audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
1405  if (err) {
1406    console.error(`Failed to obtain the minimum volume. ${err}`);
1407    return;
1408  }
1409  console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
1410});
1411```
1412
1413### getMinVolume<sup>(deprecated)</sup>
1414
1415getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
1416
1417获取指定流的最小音量,使用Promise方式异步返回结果。
1418
1419> **说明:**
1420> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getMinVolume](#getminvolume9)替代。
1421
1422**系统能力:** SystemCapability.Multimedia.Audio.Volume
1423
1424**参数:**
1425
1426| 参数名     | 类型                                | 必填 | 说明         |
1427| ---------- | ----------------------------------- | ---- | ------------ |
1428| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
1429
1430**返回值:**
1431
1432| 类型                  | 说明                      |
1433| --------------------- | ------------------------- |
1434| Promise&lt;number&gt; | Promise对象,返回最小音量。 |
1435
1436**示例:**
1437
1438```ts
1439audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value: number) => {
1440  console.info(`Promised returned to indicate that the minimum volume is obtained. ${value}`);
1441});
1442```
1443
1444### getMaxVolume<sup>(deprecated)</sup>
1445
1446getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
1447
1448获取指定流的最大音量,使用callback方式异步返回结果。
1449
1450> **说明:**
1451> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getMaxVolume](#getmaxvolume9)替代。
1452
1453**系统能力:** SystemCapability.Multimedia.Audio.Volume
1454
1455**参数:**
1456
1457| 参数名     | 类型                                | 必填 | 说明                   |
1458| ---------- | ----------------------------------- | ---- | ---------------------- |
1459| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。           |
1460| callback   | AsyncCallback&lt;number&gt;         | 是   | 回调函数。当获取指定流的最大音量成功,err为undefined,data为获取到的指定流的最大音量;否则为错误对象。 |
1461
1462**示例:**
1463
1464```ts
1465import { BusinessError } from '@kit.BasicServicesKit';
1466
1467audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
1468  if (err) {
1469    console.error(`Failed to obtain the maximum volume. ${err}`);
1470    return;
1471  }
1472  console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`);
1473});
1474```
1475
1476### getMaxVolume<sup>(deprecated)</sup>
1477
1478getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
1479
1480获取指定流的最大音量,使用Promise方式异步返回结果。
1481
1482> **说明:**
1483> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getMaxVolume](#getmaxvolume9)替代。
1484
1485**系统能力:** SystemCapability.Multimedia.Audio.Volume
1486
1487**参数:**
1488
1489| 参数名     | 类型                                | 必填 | 说明         |
1490| ---------- | ----------------------------------- | ---- | ------------ |
1491| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
1492
1493**返回值:**
1494
1495| 类型                  | 说明                          |
1496| --------------------- | ----------------------------- |
1497| Promise&lt;number&gt; | Promise对象,返回最大音量。 |
1498
1499**示例:**
1500
1501```ts
1502audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data: number) => {
1503  console.info('Promised returned to indicate that the maximum volume is obtained.');
1504});
1505```
1506
1507### mute<sup>(deprecated)</sup>
1508
1509mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
1510
1511设置指定音量流静音,当该音量流可设置的最小音量不能为0时会返回false,例如:闹钟、通话,使用callback方式异步返回结果。
1512
1513> **说明:**
1514> 从 API version 7 开始支持,从 API version 9 开始废弃。替代接口仅面向系统应用开放。
1515
1516**系统能力:** SystemCapability.Multimedia.Audio.Volume
1517
1518**参数:**
1519
1520| 参数名     | 类型                                | 必填 | 说明                                  |
1521| ---------- | ----------------------------------- | ---- | ------------------------------------- |
1522| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                          |
1523| mute       | boolean                             | 是   | 静音状态,true为静音,false为非静音。 |
1524| callback   | AsyncCallback&lt;void&gt;           | 是   | 回调函数。当设置指定音量流静音成功,err为undefined,否则为错误对象。 |
1525
1526**示例:**
1527
1528```ts
1529import { BusinessError } from '@kit.BasicServicesKit';
1530
1531audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err: BusinessError) => {
1532  if (err) {
1533    console.error(`Failed to mute the stream. ${err}`);
1534    return;
1535  }
1536  console.info('Callback invoked to indicate that the stream is muted.');
1537});
1538```
1539
1540### mute<sup>(deprecated)</sup>
1541
1542mute(volumeType: AudioVolumeType, mute: boolean): Promise&lt;void&gt;
1543
1544设置指定音量流静音,当该音量流可设置的最小音量不能为0时会返回false,例如:闹钟、通话,使用Promise方式异步返回结果。
1545
1546> **说明:**
1547> 从 API version 7 开始支持,从 API version 9 开始废弃。替代接口仅面向系统应用开放。
1548
1549**系统能力:** SystemCapability.Multimedia.Audio.Volume
1550
1551**参数:**
1552
1553| 参数名     | 类型                                | 必填 | 说明                                  |
1554| ---------- | ----------------------------------- | ---- | ------------------------------------- |
1555| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                          |
1556| mute       | boolean                             | 是   | 静音状态,true为静音,false为非静音。 |
1557
1558**返回值:**
1559
1560| 类型                | 说明                          |
1561| ------------------- | ----------------------------- |
1562| Promise&lt;void&gt; | Promise对象,无返回结果。 |
1563
1564**示例:**
1565
1566
1567```ts
1568audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
1569  console.info('Promise returned to indicate that the stream is muted.');
1570});
1571```
1572
1573### isMute<sup>(deprecated)</sup>
1574
1575isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
1576
1577获取指定音量流是否被静音,使用callback方式异步返回结果。
1578
1579> **说明:**
1580> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[isMute](#ismute9)替代。
1581
1582**系统能力:** SystemCapability.Multimedia.Audio.Volume
1583
1584**参数:**
1585
1586| 参数名     | 类型                                | 必填 | 说明                                            |
1587| ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
1588| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                    |
1589| callback   | AsyncCallback&lt;boolean&gt;        | 是   | 回调函数。当获取指定音量流是否被静音成功,err为undefined,data为true为静音,false为非静音;否则为错误对象。 |
1590
1591**示例:**
1592
1593```ts
1594import { BusinessError } from '@kit.BasicServicesKit';
1595
1596audioManager.isMute(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => {
1597  if (err) {
1598    console.error(`Failed to obtain the mute status. ${err}`);
1599    return;
1600  }
1601  console.info(`Callback invoked to indicate that the mute status of the stream is obtained. ${value}`);
1602});
1603```
1604
1605### isMute<sup>(deprecated)</sup>
1606
1607isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
1608
1609获取指定音量流是否被静音,使用Promise方式异步返回结果。
1610
1611> **说明:**
1612> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[isMute](#ismute9)替代。
1613
1614**系统能力:** SystemCapability.Multimedia.Audio.Volume
1615
1616**参数:**
1617
1618| 参数名     | 类型                                | 必填 | 说明         |
1619| ---------- | ----------------------------------- | ---- | ------------ |
1620| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
1621
1622**返回值:**
1623
1624| 类型                   | 说明                                                   |
1625| ---------------------- | ------------------------------------------------------ |
1626| Promise&lt;boolean&gt; | Promise对象,返回流静音状态,true为静音,false为非静音。 |
1627
1628**示例:**
1629
1630```ts
1631audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value: boolean) => {
1632  console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`);
1633});
1634```
1635
1636### isActive<sup>(deprecated)</sup>
1637
1638isActive(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
1639
1640获取指定音量流是否为活跃状态,使用callback方式异步返回结果。
1641
1642> **说明:**
1643> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioStreamManager中的[isActive](#isactive9)替代。
1644
1645**系统能力:** SystemCapability.Multimedia.Audio.Volume
1646
1647**参数:**
1648
1649| 参数名     | 类型                                | 必填 | 说明                                              |
1650| ---------- | ----------------------------------- | ---- | ------------------------------------------------- |
1651| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                      |
1652| callback   | AsyncCallback&lt;boolean&gt;        | 是   | 回调函数。当获取指定音量流是否为活跃状态成功,err为undefined,data为true为活跃,false为不活跃;否则为错误对象。 |
1653
1654**示例:**
1655
1656```ts
1657import { BusinessError } from '@kit.BasicServicesKit';
1658
1659audioManager.isActive(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => {
1660  if (err) {
1661    console.error(`Failed to obtain the active status of the stream. ${err}`);
1662    return;
1663  }
1664  console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`);
1665});
1666```
1667
1668### isActive<sup>(deprecated)</sup>
1669
1670isActive(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
1671
1672获取指定音量流是否为活跃状态,使用Promise方式异步返回结果。
1673
1674> **说明:**
1675> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioStreamManager中的[isActive](#isactive9)替代。
1676
1677**系统能力:** SystemCapability.Multimedia.Audio.Volume
1678
1679**参数:**
1680
1681| 参数名     | 类型                                | 必填 | 说明         |
1682| ---------- | ----------------------------------- | ---- | ------------ |
1683| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
1684
1685**返回值:**
1686
1687| 类型                   | 说明                                                     |
1688| ---------------------- | -------------------------------------------------------- |
1689| Promise&lt;boolean&gt; | Promise对象,返回流的活跃状态,true为活跃,false为不活跃。 |
1690
1691**示例:**
1692
1693```ts
1694audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value: boolean) => {
1695  console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`);
1696});
1697```
1698
1699### setRingerMode<sup>(deprecated)</sup>
1700
1701setRingerMode(mode: AudioRingMode, callback: AsyncCallback&lt;void&gt;): void
1702
1703设置铃声模式,使用callback方式异步返回结果。
1704
1705> **说明:**
1706> 从 API version 7 开始支持,从 API version 9 开始废弃。替代接口仅面向系统应用开放。
1707
1708**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
1709
1710仅在静音和非静音状态切换时需要该权限。
1711
1712**系统能力:** SystemCapability.Multimedia.Audio.Communication
1713
1714**参数:**
1715
1716| 参数名   | 类型                            | 必填 | 说明                     |
1717| -------- | ------------------------------- | ---- | ------------------------ |
1718| mode     | [AudioRingMode](#audioringmode) | 是   | 音频铃声模式。           |
1719| callback | AsyncCallback&lt;void&gt;       | 是   | 回调函数。当设置铃声模式成功,err为undefined,否则为错误对象。 |
1720
1721**示例:**
1722
1723```ts
1724import { BusinessError } from '@kit.BasicServicesKit';
1725
1726audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err: BusinessError) => {
1727  if (err) {
1728    console.error(`Failed to set the ringer mode. ${err}`);
1729    return;
1730  }
1731  console.info('Callback invoked to indicate a successful setting of the ringer mode.');
1732});
1733```
1734
1735### setRingerMode<sup>(deprecated)</sup>
1736
1737setRingerMode(mode: AudioRingMode): Promise&lt;void&gt;
1738
1739设置铃声模式,使用Promise方式异步返回结果。
1740
1741> **说明:**
1742> 从 API version 7 开始支持,从 API version 9 开始废弃。替代接口仅面向系统应用开放。
1743
1744
1745**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
1746
1747仅在静音和非静音状态切换时需要该权限。
1748
1749**系统能力:** SystemCapability.Multimedia.Audio.Communication
1750
1751**参数:**
1752
1753| 参数名 | 类型                            | 必填 | 说明           |
1754| ------ | ------------------------------- | ---- | -------------- |
1755| mode   | [AudioRingMode](#audioringmode) | 是   | 音频铃声模式。 |
1756
1757**返回值:**
1758
1759| 类型                | 说明                            |
1760| ------------------- | ------------------------------- |
1761| Promise&lt;void&gt; | Promise对象,无返回结果。 |
1762
1763**示例:**
1764
1765```ts
1766audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
1767  console.info('Promise returned to indicate a successful setting of the ringer mode.');
1768});
1769```
1770
1771### getRingerMode<sup>(deprecated)</sup>
1772
1773getRingerMode(callback: AsyncCallback&lt;AudioRingMode&gt;): void
1774
1775获取铃声模式,使用callback方式异步返回结果。
1776
1777> **说明:**
1778> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getRingerMode](#getringermode9)替代。
1779
1780**系统能力:** SystemCapability.Multimedia.Audio.Communication
1781
1782**参数:**
1783
1784| 参数名   | 类型                                                 | 必填 | 说明                     |
1785| -------- | ---------------------------------------------------- | ---- | ------------------------ |
1786| callback | AsyncCallback&lt;[AudioRingMode](#audioringmode)&gt; | 是   | 回调函数。当获取铃声模式成功,err为undefined,data为获取到的铃声模式;否则为错误对象。 |
1787
1788**示例:**
1789
1790```ts
1791import { BusinessError } from '@kit.BasicServicesKit';
1792
1793audioManager.getRingerMode((err: BusinessError, value: audio.AudioRingMode) => {
1794  if (err) {
1795    console.error(`Failed to obtain the ringer mode. ${err}`);
1796    return;
1797  }
1798  console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`);
1799});
1800```
1801
1802### getRingerMode<sup>(deprecated)</sup>
1803
1804getRingerMode(): Promise&lt;AudioRingMode&gt;
1805
1806获取铃声模式,使用Promise方式异步返回结果。
1807
1808> **说明:**
1809> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getRingerMode](#getringermode9)替代。
1810
1811**系统能力:** SystemCapability.Multimedia.Audio.Communication
1812
1813**返回值:**
1814
1815| 类型                                           | 说明                            |
1816| ---------------------------------------------- | ------------------------------- |
1817| Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise对象,返回系统的铃声模式。 |
1818
1819**示例:**
1820
1821```ts
1822audioManager.getRingerMode().then((value: audio.AudioRingMode) => {
1823  console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`);
1824});
1825```
1826
1827### getDevices<sup>(deprecated)</sup>
1828
1829getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
1830
1831获取音频设备列表,使用callback方式异步返回结果。
1832
1833> **说明:**
1834> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[getDevices](#getdevices9)替代。
1835
1836**系统能力:** SystemCapability.Multimedia.Audio.Device
1837
1838**参数:**
1839
1840| 参数名     | 类型                                                         | 必填 | 说明                 |
1841| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
1842| deviceFlag | [DeviceFlag](#deviceflag)                                    | 是   | 设备类型的flag。     |
1843| callback   | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | 是   | 回调函数。当获取音频设备列表成功,err为undefined,data为获取到的音频设备列表;否则为错误对象。 |
1844
1845**示例:**
1846```ts
1847import { BusinessError } from '@kit.BasicServicesKit';
1848
1849audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err: BusinessError, value: audio.AudioDeviceDescriptors) => {
1850  if (err) {
1851    console.error(`Failed to obtain the device list. ${err}`);
1852    return;
1853  }
1854  console.info('Callback invoked to indicate that the device list is obtained.');
1855});
1856```
1857
1858### getDevices<sup>(deprecated)</sup>
1859
1860getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
1861
1862获取音频设备列表,使用Promise方式异步返回结果。
1863
1864> **说明:**
1865> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[getDevices](#getdevices9)替代。
1866
1867**系统能力:** SystemCapability.Multimedia.Audio.Device
1868
1869**参数:**
1870
1871| 参数名     | 类型                      | 必填 | 说明             |
1872| ---------- | ------------------------- | ---- | ---------------- |
1873| deviceFlag | [DeviceFlag](#deviceflag) | 是   | 设备类型的flag。 |
1874
1875**返回值:**
1876
1877| 类型                                                         | 说明                      |
1878| ------------------------------------------------------------ | ------------------------- |
1879| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise对象,返回设备列表。 |
1880
1881**示例:**
1882
1883```ts
1884audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data: audio.AudioDeviceDescriptors) => {
1885  console.info('Promise returned to indicate that the device list is obtained.');
1886});
1887```
1888
1889### setDeviceActive<sup>(deprecated)</sup>
1890
1891setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
1892
1893设置设备激活状态,使用callback方式异步返回结果。
1894
1895> **说明:**
1896> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[setCommunicationDevice](#setcommunicationdevice9)替代。
1897
1898**系统能力:** SystemCapability.Multimedia.Audio.Device
1899
1900**参数:**
1901
1902| 参数名     | 类型                                  | 必填 | 说明          |
1903| ---------- | ------------------------------------- | ---- |-------------|
1904| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | 是   | 活跃音频设备类型。   |
1905| active     | boolean                               | 是   | 设备激活状态。     |
1906| callback   | AsyncCallback&lt;void&gt;             | 是   | 回调函数。当设置设备激活状态成功,err为undefined,否则为错误对象。 |
1907
1908**示例:**
1909
1910```ts
1911import { BusinessError } from '@kit.BasicServicesKit';
1912
1913audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err: BusinessError) => {
1914  if (err) {
1915    console.error(`Failed to set the active status of the device. ${err}`);
1916    return;
1917  }
1918  console.info('Callback invoked to indicate that the device is set to the active status.');
1919});
1920```
1921
1922### setDeviceActive<sup>(deprecated)</sup>
1923
1924setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise&lt;void&gt;
1925
1926设置设备激活状态,使用Promise方式异步返回结果。
1927
1928> **说明:**
1929> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[setCommunicationDevice](#setcommunicationdevice9)替代。
1930
1931**系统能力:** SystemCapability.Multimedia.Audio.Device
1932
1933**参数:**
1934
1935| 参数名     | 类型                                  | 必填 | 说明               |
1936| ---------- | ------------------------------------- | ---- | ------------------ |
1937| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | 是   | 活跃音频设备类型。 |
1938| active     | boolean                               | 是   | 设备激活状态。     |
1939
1940**返回值:**
1941
1942| 类型                | 说明                            |
1943| ------------------- | ------------------------------- |
1944| Promise&lt;void&gt; | Promise对象,无返回结果。 |
1945
1946**示例:**
1947
1948
1949```ts
1950audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => {
1951  console.info('Promise returned to indicate that the device is set to the active status.');
1952});
1953```
1954
1955### isDeviceActive<sup>(deprecated)</sup>
1956
1957isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
1958
1959获取指定设备的激活状态,使用callback方式异步返回结果。
1960
1961> **说明:**
1962> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[isCommunicationDeviceActive](#iscommunicationdeviceactive9)替代。
1963
1964**系统能力:** SystemCapability.Multimedia.Audio.Device
1965
1966**参数:**
1967
1968| 参数名     | 类型                                  | 必填 | 说明                     |
1969| ---------- | ------------------------------------- | ---- | ------------------------ |
1970| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | 是   | 活跃音频设备类型。       |
1971| callback   | AsyncCallback&lt;boolean&gt;          | 是   | 回调函数。当获取指定设备的激活状态成功,err为undefined,data为true为激活,false为未激活;否则为错误对象。 |
1972
1973**示例:**
1974
1975```ts
1976import { BusinessError } from '@kit.BasicServicesKit';
1977
1978audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err: BusinessError, value: boolean) => {
1979  if (err) {
1980    console.error(`Failed to obtain the active status of the device. ${err}`);
1981    return;
1982  }
1983  console.info('Callback invoked to indicate that the active status of the device is obtained.');
1984});
1985```
1986
1987### isDeviceActive<sup>(deprecated)</sup>
1988
1989isDeviceActive(deviceType: ActiveDeviceType): Promise&lt;boolean&gt;
1990
1991获取指定设备的激活状态,使用Promise方式异步返回结果。
1992
1993> **说明:**
1994> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[isCommunicationDeviceActive](#iscommunicationdeviceactive9)替代。
1995
1996**系统能力:** SystemCapability.Multimedia.Audio.Device
1997
1998**参数:**
1999
2000| 参数名     | 类型                                  | 必填 | 说明               |
2001| ---------- | ------------------------------------- | ---- | ------------------ |
2002| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | 是   | 活跃音频设备类型。 |
2003
2004**返回值:**
2005
2006| Type                   | Description                           |
2007| ---------------------- |---------------------------------------|
2008| Promise&lt;boolean&gt; | Promise对象,返回设备的激活状态,true激活,false未激活。  |
2009
2010**示例:**
2011
2012```ts
2013audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value: boolean) => {
2014  console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
2015});
2016```
2017
2018### setMicrophoneMute<sup>(deprecated)</sup>
2019
2020setMicrophoneMute(mute: boolean, callback: AsyncCallback&lt;void&gt;): void
2021
2022设置麦克风静音状态,使用callback方式异步返回结果。
2023
2024> **说明:**
2025> 从 API version 7 开始支持,从 API version 9 开始废弃。替代接口仅面向系统应用开放。
2026
2027**需要权限:** ohos.permission.MICROPHONE
2028
2029**系统能力:** SystemCapability.Multimedia.Audio.Device
2030
2031**参数:**
2032
2033| 参数名   | 类型                      | 必填 | 说明                                          |
2034| -------- | ------------------------- | ---- | --------------------------------------------- |
2035| mute     | boolean                   | 是   | 待设置的静音状态,true为静音,false为非静音。 |
2036| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。当设置麦克风静音状态成功,err为undefined,否则为错误对象。 |
2037
2038**示例:**
2039
2040```ts
2041import { BusinessError } from '@kit.BasicServicesKit';
2042
2043audioManager.setMicrophoneMute(true, (err: BusinessError) => {
2044  if (err) {
2045    console.error(`Failed to mute the microphone. ${err}`);
2046    return;
2047  }
2048  console.info('Callback invoked to indicate that the microphone is muted.');
2049});
2050```
2051
2052### setMicrophoneMute<sup>(deprecated)</sup>
2053
2054setMicrophoneMute(mute: boolean): Promise&lt;void&gt;
2055
2056设置麦克风静音状态,使用Promise方式异步返回结果。
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
2071**返回值:**
2072
2073| 类型                | 说明                            |
2074| ------------------- | ------------------------------- |
2075| Promise&lt;void&gt; | Promise对象,无返回结果。 |
2076
2077**示例:**
2078
2079```ts
2080audioManager.setMicrophoneMute(true).then(() => {
2081  console.info('Promise returned to indicate that the microphone is muted.');
2082});
2083```
2084
2085### isMicrophoneMute<sup>(deprecated)</sup>
2086
2087isMicrophoneMute(callback: AsyncCallback&lt;boolean&gt;): void
2088
2089获取麦克风静音状态,使用callback方式异步返回结果。
2090
2091> **说明:**
2092> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[isMicrophoneMute](#ismicrophonemute9)替代。
2093
2094**需要权限:** ohos.permission.MICROPHONE
2095
2096**系统能力:** SystemCapability.Multimedia.Audio.Device
2097
2098**参数:**
2099
2100| 参数名   | 类型                         | 必填 | 说明                                                    |
2101| -------- | ---------------------------- | ---- | ------------------------------------------------------- |
2102| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。当获取麦克风静音状态成功,err为undefined,data为true为静音,false为非静音;否则为错误对象。 |
2103
2104**示例:**
2105
2106```ts
2107import { BusinessError } from '@kit.BasicServicesKit';
2108
2109audioManager.isMicrophoneMute((err: BusinessError, value: boolean) => {
2110  if (err) {
2111    console.error(`Failed to obtain the mute status of the microphone. ${err}`);
2112    return;
2113  }
2114  console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`);
2115});
2116```
2117
2118### isMicrophoneMute<sup>(deprecated)</sup>
2119
2120isMicrophoneMute(): Promise&lt;boolean&gt;
2121
2122获取麦克风静音状态,使用Promise方式异步返回结果。
2123
2124> **说明:**
2125> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[isMicrophoneMute](#ismicrophonemute9)替代。
2126
2127**需要权限:** ohos.permission.MICROPHONE
2128
2129**系统能力:** SystemCapability.Multimedia.Audio.Device
2130
2131**返回值:**
2132
2133| 类型                   | 说明                                                         |
2134| ---------------------- | ------------------------------------------------------------ |
2135| Promise&lt;boolean&gt; | Promise对象,返回系统麦克风静音状态,true为静音,false为非静音。 |
2136
2137**示例:**
2138
2139```ts
2140audioManager.isMicrophoneMute().then((value: boolean) => {
2141  console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`);
2142});
2143```
2144
2145### on('deviceChange')<sup>(deprecated)</sup>
2146
2147on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void
2148
2149监听音频设备连接变化事件(当音频设备连接状态发生变化时触发),使用callback方式返回结果。
2150
2151> **说明:**
2152> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[on('deviceChange')](#ondevicechange9)替代。
2153
2154**系统能力:** SystemCapability.Multimedia.Audio.Device
2155
2156**参数:**
2157
2158| 参数名   | 类型                                                 | 必填 | 说明                                       |
2159| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
2160| type     | string                                               | 是   | 监听事件,固定为:'deviceChange'。 |
2161| callback | Callback<[DeviceChangeAction](#devicechangeaction)\> | 是   | 回调函数,返回设备更新详情。 |
2162
2163**示例:**
2164
2165```ts
2166audioManager.on('deviceChange', (deviceChanged: audio.DeviceChangeAction) => {
2167  console.info(`device change type : ${deviceChanged.type} `);
2168  console.info(`device descriptor size : ${deviceChanged.deviceDescriptors.length} `);
2169  console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceRole} `);
2170  console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceType} `);
2171});
2172```
2173
2174### off('deviceChange')<sup>(deprecated)</sup>
2175
2176off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void
2177
2178取消监听音频设备连接变化事件,使用callback方式返回结果。
2179
2180> **说明:**
2181> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[off('deviceChange')](#offdevicechange9)替代。
2182
2183**系统能力:** SystemCapability.Multimedia.Audio.Device
2184
2185**参数:**
2186
2187| 参数名   | 类型                                                | 必填 | 说明                                       |
2188| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
2189| type     | string                                              | 是   | 监听事件,固定为:'deviceChange'。 |
2190| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | 否   | 回调函数,返回设备更新详情。 |
2191
2192**示例:**
2193
2194```ts
2195// 取消该事件的所有监听
2196audioManager.off('deviceChange');
2197
2198// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
2199let deviceChangeCallback = (deviceChanged: audio.DeviceChangeAction) => {
2200  console.info(`device change type : ${deviceChanged.type} `);
2201  console.info(`device descriptor size : ${deviceChanged.deviceDescriptors.length} `);
2202  console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceRole} `);
2203  console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceType} `);
2204};
2205
2206audioManager.on('deviceChange', deviceChangeCallback);
2207
2208audioManager.off('deviceChange', deviceChangeCallback);
2209```
2210
2211### on('interrupt')<sup>(deprecated)</sup>
2212
2213on(type: 'interrupt', interrupt: AudioInterrupt, callback: Callback\<InterruptAction>): void
2214
2215监听音频打断事件(当应用程序的音频被另一个播放事件中断时触发,回调通知此应用程序),使用callback方式返回结果。
2216
2217与[on('audioInterrupt')](#onaudiointerrupt9)作用一致,均用于监听焦点变化。为无音频流的场景(未曾创建AudioRenderer对象),比如FM、语音唤醒等提供焦点变化监听功能。
2218
2219> **说明:**
2220> 从 API version 7 开始支持,从 API version 11 开始废弃,建议使用AudioCapturer中的[on('audioInterrupt')](#onaudiointerrupt10)替代。
2221
2222**系统能力:** SystemCapability.Multimedia.Audio.Renderer
2223
2224**参数:**
2225
2226| 参数名    | 类型                                                      | 必填 | 说明                                                         |
2227| --------- |---------------------------------------------------------| ---- | ------------------------------------------------------------ |
2228| type      | string                                                  | 是   | 监听事件,固定为:'interrupt'。 |
2229| interrupt | [AudioInterrupt](#audiointerruptdeprecated)             | 是   | 音频打断事件类型的参数。                                     |
2230| callback  | Callback<[InterruptAction](#interruptactiondeprecated)> | 是   | 回调函数,返回音频打断时,应用接收的中断事件信息。 |
2231
2232**示例:**
2233
2234```ts
2235import { audio } from '@kit.AudioKit';
2236
2237let interAudioInterrupt: audio.AudioInterrupt = {
2238  streamUsage:2,
2239  contentType:0,
2240  pauseWhenDucked:true
2241};
2242
2243audioManager.on('interrupt', interAudioInterrupt, (interruptAction: audio.InterruptAction) => {
2244  if (interruptAction.actionType === 0) {
2245    console.info('An event to gain the audio focus starts.');
2246    console.info(`Focus gain event: ${interruptAction} `);
2247  }
2248  if (interruptAction.actionType === 1) {
2249    console.info('An audio interruption event starts.');
2250    console.info(`Audio interruption event: ${interruptAction} `);
2251  }
2252});
2253```
2254
2255### off('interrupt')<sup>(deprecated)</sup>
2256
2257off(type: 'interrupt', interrupt: AudioInterrupt, callback?: Callback\<InterruptAction>): void
2258
2259取消监听音频打断事件,使用callback方式返回结果。
2260
2261> **说明:**
2262> 从 API version 7 开始支持,从 API version 11 开始废弃,建议使用AudioCapturer中的[off('audioInterrupt')](#offaudiointerrupt10)替代。
2263
2264**系统能力:** SystemCapability.Multimedia.Audio.Renderer
2265
2266**参数:**
2267
2268| 参数名    | 类型                                                      | 必填 | 说明                                                         |
2269| --------- |---------------------------------------------------------| ---- | ------------------------------------------------------------ |
2270| type      | string                                                  | 是   | 监听事件,固定为:'interrupt'。 |
2271| interrupt | [AudioInterrupt](#audiointerruptdeprecated)                       | 是   | 音频打断事件类型的参数。                                     |
2272| callback  | Callback<[InterruptAction](#interruptactiondeprecated)> | 否   | 回调函数,返回删除监听事件,取消打断时,应用接收的中断事件信息。 |
2273
2274**示例:**
2275
2276```ts
2277import { audio } from '@kit.AudioKit';
2278
2279let interAudioInterrupt: audio.AudioInterrupt = {
2280  streamUsage:2,
2281  contentType:0,
2282  pauseWhenDucked:true
2283};
2284
2285// 取消该事件的所有监听
2286audioManager.off('interrupt', interAudioInterrupt);
2287
2288// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
2289let interruptCallback = (interruptAction: audio.InterruptAction) => {
2290  if (interruptAction.actionType === 0) {
2291    console.info('An event to gain the audio focus starts.');
2292    console.info(`Focus gain event: ${interruptAction} `);
2293  }
2294  if (interruptAction.actionType === 1) {
2295    console.info('An audio interruption event starts.');
2296    console.info(`Audio interruption event: ${interruptAction} `);
2297  }
2298};
2299
2300audioManager.on('interrupt', interAudioInterrupt, interruptCallback);
2301
2302audioManager.off('interrupt', interAudioInterrupt, interruptCallback);
2303```
2304
2305## AudioVolumeManager<sup>9+</sup>
2306
2307音量管理。在使用AudioVolumeManager的接口前,需要使用[getVolumeManager](#getvolumemanager9)获取AudioVolumeManager实例。
2308
2309### getVolumeGroupManager<sup>9+</sup>
2310
2311getVolumeGroupManager(groupId: number, callback: AsyncCallback<AudioVolumeGroupManager\>\): void
2312
2313获取音频组管理器,使用callback方式异步返回结果。
2314
2315**系统能力:** SystemCapability.Multimedia.Audio.Volume
2316
2317**参数:**
2318
2319| 参数名     | 类型                                                         | 必填 | 说明                                                        |
2320| ---------- | ------------------------------------------------------------ | ---- |-----------------------------------------------------------|
2321| groupId    | number                                    | 是   | 音量组id,默认使用LOCAL_VOLUME_GROUP_ID。                          |
2322| callback   | AsyncCallback&lt;[AudioVolumeGroupManager](#audiovolumegroupmanager9)&gt; | 是   | 回调函数。当获取音频组管理器成功,err为undefined,data为获取到的音频组管理器对象;否则为错误对象。 |
2323
2324**示例:**
2325
2326```ts
2327import { BusinessError } from '@kit.BasicServicesKit';
2328
2329let groupId: number = audio.DEFAULT_VOLUME_GROUP_ID;
2330
2331audioVolumeManager.getVolumeGroupManager(groupId, (err: BusinessError, value: audio.AudioVolumeGroupManager) => {
2332  if (err) {
2333    console.error(`Failed to obtain the volume group infos list. ${err}`);
2334    return;
2335  }
2336  console.info('Callback invoked to indicate that the volume group infos list is obtained.');
2337});
2338
2339```
2340
2341### getVolumeGroupManager<sup>9+</sup>
2342
2343getVolumeGroupManager(groupId: number\): Promise<AudioVolumeGroupManager\>
2344
2345获取音频组管理器,使用Promise方式异步返回结果。
2346
2347**系统能力:** SystemCapability.Multimedia.Audio.Volume
2348
2349**参数:**
2350
2351| 参数名     | 类型                                      | 必填 | 说明                               |
2352| ---------- | ---------------------------------------- | ---- |----------------------------------|
2353| groupId    | number                                   | 是   | 音量组id,默认使用LOCAL_VOLUME_GROUP_ID。 |
2354
2355**返回值:**
2356
2357| 类型                | 说明                          |
2358| ------------------- | ----------------------------- |
2359| Promise&lt; [AudioVolumeGroupManager](#audiovolumegroupmanager9) &gt; | Promise对象,返回音量组实例。 |
2360
2361**示例:**
2362
2363```ts
2364import { audio } from '@kit.AudioKit';
2365
2366let groupId: number = audio.DEFAULT_VOLUME_GROUP_ID;
2367let audioVolumeGroupManager: audio.AudioVolumeGroupManager | undefined = undefined;
2368
2369async function getVolumeGroupManager(){
2370  audioVolumeGroupManager = await audioVolumeManager.getVolumeGroupManager(groupId);
2371  console.info('Promise returned to indicate that the volume group infos list is obtained.');
2372}
2373```
2374
2375### getVolumeGroupManagerSync<sup>10+</sup>
2376
2377getVolumeGroupManagerSync(groupId: number\): AudioVolumeGroupManager
2378
2379获取音频组管理器,同步返回结果。
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| [AudioVolumeGroupManager](#audiovolumegroupmanager9) | 音量组实例。 |
2394
2395**错误码:**
2396
2397以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2398
2399| 错误码ID | 错误信息 |
2400| ------- | --------------------------------------------|
2401| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2402| 6800101 | Parameter verification failed. |
2403
2404**示例:**
2405
2406```ts
2407import { BusinessError } from '@kit.BasicServicesKit';
2408
2409try {
2410  let audioVolumeGroupManager: audio.AudioVolumeGroupManager = audioVolumeManager.getVolumeGroupManagerSync(audio.DEFAULT_VOLUME_GROUP_ID);
2411  console.info(`Get audioVolumeGroupManager success.`);
2412} catch (err) {
2413  let error = err as BusinessError;
2414  console.error(`Failed to get audioVolumeGroupManager, error: ${error}`);
2415}
2416```
2417
2418### on('volumeChange')<sup>9+</sup>
2419
2420on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
2421
2422监听系统音量变化事件(当系统音量发生变化时触发),使用callback方式返回结果。
2423
2424**系统能力:** SystemCapability.Multimedia.Audio.Volume
2425
2426**参数:**
2427
2428| 参数名   | 类型                                   | 必填 | 说明                                                         |
2429| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
2430| type     | string                                 | 是   | 监听事件,固定为:'volumeChange'。 |
2431| callback | Callback<[VolumeEvent](#volumeevent9)> | 是   | 回调函数,返回变化后的音量信息。 |
2432
2433**错误码:**
2434
2435以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2436
2437| 错误码ID | 错误信息 |
2438| ------- | --------------------------------------------|
2439| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2440| 6800101 | Parameter verification failed. |
2441
2442**示例:**
2443
2444```ts
2445audioVolumeManager.on('volumeChange', (volumeEvent: audio.VolumeEvent) => {
2446  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
2447  console.info(`Volume level: ${volumeEvent.volume} `);
2448  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
2449});
2450```
2451
2452### off('volumeChange')<sup>12+</sup>
2453
2454off(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 missing; 2.Incorrect parameter types. |
2474| 6800101 | Parameter verification failed. |
2475
2476**示例:**
2477
2478```ts
2479// 取消该事件的所有监听
2480audioVolumeManager.off('volumeChange');
2481
2482// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
2483let volumeChangeCallback = (volumeEvent: audio.VolumeEvent) => {
2484  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
2485  console.info(`Volume level: ${volumeEvent.volume} `);
2486  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
2487};
2488
2489audioVolumeManager.on('volumeChange', volumeChangeCallback);
2490
2491audioVolumeManager.off('volumeChange', volumeChangeCallback);
2492```
2493
2494## AudioVolumeGroupManager<sup>9+</sup>
2495
2496管理音频组音量。在调用AudioVolumeGroupManager的接口前,需要先通过 [getVolumeGroupManager](#getvolumegroupmanager9) 创建实例。
2497
2498### getVolume<sup>9+</sup>
2499
2500getVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
2501
2502获取指定流的音量,使用callback方式异步返回结果。
2503
2504**系统能力:** SystemCapability.Multimedia.Audio.Volume
2505
2506**参数:**
2507
2508| 参数名     | 类型                                | 必填 | 说明               |
2509| ---------- | ----------------------------------- | ---- | ------------------ |
2510| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。       |
2511| callback   | AsyncCallback&lt;number&gt;         | 是   | 回调函数。当获取指定流的音量成功,err为undefined,data为获取到的指定流的音量;否则为错误对象。指定流的音量等级范围可通过[getMinVolume](#getminvolume9)和[getMaxVolume](#getmaxvolume9)获取。 |
2512
2513**示例:**
2514
2515```ts
2516import { BusinessError } from '@kit.BasicServicesKit';
2517
2518audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
2519  if (err) {
2520    console.error(`Failed to obtain the volume. ${err}`);
2521    return;
2522  }
2523  console.info('Callback invoked to indicate that the volume is obtained.');
2524});
2525```
2526
2527### getVolume<sup>9+</sup>
2528
2529getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
2530
2531获取指定流的音量,使用Promise方式异步返回结果。
2532
2533**系统能力:** SystemCapability.Multimedia.Audio.Volume
2534
2535**参数:**
2536
2537| 参数名     | 类型                                | 必填 | 说明         |
2538| ---------- | ----------------------------------- | ---- | ------------ |
2539| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
2540
2541**返回值:**
2542
2543| 类型                  | 说明                      |
2544| --------------------- | ------------------------- |
2545| Promise&lt;number&gt; | Promise对象,返回指定流的音量。指定流的音量等级范围可通过[getMinVolume](#getminvolume9)和[getMaxVolume](#getmaxvolume9)获取。 |
2546
2547**示例:**
2548
2549```ts
2550audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA).then((value: number) => {
2551  console.info(`Promise returned to indicate that the volume is obtained ${value}.`);
2552});
2553```
2554
2555### getVolumeSync<sup>10+</sup>
2556
2557getVolumeSync(volumeType: AudioVolumeType): number;
2558
2559获取指定流的音量,同步返回结果。
2560
2561**系统能力:** SystemCapability.Multimedia.Audio.Volume
2562
2563**参数:**
2564
2565| 参数名     | 类型                                | 必填 | 说明         |
2566| ---------- | ----------------------------------- | ---- | ------------ |
2567| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
2568
2569**返回值:**
2570
2571| 类型                  | 说明                      |
2572| --------------------- | ------------------------- |
2573| number | 返回指定流的音量。指定流的音量等级范围可通过[getMinVolume](#getminvolume9)和[getMaxVolume](#getmaxvolume9)获取。 |
2574
2575**错误码:**
2576
2577以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2578
2579| 错误码ID | 错误信息 |
2580| ------- | --------------------------------------------|
2581| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2582| 6800101 | Parameter verification failed. |
2583
2584**示例:**
2585
2586```ts
2587import { BusinessError } from '@kit.BasicServicesKit';
2588
2589try {
2590  let value: number = audioVolumeGroupManager.getVolumeSync(audio.AudioVolumeType.MEDIA);
2591  console.info(`Indicate that the volume is obtained ${value}.`);
2592} catch (err) {
2593  let error = err as BusinessError;
2594  console.error(`Failed to obtain the volume, error ${error}.`);
2595}
2596```
2597
2598### getMinVolume<sup>9+</sup>
2599
2600getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
2601
2602获取指定流的最小音量,使用callback方式异步返回结果。
2603
2604**系统能力:** SystemCapability.Multimedia.Audio.Volume
2605
2606**参数:**
2607
2608| 参数名     | 类型                                | 必填 | 说明               |
2609| ---------- | ----------------------------------- | ---- | ------------------ |
2610| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。       |
2611| callback   | AsyncCallback&lt;number&gt;         | 是   | 回调函数。当获取指定流的最小音量成功,err为undefined,data为获取到的指定流的最小音量;否则为错误对象。 |
2612
2613**示例:**
2614
2615```ts
2616import { BusinessError } from '@kit.BasicServicesKit';
2617
2618audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
2619  if (err) {
2620    console.error(`Failed to obtain the minimum volume. ${err}`);
2621    return;
2622  }
2623  console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
2624});
2625```
2626
2627### getMinVolume<sup>9+</sup>
2628
2629getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
2630
2631获取指定流的最小音量,使用Promise方式异步返回结果。
2632
2633**系统能力:** SystemCapability.Multimedia.Audio.Volume
2634
2635**参数:**
2636
2637| 参数名     | 类型                                | 必填 | 说明         |
2638| ---------- | ----------------------------------- | ---- | ------------ |
2639| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
2640
2641**返回值:**
2642
2643| 类型                  | 说明                      |
2644| --------------------- | ------------------------- |
2645| Promise&lt;number&gt; | Promise对象,返回最小音量。 |
2646
2647**示例:**
2648
2649```ts
2650audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value: number) => {
2651  console.info(`Promised returned to indicate that the minimum volume is obtained ${value}.`);
2652});
2653```
2654
2655### getMinVolumeSync<sup>10+</sup>
2656
2657getMinVolumeSync(volumeType: AudioVolumeType): number;
2658
2659获取指定流的最小音量,同步返回结果。
2660
2661**系统能力:** SystemCapability.Multimedia.Audio.Volume
2662
2663**参数:**
2664
2665| 参数名     | 类型                                | 必填 | 说明         |
2666| ---------- | ----------------------------------- | ---- | ------------ |
2667| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
2668
2669**返回值:**
2670
2671| 类型                  | 说明                      |
2672| --------------------- | ------------------------- |
2673| number | 返回最小音量。 |
2674
2675**错误码:**
2676
2677以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2678
2679| 错误码ID | 错误信息 |
2680| ------- | --------------------------------------------|
2681| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2682| 6800101 | Parameter verification failed. |
2683
2684**示例:**
2685
2686```ts
2687import { BusinessError } from '@kit.BasicServicesKit';
2688
2689try {
2690  let value: number = audioVolumeGroupManager.getMinVolumeSync(audio.AudioVolumeType.MEDIA);
2691  console.info(`Indicate that the minimum volume is obtained ${value}.`);
2692} catch (err) {
2693  let error = err as BusinessError;
2694  console.error(`Failed to obtain the minimum volume, error ${error}.`);
2695}
2696```
2697
2698### getMaxVolume<sup>9+</sup>
2699
2700getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
2701
2702获取指定流的最大音量,使用callback方式异步返回结果。
2703
2704**系统能力:** SystemCapability.Multimedia.Audio.Volume
2705
2706**参数:**
2707
2708| 参数名     | 类型                                | 必填 | 说明                   |
2709| ---------- | ----------------------------------- | ---- | ---------------------- |
2710| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。           |
2711| callback   | AsyncCallback&lt;number&gt;         | 是   | 回调函数。当获取指定流的最大音量成功,err为undefined,data为获取到的指定流的最大音量;否则为错误对象。 |
2712
2713**示例:**
2714
2715```ts
2716import { BusinessError } from '@kit.BasicServicesKit';
2717
2718audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => {
2719  if (err) {
2720    console.error(`Failed to obtain the maximum volume. ${err}`);
2721    return;
2722  }
2723  console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`);
2724});
2725```
2726
2727### getMaxVolume<sup>9+</sup>
2728
2729getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
2730
2731获取指定流的最大音量,使用Promise方式异步返回结果。
2732
2733**系统能力:** SystemCapability.Multimedia.Audio.Volume
2734
2735**参数:**
2736
2737| 参数名     | 类型                                | 必填 | 说明         |
2738| ---------- | ----------------------------------- | ---- | ------------ |
2739| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
2740
2741**返回值:**
2742
2743| 类型                  | 说明                          |
2744| --------------------- | ----------------------------- |
2745| Promise&lt;number&gt; | Promise对象,返回最大音量大小。 |
2746
2747**示例:**
2748
2749```ts
2750audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data: number) => {
2751  console.info('Promised returned to indicate that the maximum volume is obtained.');
2752});
2753```
2754
2755### getMaxVolumeSync<sup>10+</sup>
2756
2757getMaxVolumeSync(volumeType: AudioVolumeType): number;
2758
2759获取指定流的最大音量,同步返回结果。
2760
2761**系统能力:** SystemCapability.Multimedia.Audio.Volume
2762
2763**参数:**
2764
2765| 参数名     | 类型                                | 必填 | 说明         |
2766| ---------- | ----------------------------------- | ---- | ------------ |
2767| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
2768
2769**返回值:**
2770
2771| 类型                  | 说明                          |
2772| --------------------- | ----------------------------- |
2773| number | 返回最大音量大小。 |
2774
2775**错误码:**
2776
2777以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2778
2779| 错误码ID | 错误信息 |
2780| ------- | --------------------------------------------|
2781| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2782| 6800101 | Parameter verification failed. |
2783
2784**示例:**
2785
2786```ts
2787import { BusinessError } from '@kit.BasicServicesKit';
2788
2789try {
2790  let value: number = audioVolumeGroupManager.getMaxVolumeSync(audio.AudioVolumeType.MEDIA);
2791  console.info(`Indicate that the maximum volume is obtained. ${value}`);
2792} catch (err) {
2793  let error = err as BusinessError;
2794  console.error(`Failed to obtain the maximum volume, error ${error}.`);
2795}
2796```
2797
2798### isMute<sup>9+</sup>
2799
2800isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
2801
2802获取指定音量流是否被静音,使用callback方式异步返回结果。
2803
2804**系统能力:** SystemCapability.Multimedia.Audio.Volume
2805
2806**参数:**
2807
2808| 参数名     | 类型                                | 必填 | 说明                                            |
2809| ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
2810| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                    |
2811| callback   | AsyncCallback&lt;boolean&gt;        | 是   | 回调函数。当获取指定音量流是否被静音成功,err为undefined,data为true为静音,false为非静音;否则为错误对象。 |
2812
2813**示例:**
2814
2815```ts
2816import { BusinessError } from '@kit.BasicServicesKit';
2817
2818audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => {
2819  if (err) {
2820    console.error(`Failed to obtain the mute status. ${err}`);
2821    return;
2822  }
2823  console.info(`Callback invoked to indicate that the mute status of the stream is obtained ${value}.`);
2824});
2825```
2826
2827### isMute<sup>9+</sup>
2828
2829isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
2830
2831获取指定音量流是否被静音,使用Promise方式异步返回结果。
2832
2833**系统能力:** SystemCapability.Multimedia.Audio.Volume
2834
2835**参数:**
2836
2837| 参数名     | 类型                                | 必填 | 说明         |
2838| ---------- | ----------------------------------- | ---- | ------------ |
2839| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
2840
2841**返回值:**
2842
2843| 类型                   | 说明                                                   |
2844| ---------------------- | ------------------------------------------------------ |
2845| Promise&lt;boolean&gt; | Promise对象,返回流静音状态,true为静音,false为非静音。 |
2846
2847**示例:**
2848
2849```ts
2850audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA).then((value: boolean) => {
2851  console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`);
2852});
2853```
2854
2855### isMuteSync<sup>10+</sup>
2856
2857isMuteSync(volumeType: AudioVolumeType): boolean
2858
2859获取指定音量流是否被静音,同步返回结果。
2860
2861**系统能力:** SystemCapability.Multimedia.Audio.Volume
2862
2863**参数:**
2864
2865| 参数名     | 类型                                | 必填 | 说明         |
2866| ---------- | ----------------------------------- | ---- | ------------ |
2867| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
2868
2869**返回值:**
2870
2871| 类型                   | 说明                                                   |
2872| ---------------------- | ------------------------------------------------------ |
2873| boolean | 返回流静音状态,true为静音,false为非静音。 |
2874
2875**错误码:**
2876
2877以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2878
2879| 错误码ID | 错误信息 |
2880| ------- | --------------------------------------------|
2881| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2882| 6800101 | Parameter verification failed. |
2883
2884**示例:**
2885
2886```ts
2887import { BusinessError } from '@kit.BasicServicesKit';
2888
2889try {
2890  let value: boolean = audioVolumeGroupManager.isMuteSync(audio.AudioVolumeType.MEDIA);
2891  console.info(`Indicate that the mute status of the stream is obtained ${value}.`);
2892} catch (err) {
2893  let error = err as BusinessError;
2894  console.error(`Failed to obtain the mute status of the stream, error ${error}.`);
2895}
2896```
2897
2898### getRingerMode<sup>9+</sup>
2899
2900getRingerMode(callback: AsyncCallback&lt;AudioRingMode&gt;): void
2901
2902获取铃声模式,使用callback方式异步返回结果。
2903
2904**系统能力:** SystemCapability.Multimedia.Audio.Volume
2905
2906**参数:**
2907
2908| 参数名   | 类型                                                 | 必填 | 说明                     |
2909| -------- | ---------------------------------------------------- | ---- | ------------------------ |
2910| callback | AsyncCallback&lt;[AudioRingMode](#audioringmode)&gt; | 是   | 回调函数。当获取铃声模式成功,err为undefined,data为获取到的铃声模式;否则为错误对象。 |
2911
2912**示例:**
2913
2914```ts
2915import { BusinessError } from '@kit.BasicServicesKit';
2916
2917audioVolumeGroupManager.getRingerMode((err: BusinessError, value: audio.AudioRingMode) => {
2918  if (err) {
2919    console.error(`Failed to obtain the ringer mode. ${err}`);
2920    return;
2921  }
2922  console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`);
2923});
2924```
2925
2926### getRingerMode<sup>9+</sup>
2927
2928getRingerMode(): Promise&lt;AudioRingMode&gt;
2929
2930获取铃声模式,使用Promise方式异步返回结果。
2931
2932**系统能力:** SystemCapability.Multimedia.Audio.Volume
2933
2934**返回值:**
2935
2936| 类型                                           | 说明                            |
2937| ---------------------------------------------- | ------------------------------- |
2938| Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise对象,返回系统的铃声模式。 |
2939
2940**示例:**
2941
2942```ts
2943audioVolumeGroupManager.getRingerMode().then((value: audio.AudioRingMode) => {
2944  console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`);
2945});
2946```
2947
2948### getRingerModeSync<sup>10+</sup>
2949
2950getRingerModeSync(): AudioRingMode
2951
2952获取铃声模式,同步返回结果。
2953
2954**系统能力:** SystemCapability.Multimedia.Audio.Volume
2955
2956**返回值:**
2957
2958| 类型                                           | 说明                            |
2959| ---------------------------------------------- | ------------------------------- |
2960| [AudioRingMode](#audioringmode) | 返回系统的铃声模式。 |
2961
2962**示例:**
2963
2964```ts
2965import { BusinessError } from '@kit.BasicServicesKit';
2966
2967try {
2968  let value: audio.AudioRingMode = audioVolumeGroupManager.getRingerModeSync();
2969  console.info(`Indicate that the ringer mode is obtained ${value}.`);
2970} catch (err) {
2971  let error = err as BusinessError;
2972  console.error(`Failed to obtain the ringer mode, error ${error}.`);
2973}
2974```
2975
2976### on('ringerModeChange')<sup>9+</sup>
2977
2978on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void
2979
2980监听铃声模式变化事件(当[铃声模式](#audioringmode)发生变化时触发),使用callback方式返回结果。
2981
2982**系统能力:** SystemCapability.Multimedia.Audio.Volume
2983
2984**参数:**
2985
2986| 参数名   | 类型                                      | 必填 | 说明                                                         |
2987| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
2988| type     | string                                    | 是   | 监听事件,固定为:'ringerModeChange'。 |
2989| callback | Callback<[AudioRingMode](#audioringmode)> | 是   | 回调函数,返回变化后的铃音模式。 |
2990
2991**错误码:**
2992
2993以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2994
2995| 错误码ID | 错误信息 |
2996| ------- | --------------------------------------------|
2997| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2998| 6800101 | Parameter verification failed. |
2999
3000**示例:**
3001
3002```ts
3003audioVolumeGroupManager.on('ringerModeChange', (ringerMode: audio.AudioRingMode) => {
3004  console.info(`Updated ringermode: ${ringerMode}`);
3005});
3006```
3007
3008### setMicrophoneMute<sup>(deprecated)</sup>
3009
3010setMicrophoneMute(mute: boolean, callback: AsyncCallback&lt;void&gt;): void
3011
3012设置麦克风静音状态,使用callback方式异步返回结果。
3013
3014> **说明:**
3015>
3016> 从 API version 9开始支持,从API version 11 开始废弃。替代接口仅面向系统应用开放。
3017
3018**需要权限:** ohos.permission.MANAGE_AUDIO_CONFIG,该权限仅系统应用可申请。
3019
3020**系统能力:** SystemCapability.Multimedia.Audio.Volume
3021
3022**参数:**
3023
3024| 参数名   | 类型                      | 必填 | 说明                                          |
3025| -------- | ------------------------- | ---- | --------------------------------------------- |
3026| mute     | boolean                   | 是   | 待设置的静音状态,true为静音,false为非静音。 |
3027| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。当设置麦克风静音状态成功,err为undefined,否则为错误对象。 |
3028
3029**示例:**
3030
3031```ts
3032import { BusinessError } from '@kit.BasicServicesKit';
3033
3034audioVolumeGroupManager.setMicrophoneMute(true, (err: BusinessError) => {
3035  if (err) {
3036    console.error(`Failed to mute the microphone. ${err}`);
3037    return;
3038  }
3039  console.info('Callback invoked to indicate that the microphone is muted.');
3040});
3041```
3042
3043### setMicrophoneMute<sup>(deprecated)</sup>
3044
3045setMicrophoneMute(mute: boolean): Promise&lt;void&gt;
3046
3047设置麦克风静音状态,使用Promise方式异步返回结果。
3048
3049> **说明:**
3050>
3051> 从 API version 9开始支持,从API version 11 开始废弃。替代接口仅面向系统应用开放。
3052
3053**需要权限:** ohos.permission.MANAGE_AUDIO_CONFIG,该权限仅系统应用可申请。
3054
3055**系统能力:** SystemCapability.Multimedia.Audio.Volume
3056
3057**参数:**
3058
3059| 参数名 | 类型    | 必填 | 说明                                          |
3060| ------ | ------- | ---- | --------------------------------------------- |
3061| mute   | boolean | 是   | 待设置的静音状态,true为静音,false为非静音。 |
3062
3063**返回值:**
3064
3065| 类型                | 说明                            |
3066| ------------------- | ------------------------------- |
3067| Promise&lt;void&gt; | Promise对象,无返回结果。 |
3068
3069**示例:**
3070
3071```ts
3072audioVolumeGroupManager.setMicrophoneMute(true).then(() => {
3073  console.info('Promise returned to indicate that the microphone is muted.');
3074});
3075```
3076
3077### isMicrophoneMute<sup>9+</sup>
3078
3079isMicrophoneMute(callback: AsyncCallback&lt;boolean&gt;): void
3080
3081获取麦克风静音状态,使用callback方式异步返回结果。
3082
3083**系统能力:** SystemCapability.Multimedia.Audio.Volume
3084
3085**参数:**
3086
3087| 参数名   | 类型                         | 必填 | 说明                                                    |
3088| -------- | ---------------------------- | ---- | ------------------------------------------------------- |
3089| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。当获取麦克风静音状态成功,err为undefined,data为true为静音,false为非静音;否则为错误对象。 |
3090
3091**示例:**
3092
3093```ts
3094import { BusinessError } from '@kit.BasicServicesKit';
3095
3096audioVolumeGroupManager.isMicrophoneMute((err: BusinessError, value: boolean) => {
3097  if (err) {
3098    console.error(`Failed to obtain the mute status of the microphone. ${err}`);
3099    return;
3100  }
3101  console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`);
3102});
3103```
3104
3105### isMicrophoneMute<sup>9+</sup>
3106
3107isMicrophoneMute(): Promise&lt;boolean&gt;
3108
3109获取麦克风静音状态,使用Promise方式异步返回结果。
3110
3111**系统能力:** SystemCapability.Multimedia.Audio.Volume
3112
3113**返回值:**
3114
3115| 类型                   | 说明                                                         |
3116| ---------------------- | ------------------------------------------------------------ |
3117| Promise&lt;boolean&gt; | Promise对象,返回系统麦克风静音状态,true为静音,false为非静音。 |
3118
3119**示例:**
3120
3121```ts
3122audioVolumeGroupManager.isMicrophoneMute().then((value: boolean) => {
3123  console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`);
3124});
3125```
3126
3127### isMicrophoneMuteSync<sup>10+</sup>
3128
3129isMicrophoneMuteSync(): boolean
3130
3131获取麦克风静音状态,同步返回结果。
3132
3133**系统能力:** SystemCapability.Multimedia.Audio.Volume
3134
3135**返回值:**
3136
3137| 类型                   | 说明                                                         |
3138| ---------------------- | ------------------------------------------------------------ |
3139| boolean | 返回系统麦克风静音状态,true为静音,false为非静音。 |
3140
3141**示例:**
3142
3143```ts
3144import { BusinessError } from '@kit.BasicServicesKit';
3145
3146try {
3147  let value: boolean = audioVolumeGroupManager.isMicrophoneMuteSync();
3148  console.info(`Indicate that the mute status of the microphone is obtained ${value}.`);
3149} catch (err) {
3150  let error = err as BusinessError;
3151  console.error(`Failed to obtain the mute status of the microphone, error ${error}.`);
3152}
3153```
3154
3155### on('micStateChange')<sup>9+</sup>
3156
3157on(type: 'micStateChange', callback: Callback&lt;MicStateChangeEvent&gt;): void
3158
3159监听系统麦克风状态更改事件(当检测到系统麦克风状态发生改变时触发),使用callback方式返回结果。
3160
3161目前此订阅接口在单进程多AudioManager实例的使用场景下,仅最后一个实例的订阅生效,其他实例的订阅会被覆盖(即使最后一个实例没有进行订阅),因此推荐使用单一AudioManager实例进行开发。
3162
3163**系统能力:** SystemCapability.Multimedia.Audio.Volume
3164
3165**参数:**
3166
3167| 参数名   | 类型                                   | 必填 | 说明                                                         |
3168| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
3169| type     | string                                 | 是   | 监听事件,固定为:'micStateChange'。 |
3170| callback | Callback<[MicStateChangeEvent](#micstatechangeevent9)> | 是   | 回调函数,返回变更后的麦克风状态。 |
3171
3172**错误码:**
3173
3174以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3175
3176| 错误码ID | 错误信息 |
3177| ------- | --------------------------------------------|
3178| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3179| 6800101 | Parameter verification failed. |
3180
3181**示例:**
3182
3183```ts
3184audioVolumeGroupManager.on('micStateChange', (micStateChange: audio.MicStateChangeEvent) => {
3185  console.info(`Current microphone status is: ${micStateChange.mute} `);
3186});
3187```
3188
3189### isVolumeUnadjustable<sup>10+</sup>
3190
3191isVolumeUnadjustable(): boolean
3192
3193获取固定音量模式开关状态,打开时进入固定音量模式,此时音量固定无法被调节,使用同步方式返回结果。
3194
3195**系统能力:** SystemCapability.Multimedia.Audio.Volume
3196
3197**返回值:**
3198
3199| 类型                   | 说明                                                   |
3200| ---------------------- | ------------------------------------------------------ |
3201| boolean            | 同步接口,返回固定音量模式开关状态,true为固定音量模式,false为非固定音量模式。 |
3202
3203**示例:**
3204
3205```ts
3206let volumeAdjustSwitch: boolean = audioVolumeGroupManager.isVolumeUnadjustable();
3207console.info(`Whether it is volume unadjustable: ${volumeAdjustSwitch}.`);
3208```
3209
3210### getSystemVolumeInDb<sup>10+</sup>
3211
3212getSystemVolumeInDb(volumeType: AudioVolumeType, volumeLevel: number, device: DeviceType, callback: AsyncCallback&lt;number&gt;): void
3213
3214获取音量增益dB值,使用callback方式异步返回结果。
3215
3216**系统能力:** SystemCapability.Multimedia.Audio.Volume
3217
3218**参数:**
3219
3220| 参数名     | 类型                                | 必填 | 说明                                                     |
3221| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3222| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
3223| volumeLevel | number                         | 是   | 音量等级。                                               |
3224| device     | [DeviceType](#devicetype)           | 是   | 设备类型。                                               |
3225| callback   | AsyncCallback&lt;number&gt;           | 是   | 回调函数。当获取音量增益dB值成功,err为undefined,data为获取到的音量增益dB值;否则为错误对象。 |
3226
3227**错误码:**
3228
3229以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3230
3231| 错误码ID | 错误信息 |
3232| ------- | --------------------------------------------|
3233| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3234| 6800101 | Parameter verification failed. Return by callback.                     |
3235| 6800301 | System error. Return by callback.                                |
3236
3237**示例:**
3238
3239```ts
3240import { BusinessError } from '@kit.BasicServicesKit';
3241
3242audioVolumeGroupManager.getSystemVolumeInDb(audio.AudioVolumeType.MEDIA, 3, audio.DeviceType.SPEAKER, (err: BusinessError, dB: number) => {
3243  if (err) {
3244    console.error(`Failed to get the volume DB. ${err}`);
3245  } else {
3246    console.info(`Success to get the volume DB. ${dB}`);
3247  }
3248});
3249```
3250### getSystemVolumeInDb<sup>10+</sup>
3251
3252getSystemVolumeInDb(volumeType: AudioVolumeType, volumeLevel: number, device: DeviceType): Promise&lt;number&gt;
3253
3254获取音量增益dB值,使用Promise方式异步返回结果。
3255
3256**系统能力:** SystemCapability.Multimedia.Audio.Volume
3257
3258**参数:**
3259
3260| 参数名     | 类型                                | 必填 | 说明                                                     |
3261| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3262| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
3263| volumeLevel | number                              | 是   | 音量等级。                                             |
3264| device     | [DeviceType](#devicetype)           | 是   | 设备类型。                                               |
3265
3266**返回值:**
3267
3268| 类型                  | 说明                               |
3269| --------------------- | ---------------------------------- |
3270| Promise&lt;number&gt; | Promise对象,返回对应的音量增益dB值。 |
3271
3272**错误码:**
3273
3274以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3275
3276| 错误码ID | 错误信息 |
3277| ------- | --------------------------------------------|
3278| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3279| 6800101 | Parameter verification failed. Return by promise.                     |
3280| 6800301 | System error. Return by promise.                                |
3281
3282**示例:**
3283
3284```ts
3285import { BusinessError } from '@kit.BasicServicesKit';
3286
3287audioVolumeGroupManager.getSystemVolumeInDb(audio.AudioVolumeType.MEDIA, 3, audio.DeviceType.SPEAKER).then((value: number) => {
3288  console.info(`Success to get the volume DB. ${value}`);
3289}).catch((error: BusinessError) => {
3290  console.error(`Fail to adjust the system volume by step. ${error}`);
3291});
3292```
3293
3294### getSystemVolumeInDbSync<sup>10+</sup>
3295
3296getSystemVolumeInDbSync(volumeType: AudioVolumeType, volumeLevel: number, device: DeviceType): number
3297
3298获取音量增益dB值,同步返回结果。
3299
3300**系统能力:** SystemCapability.Multimedia.Audio.Volume
3301
3302**参数:**
3303
3304| 参数名     | 类型                                | 必填 | 说明                                                     |
3305| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
3306| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
3307| volumeLevel | number                              | 是   | 音量等级。                                             |
3308| device     | [DeviceType](#devicetype)           | 是   | 设备类型。                                               |
3309
3310**返回值:**
3311
3312| 类型                  | 说明                               |
3313| --------------------- | ---------------------------------- |
3314| number | 返回对应的音量增益dB值。 |
3315
3316**错误码:**
3317
3318以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3319
3320| 错误码ID | 错误信息 |
3321| ------- | --------------------------------------------|
3322| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3323| 6800101 | Parameter verification failed. |
3324
3325**示例:**
3326
3327```ts
3328import { BusinessError } from '@kit.BasicServicesKit';
3329
3330try {
3331  let value: number = audioVolumeGroupManager.getSystemVolumeInDbSync(audio.AudioVolumeType.MEDIA, 3, audio.DeviceType.SPEAKER);
3332  console.info(`Success to get the volume DB. ${value}`);
3333} catch (err) {
3334  let error = err as BusinessError;
3335  console.error(`Fail to adjust the system volume by step. ${error}`);
3336}
3337```
3338
3339### getMaxAmplitudeForInputDevice<sup>12+</sup>
3340
3341getMaxAmplitudeForInputDevice(inputDevice: AudioDeviceDescriptor): Promise&lt;number&gt;
3342
3343获取输入设备音频流的最大电平值,大小取值在0-1之间,最小为0,使用Promise方式异步返回结果。
3344
3345**系统能力:** SystemCapability.Multimedia.Audio.Volume
3346
3347**参数:**
3348
3349| 参数名     | 类型                                | 必填 | 说明                                                     |
3350| ----------- | ------------------------------------- | ---- | --------------------------------------------------- |
3351| inputDevice | [AudioDeviceDescriptor](#audiodevicedescriptor) | 是   | 获取最大电平值的设备信息。                                 |
3352
3353**返回值:**
3354
3355| 类型                  | 说明                               |
3356| --------------------- | ---------------------------------- |
3357| Promise&lt;number&gt; | Promise对象,返回对应设备的电平值,大小在0-1之间。 |
3358
3359**错误码:**
3360
3361以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3362
3363| 错误码ID | 错误信息 |
3364| ------- | --------------------------------------------|
3365| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3366| 6800101 | Parameter verification failed. Return by promise. |
3367| 6800301 | System error. Return by promise. |
3368
3369**示例:**
3370
3371```ts
3372import { BusinessError } from '@kit.BasicServicesKit';
3373
3374let capturerInfo: audio.AudioCapturerInfo = {
3375  source: audio.SourceType.SOURCE_TYPE_MIC,
3376  capturerFlags: 0
3377};
3378
3379audio.getAudioManager().getRoutingManager().getPreferredInputDeviceForCapturerInfo(capturerInfo).then((data) => {
3380  audioVolumeGroupManager.getMaxAmplitudeForInputDevice(data[0]).then((value) => {
3381    console.info(`mic volatileume amplitude is: ${value}`);
3382  }).catch((err: BusinessError) => {
3383    console.error("getMaxAmplitudeForInputDevice error" + JSON.stringify(err));
3384  })
3385}).catch((err: BusinessError) => {
3386  console.error("get outputDeviceId error" + JSON.stringify(err));
3387})
3388```
3389
3390### getMaxAmplitudeForOutputDevice<sup>12+</sup>
3391
3392getMaxAmplitudeForOutputDevice(outputDevice: AudioDeviceDescriptor): Promise&lt;number&gt;
3393
3394获取输出设备音频流的最大电平值,大小取值在0-1之间,最小为0,使用Promise方式异步返回结果。
3395
3396**系统能力:** SystemCapability.Multimedia.Audio.Volume
3397
3398**参数:**
3399
3400| 参数名     | 类型                                | 必填 | 说明                                                     |
3401| ------------ | --------------------------------------- | ---- | -------------------------------------------------------- |
3402| outputDevice | [AudioDeviceDescriptor](#audiodevicedescriptor) | 是   | 获取最大电平值的设备信息。                                             |
3403
3404**返回值:**
3405
3406| 类型                  | 说明                               |
3407| --------------------- | ---------------------------------- |
3408| Promise&lt;number&gt; | Promise对象,返回对应设备的电平值,大小在0-1之间。 |
3409
3410**错误码:**
3411
3412以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3413
3414| 错误码ID | 错误信息 |
3415| ------- | --------------------------------------------|
3416| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3417| 6800101 | Parameter verification failed. Return by promise. |
3418| 6800301 | System error. Return by promise. |
3419
3420**示例:**
3421
3422```ts
3423import { BusinessError } from '@kit.BasicServicesKit';
3424
3425let rendererInfo: audio.AudioRendererInfo = {
3426  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
3427  rendererFlags : 0
3428};
3429
3430audio.getAudioManager().getRoutingManager().getPreferOutputDeviceForRendererInfo(rendererInfo).then((data) => {
3431  audioVolumeGroupManager.getMaxAmplitudeForOutputDevice(data[0]).then((value) => {
3432    console.info(`mic volatileume amplitude is: ${value}`);
3433  }).catch((err: BusinessError) => {
3434    console.error("getMaxAmplitudeForOutputDevice error" + JSON.stringify(err));
3435  })
3436}).catch((err: BusinessError) => {
3437  console.error("getPreferOutputDeviceForRendererInfo error" + JSON.stringify(err));
3438})
3439```
3440
3441## AudioStreamManager<sup>9+</sup>
3442
3443管理音频流。在使用AudioStreamManager的API前,需要使用[getStreamManager](#getstreammanager9)获取AudioStreamManager实例。
3444
3445### getCurrentAudioRendererInfoArray<sup>9+</sup>
3446
3447getCurrentAudioRendererInfoArray(callback: AsyncCallback&lt;AudioRendererChangeInfoArray&gt;): void
3448
3449获取当前音频渲染器的信息。使用callback异步回调。
3450
3451**系统能力**: SystemCapability.Multimedia.Audio.Renderer
3452
3453**参数:**
3454
3455| 参数名     | 类型                                 | 必填     | 说明                         |
3456| -------- | ----------------------------------- | -------- | --------------------------- |
3457| callback | AsyncCallback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | 是     | 回调函数。当获取当前音频渲染器的信息成功,err为undefined,data为获取到的当前音频渲染器的信息;否则为错误对象。 |
3458
3459**示例:**
3460
3461```ts
3462import { BusinessError } from '@kit.BasicServicesKit';
3463
3464audioStreamManager.getCurrentAudioRendererInfoArray(async (err: BusinessError, AudioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray) => {
3465  console.info('getCurrentAudioRendererInfoArray **** Get Callback Called ****');
3466  if (err) {
3467    console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`);
3468  } else {
3469    if (AudioRendererChangeInfoArray != null) {
3470      for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
3471        let AudioRendererChangeInfo: audio.AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
3472        console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
3473        console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
3474        console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
3475        console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
3476        for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
3477          console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
3478          console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
3479          console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
3480          console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
3481          console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
3482          console.info(`SampleRate: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
3483          console.info(`ChannelCount: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
3484          console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
3485        }
3486      }
3487    }
3488  }
3489});
3490```
3491
3492### getCurrentAudioRendererInfoArray<sup>9+</sup>
3493
3494getCurrentAudioRendererInfoArray(): Promise&lt;AudioRendererChangeInfoArray&gt;
3495
3496获取当前音频渲染器的信息。使用Promise异步回调。
3497
3498**系统能力:** SystemCapability.Multimedia.Audio.Renderer
3499
3500**返回值:**
3501
3502| 类型                                                                              | 说明                                    |
3503| ---------------------------------------------------------------------------------| --------------------------------------- |
3504| Promise<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)>          | Promise对象,返回当前音频渲染器信息。      |
3505
3506**示例:**
3507
3508```ts
3509import { BusinessError } from '@kit.BasicServicesKit';
3510
3511async function getCurrentAudioRendererInfoArray(){
3512  await audioStreamManager.getCurrentAudioRendererInfoArray().then((AudioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray) => {
3513    console.info(`getCurrentAudioRendererInfoArray ######### Get Promise is called ##########`);
3514    if (AudioRendererChangeInfoArray != null) {
3515      for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
3516        let AudioRendererChangeInfo: audio.AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
3517        console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
3518        console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
3519        console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
3520        console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
3521        for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
3522          console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
3523          console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
3524          console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
3525          console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
3526          console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
3527          console.info(`SampleRate: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
3528          console.info(`ChannelCount: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
3529          console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
3530        }
3531      }
3532    }
3533  }).catch((err: BusinessError) => {
3534    console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`);
3535  });
3536}
3537```
3538### getCurrentAudioRendererInfoArraySync<sup>10+</sup>
3539
3540getCurrentAudioRendererInfoArraySync(): AudioRendererChangeInfoArray
3541
3542获取当前音频渲染器的信息,同步返回结果。
3543
3544**系统能力:** SystemCapability.Multimedia.Audio.Renderer
3545
3546**返回值:**
3547
3548| 类型                                                                              | 说明                                    |
3549| ---------------------------------------------------------------------------------| --------------------------------------- |
3550| [AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)          | 返回当前音频渲染器信息。      |
3551
3552**示例:**
3553
3554```ts
3555import { BusinessError } from '@kit.BasicServicesKit';
3556
3557try {
3558  let audioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray = audioStreamManager.getCurrentAudioRendererInfoArraySync();
3559  console.info(`getCurrentAudioRendererInfoArraySync success.`);
3560  if (audioRendererChangeInfoArray != null) {
3561    for (let i = 0; i < audioRendererChangeInfoArray.length; i++) {
3562      let AudioRendererChangeInfo: audio.AudioRendererChangeInfo = audioRendererChangeInfoArray[i];
3563      console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
3564      console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
3565      console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
3566      console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
3567      for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
3568        console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
3569        console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
3570        console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
3571        console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
3572        console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
3573        console.info(`SampleRate: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
3574        console.info(`ChannelCount: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
3575        console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
3576      }
3577    }
3578  }
3579} catch (err) {
3580  let error = err as BusinessError;
3581  console.error(`getCurrentAudioRendererInfoArraySync :ERROR: ${error}`);
3582}
3583```
3584
3585### getCurrentAudioCapturerInfoArray<sup>9+</sup>
3586
3587getCurrentAudioCapturerInfoArray(callback: AsyncCallback&lt;AudioCapturerChangeInfoArray&gt;): void
3588
3589获取当前音频采集器的信息。使用callback异步回调。
3590
3591**系统能力:** SystemCapability.Multimedia.Audio.Renderer
3592
3593**参数:**
3594
3595| 参数名        | 类型                                 | 必填      | 说明                                                      |
3596| ---------- | ----------------------------------- | --------- | -------------------------------------------------------- |
3597| callback   | AsyncCallback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | 是    | 回调函数。当获取当前音频采集器的信息成功,err为undefined,data为获取到的当前音频采集器的信息;否则为错误对象。 |
3598
3599**示例:**
3600
3601```ts
3602import { BusinessError } from '@kit.BasicServicesKit';
3603
3604audioStreamManager.getCurrentAudioCapturerInfoArray(async (err: BusinessError, AudioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray) => {
3605  console.info('getCurrentAudioCapturerInfoArray **** Get Callback Called ****');
3606  if (err) {
3607    console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
3608  } else {
3609    if (AudioCapturerChangeInfoArray != null) {
3610      for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
3611        console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
3612        console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
3613        console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
3614        for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
3615          console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
3616          console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
3617          console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
3618          console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
3619          console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
3620          console.info(`SampleRate: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
3621          console.info(`ChannelCount: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
3622          console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
3623        }
3624      }
3625    }
3626  }
3627});
3628```
3629
3630### getCurrentAudioCapturerInfoArray<sup>9+</sup>
3631
3632getCurrentAudioCapturerInfoArray(): Promise&lt;AudioCapturerChangeInfoArray&gt;
3633
3634获取当前音频采集器的信息。使用Promise异步回调。
3635
3636**系统能力:** SystemCapability.Multimedia.Audio.Renderer
3637
3638**返回值:**
3639
3640| 类型                                                                         | 说明                                 |
3641| -----------------------------------------------------------------------------| ----------------------------------- |
3642| Promise<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)>      | Promise对象,返回当前音频采集器信息。  |
3643
3644**示例:**
3645
3646```ts
3647import { BusinessError } from '@kit.BasicServicesKit';
3648
3649async function getCurrentAudioCapturerInfoArray(){
3650  await audioStreamManager.getCurrentAudioCapturerInfoArray().then((AudioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray) => {
3651    console.info('getCurrentAudioCapturerInfoArray **** Get Promise Called ****');
3652    if (AudioCapturerChangeInfoArray != null) {
3653      for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
3654        console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
3655        console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
3656        console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
3657        for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
3658          console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
3659          console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
3660          console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
3661          console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
3662          console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
3663          console.info(`SampleRate: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
3664          console.info(`ChannelCount: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
3665          console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
3666        }
3667      }
3668    }
3669  }).catch((err: BusinessError) => {
3670    console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
3671  });
3672}
3673```
3674### getCurrentAudioCapturerInfoArraySync<sup>10+</sup>
3675
3676getCurrentAudioCapturerInfoArraySync(): AudioCapturerChangeInfoArray
3677
3678获取当前音频采集器的信息,同步返回结果。
3679
3680**系统能力:** SystemCapability.Multimedia.Audio.Capturer
3681
3682**返回值:**
3683
3684| 类型                                                                         | 说明                                 |
3685| -----------------------------------------------------------------------------| ----------------------------------- |
3686| [AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)      | 返回当前音频采集器信息。  |
3687
3688**示例:**
3689
3690```ts
3691import { BusinessError } from '@kit.BasicServicesKit';
3692
3693try {
3694  let audioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray = audioStreamManager.getCurrentAudioCapturerInfoArraySync();
3695  console.info('getCurrentAudioCapturerInfoArraySync success.');
3696  if (audioCapturerChangeInfoArray != null) {
3697    for (let i = 0; i < audioCapturerChangeInfoArray.length; i++) {
3698      console.info(`StreamId for ${i} is: ${audioCapturerChangeInfoArray[i].streamId}`);
3699      console.info(`Source for ${i} is: ${audioCapturerChangeInfoArray[i].capturerInfo.source}`);
3700      console.info(`Flag  ${i} is: ${audioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
3701      for (let j = 0; j < audioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
3702        console.info(`Id: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
3703        console.info(`Type: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
3704        console.info(`Role: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
3705        console.info(`Name: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
3706        console.info(`Address: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
3707        console.info(`SampleRate: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
3708        console.info(`ChannelCount: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
3709        console.info(`ChannelMask: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
3710      }
3711    }
3712  }
3713} catch (err) {
3714  let error = err as BusinessError;
3715  console.error(`getCurrentAudioCapturerInfoArraySync ERROR: ${error}`);
3716}
3717```
3718
3719### on('audioRendererChange')<sup>9+</sup>
3720
3721on(type: 'audioRendererChange', callback: Callback&lt;AudioRendererChangeInfoArray&gt;): void
3722
3723监听音频渲染器更改事件(当音频播放流状态变化、设备变化时触发),使用callback方式返回结果。
3724
3725**系统能力:** SystemCapability.Multimedia.Audio.Renderer
3726
3727**参数:**
3728
3729| 参数名      | 类型        | 必填      | 说明                                                                     |
3730| -------- | ---------- | --------- | ------------------------------------------------------------------------ |
3731| type     | string     | 是        | 监听事件,固定为:'audioRendererChange'。     |
3732| callback | Callback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | 是  |  回调函数,返回当前音频渲染器信息。 |
3733
3734**错误码:**
3735
3736以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3737
3738| 错误码ID | 错误信息 |
3739| ------- | --------------------------------------------|
3740| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3741| 6800101 | Parameter verification failed. |
3742
3743**示例:**
3744
3745```ts
3746audioStreamManager.on('audioRendererChange',  (audioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray) => {
3747  for (let i = 0; i < audioRendererChangeInfoArray.length; i++) {
3748    let audioRendererChangeInfo: audio.AudioRendererChangeInfo = audioRendererChangeInfoArray[i];
3749    console.info(`## RendererChange on is called for ${i} ##`);
3750    console.info(`StreamId for ${i} is: ${audioRendererChangeInfo.streamId}`);
3751    console.info(`Content ${i} is: ${audioRendererChangeInfo.rendererInfo.content}`);
3752    console.info(`Stream ${i} is: ${audioRendererChangeInfo.rendererInfo.usage}`);
3753    console.info(`Flag ${i} is: ${audioRendererChangeInfo.rendererInfo.rendererFlags}`);
3754    for (let j = 0;j < audioRendererChangeInfo.deviceDescriptors.length; j++) {
3755      console.info(`Id: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].id}`);
3756      console.info(`Type: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
3757      console.info(`Role: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
3758      console.info(`Name: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].name}`);
3759      console.info(`Address: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].address}`);
3760      console.info(`SampleRate: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
3761      console.info(`ChannelCount: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
3762      console.info(`ChannelMask: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
3763    }
3764  }
3765});
3766```
3767
3768### off('audioRendererChange')<sup>9+</sup>
3769
3770off(type: 'audioRendererChange'): void
3771
3772取消监听音频渲染器更改事件。
3773
3774**系统能力:** SystemCapability.Multimedia.Audio.Renderer
3775
3776**参数:**
3777
3778| 参数名     | 类型     | 必填 | 说明              |
3779| -------- | ------- | ---- | ---------------- |
3780| type     | string  | 是   | 监听事件,固定为:'audioRendererChange'。 |
3781
3782**错误码:**
3783
3784以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3785
3786| 错误码ID | 错误信息                     |
3787| ------- |--------------------------|
3788| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3789| 6800101 | Parameter verification failed. |
3790
3791**示例:**
3792
3793```ts
3794audioStreamManager.off('audioRendererChange');
3795```
3796
3797### on('audioCapturerChange')<sup>9+</sup>
3798
3799on(type: 'audioCapturerChange', callback: Callback&lt;AudioCapturerChangeInfoArray&gt;): void
3800
3801监听音频采集器更改事件(当音频录制流状态变化、设备变化时触发),使用callback方式返回结果。
3802
3803**系统能力:** SystemCapability.Multimedia.Audio.Capturer
3804
3805**参数:**
3806
3807| 参数名     | 类型     | 必填      | 说明                                                                                          |
3808| -------- | ------- | --------- | ---------------------------------------------------------------------- |
3809| type     | string  | 是        | 监听事件,固定为:'audioCapturerChange'。     |
3810| callback | Callback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | 是     | 回调函数,返回当前音频采集器信息。 |
3811
3812**错误码:**
3813
3814以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3815
3816| 错误码ID | 错误信息 |
3817| ------- | --------------------------------------------|
3818| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3819| 6800101 | Parameter verification failed. |
3820
3821**示例:**
3822
3823```ts
3824audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray) =>  {
3825  for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
3826    console.info(`## CapChange on is called for element ${i} ##`);
3827    console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
3828    console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
3829    console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
3830    for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
3831      console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
3832      console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
3833      console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
3834      console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
3835      console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
3836      console.info(`SampleRate: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
3837      console.info(`ChannelCount: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
3838      console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
3839    }
3840  }
3841});
3842```
3843
3844### off('audioCapturerChange')<sup>9+</sup>
3845
3846off(type: 'audioCapturerChange'): void
3847
3848取消监听音频采集器更改事件。
3849
3850**系统能力:** SystemCapability.Multimedia.Audio.Capturer
3851
3852**参数:**
3853
3854| 参数名       | 类型     | 必填 | 说明                                                          |
3855| -------- | -------- | --- | ------------------------------------------------------------- |
3856| type     | string   |是   | 监听事件,固定为:'audioCapturerChange'。 |
3857
3858**错误码:**
3859
3860以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3861
3862| 错误码ID | 错误信息 |
3863| ------- | --------------------------------------------|
3864| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3865| 6800101 | Parameter verification failed. |
3866
3867**示例:**
3868
3869```ts
3870audioStreamManager.off('audioCapturerChange');
3871```
3872
3873### isActive<sup>9+</sup>
3874
3875isActive(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
3876
3877获取指定音频流是否为活跃状态,使用callback方式异步返回结果。
3878
3879**系统能力:** SystemCapability.Multimedia.Audio.Renderer
3880
3881**参数:**
3882
3883| 参数名     | 类型                                | 必填 | 说明                                              |
3884| ---------- | ----------------------------------- | ---- | ------------------------------------------------- |
3885| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音频流类型。                                      |
3886| callback   | AsyncCallback&lt;boolean&gt;        | 是   | 回调函数。当获取指定音频流是否为活跃状态成功,err为undefined,data为true为活跃,false为不活跃;否则为错误对象。 |
3887
3888**示例:**
3889
3890```ts
3891import { BusinessError } from '@kit.BasicServicesKit';
3892
3893audioStreamManager.isActive(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => {
3894if (err) {
3895  console.error(`Failed to obtain the active status of the stream. ${err}`);
3896  return;
3897}
3898  console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`);
3899});
3900```
3901
3902### isActive<sup>9+</sup>
3903
3904isActive(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
3905
3906获取指定音频流是否为活跃状态,使用Promise方式异步返回结果。
3907
3908**系统能力:** SystemCapability.Multimedia.Audio.Renderer
3909
3910**参数:**
3911
3912| 参数名     | 类型                                | 必填 | 说明         |
3913| ---------- | ----------------------------------- | ---- | ------------ |
3914| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音频流类型。 |
3915
3916**返回值:**
3917
3918| 类型                   | 说明                                                     |
3919| ---------------------- | -------------------------------------------------------- |
3920| Promise&lt;boolean&gt; | Promise对象,返回流的活跃状态,true为活跃,false为不活跃。 |
3921
3922**示例:**
3923
3924```ts
3925audioStreamManager.isActive(audio.AudioVolumeType.MEDIA).then((value: boolean) => {
3926  console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`);
3927});
3928```
3929
3930### isActiveSync<sup>10+</sup>
3931
3932isActiveSync(volumeType: AudioVolumeType): boolean
3933
3934获取指定音频流是否为活跃状态,同步返回结果。
3935
3936**系统能力:** SystemCapability.Multimedia.Audio.Renderer
3937
3938**参数:**
3939
3940| 参数名     | 类型                                | 必填 | 说明         |
3941| ---------- | ----------------------------------- | ---- | ------------ |
3942| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音频流类型。 |
3943
3944**返回值:**
3945
3946| 类型                   | 说明                                                     |
3947| ---------------------- | -------------------------------------------------------- |
3948| boolean | 返回流的活跃状态,true为活跃,false为不活跃。 |
3949
3950**错误码:**
3951
3952以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3953
3954| 错误码ID | 错误信息 |
3955| ------- | --------------------------------------------|
3956| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3957| 6800101 | Parameter verification failed. |
3958
3959**示例:**
3960
3961```ts
3962import { BusinessError } from '@kit.BasicServicesKit';
3963
3964try {
3965  let value: boolean = audioStreamManager.isActiveSync(audio.AudioVolumeType.MEDIA);
3966  console.info(`Indicate that the active status of the stream is obtained ${value}.`);
3967} catch (err) {
3968  let error = err as BusinessError;
3969  console.error(`Failed to obtain the active status of the stream ${error}.`);
3970}
3971```
3972
3973### getAudioEffectInfoArray<sup>10+</sup>
3974
3975getAudioEffectInfoArray(usage: StreamUsage, callback: AsyncCallback&lt;AudioEffectInfoArray&gt;): void
3976
3977获取当前音效模式的信息。使用callback异步回调。
3978
3979**系统能力**: SystemCapability.Multimedia.Audio.Renderer
3980
3981**参数:**
3982
3983| 参数名    | 类型                                | 必填     | 说明                         |
3984| -------- | ----------------------------------- | -------- | --------------------------- |
3985| usage    | [StreamUsage](#streamusage)                                    | 是     |  音频流使用类型。                |
3986| callback | AsyncCallback<[AudioEffectInfoArray](#audioeffectinfoarray10)> | 是     | 回调函数。当获取当前音效模式的信息成功,err为undefined,data为获取到的当前音效模式的信息;否则为错误对象。|
3987
3988**错误码:**
3989
3990以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3991
3992| 错误码ID | 错误信息 |
3993| ------- | --------------------------------------------|
3994| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3995| 6800101 | Parameter verification failed. Return by callback.|
3996
3997**示例:**
3998
3999```ts
4000import { BusinessError } from '@kit.BasicServicesKit';
4001
4002audioStreamManager.getAudioEffectInfoArray(audio.StreamUsage.STREAM_USAGE_MUSIC, async (err: BusinessError, audioEffectInfoArray: audio.AudioEffectInfoArray) => {
4003  console.info('getAudioEffectInfoArray **** Get Callback Called ****');
4004  if (err) {
4005    console.error(`getAudioEffectInfoArray :ERROR: ${err}`);
4006    return;
4007  } else {
4008    console.info(`The effect modes are: ${audioEffectInfoArray}`);
4009  }
4010});
4011```
4012
4013### getAudioEffectInfoArray<sup>10+</sup>
4014
4015getAudioEffectInfoArray(usage: StreamUsage): Promise&lt;AudioEffectInfoArray&gt;
4016
4017获取当前音效模式的信息。使用Promise异步回调。
4018
4019**系统能力:** SystemCapability.Multimedia.Audio.Renderer
4020
4021**参数:**
4022
4023| 参数名    | 类型                                | 必填     | 说明                         |
4024| -------- | ----------------------------------- | -------- | --------------------------- |
4025| usage    | [StreamUsage](#streamusage)         | 是     |  音频流使用类型。               |
4026
4027**返回值:**
4028
4029| 类型                                                                      | 说明                                    |
4030| --------------------------------------------------------------------------| --------------------------------------- |
4031| Promise<[AudioEffectInfoArray](#audioeffectinfoarray10)>                  | Promise对象,返回当前音效模式的信息。      |
4032
4033**错误码:**
4034
4035以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4036
4037| 错误码ID | 错误信息 |
4038| ------- | --------------------------------------------|
4039| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4040| 6800101 | Parameter verification failed. Return by promise. |
4041
4042**示例:**
4043
4044```ts
4045import { BusinessError } from '@kit.BasicServicesKit';
4046
4047audioStreamManager.getAudioEffectInfoArray(audio.StreamUsage.STREAM_USAGE_MUSIC).then((audioEffectInfoArray: audio.AudioEffectInfoArray) => {
4048  console.info('getAudioEffectInfoArray ######### Get Promise is called ##########');
4049  console.info(`The effect modes are: ${audioEffectInfoArray}`);
4050}).catch((err: BusinessError) => {
4051  console.error(`getAudioEffectInfoArray :ERROR: ${err}`);
4052});
4053```
4054
4055### getAudioEffectInfoArraySync<sup>10+</sup>
4056
4057getAudioEffectInfoArraySync(usage: StreamUsage): AudioEffectInfoArray
4058
4059获取当前音效模式的信息,同步返回结果。
4060
4061**系统能力:** SystemCapability.Multimedia.Audio.Renderer
4062
4063**参数:**
4064
4065| 参数名    | 类型                                | 必填     | 说明                         |
4066| -------- | ----------------------------------- | -------- | --------------------------- |
4067| usage    | [StreamUsage](#streamusage)         | 是     |  音频流使用类型。               |
4068
4069**返回值:**
4070
4071| 类型                                                                      | 说明                                    |
4072| --------------------------------------------------------------------------| --------------------------------------- |
4073| [AudioEffectInfoArray](#audioeffectinfoarray10)                  | 返回当前音效模式的信息。      |
4074
4075**错误码:**
4076
4077以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4078
4079| 错误码ID | 错误信息 |
4080| ------- | --------------------------------------------|
4081| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4082| 6800101 | Parameter verification failed. |
4083
4084**示例:**
4085
4086```ts
4087import { BusinessError } from '@kit.BasicServicesKit';
4088
4089try {
4090  let audioEffectInfoArray: audio.AudioEffectInfoArray = audioStreamManager.getAudioEffectInfoArraySync(audio.StreamUsage.STREAM_USAGE_MUSIC);
4091  console.info(`The effect modes are: ${audioEffectInfoArray}`);
4092} catch (err) {
4093  let error = err as BusinessError;
4094  console.error(`getAudioEffectInfoArraySync ERROR: ${error}`);
4095}
4096```
4097
4098## AudioRoutingManager<sup>9+</sup>
4099
4100音频路由管理。在使用AudioRoutingManager的接口前,需要使用[getRoutingManager](#getroutingmanager9)获取AudioRoutingManager实例。
4101
4102### getDevices<sup>9+</sup>
4103
4104getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
4105
4106获取音频设备列表,使用callback方式异步返回结果。
4107
4108**系统能力:** SystemCapability.Multimedia.Audio.Device
4109
4110**参数:**
4111
4112| 参数名     | 类型                                                         | 必填 | 说明                 |
4113| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
4114| deviceFlag | [DeviceFlag](#deviceflag)                                    | 是   | 设备类型的flag。     |
4115| callback   | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | 是   | 回调函数。当获取音频设备列表成功,err为undefined,data为获取到的音频设备列表;否则为错误对象。 |
4116
4117**示例:**
4118
4119```ts
4120import { BusinessError } from '@kit.BasicServicesKit';
4121
4122audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err: BusinessError, value: audio.AudioDeviceDescriptors) => {
4123  if (err) {
4124    console.error(`Failed to obtain the device list. ${err}`);
4125    return;
4126  }
4127  console.info('Callback invoked to indicate that the device list is obtained.');
4128});
4129```
4130
4131### getDevices<sup>9+</sup>
4132
4133getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
4134
4135获取音频设备列表,使用Promise方式异步返回结果。
4136
4137**系统能力:** SystemCapability.Multimedia.Audio.Device
4138
4139**参数:**
4140
4141| 参数名     | 类型                      | 必填 | 说明             |
4142| ---------- | ------------------------- | ---- | ---------------- |
4143| deviceFlag | [DeviceFlag](#deviceflag) | 是   | 设备类型的flag。 |
4144
4145**返回值:**
4146
4147| 类型                                                         | 说明                      |
4148| ------------------------------------------------------------ | ------------------------- |
4149| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise对象,返回设备列表。 |
4150
4151**示例:**
4152
4153```ts
4154audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data: audio.AudioDeviceDescriptors) => {
4155  console.info('Promise returned to indicate that the device list is obtained.');
4156});
4157```
4158
4159### getDevicesSync<sup>10+</sup>
4160
4161getDevicesSync(deviceFlag: DeviceFlag): AudioDeviceDescriptors
4162
4163获取音频设备列表,同步返回结果。
4164
4165**系统能力:** SystemCapability.Multimedia.Audio.Device
4166
4167**参数:**
4168
4169| 参数名     | 类型                      | 必填 | 说明             |
4170| ---------- | ------------------------- | ---- | ---------------- |
4171| deviceFlag | [DeviceFlag](#deviceflag) | 是   | 设备类型的flag。 |
4172
4173**返回值:**
4174
4175| 类型                                                         | 说明                      |
4176| ------------------------------------------------------------ | ------------------------- |
4177| [AudioDeviceDescriptors](#audiodevicedescriptors) | 返回设备列表。 |
4178
4179**错误码:**
4180
4181以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4182
4183| 错误码ID | 错误信息 |
4184| ------- | --------------------------------------------|
4185| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4186| 6800101 | Parameter verification failed. |
4187
4188**示例:**
4189
4190```ts
4191import { BusinessError } from '@kit.BasicServicesKit';
4192
4193try {
4194  let data: audio.AudioDeviceDescriptors = audioRoutingManager.getDevicesSync(audio.DeviceFlag.OUTPUT_DEVICES_FLAG);
4195  console.info(`Indicate that the device list is obtained ${data}`);
4196} catch (err) {
4197  let error = err as BusinessError;
4198  console.error(`Failed to obtain the device list. ${error}`);
4199}
4200```
4201
4202### on('deviceChange')<sup>9+</sup>
4203
4204on(type: 'deviceChange', deviceFlag: DeviceFlag, callback: Callback<DeviceChangeAction\>): void
4205
4206监听音频设备连接变化事件(当音频设备连接状态发生变化时触发),使用callback方式返回结果。
4207
4208**系统能力:** SystemCapability.Multimedia.Audio.Device
4209
4210**参数:**
4211
4212| 参数名   | 类型                                                 | 必填 | 说明                      |
4213| :------- | :--------------------------------------------------- | :--- |:------------------------|
4214| type     | string                                               | 是   | 监听事件,固定为:'deviceChange'。 |
4215| deviceFlag | [DeviceFlag](#deviceflag)                                    | 是   | 设备类型的flag。              |
4216| callback | Callback<[DeviceChangeAction](#devicechangeaction)\> | 是   | 回调函数,返回设备更新详情。          |
4217
4218**错误码:**
4219
4220以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4221
4222| 错误码ID | 错误信息 |
4223| ------- | --------------------------------------------|
4224| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4225| 6800101 | Parameter verification failed. |
4226
4227**示例:**
4228
4229```ts
4230audioRoutingManager.on('deviceChange', audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (deviceChanged: audio.DeviceChangeAction) => {
4231  console.info('device change type : ' + deviceChanged.type);
4232  console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
4233  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole);
4234  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType);
4235});
4236```
4237
4238### off('deviceChange')<sup>9+</sup>
4239
4240off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void
4241
4242取消监听音频设备连接变化事件,使用callback方式返回结果。
4243
4244**系统能力:** SystemCapability.Multimedia.Audio.Device
4245
4246**参数:**
4247
4248| 参数名   | 类型                                                | 必填 | 说明                                       |
4249| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
4250| type     | string                                              | 是   | 监听事件,固定为:'deviceChange'。 |
4251| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | 否   | 回调函数,返回设备更新详情。 |
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
4265// 取消该事件的所有监听
4266audioRoutingManager.off('deviceChange');
4267
4268// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
4269let deviceChangeCallback = (deviceChanged: audio.DeviceChangeAction) => {
4270  console.info('device change type : ' + deviceChanged.type);
4271  console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
4272  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole);
4273  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType);
4274};
4275
4276audioRoutingManager.on('deviceChange', audio.DeviceFlag.OUTPUT_DEVICES_FLAG, deviceChangeCallback);
4277
4278audioRoutingManager.off('deviceChange', deviceChangeCallback);
4279```
4280
4281### setCommunicationDevice<sup>9+</sup>
4282
4283setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
4284
4285设置通信设备激活状态,使用callback方式异步返回结果。
4286
4287该接口由于功能设计变化,将在后续版本废弃,不建议开发者使用。
4288
4289推荐开发者使用AVSession提供的[设备切换组件](../../media/avsession/using-switch-call-devices.md),实现通话设备切换。
4290
4291**系统能力:** SystemCapability.Multimedia.Audio.Communication
4292
4293**参数:**
4294
4295| 参数名     | 类型                                  | 必填 | 说明                      |
4296| ---------- | ------------------------------------- | ---- |-------------------------|
4297| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | 是   | 音频设备类型。                 |
4298| active     | boolean                               | 是   | 设备激活状态,true激活,false未激活。 |
4299| callback   | AsyncCallback&lt;void&gt;             | 是   | 回调函数。当设置通信设备激活状态成功,err为undefined,否则为错误对象。 |
4300
4301**示例:**
4302
4303```ts
4304import { BusinessError } from '@kit.BasicServicesKit';
4305
4306audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true, (err: BusinessError) => {
4307  if (err) {
4308    console.error(`Failed to set the active status of the device. ${err}`);
4309    return;
4310  }
4311  console.info('Callback invoked to indicate that the device is set to the active status.');
4312});
4313```
4314
4315### getAvailableDevices<sup>12+</sup>
4316
4317getAvailableDevices(deviceUsage: DeviceUsage): AudioDeviceDescriptors
4318
4319获取音频可选设备列表,同步返回结果。
4320
4321**系统能力:** SystemCapability.Multimedia.Audio.Device
4322
4323**参数:**
4324
4325| 参数名     | 类型                      | 必填 | 说明             |
4326| ---------- | ------------------------- | ---- | ---------------- |
4327| deviceUsage| [DeviceUsage](#deviceusage12) | 是   | 设备的usage。 |
4328
4329**返回值:**
4330
4331| 类型                                                         | 说明                      |
4332| ------------------------------------------------------------ | ------------------------- |
4333| [AudioDeviceDescriptors](js-apis-audio.md#audiodevicedescriptors) | 返回设备列表。 |
4334
4335**错误码:**
4336
4337以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4338
4339| 错误码ID | 错误信息 |
4340| ------- | --------------------------------------------|
4341| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4342| 6800101 | Parameter verification failed. |
4343
4344**示例:**
4345
4346```ts
4347import { BusinessError } from '@kit.BasicServicesKit';
4348
4349try {
4350  let data: audio.AudioDeviceDescriptors = audioRoutingManager.getAvailableDevices(audio.DeviceUsage.MEDIA_OUTPUT_DEVICES);
4351  console.info(`Indicate that the device list is obtained ${data}`);
4352} catch (err) {
4353  let error = err as BusinessError;
4354  console.error(`Failed to obtain the device list. ${error}`);
4355}
4356```
4357
4358### on('availableDeviceChange')<sup>12+</sup>
4359
4360on(type: 'availableDeviceChange', deviceUsage: DeviceUsage, callback: Callback<DeviceChangeAction\>): void
4361
4362监听音频可选设备连接变化事件(当音频可选设备连接状态发生变化时触发),使用callback方式返回结果。
4363
4364**系统能力:** SystemCapability.Multimedia.Audio.Device
4365
4366**参数:**
4367
4368| 参数名   | 类型                                                 | 必填 | 说明                                       |
4369| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
4370| type     | string                                               | 是   | 监听事件,固定为:'availableDeviceChange'。 |
4371| deviceUsage | [DeviceUsage](#deviceusage12)                       | 是   | 设备的usage。     |
4372| callback | Callback<[DeviceChangeAction](js-apis-audio.md#devicechangeaction)\> | 是   | 回调函数,返回设备更新详情。 |
4373
4374**错误码:**
4375
4376以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4377
4378| 错误码ID | 错误信息 |
4379| ------- | --------------------------------------------|
4380| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4381| 6800101 | Parameter verification failed. |
4382
4383**示例:**
4384
4385```ts
4386audioRoutingManager.on('availableDeviceChange', audio.DeviceUsage.MEDIA_OUTPUT_DEVICES, (deviceChanged: audio.DeviceChangeAction) => {
4387  console.info('device change type : ' + deviceChanged.type);
4388  console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
4389  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole);
4390  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType);
4391});
4392```
4393
4394### off('availableDeviceChange')<sup>12+</sup>
4395
4396off(type: 'availableDeviceChange', callback?: Callback<DeviceChangeAction\>): void
4397
4398取消监听音频可选设备连接变化事件,使用callback方式返回结果。
4399
4400**系统能力:** SystemCapability.Multimedia.Audio.Device
4401
4402**参数:**
4403
4404| 参数名   | 类型                                                | 必填 | 说明                                       |
4405| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
4406| type     | string                                              | 是   | 监听事件,固定为:'availableDeviceChange'。 |
4407| callback | Callback<[DeviceChangeAction](js-apis-audio.md#devicechangeaction)> | 否   | 回调函数,返回可选设备更新详情。 |
4408
4409**错误码:**
4410
4411以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4412
4413| 错误码ID | 错误信息 |
4414| ------- | --------------------------------------------|
4415| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4416| 6800101 | Parameter verification failed. |
4417
4418**示例:**
4419
4420```ts
4421// 取消该事件的所有监听
4422audioRoutingManager.off('availableDeviceChange');
4423
4424// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
4425let availableDeviceChangeCallback = (deviceChanged: audio.DeviceChangeAction) => {
4426  console.info('device change type : ' + deviceChanged.type);
4427  console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
4428  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole);
4429  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType);
4430};
4431
4432audioRoutingManager.on('availableDeviceChange', audio.DeviceUsage.MEDIA_OUTPUT_DEVICES, availableDeviceChangeCallback);
4433
4434audioRoutingManager.off('availableDeviceChange', availableDeviceChangeCallback);
4435```
4436
4437### setCommunicationDevice<sup>9+</sup>
4438
4439setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean): Promise&lt;void&gt;
4440
4441设置通信设备激活状态,使用Promise方式异步返回结果。
4442
4443该接口由于功能设计变化,将在后续版本废弃,不建议开发者使用。
4444
4445推荐开发者使用AVSession提供的[设备切换组件](../../media/avsession/using-switch-call-devices.md),实现通话设备切换。
4446
4447**系统能力:** SystemCapability.Multimedia.Audio.Communication
4448
4449**参数:**
4450
4451| 参数名     | 类型                                                   | 必填 | 说明               |
4452| ---------- | ----------------------------------------------------- | ---- | ------------------ |
4453| deviceType | [CommunicationDeviceType](#communicationdevicetype9)  | 是   | 活跃音频设备类型。 |
4454| active     | boolean                                               | 是   | 设备激活状态,true激活,false未激活。     |
4455
4456**返回值:**
4457
4458| 类型                | 说明                            |
4459| ------------------- | ------------------------------- |
4460| Promise&lt;void&gt; | Promise对象,无返回结果。 |
4461
4462**示例:**
4463
4464```ts
4465audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true).then(() => {
4466  console.info('Promise returned to indicate that the device is set to the active status.');
4467});
4468```
4469
4470### isCommunicationDeviceActive<sup>9+</sup>
4471
4472isCommunicationDeviceActive(deviceType: CommunicationDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
4473
4474获取指定通信设备的激活状态,使用callback方式异步返回结果。
4475
4476**系统能力:** SystemCapability.Multimedia.Audio.Communication
4477
4478**参数:**
4479
4480| 参数名     | 类型                                                  | 必填 | 说明                     |
4481| ---------- | ---------------------------------------------------- | ---- | ------------------------ |
4482| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | 是   | 活跃音频设备类型。       |
4483| callback   | AsyncCallback&lt;boolean&gt;                         | 是   | 回调函数。当获取指定通信设备的激活状态成功,err为undefined,data为true为激活,false为未激活;否则为错误对象。 |
4484
4485**示例:**
4486
4487```ts
4488import { BusinessError } from '@kit.BasicServicesKit';
4489
4490audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER, (err: BusinessError, value: boolean) => {
4491  if (err) {
4492    console.error(`Failed to obtain the active status of the device. ${err}`);
4493    return;
4494  }
4495  console.info('Callback invoked to indicate that the active status of the device is obtained.');
4496});
4497```
4498
4499### isCommunicationDeviceActive<sup>9+</sup>
4500
4501isCommunicationDeviceActive(deviceType: CommunicationDeviceType): Promise&lt;boolean&gt;
4502
4503获取指定通信设备的激活状态,使用Promise方式异步返回结果。
4504
4505**系统能力:** SystemCapability.Multimedia.Audio.Communication
4506
4507**参数:**
4508
4509| 参数名     | 类型                                                  | 必填 | 说明               |
4510| ---------- | ---------------------------------------------------- | ---- | ------------------ |
4511| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | 是   | 活跃音频设备类型。 |
4512
4513**返回值:**
4514
4515| Type                   | Description                     |
4516| ---------------------- | ------------------------------- |
4517| Promise&lt;boolean&gt; | Promise对象,返回设备的激活状态,true激活,false未激活。 |
4518
4519**示例:**
4520
4521```ts
4522audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER).then((value: boolean) => {
4523  console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
4524});
4525```
4526
4527### isCommunicationDeviceActiveSync<sup>10+</sup>
4528
4529isCommunicationDeviceActiveSync(deviceType: CommunicationDeviceType): boolean
4530
4531获取指定通信设备的激活状态,同步返回结果。
4532
4533**系统能力:** SystemCapability.Multimedia.Audio.Communication
4534
4535**参数:**
4536
4537| 参数名     | 类型                                                  | 必填 | 说明               |
4538| ---------- | ---------------------------------------------------- | ---- | ------------------ |
4539| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | 是   | 活跃音频设备类型。 |
4540
4541**返回值:**
4542
4543| Type                   | Description                     |
4544| ---------------------- | ------------------------------- |
4545| boolean | 返回设备的激活状态,true激活,false未激活。 |
4546
4547**错误码:**
4548
4549以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4550
4551| 错误码ID | 错误信息 |
4552| ------- | --------------------------------------------|
4553| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4554| 6800101 | Parameter verification failed. |
4555
4556**示例:**
4557
4558```ts
4559import { BusinessError } from '@kit.BasicServicesKit';
4560
4561try {
4562  let value: boolean = audioRoutingManager.isCommunicationDeviceActiveSync(audio.CommunicationDeviceType.SPEAKER);
4563  console.info(`Indicate that the active status of the device is obtained ${value}.`);
4564} catch (err) {
4565  let error = err as BusinessError;
4566  console.error(`Failed to obtain the active status of the device ${error}.`);
4567}
4568```
4569
4570### getPreferOutputDeviceForRendererInfo<sup>10+</sup>
4571
4572getPreferOutputDeviceForRendererInfo(rendererInfo: AudioRendererInfo, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
4573
4574根据音频信息,返回优先级最高的输出设备,使用callback方式异步返回结果。
4575
4576**系统能力:** SystemCapability.Multimedia.Audio.Device
4577
4578**参数:**
4579
4580| 参数名                       | 类型                                                         | 必填 | 说明                      |
4581| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
4582| rendererInfo                | [AudioRendererInfo](#audiorendererinfo8)                     | 是   | 表示渲染器信息。             |
4583| callback                    | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt;  | 是   | 回调函数。当获取优先级最高的输出设备成功,err为undefined,data为获取到的优先级最高的输出设备信息;否则为错误对象。 |
4584
4585**错误码:**
4586
4587以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4588
4589| 错误码ID | 错误信息                                           |
4590| ------- |--------------------------------------------------|
4591| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4592| 6800101 | Parameter verification failed. Return by callback. |
4593| 6800301 | System error. Return by callback.                |
4594
4595**示例:**
4596```ts
4597import { audio } from '@kit.AudioKit';
4598import { BusinessError } from '@kit.BasicServicesKit';
4599
4600let rendererInfo: audio.AudioRendererInfo = {
4601  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
4602  rendererFlags : 0
4603};
4604
4605async function getPreferOutputDevice() {
4606  audioRoutingManager.getPreferOutputDeviceForRendererInfo(rendererInfo, (err: BusinessError, desc: audio.AudioDeviceDescriptors) => {
4607    if (err) {
4608      console.error(`Result ERROR: ${err}`);
4609    } else {
4610      console.info(`device descriptor: ${desc}`);
4611    }
4612  });
4613}
4614```
4615
4616### getPreferOutputDeviceForRendererInfo<sup>10+</sup>
4617getPreferOutputDeviceForRendererInfo(rendererInfo: AudioRendererInfo): Promise&lt;AudioDeviceDescriptors&gt;
4618
4619根据音频信息,返回优先级最高的输出设备,使用Promise方式异步返回结果。
4620
4621**系统能力:** SystemCapability.Multimedia.Audio.Device
4622
4623**参数:**
4624
4625| 参数名                 | 类型                                                         | 必填 | 说明                      |
4626| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
4627| rendererInfo          | [AudioRendererInfo](#audiorendererinfo8)                     | 是   | 表示渲染器信息。            |
4628
4629**返回值:**
4630
4631| 类型                  | 说明                         |
4632| --------------------- | --------------------------- |
4633| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt;   | Promise对象,返回优先级最高的输出设备信息。 |
4634
4635**错误码:**
4636
4637以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4638
4639| 错误码ID | 错误信息                                          |
4640| ------- |-------------------------------------------------|
4641| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4642| 6800101 | Parameter verification failed. Return by promise. |
4643| 6800301 | System error. Return by promise.                |
4644
4645**示例:**
4646
4647```ts
4648import { audio } from '@kit.AudioKit';
4649import { BusinessError } from '@kit.BasicServicesKit';
4650
4651let rendererInfo: audio.AudioRendererInfo = {
4652  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
4653  rendererFlags : 0
4654};
4655
4656async function getPreferOutputDevice() {
4657  audioRoutingManager.getPreferOutputDeviceForRendererInfo(rendererInfo).then((desc: audio.AudioDeviceDescriptors) => {
4658    console.info(`device descriptor: ${desc}`);
4659  }).catch((err: BusinessError) => {
4660    console.error(`Result ERROR: ${err}`);
4661  })
4662}
4663```
4664
4665### getPreferredOutputDeviceForRendererInfoSync<sup>10+</sup>
4666getPreferredOutputDeviceForRendererInfoSync(rendererInfo: AudioRendererInfo): AudioDeviceDescriptors
4667
4668根据音频信息,返回优先级最高的输出设备,同步返回结果。
4669
4670**系统能力:** SystemCapability.Multimedia.Audio.Device
4671
4672**参数:**
4673
4674| 参数名                 | 类型                                                         | 必填 | 说明                      |
4675| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
4676| rendererInfo          | [AudioRendererInfo](#audiorendererinfo8)                     | 是   | 表示渲染器信息。            |
4677
4678**返回值:**
4679
4680| 类型                  | 说明                         |
4681| --------------------- | --------------------------- |
4682| [AudioDeviceDescriptors](#audiodevicedescriptors)   | 返回优先级最高的输出设备信息。 |
4683
4684**错误码:**
4685
4686以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4687
4688| 错误码ID | 错误信息                     |
4689| ------- |--------------------------|
4690| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4691| 6800101 | Parameter verification failed. |
4692
4693**示例:**
4694
4695```ts
4696import { audio } from '@kit.AudioKit';
4697import { BusinessError } from '@kit.BasicServicesKit';
4698
4699let rendererInfo: audio.AudioRendererInfo = {
4700  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
4701  rendererFlags : 0
4702};
4703
4704try {
4705  let desc: audio.AudioDeviceDescriptors = audioRoutingManager.getPreferredOutputDeviceForRendererInfoSync(rendererInfo);
4706  console.info(`device descriptor: ${desc}`);
4707} catch (err) {
4708  let error = err as BusinessError;
4709  console.error(`Result ERROR: ${error}`);
4710}
4711```
4712
4713### on('preferOutputDeviceChangeForRendererInfo')<sup>10+</sup>
4714
4715on(type: 'preferOutputDeviceChangeForRendererInfo', rendererInfo: AudioRendererInfo, callback: Callback<AudioDeviceDescriptors\>): void
4716
4717监听最高优先级输出设备变化事件(当最高优先级输出设备发生变化时触发),使用callback方式返回结果。
4718
4719**系统能力:** SystemCapability.Multimedia.Audio.Device
4720
4721**参数:**
4722
4723| 参数名   | 类型                                                 | 必填 | 说明                                                      |
4724| :------- | :--------------------------------------------------- | :--- |:--------------------------------------------------------|
4725| type     | string                                               | 是   | 监听事件,固定为:'preferOutputDeviceChangeForRendererInfo' |
4726| rendererInfo  | [AudioRendererInfo](#audiorendererinfo8)        | 是   | 表示渲染器信息。                                                |
4727| callback | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)\> | 是   | 回调函数,返回优先级最高的输出设备信息。 |
4728
4729**错误码:**
4730
4731以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4732
4733| 错误码ID | 错误信息 |
4734| ------- | --------------------------------------------|
4735| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4736| 6800101 | Parameter verification failed. |
4737
4738**示例:**
4739
4740```ts
4741import { audio } from '@kit.AudioKit';
4742
4743let rendererInfo: audio.AudioRendererInfo = {
4744  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
4745  rendererFlags : 0
4746};
4747
4748audioRoutingManager.on('preferOutputDeviceChangeForRendererInfo', rendererInfo, (desc: audio.AudioDeviceDescriptors) => {
4749  console.info(`device descriptor: ${desc}`);
4750});
4751```
4752
4753### off('preferOutputDeviceChangeForRendererInfo')<sup>10+</sup>
4754
4755off(type: 'preferOutputDeviceChangeForRendererInfo', callback?: Callback<AudioDeviceDescriptors\>): void
4756
4757取消监听最高优先级输出音频设备变化事件,使用callback方式返回结果。
4758
4759**系统能力:** SystemCapability.Multimedia.Audio.Device
4760
4761**参数:**
4762
4763| 参数名   | 类型                                                | 必填 | 说明                                       |
4764| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
4765| type     | string                                              | 是   | 监听事件,固定为:'preferOutputDeviceChangeForRendererInfo'。 |
4766| callback | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 否   | 回调函数,返回优先级最高的输出设备信息。 |
4767
4768**错误码:**
4769
4770以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4771
4772| 错误码ID | 错误信息 |
4773| ------- | --------------------------------------------|
4774| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4775| 6800101 | Parameter verification failed. |
4776
4777**示例:**
4778
4779```ts
4780// 取消该事件的所有监听
4781audioRoutingManager.off('preferOutputDeviceChangeForRendererInfo');
4782
4783// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
4784let preferOutputDeviceChangeForRendererInfoCallback = (desc: audio.AudioDeviceDescriptors) => {
4785  console.info(`device descriptor: ${desc}`);
4786};
4787let rendererInfo: audio.AudioRendererInfo = {
4788  usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
4789  rendererFlags : 0
4790};
4791
4792audioRoutingManager.on('preferOutputDeviceChangeForRendererInfo', rendererInfo, preferOutputDeviceChangeForRendererInfoCallback);
4793
4794audioRoutingManager.off('preferOutputDeviceChangeForRendererInfo', preferOutputDeviceChangeForRendererInfoCallback);
4795```
4796
4797### getPreferredInputDeviceForCapturerInfo<sup>10+</sup>
4798
4799getPreferredInputDeviceForCapturerInfo(capturerInfo: AudioCapturerInfo, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
4800
4801根据音频信息,返回优先级最高的输入设备,使用callback方式异步返回结果。
4802
4803**系统能力:** SystemCapability.Multimedia.Audio.Device
4804
4805**参数:**
4806
4807| 参数名                       | 类型                                                         | 必填 | 说明                      |
4808| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
4809| capturerInfo                | [AudioCapturerInfo](#audiocapturerinfo8)                     | 是   | 表示采集器信息。             |
4810| callback                    | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt;  | 是   | 回调函数。当获取优先级最高的输入设备成功,err为undefined,data为获取到的优先级最高的输入设备信息;否则为错误对象。 |
4811
4812**错误码:**
4813
4814以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4815
4816| 错误码ID | 错误信息 |
4817| ------- | --------------------------------------------|
4818| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4819| 6800101 | Parameter verification failed. Return by callback.|
4820| 6800301 | System error. Return by callback. |
4821
4822**示例:**
4823```ts
4824import { audio } from '@kit.AudioKit';
4825import { BusinessError } from '@kit.BasicServicesKit';
4826
4827let capturerInfo: audio.AudioCapturerInfo = {
4828  source: audio.SourceType.SOURCE_TYPE_MIC,
4829  capturerFlags: 0
4830};
4831
4832audioRoutingManager.getPreferredInputDeviceForCapturerInfo(capturerInfo, (err: BusinessError, desc: audio.AudioDeviceDescriptors) => {
4833  if (err) {
4834    console.error(`Result ERROR: ${err}`);
4835  } else {
4836    console.info(`device descriptor: ${desc}`);
4837  }
4838});
4839```
4840
4841### getPreferredInputDeviceForCapturerInfo<sup>10+</sup>
4842
4843getPreferredInputDeviceForCapturerInfo(capturerInfo: AudioCapturerInfo): Promise&lt;AudioDeviceDescriptors&gt;
4844
4845根据音频信息,返回优先级最高的输入设备,使用Promise方式异步返回结果。
4846
4847**系统能力:** SystemCapability.Multimedia.Audio.Device
4848
4849**参数:**
4850
4851| 参数名                 | 类型                                                         | 必填 | 说明                      |
4852| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
4853| capturerInfo          | [AudioCapturerInfo](#audiocapturerinfo8)                     | 是   | 表示采集器信息。            |
4854
4855**返回值:**
4856
4857| 类型                  | 说明                         |
4858| --------------------- | --------------------------- |
4859| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt;   | Promise对象,返回优先级最高的输入设备信息。 |
4860
4861**错误码:**
4862
4863以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4864
4865| 错误码ID | 错误信息 |
4866| ------- | --------------------------------------------|
4867| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4868| 6800101 | Parameter verification failed. Return by promise. |
4869| 6800301 | System error. Return by promise. |
4870
4871**示例:**
4872
4873```ts
4874import { audio } from '@kit.AudioKit';
4875import { BusinessError } from '@kit.BasicServicesKit';
4876
4877let capturerInfo: audio.AudioCapturerInfo = {
4878  source: audio.SourceType.SOURCE_TYPE_MIC,
4879  capturerFlags: 0
4880};
4881
4882audioRoutingManager.getPreferredInputDeviceForCapturerInfo(capturerInfo).then((desc: audio.AudioDeviceDescriptors) => {
4883  console.info(`device descriptor: ${desc}`);
4884}).catch((err: BusinessError) => {
4885  console.error(`Result ERROR: ${err}`);
4886});
4887```
4888
4889### getPreferredInputDeviceForCapturerInfoSync<sup>10+</sup>
4890
4891getPreferredInputDeviceForCapturerInfoSync(capturerInfo: AudioCapturerInfo): AudioDeviceDescriptors
4892
4893根据音频信息,返回优先级最高的输入设备,同步返回结果。
4894
4895**系统能力:** SystemCapability.Multimedia.Audio.Device
4896
4897**参数:**
4898
4899| 参数名                 | 类型                                                         | 必填 | 说明                      |
4900| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
4901| capturerInfo          | [AudioCapturerInfo](#audiocapturerinfo8)                     | 是   | 表示采集器信息。            |
4902
4903**返回值:**
4904
4905| 类型                  | 说明                         |
4906| --------------------- | --------------------------- |
4907| [AudioDeviceDescriptors](#audiodevicedescriptors)   | 返回优先级最高的输入设备信息。 |
4908
4909**错误码:**
4910
4911以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4912
4913| 错误码ID | 错误信息 |
4914| ------- | --------------------------------------------|
4915| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4916| 6800101 | Parameter verification failed. |
4917
4918**示例:**
4919
4920```ts
4921import { audio } from '@kit.AudioKit';
4922import { BusinessError } from '@kit.BasicServicesKit';
4923
4924let capturerInfo: audio.AudioCapturerInfo = {
4925  source: audio.SourceType.SOURCE_TYPE_MIC,
4926  capturerFlags: 0
4927};
4928
4929try {
4930  let desc: audio.AudioDeviceDescriptors = audioRoutingManager.getPreferredInputDeviceForCapturerInfoSync(capturerInfo);
4931  console.info(`device descriptor: ${desc}`);
4932} catch (err) {
4933  let error = err as BusinessError;
4934  console.error(`Result ERROR: ${error}`);
4935}
4936```
4937
4938### on('preferredInputDeviceChangeForCapturerInfo')<sup>10+</sup>
4939
4940on(type: 'preferredInputDeviceChangeForCapturerInfo', capturerInfo: AudioCapturerInfo, callback: Callback<AudioDeviceDescriptors\>): void
4941
4942监听最高优先级输入设备变化事件(当最高优先级输入设备发生变化时触发),使用callback方式返回结果。
4943
4944**系统能力:** SystemCapability.Multimedia.Audio.Device
4945
4946**参数:**
4947
4948| 参数名   | 类型                                                 | 必填 | 说明                                       |
4949| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
4950| type     | string                                               | 是   | 监听事件,固定为:'preferredInputDeviceChangeForCapturerInfo' |
4951| capturerInfo  | [AudioCapturerInfo](#audiocapturerinfo8)        | 是   | 表示采集器信息。              |
4952| callback | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)\> | 是   | 回调函数,返回优先级最高的输入设备信息。 |
4953
4954**错误码:**
4955
4956以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4957
4958| 错误码ID | 错误信息 |
4959| ------- | --------------------------------------------|
4960| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4961| 6800101 | Parameter verification failed. |
4962
4963**示例:**
4964
4965```ts
4966import { audio } from '@kit.AudioKit';
4967
4968let capturerInfo: audio.AudioCapturerInfo = {
4969  source: audio.SourceType.SOURCE_TYPE_MIC,
4970  capturerFlags: 0
4971};
4972
4973audioRoutingManager.on('preferredInputDeviceChangeForCapturerInfo', capturerInfo, (desc: audio.AudioDeviceDescriptors) => {
4974  console.info(`device descriptor: ${desc}`);
4975});
4976```
4977
4978### off('preferredInputDeviceChangeForCapturerInfo')<sup>10+</sup>
4979
4980off(type: 'preferredInputDeviceChangeForCapturerInfo', callback?: Callback<AudioDeviceDescriptors\>): void
4981
4982取消监听最高优先级输入音频设备变化事件,使用callback方式返回结果。
4983
4984**系统能力:** SystemCapability.Multimedia.Audio.Device
4985
4986**参数:**
4987
4988| 参数名   | 类型                                                | 必填 | 说明                                       |
4989| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
4990| type     | string                                              | 是   | 监听事件,固定为:'preferredInputDeviceChangeForCapturerInfo' |
4991| callback | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 否   | 回调函数,返回优先级最高的输入设备信息。 |
4992
4993**错误码:**
4994
4995以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4996
4997| 错误码ID | 错误信息 |
4998| ------- | --------------------------------------------|
4999| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
5000| 6800101 | Parameter verification failed. |
5001
5002**示例:**
5003
5004```ts
5005// 取消该事件的所有监听
5006audioRoutingManager.off('preferredInputDeviceChangeForCapturerInfo');
5007
5008// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
5009let preferredInputDeviceChangeForCapturerInfoCallback = (desc: audio.AudioDeviceDescriptors) => {
5010  console.info(`device descriptor: ${desc}`);
5011};
5012let capturerInfo: audio.AudioCapturerInfo = {
5013  source: audio.SourceType.SOURCE_TYPE_MIC,
5014  capturerFlags: 0
5015};
5016
5017audioRoutingManager.on('preferredInputDeviceChangeForCapturerInfo', capturerInfo, preferredInputDeviceChangeForCapturerInfoCallback);
5018
5019audioRoutingManager.off('preferredInputDeviceChangeForCapturerInfo', preferredInputDeviceChangeForCapturerInfoCallback);
5020```
5021
5022## AudioSessionManager<sup>12+</sup>
5023
5024音频会话管理。在使用AudioSessionManager的接口前,需要使用[getSessionManager](#getsessionmanager12)获取AudioSessionManager实例。
5025
5026### activateAudioSession<sup>12+</sup>
5027
5028activateAudioSession(strategy: AudioSessionStrategy): Promise\<void>
5029
5030激活音频会话。使用Promise方式异步返回结果。
5031
5032**系统能力:** SystemCapability.Multimedia.Audio.Core
5033
5034**参数:**
5035
5036| 参数名 | 类型                                              | 必填 | 说明         |
5037| ------ |-------------------------------------------------| ---- | ------------ |
5038| strategy | [AudioSessionStrategy](#audiosessionstrategy12) | 是   | 音频会话策略。 |
5039
5040**返回值:**
5041
5042| 类型           | 说明                      |
5043| -------------- | ------------------------- |
5044| Promise\<void> | Promise对象,无返回结果。 |
5045
5046**错误码:**
5047
5048以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
5049
5050| 错误码ID | 错误信息 |
5051| ------- | ---------------------------------------------|
5052| 401 | Parameter error. Possible causes: 1.Mandatory parameters unspecified. 2.Incorrect parameter types. |
5053| 6800101 | Parameter verification failed.|
5054| 6800301 | System error. Returned by promise. |
5055
5056**示例:**
5057
5058```ts
5059import { BusinessError } from '@kit.BasicServicesKit';
5060
5061let strategy: audio.AudioSessionStrategy = {
5062  concurrencyMode: audio.AudioConcurrencyMode.CONCURRENCY_MIX_WITH_OTHERS
5063};
5064
5065audioSessionManager.activateAudioSession(strategy).then(() => {
5066  console.info('activateAudioSession SUCCESS');
5067}).catch((err: BusinessError) => {
5068  console.error(`ERROR: ${err}`);
5069});
5070```
5071
5072### deactivateAudioSession<sup>12+</sup>
5073
5074deactivateAudioSession(): Promise\<void>
5075
5076停用音频会话。使用Promise方式异步返回结果。
5077
5078**系统能力:** SystemCapability.Multimedia.Audio.Core
5079
5080**返回值:**
5081
5082| 类型           | 说明                      |
5083| -------------- | ------------------------- |
5084| Promise\<void> | Promise对象,无返回结果。 |
5085
5086**错误码:**
5087
5088以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
5089
5090| 错误码ID | 错误信息 |
5091| ------- | ---------------------------------------------|
5092| 6800301 | System error. Returned by promise. |
5093
5094**示例:**
5095
5096```ts
5097import { BusinessError } from '@kit.BasicServicesKit';
5098
5099audioSessionManager.deactivateAudioSession().then(() => {
5100  console.info('deactivateAudioSession SUCCESS');
5101}).catch((err: BusinessError) => {
5102  console.error(`ERROR: ${err}`);
5103});
5104```
5105
5106### isAudioSessionActivated<sup>12+</sup>
5107
5108isAudioSessionActivated(): boolean
5109
5110检查音频会话是否已激活。
5111
5112**系统能力:** SystemCapability.Multimedia.Audio.Core
5113
5114**返回值:**
5115
5116| 类型                                              | 说明                                    |
5117| ------------------------------------------------- |---------------------------------------|
5118| boolean | 返回当前pid应用程序的音频会话是否已激活,true表示已激活,false表示已停用。 |
5119
5120**示例:**
5121
5122```ts
5123let isActivated = audioSessionManager.isAudioSessionActivated();
5124```
5125
5126### on('audioSessionDeactivated')<sup>12+</sup>
5127
5128on(type: 'audioSessionDeactivated', callback: Callback\<AudioSessionDeactivatedEvent>): void
5129
5130监听音频会话停用事件(当音频会话停用时触发),使用callback方式返回结果。
5131
5132**系统能力:** SystemCapability.Multimedia.Audio.Core
5133
5134**参数:**
5135
5136| 参数名   | 类型                                                                        | 必填 | 说明                                                         |
5137| -------- |---------------------------------------------------------------------------| ---- | ------------------------------------------------------------ |
5138| type     | string                                                                    | 是   | 监听事件,固定为:'audioSessionDeactivated'。 |
5139| callback | Callback<[AudioSessionDeactivatedEvent](#audiosessiondeactivatedevent12)> | 是   | 回调函数,返回音频会话停用原因。 |
5140
5141**错误码:**
5142
5143以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
5144
5145| 错误码ID | 错误信息 |
5146| ------- | --------------------------------------------|
5147| 401 | Parameter error. Possible causes: 1.Mandatory parameters unspecified. 2.Incorrect parameter types. |
5148| 6800101 | Parameter verification failed. |
5149
5150**示例:**
5151
5152```ts
5153audioSessionManager.on('audioSessionDeactivated', (audioSessionDeactivatedEvent: audio.AudioSessionDeactivatedEvent) => {
5154  console.info(`reason of audioSessionDeactivated: ${audioSessionDeactivatedEvent.reason} `);
5155});
5156```
5157
5158### off('audioSessionDeactivated')<sup>12+</sup>
5159
5160off(type: 'audioSessionDeactivated', callback?: Callback\<AudioSessionDeactivatedEvent>): void
5161
5162取消监听音频会话停用事件,使用callback方式返回结果。
5163
5164**系统能力:** SystemCapability.Multimedia.Audio.Core
5165
5166**参数:**
5167
5168| 参数名   | 类型                                   | 必填 | 说明                                                         |
5169| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
5170| type     | string                                 | 是   | 监听事件,固定为:'audioSessionDeactivated'。 |
5171| callback |Callback<[AudioSessionDeactivatedEvent](#audiosessiondeactivatedevent12)> | 否   | 回调函数,返回音频会话停用原因。 |
5172
5173**错误码:**
5174
5175以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
5176
5177| 错误码ID | 错误信息 |
5178| ------- | --------------------------------------------|
5179| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
5180| 6800101 | Parameter verification failed. |
5181
5182**示例:**
5183
5184```ts
5185// 取消该事件的所有监听
5186audioSessionManager.off('audioSessionDeactivated');
5187
5188// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
5189let audioSessionDeactivatedCallback = (audioSessionDeactivatedEvent: audio.AudioSessionDeactivatedEvent) => {
5190  console.info(`reason of audioSessionDeactivated: ${audioSessionDeactivatedEvent.reason} `);
5191};
5192
5193audioSessionManager.on('audioSessionDeactivated', audioSessionDeactivatedCallback);
5194
5195audioSessionManager.off('audioSessionDeactivated', audioSessionDeactivatedCallback);
5196```
5197
5198## AudioRendererChangeInfoArray<sup>9+</sup>
5199
5200数组类型,AudioRenderChangeInfo数组,只读。
5201
5202**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5203
5204## AudioRendererChangeInfo<sup>9+</sup>
5205
5206描述音频渲染器更改信息。
5207
5208**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5209
5210| 名称               | 类型                                       | 可读 | 可写 | 说明                          |
5211| -------------------| ----------------------------------------- | ---- | ---- | ---------------------------- |
5212| streamId           | number                                    | 是   | 否   | 音频流唯一id。                |
5213| rendererInfo       | [AudioRendererInfo](#audiorendererinfo8)  | 是   | 否   | 音频渲染器信息。               |
5214| deviceDescriptors  | [AudioDeviceDescriptors](#audiodevicedescriptors)      | 是   | 否   | 音频设备描述。|
5215
5216**示例:**
5217
5218```ts
5219import { audio } from '@kit.AudioKit';
5220
5221const audioManager = audio.getAudioManager();
5222let audioStreamManager = audioManager.getStreamManager();
5223
5224audioStreamManager.on('audioRendererChange',  (AudioRendererChangeInfoArray) => {
5225  for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
5226    console.info(`## RendererChange on is called for ${i} ##`);
5227    console.info(`StreamId for ${i} is: ${AudioRendererChangeInfoArray[i].streamId}`);
5228    console.info(`Content for ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.content}`);
5229    console.info(`Stream for ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.usage}`);
5230    console.info(`Flag ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.rendererFlags}`);
5231    let devDescriptor = AudioRendererChangeInfoArray[i].deviceDescriptors;
5232    for (let j = 0; j < AudioRendererChangeInfoArray[i].deviceDescriptors.length; j++) {
5233      console.info(`Id: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].id}`);
5234      console.info(`Type: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
5235      console.info(`Role: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
5236      console.info(`Name: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].name}`);
5237      console.info(`Addr: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].address}`);
5238      console.info(`SR: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
5239      console.info(`C ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
5240      console.info(`CM: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
5241    }
5242  }
5243});
5244```
5245
5246
5247## AudioCapturerChangeInfoArray<sup>9+</sup>
5248
5249数组类型,AudioCapturerChangeInfo数组,只读。
5250
5251**系统能力:** SystemCapability.Multimedia.Audio.Capturer
5252
5253## AudioCapturerChangeInfo<sup>9+</sup>
5254
5255描述音频采集器更改信息。
5256
5257**系统能力:** SystemCapability.Multimedia.Audio.Capturer
5258
5259| 名称               | 类型                                       | 可读 | 可写 | 说明                          |
5260| -------------------| ----------------------------------------- | ---- | ---- | ---------------------------- |
5261| streamId           | number                                    | 是   | 否   | 音频流唯一id。                |
5262| capturerInfo       | [AudioCapturerInfo](#audiocapturerinfo8)  | 是   | 否   | 音频采集器信息。               |
5263| deviceDescriptors  | [AudioDeviceDescriptors](#audiodevicedescriptors)      | 是   | 否   | 音频设备描述。|
5264| muted<sup>11+</sup>  | boolean    | 是   | 否   | 音频采集器静音状态。true表示音频采集器为静音状态,false表示音频采集器为非静音状态。|
5265
5266**示例:**
5267
5268```ts
5269import { audio } from '@kit.AudioKit';
5270
5271const audioManager = audio.getAudioManager();
5272let audioStreamManager = audioManager.getStreamManager();
5273
5274audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) =>  {
5275  for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
5276    console.info(`## CapChange on is called for element ${i} ##`);
5277    console.info(`StrId for  ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
5278    console.info(`Src for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
5279    console.info(`Flag ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
5280    let devDescriptor = AudioCapturerChangeInfoArray[i].deviceDescriptors;
5281    for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
5282      console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
5283      console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
5284      console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
5285      console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
5286      console.info(`Addr: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
5287      console.info(`SR: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
5288      console.info(`C ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
5289      console.info(`CM ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
5290    }
5291  }
5292});
5293```
5294
5295## AudioEffectInfoArray<sup>10+</sup>
5296
5297待查询ContentType和StreamUsage组合场景下的音效模式数组类型,[AudioEffectMode](#audioeffectmode10)数组,只读。
5298
5299## AudioDeviceDescriptors
5300
5301设备属性数组类型,为[AudioDeviceDescriptor](#audiodevicedescriptor)的数组,只读。
5302
5303**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5304
5305## AudioDeviceDescriptor
5306
5307描述音频设备。
5308
5309**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5310
5311| 名称                          | 类型                       | 可读 | 可写 | 说明       |
5312| ----------------------------- | -------------------------- | ---- | ---- | ---------- |
5313| deviceRole                    | [DeviceRole](#devicerole)  | 是   | 否   | 设备角色。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
5314| deviceType                    | [DeviceType](#devicetype)  | 是   | 否   | 设备类型。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
5315| id<sup>9+</sup>               | number                     | 是   | 否   | 设备id,唯一。  <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
5316| name<sup>9+</sup>             | string                     | 是   | 否   | 设备名称。<br>如果是蓝牙设备,需要申请权限ohos.permission.USE_BLUETOOTH。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
5317| address<sup>9+</sup>          | string                     | 是   | 否   | 设备地址。<br>如果是蓝牙设备,需要申请权限ohos.permission.USE_BLUETOOTH。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
5318| sampleRates<sup>9+</sup>      | Array&lt;number&gt;        | 是   | 否   | 支持的采样率。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
5319| channelCounts<sup>9+</sup>    | Array&lt;number&gt;        | 是   | 否   | 支持的通道数。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
5320| channelMasks<sup>9+</sup>     | Array&lt;number&gt;        | 是   | 否   | 支持的通道掩码。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
5321| displayName<sup>10+</sup>     | string                     | 是   | 否   | 设备显示名。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
5322| encodingTypes<sup>11+</sup>    | Array&lt;[AudioEncodingType](#audioencodingtype8)&gt;                     | 是   | 否   | 支持的编码类型。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Core|
5323
5324**示例:**
5325
5326```ts
5327import { audio } from '@kit.AudioKit';
5328
5329function displayDeviceProp(value: audio.AudioDeviceDescriptor) {
5330  deviceRoleValue = value.deviceRole;
5331  deviceTypeValue = value.deviceType;
5332}
5333
5334let deviceRoleValue: audio.DeviceRole | undefined = undefined;
5335let deviceTypeValue: audio.DeviceType | undefined = undefined;
5336audio.getAudioManager().getDevices(1).then((value: audio.AudioDeviceDescriptors) => {
5337  console.info('AudioFrameworkTest: Promise: getDevices OUTPUT_DEVICES_FLAG');
5338  value.forEach(displayDeviceProp);
5339  if (deviceTypeValue != undefined && deviceRoleValue != undefined){
5340    console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  PASS');
5341  } else {
5342    console.error('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  FAIL');
5343  }
5344});
5345```
5346## AudioDataCallbackResult<sup>12+</sup>
5347
5348枚举,表示音频数据回调的结果。
5349
5350**系统能力:** SystemCapability.Multimedia.Audio.Core
5351
5352| 名称                 | 值      | 说明         |
5353| ---------------------| --------| ----------------- |
5354| INVALID  | -1 | 表示该回调数据无效。      |
5355| VALID      | 0 | 表示该回调数据有效。     |
5356
5357## AudioRendererWriteDataCallback<sup>12+</sup>
5358
5359type AudioRendererWriteDataCallback = (data: ArrayBuffer) => AudioDataCallbackResult | void
5360
5361回调函数类型,用于音频渲染器的数据写入。
5362
5363**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5364
5365**参数:**
5366
5367| 参数名          | 类型      |必填   | 说明         |
5368| :--------------| :--------| :----- | :------------ |
5369| data           | ArrayBuffer  | 是 | 待写入缓冲区的数据。 |
5370
5371**返回值:** 
5372
5373| 类型                                                           | 说明 |
5374|--------------------------------------------------------------| ------- |
5375| [AudioDataCallbackResult](#audiodatacallbackresult12) \| void | 如果返回 void 或 AudioDataCallbackResult.VALID ,表示数据有效并将被播放;如果返回 AudioDataCallbackResult.INVALID ,表示数据无效并将不会被播放。|
5376
5377## AudioRenderer<sup>8+</sup>
5378
5379提供音频渲染的相关接口。在调用AudioRenderer的接口前,需要先通过[createAudioRenderer](#audiocreateaudiorenderer8)创建实例。
5380
5381### 属性
5382
5383**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5384
5385| 名称  | 类型                     | 可读 | 可写 | 说明               |
5386| ----- | -------------------------- | ---- | ---- | ------------------ |
5387| state<sup>8+</sup> | [AudioState](#audiostate8) | 是   | 否   | 音频渲染器的状态。 |
5388
5389**示例:**
5390
5391```ts
5392import { audio } from '@kit.AudioKit';
5393
5394let state: audio.AudioState = audioRenderer.state;
5395```
5396
5397### getRendererInfo<sup>8+</sup>
5398
5399getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void
5400
5401获取当前被创建的音频渲染器的信息,使用callback方式异步返回结果。
5402
5403**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5404
5405**参数:**
5406
5407| 参数名   | 类型                                                     | 必填 | 说明                   |
5408| :------- | :------------------------------------------------------- | :--- | :--------------------- |
5409| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | 是   | 回调函数。当获取音频渲染器的信息成功,err为undefined,data为获取到的音频渲染器的信息;否则为错误对象。 |
5410
5411**示例:**
5412
5413```ts
5414import { BusinessError } from '@kit.BasicServicesKit';
5415
5416audioRenderer.getRendererInfo((err: BusinessError, rendererInfo: audio.AudioRendererInfo) => {
5417  console.info('Renderer GetRendererInfo:');
5418  console.info(`Renderer content: ${rendererInfo.content}`);
5419  console.info(`Renderer usage: ${rendererInfo.usage}`);
5420  console.info(`Renderer flags: ${rendererInfo.rendererFlags}`);
5421});
5422```
5423
5424### getRendererInfo<sup>8+</sup>
5425
5426getRendererInfo(): Promise<AudioRendererInfo\>
5427
5428获取当前被创建的音频渲染器的信息,使用Promise方式异步返回结果。
5429
5430**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5431
5432**返回值:**
5433
5434| 类型                                               | 说明                            |
5435| -------------------------------------------------- | ------------------------------- |
5436| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise对象,返回音频渲染器信息。 |
5437
5438**示例:**
5439
5440```ts
5441import { BusinessError } from '@kit.BasicServicesKit';
5442
5443audioRenderer.getRendererInfo().then((rendererInfo: audio.AudioRendererInfo) => {
5444  console.info('Renderer GetRendererInfo:');
5445  console.info(`Renderer content: ${rendererInfo.content}`);
5446  console.info(`Renderer usage: ${rendererInfo.usage}`);
5447  console.info(`Renderer flags: ${rendererInfo.rendererFlags}`)
5448}).catch((err: BusinessError) => {
5449  console.error(`AudioFrameworkRenderLog: RendererInfo :ERROR: ${err}`);
5450});
5451```
5452
5453### getRendererInfoSync<sup>10+</sup>
5454
5455getRendererInfoSync(): AudioRendererInfo
5456
5457获取当前被创建的音频渲染器的信息,同步返回结果。
5458
5459**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5460
5461**返回值:**
5462
5463| 类型                                               | 说明                            |
5464| -------------------------------------------------- | ------------------------------- |
5465| [AudioRendererInfo](#audiorendererinfo8) | 返回音频渲染器信息。 |
5466
5467**示例:**
5468
5469```ts
5470import { BusinessError } from '@kit.BasicServicesKit';
5471
5472try {
5473  let rendererInfo: audio.AudioRendererInfo = audioRenderer.getRendererInfoSync();
5474  console.info(`Renderer content: ${rendererInfo.content}`);
5475  console.info(`Renderer usage: ${rendererInfo.usage}`);
5476  console.info(`Renderer flags: ${rendererInfo.rendererFlags}`)
5477} catch (err) {
5478  let error = err as BusinessError;
5479  console.error(`AudioFrameworkRenderLog: RendererInfo :ERROR: ${error}`);
5480}
5481```
5482
5483### getStreamInfo<sup>8+</sup>
5484
5485getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
5486
5487获取音频流信息,使用callback方式异步返回结果。
5488
5489**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5490
5491**参数:**
5492
5493| 参数名   | 类型                                                 | 必填 | 说明                 |
5494| :------- | :--------------------------------------------------- | :--- | :------------------- |
5495| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | 是   | 回调函数。当获取音频流信息成功,err为undefined,data为获取到的音频流信息;否则为错误对象。 |
5496
5497**示例:**
5498
5499```ts
5500import { BusinessError } from '@kit.BasicServicesKit';
5501
5502audioRenderer.getStreamInfo((err: BusinessError, streamInfo: audio.AudioStreamInfo) => {
5503  console.info('Renderer GetStreamInfo:');
5504  console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
5505  console.info(`Renderer channel: ${streamInfo.channels}`);
5506  console.info(`Renderer format: ${streamInfo.sampleFormat}`);
5507  console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
5508});
5509```
5510
5511### getStreamInfo<sup>8+</sup>
5512
5513getStreamInfo(): Promise<AudioStreamInfo\>
5514
5515获取音频流信息,使用Promise方式异步返回结果。
5516
5517**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5518
5519**返回值:**
5520
5521| 类型                                           | 说明                   |
5522| :--------------------------------------------- | :--------------------- |
5523| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise对象,返回音频流信息. |
5524
5525**示例:**
5526
5527```ts
5528import { BusinessError } from '@kit.BasicServicesKit';
5529
5530audioRenderer.getStreamInfo().then((streamInfo: audio.AudioStreamInfo) => {
5531  console.info('Renderer GetStreamInfo:');
5532  console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
5533  console.info(`Renderer channel: ${streamInfo.channels}`);
5534  console.info(`Renderer format: ${streamInfo.sampleFormat}`);
5535  console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
5536}).catch((err: BusinessError) => {
5537  console.error(`ERROR: ${err}`);
5538});
5539```
5540
5541### getStreamInfoSync<sup>10+</sup>
5542
5543getStreamInfoSync(): AudioStreamInfo
5544
5545获取音频流信息,同步返回结果。
5546
5547**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5548
5549**返回值:**
5550
5551| 类型                                           | 说明                   |
5552| :--------------------------------------------- | :--------------------- |
5553| [AudioStreamInfo](#audiostreaminfo8) | 返回音频流信息. |
5554
5555**示例:**
5556
5557```ts
5558import { BusinessError } from '@kit.BasicServicesKit';
5559
5560try {
5561  let streamInfo: audio.AudioStreamInfo = audioRenderer.getStreamInfoSync();
5562  console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
5563  console.info(`Renderer channel: ${streamInfo.channels}`);
5564  console.info(`Renderer format: ${streamInfo.sampleFormat}`);
5565  console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
5566} catch (err) {
5567  let error = err as BusinessError;
5568  console.error(`ERROR: ${error}`);
5569}
5570```
5571
5572### getAudioStreamId<sup>9+</sup>
5573
5574getAudioStreamId(callback: AsyncCallback<number\>): void
5575
5576获取音频流id,使用callback方式异步返回结果。
5577
5578**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5579
5580**参数:**
5581
5582| 参数名   | 类型                                                 | 必填 | 说明                 |
5583| :------- | :--------------------------------------------------- | :--- | :------------------- |
5584| callback | AsyncCallback<number\> | 是   | 回调函数。当获取音频流id成功,err为undefined,data为获取到的音频流id;否则为错误对象。 |
5585
5586**示例:**
5587
5588```ts
5589import { BusinessError } from '@kit.BasicServicesKit';
5590
5591audioRenderer.getAudioStreamId((err: BusinessError, streamId: number) => {
5592  console.info(`Renderer GetStreamId: ${streamId}`);
5593});
5594```
5595
5596### getAudioStreamId<sup>9+</sup>
5597
5598getAudioStreamId(): Promise<number\>
5599
5600获取音频流id,使用Promise方式异步返回结果。
5601
5602**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5603
5604**返回值:**
5605
5606| 类型                                           | 说明                   |
5607| :--------------------------------------------- | :--------------------- |
5608| Promise<number\> | Promise对象,返回音频流id。 |
5609
5610**示例:**
5611
5612```ts
5613import { BusinessError } from '@kit.BasicServicesKit';
5614
5615audioRenderer.getAudioStreamId().then((streamId: number) => {
5616  console.info(`Renderer getAudioStreamId: ${streamId}`);
5617}).catch((err: BusinessError) => {
5618  console.error(`ERROR: ${err}`);
5619});
5620```
5621
5622### getAudioStreamIdSync<sup>10+</sup>
5623
5624getAudioStreamIdSync(): number
5625
5626获取音频流id,同步返回结果。
5627
5628**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5629
5630**返回值:**
5631
5632| 类型                                           | 说明                   |
5633| :--------------------------------------------- | :--------------------- |
5634| number | 返回音频流id。 |
5635
5636**示例:**
5637
5638```ts
5639import { BusinessError } from '@kit.BasicServicesKit';
5640
5641try {
5642  let streamId: number = audioRenderer.getAudioStreamIdSync();
5643  console.info(`Renderer getAudioStreamIdSync: ${streamId}`);
5644} catch (err) {
5645  let error = err as BusinessError;
5646  console.error(`ERROR: ${error}`);
5647}
5648```
5649
5650### setAudioEffectMode<sup>10+</sup>
5651
5652setAudioEffectMode(mode: AudioEffectMode, callback: AsyncCallback\<void>): void
5653
5654设置当前音效模式。使用callback方式异步返回结果。
5655
5656**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5657
5658**参数:**
5659
5660| 参数名   | 类型                                     | 必填 | 说明                     |
5661| -------- | ---------------------------------------- | ---- | ------------------------ |
5662| mode     | [AudioEffectMode](#audioeffectmode10)    | 是   | 音效模式。               |
5663| callback | AsyncCallback\<void>                     | 是   | 回调函数。当设置当前音效模式成功,err为undefined,否则为错误对象。 |
5664
5665**错误码:**
5666
5667以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
5668
5669| 错误码ID | 错误信息 |
5670| ------- | ----------------------------------------------|
5671| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
5672| 6800101 | Parameter verification failed. Return by callback.  |
5673
5674**示例:**
5675
5676```ts
5677import { BusinessError } from '@kit.BasicServicesKit';
5678
5679audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_DEFAULT, (err: BusinessError) => {
5680  if (err) {
5681    console.error('Failed to set params');
5682  } else {
5683    console.info('Callback invoked to indicate a successful audio effect mode setting.');
5684  }
5685});
5686```
5687
5688### setAudioEffectMode<sup>10+</sup>
5689
5690setAudioEffectMode(mode: AudioEffectMode): Promise\<void>
5691
5692设置当前音效模式。使用Promise方式异步返回结果。
5693
5694**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5695
5696**参数:**
5697
5698| 参数名 | 类型                                     | 必填 | 说明         |
5699| ------ | ---------------------------------------- | ---- | ------------ |
5700| mode   | [AudioEffectMode](#audioeffectmode10)   | 是   | 音效模式。 |
5701
5702**返回值:**
5703
5704| 类型           | 说明                      |
5705| -------------- | ------------------------- |
5706| Promise\<void> | Promise对象,无返回结果。 |
5707
5708**错误码:**
5709
5710以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
5711
5712| 错误码ID | 错误信息 |
5713| ------- | ---------------------------------------------|
5714| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
5715| 6800101 | Parameter verification failed. Return by promise. |
5716
5717**示例:**
5718
5719```ts
5720import { BusinessError } from '@kit.BasicServicesKit';
5721
5722audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_DEFAULT).then(() => {
5723  console.info('setAudioEffectMode SUCCESS');
5724}).catch((err: BusinessError) => {
5725  console.error(`ERROR: ${err}`);
5726});
5727```
5728
5729### getAudioEffectMode<sup>10+</sup>
5730
5731getAudioEffectMode(callback: AsyncCallback\<AudioEffectMode>): void
5732
5733获取当前音效模式。使用callback方式异步返回结果。
5734
5735**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5736
5737**参数:**
5738
5739| 参数名   | 类型                                                    | 必填 | 说明               |
5740| -------- | ------------------------------------------------------- | ---- | ------------------ |
5741| callback | AsyncCallback<[AudioEffectMode](#audioeffectmode10)> | 是   | 回调函数。当获取当前音效模式成功,err为undefined,data为获取到的当前音效模式;否则为错误对象。 |
5742
5743**示例:**
5744
5745```ts
5746import { BusinessError } from '@kit.BasicServicesKit';
5747
5748audioRenderer.getAudioEffectMode((err: BusinessError, effectMode: audio.AudioEffectMode) => {
5749  if (err) {
5750    console.error('Failed to get params');
5751  } else {
5752    console.info(`getAudioEffectMode: ${effectMode}`);
5753  }
5754});
5755```
5756
5757### getAudioEffectMode<sup>10+</sup>
5758
5759getAudioEffectMode(): Promise\<AudioEffectMode>
5760
5761获取当前音效模式。使用Promise方式异步返回结果。
5762
5763**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5764
5765**返回值:**
5766
5767| 类型                                              | 说明                      |
5768| ------------------------------------------------- | ------------------------- |
5769| Promise<[AudioEffectMode](#audioeffectmode10)> | Promise对象,返回当前音效模式。 |
5770
5771**示例:**
5772
5773```ts
5774import { BusinessError } from '@kit.BasicServicesKit';
5775
5776audioRenderer.getAudioEffectMode().then((effectMode: audio.AudioEffectMode) => {
5777  console.info(`getAudioEffectMode: ${effectMode}`);
5778}).catch((err: BusinessError) => {
5779  console.error(`ERROR: ${err}`);
5780});
5781```
5782
5783### start<sup>8+</sup>
5784
5785start(callback: AsyncCallback<void\>): void
5786
5787启动音频渲染器。使用callback方式异步返回结果。
5788
5789**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5790
5791**参数:**
5792
5793| 参数名   | 类型                 | 必填 | 说明       |
5794| -------- | -------------------- | ---- | ---------- |
5795| callback | AsyncCallback\<void> | 是   | Callback对象,成功表示启动音频采集器成功,异常将返回error对象:<br>错误码6800301,表示包含状态检查异常、焦点抢占失败、系统处理异常(具体错误查看系统日志)。 |
5796
5797**示例:**
5798
5799```ts
5800import { BusinessError } from '@kit.BasicServicesKit';
5801
5802audioRenderer.start((err: BusinessError) => {
5803  if (err) {
5804    console.error('Renderer start failed.');
5805  } else {
5806    console.info('Renderer start success.');
5807  }
5808});
5809```
5810
5811### start<sup>8+</sup>
5812
5813start(): Promise<void\>
5814
5815启动音频渲染器。使用Promise方式异步返回结果。
5816
5817**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5818
5819**返回值:**
5820
5821| 类型           | 说明                      |
5822| -------------- | ------------------------- |
5823| Promise\<void> | Promise对象,成功表示启动音频采集器成功,异常将返回error对象:<br>错误码6800301,表示包含状态检查异常、焦点抢占失败、系统处理异常(具体错误查看系统日志)。 |
5824
5825**示例:**
5826
5827```ts
5828import { BusinessError } from '@kit.BasicServicesKit';
5829
5830audioRenderer.start().then(() => {
5831  console.info('Renderer started');
5832}).catch((err: BusinessError) => {
5833  console.error(`ERROR: ${err}`);
5834});
5835```
5836
5837### pause<sup>8+</sup>
5838
5839pause(callback: AsyncCallback\<void>): void
5840
5841暂停渲染。使用callback方式异步返回结果。
5842
5843**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5844
5845**参数:**
5846
5847| 参数名   | 类型                 | 必填 | 说明             |
5848| -------- | -------------------- | ---- | ---------------- |
5849| callback | AsyncCallback\<void> | 是   | 回调函数。当暂停渲染成功,err为undefined,否则为错误对象。 |
5850
5851**示例:**
5852
5853```ts
5854import { BusinessError } from '@kit.BasicServicesKit';
5855
5856audioRenderer.pause((err: BusinessError) => {
5857  if (err) {
5858    console.error('Renderer pause failed');
5859  } else {
5860    console.info('Renderer paused.');
5861  }
5862});
5863```
5864
5865### pause<sup>8+</sup>
5866
5867pause(): Promise\<void>
5868
5869暂停渲染。使用Promise方式异步返回结果。
5870
5871**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5872
5873**返回值:**
5874
5875| 类型           | 说明                      |
5876| -------------- | ------------------------- |
5877| Promise\<void> | Promise对象,无返回结果。 |
5878
5879**示例:**
5880
5881```ts
5882import { BusinessError } from '@kit.BasicServicesKit';
5883
5884audioRenderer.pause().then(() => {
5885  console.info('Renderer paused');
5886}).catch((err: BusinessError) => {
5887  console.error(`ERROR: ${err}`);
5888});
5889```
5890
5891### drain<sup>8+</sup>
5892
5893drain(callback: AsyncCallback\<void>): void
5894
5895检查缓冲区是否已被耗尽。使用callback方式异步返回结果。
5896
5897**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5898
5899**参数:**
5900
5901| 参数名   | 类型                 | 必填 | 说明             |
5902| -------- | -------------------- | ---- | ---------------- |
5903| callback | AsyncCallback\<void> | 是   | 回调函数。当检查缓冲区是否已被耗尽成功,err为undefined,否则为错误对象。 |
5904
5905**示例:**
5906
5907```ts
5908import { BusinessError } from '@kit.BasicServicesKit';
5909
5910audioRenderer.drain((err: BusinessError) => {
5911  if (err) {
5912    console.error('Renderer drain failed');
5913  } else {
5914    console.info('Renderer drained.');
5915  }
5916});
5917```
5918
5919### drain<sup>8+</sup>
5920
5921drain(): Promise\<void>
5922
5923检查缓冲区是否已被耗尽。使用Promise方式异步返回结果。
5924
5925**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5926
5927**返回值:**
5928
5929| 类型           | 说明                      |
5930| -------------- | ------------------------- |
5931| Promise\<void> | Promise对象,无返回结果。 |
5932
5933**示例:**
5934
5935```ts
5936import { BusinessError } from '@kit.BasicServicesKit';
5937
5938audioRenderer.drain().then(() => {
5939  console.info('Renderer drained successfully');
5940}).catch((err: BusinessError) => {
5941  console.error(`ERROR: ${err}`);
5942});
5943```
5944
5945### flush<sup>11+</sup>
5946
5947flush(): Promise\<void>
5948
5949清空缓冲区([AudioState](#audiostate8)为STATE_RUNNING、STATE_PAUSED、STATE_STOPPED状态下可用)。使用Promise方式异步返回结果。
5950
5951**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5952
5953**返回值:**
5954
5955| 类型           | 说明                      |
5956| -------------- | ------------------------- |
5957| Promise\<void> | Promise对象,无返回结果。 |
5958
5959**错误码:**
5960
5961以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
5962
5963| 错误码ID | 错误信息 |
5964| ------- | --------------------------------------------|
5965| 6800103 | Operation not permit at current state. Return by promise. |
5966
5967**示例:**
5968
5969```ts
5970import { BusinessError } from '@kit.BasicServicesKit';
5971
5972audioRenderer.flush().then(() => {
5973  console.info('Renderer flushed successfully');
5974}).catch((err: BusinessError) => {
5975  console.error(`ERROR: ${err}`);
5976});
5977```
5978
5979### stop<sup>8+</sup>
5980
5981stop(callback: AsyncCallback\<void>): void
5982
5983停止渲染。使用callback方式异步返回结果。
5984
5985**系统能力:** SystemCapability.Multimedia.Audio.Renderer
5986
5987**参数:**
5988
5989| 参数名   | 类型                 | 必填 | 说明             |
5990| -------- | -------------------- | ---- | ---------------- |
5991| callback | AsyncCallback\<void> | 是   | 回调函数。当停止渲染成功,err为undefined,否则为错误对象。 |
5992
5993**示例:**
5994
5995```ts
5996import { BusinessError } from '@kit.BasicServicesKit';
5997
5998audioRenderer.stop((err: BusinessError) => {
5999  if (err) {
6000    console.error('Renderer stop failed');
6001  } else {
6002    console.info('Renderer stopped.');
6003  }
6004});
6005```
6006
6007### stop<sup>8+</sup>
6008
6009stop(): Promise\<void>
6010
6011停止渲染。使用Promise方式异步返回结果。
6012
6013**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6014
6015**返回值:**
6016
6017| 类型           | 说明                      |
6018| -------------- | ------------------------- |
6019| Promise\<void> | Promise对象,无返回结果。 |
6020
6021**示例:**
6022
6023```ts
6024import { BusinessError } from '@kit.BasicServicesKit';
6025
6026audioRenderer.stop().then(() => {
6027  console.info('Renderer stopped successfully');
6028}).catch((err: BusinessError) => {
6029  console.error(`ERROR: ${err}`);
6030});
6031```
6032
6033### release<sup>8+</sup>
6034
6035release(callback: AsyncCallback\<void>): void
6036
6037释放音频渲染器。使用callback方式异步返回结果。
6038
6039**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6040
6041**参数:**
6042
6043| 参数名   | 类型                 | 必填 | 说明             |
6044| -------- | -------------------- | ---- | ---------------- |
6045| callback | AsyncCallback\<void> | 是   | 回调函数。当释放音频渲染器成功,err为undefined,否则为错误对象。 |
6046
6047**示例:**
6048
6049```ts
6050import { BusinessError } from '@kit.BasicServicesKit';
6051
6052audioRenderer.release((err: BusinessError) => {
6053  if (err) {
6054    console.error('Renderer release failed');
6055  } else {
6056    console.info('Renderer released.');
6057  }
6058});
6059```
6060
6061### release<sup>8+</sup>
6062
6063release(): Promise\<void>
6064
6065释放渲染器。使用Promise方式异步返回结果。
6066
6067**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6068
6069**返回值:**
6070
6071| 类型           | 说明                      |
6072| -------------- | ------------------------- |
6073| Promise\<void> | Promise对象,无返回结果。 |
6074
6075**示例:**
6076
6077```ts
6078import { BusinessError } from '@kit.BasicServicesKit';
6079
6080audioRenderer.release().then(() => {
6081  console.info('Renderer released successfully');
6082}).catch((err: BusinessError) => {
6083  console.error(`ERROR: ${err}`);
6084});
6085```
6086
6087### write<sup>8+(deprecated)</sup>
6088
6089write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void
6090
6091写入缓冲区。使用callback方式异步返回结果。
6092
6093> **说明:**
6094> 从 API version 8 开始支持,从 API version 11 开始废弃,建议使用AudioRenderer中的[on('writeData')](#onwritedata11)替代。
6095
6096**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6097
6098**参数:**
6099
6100| 参数名   | 类型                   | 必填 | 说明                                                |
6101| -------- | ---------------------- | ---- | --------------------------------------------------- |
6102| buffer   | ArrayBuffer            | 是   | 要写入缓冲区的数据。                                |
6103| callback | AsyncCallback\<number> | 是   | 回调函数。当写入缓冲区成功,err为undefined,data为获取到的写入的字节数;否则为错误对象。 |
6104
6105**示例:**
6106
6107```ts
6108import { BusinessError } from '@kit.BasicServicesKit';
6109import { fileIo as fs } from '@kit.CoreFileKit';
6110
6111let bufferSize: number;
6112class Options {
6113  offset?: number;
6114  length?: number;
6115}
6116audioRenderer.getBufferSize().then((data: number)=> {
6117  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
6118  bufferSize = data;
6119  console.info(`Buffer size: ${bufferSize}`);
6120  let path = getContext().cacheDir;
6121  let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
6122  let file: fs.File = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
6123  fs.stat(filePath).then(async (stat: fs.Stat) => {
6124    let buf = new ArrayBuffer(bufferSize);
6125    let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1);
6126    for (let i = 0;i < len; i++) {
6127      let options: Options = {
6128        offset: i * bufferSize,
6129        length: bufferSize
6130      };
6131      let readSize: number = await fs.read(file.fd, buf, options);
6132      let writeSize: number = await new Promise((resolve,reject)=>{
6133        audioRenderer.write(buf,(err: BusinessError, writeSize: number)=>{
6134          if(err){
6135            reject(err)
6136          }else{
6137            resolve(writeSize)
6138          }
6139        })
6140      })
6141    }
6142  });
6143  }).catch((err: BusinessError) => {
6144    console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
6145});
6146```
6147
6148### write<sup>8+(deprecated)</sup>
6149
6150write(buffer: ArrayBuffer): Promise\<number>
6151
6152写入缓冲区。使用Promise方式异步返回结果。
6153
6154> **说明:**
6155> 从 API version 8 开始支持,从 API version 11 开始废弃,建议使用AudioRenderer中的[on('writeData')](#onwritedata11)替代。
6156
6157**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6158
6159**参数:**
6160
6161| 参数名   | 类型                   | 必填 | 说明                                                |
6162| -------- | ---------------------- | ---- | --------------------------------------------------- |
6163| buffer   | ArrayBuffer            | 是   | 要写入缓冲区的数据。                                |
6164
6165**返回值:**
6166
6167| 类型             | 说明                                                         |
6168| ---------------- | ------------------------------------------------------------ |
6169| Promise\<number> | Promise对象,返回写入的字节数。 |
6170
6171**示例:**
6172
6173```ts
6174import { BusinessError } from '@kit.BasicServicesKit';
6175import { fileIo as fs } from '@kit.CoreFileKit';
6176
6177let bufferSize: number;
6178class Options {
6179  offset?: number;
6180  length?: number;
6181}
6182audioRenderer.getBufferSize().then((data: number) => {
6183  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
6184  bufferSize = data;
6185  console.info(`BufferSize: ${bufferSize}`);
6186  let path = getContext().cacheDir;
6187  let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
6188  let file: fs.File = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
6189  fs.stat(filePath).then(async (stat: fs.Stat) => {
6190    let buf = new ArrayBuffer(bufferSize);
6191    let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1);
6192    for (let i = 0;i < len; i++) {
6193      let options: Options = {
6194        offset: i * bufferSize,
6195        length: bufferSize
6196      };
6197      let readSize: number = await fs.read(file.fd, buf, options);
6198      try{
6199        let writeSize: number = await audioRenderer.write(buf);
6200      } catch(err) {
6201        let error = err as BusinessError;
6202        console.error(`audioRenderer.write err: ${error}`);
6203      }
6204    }
6205  });
6206}).catch((err: BusinessError) => {
6207  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
6208});
6209```
6210
6211### getAudioTime<sup>8+</sup>
6212
6213getAudioTime(callback: AsyncCallback\<number>): void
6214
6215获取播放到当前位置时的时间戳(从 1970 年 1 月 1 日开始),单位为纳秒。使用callback方式异步返回结果。
6216
6217**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6218
6219**参数:**
6220
6221| 参数名   | 类型                   | 必填 | 说明             |
6222| -------- | ---------------------- | ---- | ---------------- |
6223| callback | AsyncCallback\<number> | 是   | 回调函数。当获取时间戳成功,err为undefined,data为获取到的时间戳;否则为错误对象。 |
6224
6225**示例:**
6226
6227```ts
6228import { BusinessError } from '@kit.BasicServicesKit';
6229
6230audioRenderer.getAudioTime((err: BusinessError, timestamp: number) => {
6231  console.info(`Current timestamp: ${timestamp}`);
6232});
6233```
6234
6235### getAudioTime<sup>8+</sup>
6236
6237getAudioTime(): Promise\<number>
6238
6239获取播放到当前位置时的时间戳(从 1970 年 1 月 1 日开始),单位为纳秒。使用Promise方式异步返回结果。
6240
6241**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6242
6243**返回值:**
6244
6245| 类型             | 描述                    |
6246| ---------------- | ----------------------- |
6247| Promise\<number> | Promise对象,返回时间戳。 |
6248
6249**示例:**
6250
6251```ts
6252import { BusinessError } from '@kit.BasicServicesKit';
6253
6254audioRenderer.getAudioTime().then((timestamp: number) => {
6255  console.info(`Current timestamp: ${timestamp}`);
6256}).catch((err: BusinessError) => {
6257  console.error(`ERROR: ${err}`);
6258});
6259```
6260
6261### getAudioTimeSync<sup>10+</sup>
6262
6263getAudioTimeSync(): number
6264
6265获取播放到当前位置时的时间戳(从 1970 年 1 月 1 日开始),单位为纳秒。同步返回结果。
6266
6267**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6268
6269**返回值:**
6270
6271| 类型             | 描述                    |
6272| ---------------- | ----------------------- |
6273| number | 返回时间戳。 |
6274
6275**示例:**
6276
6277```ts
6278import { BusinessError } from '@kit.BasicServicesKit';
6279
6280try {
6281  let timestamp: number = audioRenderer.getAudioTimeSync();
6282  console.info(`Current timestamp: ${timestamp}`);
6283} catch (err) {
6284  let error = err as BusinessError;
6285  console.error(`ERROR: ${error}`);
6286}
6287```
6288
6289### getBufferSize<sup>8+</sup>
6290
6291getBufferSize(callback: AsyncCallback\<number>): void
6292
6293获取音频渲染器的最小缓冲区大小。使用callback方式异步返回结果。
6294
6295**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6296
6297**参数:**
6298
6299| 参数名   | 类型                   | 必填 | 说明                 |
6300| -------- | ---------------------- | ---- | -------------------- |
6301| callback | AsyncCallback\<number> | 是   | 回调函数。当获取音频渲染器的最小缓冲区大小成功,err为undefined,data为获取到的最小缓冲区大小;否则为错误对象。 |
6302
6303**示例:**
6304
6305```ts
6306import { BusinessError } from '@kit.BasicServicesKit';
6307
6308let bufferSize: number;
6309
6310audioRenderer.getBufferSize((err: BusinessError, data: number) => {
6311  if (err) {
6312    console.error('getBufferSize error');
6313  } else {
6314    console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
6315    bufferSize = data;
6316  }
6317});
6318```
6319
6320### getBufferSize<sup>8+</sup>
6321
6322getBufferSize(): Promise\<number>
6323
6324获取音频渲染器的最小缓冲区大小。使用Promise方式异步返回结果。
6325
6326**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6327
6328**返回值:**
6329
6330| 类型             | 说明                        |
6331| ---------------- | --------------------------- |
6332| Promise\<number> | Promise对象,返回缓冲区大小。 |
6333
6334**示例:**
6335
6336```ts
6337import { BusinessError } from '@kit.BasicServicesKit';
6338
6339let bufferSize: number;
6340
6341audioRenderer.getBufferSize().then((data: number) => {
6342  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
6343  bufferSize = data;
6344}).catch((err: BusinessError) => {
6345  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
6346});
6347```
6348
6349### getBufferSizeSync<sup>10+</sup>
6350
6351getBufferSizeSync(): number
6352
6353获取音频渲染器的最小缓冲区大小,同步返回结果。
6354
6355**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6356
6357**返回值:**
6358
6359| 类型             | 说明                        |
6360| ---------------- | --------------------------- |
6361| number | 返回缓冲区大小。 |
6362
6363**示例:**
6364
6365```ts
6366import { BusinessError } from '@kit.BasicServicesKit';
6367
6368let bufferSize: number = 0;
6369
6370try {
6371  bufferSize = audioRenderer.getBufferSizeSync();
6372  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${bufferSize}`);
6373} catch (err) {
6374  let error = err as BusinessError;
6375  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${error}`);
6376}
6377```
6378
6379### setRenderRate<sup>8+(deprecated)</sup>
6380
6381setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\<void>): void
6382
6383设置音频渲染速率。使用callback方式异步返回结果。
6384
6385> **说明:**
6386> 从 API version 8 开始支持,从 API version 11 开始废弃。建议使用AudioRenderer中的[setSpeed](#setspeed11)替代。
6387
6388**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6389
6390**参数:**
6391
6392| 参数名   | 类型                                     | 必填 | 说明                     |
6393| -------- | ---------------------------------------- | ---- | ------------------------ |
6394| rate     | [AudioRendererRate](#audiorendererrate8) | 是   | 渲染的速率。             |
6395| callback | AsyncCallback\<void>                     | 是   | 回调函数。当设置音频渲染速率成功,err为undefined,否则为错误对象。 |
6396
6397**示例:**
6398
6399```ts
6400import { BusinessError } from '@kit.BasicServicesKit';
6401
6402audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err: BusinessError) => {
6403  if (err) {
6404    console.error('Failed to set params');
6405  } else {
6406    console.info('Callback invoked to indicate a successful render rate setting.');
6407  }
6408});
6409```
6410
6411### setRenderRate<sup>8+(deprecated)</sup>
6412
6413setRenderRate(rate: AudioRendererRate): Promise\<void>
6414
6415设置音频渲染速率。使用Promise方式异步返回结果。
6416
6417> **说明:**
6418> 从 API version 8 开始支持,从 API version 11 开始废弃。建议使用AudioRenderer中的[setSpeed](#setspeed11)替代。
6419
6420**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6421
6422**参数:**
6423
6424| 参数名 | 类型                                     | 必填 | 说明         |
6425| ------ | ---------------------------------------- | ---- | ------------ |
6426| rate   | [AudioRendererRate](#audiorendererrate8) | 是   | 渲染的速率。 |
6427
6428**返回值:**
6429
6430| 类型           | 说明                      |
6431| -------------- | ------------------------- |
6432| Promise\<void> | Promise对象,无返回结果。 |
6433
6434**示例:**
6435
6436```ts
6437import { BusinessError } from '@kit.BasicServicesKit';
6438
6439audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
6440  console.info('setRenderRate SUCCESS');
6441}).catch((err: BusinessError) => {
6442  console.error(`ERROR: ${err}`);
6443});
6444```
6445
6446### setSpeed<sup>11+</sup>
6447
6448setSpeed(speed: number): void
6449
6450设置播放倍速。
6451
6452**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6453
6454**参数:**
6455
6456| 参数名 | 类型                                     | 必填 | 说明                   |
6457| ------ | ---------------------------------------- | ---- |----------------------|
6458| speed | number | 是   | 设置播放的倍速值(倍速范围:0.125-4.0)。 |
6459
6460**错误码:**
6461
6462以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
6463
6464| 错误码ID | 错误信息 |
6465| ------- | --------------------------------------------|
6466| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
6467| 6800101 | Parameter verification failed. |
6468
6469**示例:**
6470
6471```ts
6472audioRenderer.setSpeed(1.5);
6473```
6474
6475### getRenderRate<sup>8+(deprecated)</sup>
6476
6477getRenderRate(callback: AsyncCallback\<AudioRendererRate>): void
6478
6479获取当前渲染速率。使用callback方式异步返回结果。
6480
6481> **说明:**
6482> 从 API version 8 开始支持,从 API version 11 开始废弃。建议使用AudioRenderer中的[getSpeed](#getspeed11)替代。
6483
6484**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6485
6486**参数:**
6487
6488| 参数名   | 类型                                                    | 必填 | 说明               |
6489| -------- | ------------------------------------------------------- | ---- | ------------------ |
6490| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | 是   | 回调函数。当获取当前渲染速率成功,err为undefined,data为获取到的当前渲染速率;否则为错误对象。 |
6491
6492**示例:**
6493
6494```ts
6495import { BusinessError } from '@kit.BasicServicesKit';
6496
6497audioRenderer.getRenderRate((err: BusinessError, renderRate: audio.AudioRendererRate) => {
6498  console.info(`getRenderRate: ${renderRate}`);
6499});
6500```
6501
6502### getRenderRate<sup>8+(deprecated)</sup>
6503
6504getRenderRate(): Promise\<AudioRendererRate>
6505
6506获取当前渲染速率。使用Promise方式异步返回结果。
6507
6508> **说明:**
6509> 从 API version 8 开始支持,从 API version 11 开始废弃。建议使用AudioRenderer中的[getSpeed](#getspeed11)替代。
6510
6511**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6512
6513**返回值:**
6514
6515| 类型                                              | 说明                      |
6516| ------------------------------------------------- | ------------------------- |
6517| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise对象,返回渲染速率。 |
6518
6519**示例:**
6520
6521```ts
6522import { BusinessError } from '@kit.BasicServicesKit';
6523
6524audioRenderer.getRenderRate().then((renderRate: audio.AudioRendererRate) => {
6525  console.info(`getRenderRate: ${renderRate}`);
6526}).catch((err: BusinessError) => {
6527  console.error(`ERROR: ${err}`);
6528});
6529```
6530
6531### getRenderRateSync<sup>10+(deprecated)</sup>
6532
6533getRenderRateSync(): AudioRendererRate
6534
6535获取当前渲染速率,同步返回结果。
6536
6537> **说明:**
6538> 从 API version 10 开始支持,从 API version 11 开始废弃。建议使用AudioRenderer中的[getSpeed](#getspeed11)替代。
6539
6540**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6541
6542**返回值:**
6543
6544| 类型                                              | 说明                      |
6545| ------------------------------------------------- | ------------------------- |
6546| [AudioRendererRate](#audiorendererrate8) | 返回渲染速率。 |
6547
6548**示例:**
6549
6550```ts
6551import { BusinessError } from '@kit.BasicServicesKit';
6552
6553try {
6554  let renderRate: audio.AudioRendererRate = audioRenderer.getRenderRateSync();
6555  console.info(`getRenderRate: ${renderRate}`);
6556} catch (err) {
6557  let error = err as BusinessError;
6558  console.error(`ERROR: ${error}`);
6559}
6560```
6561
6562### getSpeed<sup>11+</sup>
6563
6564getSpeed(): number
6565
6566获取播放倍速。
6567
6568**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6569
6570**返回值:**
6571
6572| 类型                                              | 说明        |
6573| ------------------------------------------------- |-----------|
6574| number | 返回播放的倍速值。 |
6575
6576**示例:**
6577
6578```ts
6579let speed = audioRenderer.getSpeed();
6580```
6581
6582### setInterruptMode<sup>9+</sup>
6583
6584setInterruptMode(mode: InterruptMode): Promise&lt;void&gt;
6585
6586设置应用的焦点模型。使用Promise异步回调。
6587
6588**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
6589
6590**参数:**
6591
6592| 参数名     | 类型                                | 必填   | 说明        |
6593| ---------- | ---------------------------------- | ------ | ---------- |
6594| mode       | [InterruptMode](#interruptmode9)    | 是     | 焦点模型。  |
6595
6596**返回值:**
6597
6598| 类型                | 说明                          |
6599| ------------------- | ----------------------------- |
6600| Promise&lt;void&gt; | Promise对象,无返回结果。 |
6601
6602**示例:**
6603
6604```ts
6605import { BusinessError } from '@kit.BasicServicesKit';
6606
6607let mode = 0;
6608
6609audioRenderer.setInterruptMode(mode).then(() => {
6610  console.info('setInterruptMode Success!');
6611}).catch((err: BusinessError) => {
6612  console.error(`setInterruptMode Fail: ${err}`);
6613});
6614```
6615### setInterruptMode<sup>9+</sup>
6616
6617setInterruptMode(mode: InterruptMode, callback: AsyncCallback\<void>): void
6618
6619设置应用的焦点模型。使用Callback回调返回执行结果。
6620
6621**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
6622
6623**参数:**
6624
6625| 参数名   | 类型                                | 必填   | 说明            |
6626| ------- | ----------------------------------- | ------ | -------------- |
6627|mode     | [InterruptMode](#interruptmode9)     | 是     | 焦点模型。|
6628|callback | AsyncCallback\<void>                 | 是     |回调函数。当设置应用的焦点模型成功,err为undefined,否则为错误对象。|
6629
6630**示例:**
6631
6632```ts
6633import { BusinessError } from '@kit.BasicServicesKit';
6634
6635let mode = 1;
6636
6637audioRenderer.setInterruptMode(mode, (err: BusinessError) => {
6638  if(err){
6639    console.error(`setInterruptMode Fail: ${err}`);
6640  }
6641  console.info('setInterruptMode Success!');
6642});
6643```
6644
6645### setInterruptModeSync<sup>10+</sup>
6646
6647setInterruptModeSync(mode: InterruptMode): void
6648
6649设置应用的焦点模型,同步设置。
6650
6651**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
6652
6653**参数:**
6654
6655| 参数名     | 类型                                | 必填   | 说明        |
6656| ---------- | ---------------------------------- | ------ | ---------- |
6657| mode       | [InterruptMode](#interruptmode9)    | 是     | 焦点模型。  |
6658
6659**错误码:**
6660
6661以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
6662
6663| 错误码ID | 错误信息 |
6664| ------- | --------------------------------------------|
6665| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
6666| 6800101 | Parameter verification failed. |
6667
6668**示例:**
6669
6670```ts
6671import { BusinessError } from '@kit.BasicServicesKit';
6672
6673try {
6674  audioRenderer.setInterruptModeSync(0);
6675  console.info('setInterruptMode Success!');
6676} catch (err) {
6677  let error = err as BusinessError;
6678  console.error(`setInterruptMode Fail: ${error}`);
6679}
6680```
6681
6682### setVolume<sup>9+</sup>
6683
6684setVolume(volume: number): Promise&lt;void&gt;
6685
6686设置应用的音量。使用Promise异步回调。
6687
6688**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6689
6690**参数:**
6691
6692| 参数名     | 类型    | 必填   | 说明                 |
6693| ---------- | ------- | ------ | ------------------- |
6694| volume     | number  | 是     | 音量值范围为0.0-1.0。 |
6695
6696**返回值:**
6697
6698| 类型                | 说明                          |
6699| ------------------- | ----------------------------- |
6700| Promise&lt;void&gt; | Promise对象,无返回结果。 |
6701
6702**示例:**
6703
6704```ts
6705import { BusinessError } from '@kit.BasicServicesKit';
6706
6707audioRenderer.setVolume(0.5).then(() => {
6708  console.info('setVolume Success!');
6709}).catch((err: BusinessError) => {
6710  console.error(`setVolume Fail: ${err}`);
6711});
6712```
6713### setVolume<sup>9+</sup>
6714
6715setVolume(volume: number, callback: AsyncCallback\<void>): void
6716
6717设置应用的音量。使用Callback回调返回执行结果。
6718
6719**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6720
6721**参数:**
6722
6723| 参数名  | 类型       | 必填   | 说明                 |
6724| ------- | -----------| ------ | ------------------- |
6725|volume   | number     | 是     | 音量值范围为0.0-1.0。 |
6726|callback | AsyncCallback\<void> | 是     |回调函数。当设置应用的音量成功,err为undefined,否则为错误对象。|
6727
6728**示例:**
6729
6730```ts
6731import { BusinessError } from '@kit.BasicServicesKit';
6732
6733audioRenderer.setVolume(0.5, (err: BusinessError) => {
6734  if(err){
6735    console.error(`setVolume Fail: ${err}`);
6736    return;
6737  }
6738  console.info('setVolume Success!');
6739});
6740```
6741### getVolume<sup>12+</sup>
6742
6743getVolume(): number
6744
6745获取音频渲染器的当前音量值,同步返回结果。
6746
6747**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6748
6749**返回值:**
6750
6751| 类型             | 说明                        |
6752| ---------------- | --------------------------- |
6753| number | 返回音量大小,音量范围[0.0-1.0]。 |
6754
6755**示例:**
6756
6757```ts
6758import { BusinessError } from '@kit.BasicServicesKit';
6759
6760try {
6761  let value: number = audioRenderer.getVolume();
6762  console.info(`Indicate that the volume is obtained ${value}.`);
6763} catch (err) {
6764  let error = err as BusinessError;
6765  console.error(`Failed to obtain the volume, error ${error}.`);
6766}
6767```
6768
6769### getMinStreamVolume<sup>10+</sup>
6770
6771getMinStreamVolume(callback: AsyncCallback&lt;number&gt;): void
6772
6773获取应用基于音频流的最小音量。使用Callback回调返回。
6774
6775**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6776
6777**参数:**
6778
6779| 参数名  | 类型       | 必填   | 说明                 |
6780| ------- | -----------| ------ | ------------------- |
6781|callback |AsyncCallback&lt;number&gt; | 是     |回调函数。当获取应用基于音频流的最小音量成功,err为undefined,data为获取到的应用基于音频流的最小音量(音量范围0-1);否则为错误对象。|
6782
6783**示例:**
6784
6785```ts
6786import { BusinessError } from '@kit.BasicServicesKit';
6787
6788audioRenderer.getMinStreamVolume((err: BusinessError, minVolume: number) => {
6789  if (err) {
6790    console.error(`getMinStreamVolume error: ${err}`);
6791  } else {
6792    console.info(`getMinStreamVolume Success! ${minVolume}`);
6793  }
6794});
6795```
6796### getMinStreamVolume<sup>10+</sup>
6797
6798getMinStreamVolume(): Promise&lt;number&gt;
6799
6800获取应用基于音频流的最小音量。使用Promise异步回调。
6801
6802**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6803
6804**返回值:**
6805
6806| 类型                | 说明                          |
6807| ------------------- | ----------------------------- |
6808| Promise&lt;number&gt;| Promise对象,返回音频流最小音量(音量范围0-1)。|
6809
6810**示例:**
6811
6812```ts
6813import { BusinessError } from '@kit.BasicServicesKit';
6814
6815audioRenderer.getMinStreamVolume().then((value: number) => {
6816  console.info(`Get min stream volume Success! ${value}`);
6817}).catch((err: BusinessError) => {
6818  console.error(`Get min stream volume Fail: ${err}`);
6819});
6820```
6821
6822### getMinStreamVolumeSync<sup>10+</sup>
6823
6824getMinStreamVolumeSync(): number
6825
6826获取应用基于音频流的最小音量,同步返回结果。
6827
6828**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6829
6830**返回值:**
6831
6832| 类型                | 说明                          |
6833| ------------------- | ----------------------------- |
6834| number| 返回音频流最小音量(音量范围0-1)。|
6835
6836**示例:**
6837
6838```ts
6839import { BusinessError } from '@kit.BasicServicesKit';
6840
6841try {
6842  let value: number = audioRenderer.getMinStreamVolumeSync();
6843  console.info(`Get min stream volume Success! ${value}`);
6844} catch (err) {
6845  let error = err as BusinessError;
6846  console.error(`Get min stream volume Fail: ${error}`);
6847}
6848```
6849
6850### getMaxStreamVolume<sup>10+</sup>
6851
6852getMaxStreamVolume(callback: AsyncCallback&lt;number&gt;): void
6853
6854获取应用基于音频流的最大音量。使用Callback回调返回。
6855
6856**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6857
6858**参数:**
6859
6860| 参数名  | 类型       | 必填   | 说明                 |
6861| ------- | -----------| ------ | ------------------- |
6862|callback | AsyncCallback&lt;number&gt; | 是     |回调函数。当获取应用基于音频流的最大音量成功,err为undefined,data为获取到的应用基于音频流的最大音量(音量范围0-1);否则为错误对象。|
6863
6864**示例:**
6865
6866```ts
6867import { BusinessError } from '@kit.BasicServicesKit';
6868
6869audioRenderer.getMaxStreamVolume((err: BusinessError, maxVolume: number) => {
6870  if (err) {
6871    console.error(`getMaxStreamVolume Fail: ${err}`);
6872  } else {
6873    console.info(`getMaxStreamVolume Success! ${maxVolume}`);
6874  }
6875});
6876```
6877### getMaxStreamVolume<sup>10+</sup>
6878
6879getMaxStreamVolume(): Promise&lt;number&gt;
6880
6881获取应用基于音频流的最大音量。使用Promise异步回调。
6882
6883**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6884
6885**返回值:**
6886
6887| 类型                | 说明                          |
6888| ------------------- | ----------------------------- |
6889| Promise&lt;number&gt;| Promise对象,返回音频流最大音量(音量范围0-1)。|
6890
6891**示例:**
6892
6893```ts
6894import { BusinessError } from '@kit.BasicServicesKit';
6895
6896audioRenderer.getMaxStreamVolume().then((value: number) => {
6897  console.info(`Get max stream volume Success! ${value}`);
6898}).catch((err: BusinessError) => {
6899  console.error(`Get max stream volume Fail: ${err}`);
6900});
6901```
6902
6903### getMaxStreamVolumeSync<sup>10+</sup>
6904
6905getMaxStreamVolumeSync(): number
6906
6907获取应用基于音频流的最大音量,同步返回结果。
6908
6909**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6910
6911**返回值:**
6912
6913| 类型                | 说明                          |
6914| ------------------- | ----------------------------- |
6915| number| 返回音频流最大音量(音量范围0-1)。|
6916
6917**示例:**
6918
6919```ts
6920import { BusinessError } from '@kit.BasicServicesKit';
6921
6922try {
6923  let value: number = audioRenderer.getMaxStreamVolumeSync();
6924  console.info(`Get max stream volume Success! ${value}`);
6925} catch (err) {
6926  let error = err as BusinessError;
6927  console.error(`Get max stream volume Fail: ${error}`);
6928}
6929```
6930
6931### getUnderflowCount<sup>10+</sup>
6932
6933getUnderflowCount(callback: AsyncCallback&lt;number&gt;): void
6934
6935获取当前播放音频流的欠载音频帧数量。使用Callback回调返回。
6936
6937**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6938
6939**参数:**
6940
6941| 参数名  | 类型       | 必填   | 说明                 |
6942| ------- | -----------| ------ | ------------------- |
6943|callback | AsyncCallback&lt;number&gt; | 是     |回调函数。当获取当前播放音频流的欠载音频帧数量成功,err为undefined,data为获取到的当前播放音频流的欠载音频帧数量;否则为错误对象。|
6944
6945**示例:**
6946
6947```ts
6948import { BusinessError } from '@kit.BasicServicesKit';
6949
6950audioRenderer.getUnderflowCount((err: BusinessError, underflowCount: number) => {
6951  if (err) {
6952    console.error(`getUnderflowCount Fail: ${err}`);
6953  } else {
6954    console.info(`getUnderflowCount Success! ${underflowCount}`);
6955  }
6956});
6957```
6958### getUnderflowCount<sup>10+</sup>
6959
6960getUnderflowCount(): Promise&lt;number&gt;
6961
6962获取当前播放音频流的欠载音频帧数量。使用Promise异步回调。
6963
6964**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6965
6966**返回值:**
6967
6968| 类型                | 说明                          |
6969| ------------------- | ----------------------------- |
6970| Promise&lt;number&gt;| Promise对象,返回音频流的欠载音频帧数量。|
6971
6972**示例:**
6973
6974```ts
6975import { BusinessError } from '@kit.BasicServicesKit';
6976
6977audioRenderer.getUnderflowCount().then((value: number) => {
6978  console.info(`Get underflow count Success! ${value}`);
6979}).catch((err: BusinessError) => {
6980  console.error(`Get underflow count Fail: ${err}`);
6981});
6982```
6983
6984### getUnderflowCountSync<sup>10+</sup>
6985
6986getUnderflowCountSync(): number
6987
6988获取当前播放音频流的欠载音频帧数量,同步返回数据。
6989
6990**系统能力:** SystemCapability.Multimedia.Audio.Renderer
6991
6992**返回值:**
6993
6994| 类型                | 说明                          |
6995| ------------------- | ----------------------------- |
6996| number| 返回音频流的欠载音频帧数量。|
6997
6998**示例:**
6999
7000```ts
7001import { BusinessError } from '@kit.BasicServicesKit';
7002
7003try {
7004  let value: number = audioRenderer.getUnderflowCountSync();
7005  console.info(`Get underflow count Success! ${value}`);
7006} catch (err) {
7007  let error = err as BusinessError;
7008  console.error(`Get underflow count Fail: ${error}`);
7009}
7010```
7011
7012### getCurrentOutputDevices<sup>10+</sup>
7013
7014getCurrentOutputDevices(callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
7015
7016获取音频流输出设备描述符。使用Callback回调返回。
7017
7018**系统能力:** SystemCapability.Multimedia.Audio.Device
7019
7020**参数:**
7021
7022| 参数名  | 类型       | 必填   | 说明                 |
7023| ------- | -----------| ------ | ------------------- |
7024|callback | AsyncCallback\<[AudioDeviceDescriptors](#audiodevicedescriptors)>| 是     |回调函数。当获取音频流输出设备描述符成功,err为undefined,data为获取到的音频流输出设备描述符;否则为错误对象。|
7025
7026**示例:**
7027
7028```ts
7029import { BusinessError } from '@kit.BasicServicesKit';
7030
7031audioRenderer.getCurrentOutputDevices((err: BusinessError, deviceInfo: audio.AudioDeviceDescriptors) => {
7032  if (err) {
7033    console.error(`getCurrentOutputDevices Fail: ${err}`);
7034  } else {
7035    for (let i = 0; i < deviceInfo.length; i++) {
7036      console.info(`DeviceInfo id: ${deviceInfo[i].id}`);
7037      console.info(`DeviceInfo type: ${deviceInfo[i].deviceType}`);
7038      console.info(`DeviceInfo role: ${deviceInfo[i].deviceRole}`);
7039      console.info(`DeviceInfo name: ${deviceInfo[i].name}`);
7040      console.info(`DeviceInfo address: ${deviceInfo[i].address}`);
7041      console.info(`DeviceInfo samplerate: ${deviceInfo[i].sampleRates[0]}`);
7042      console.info(`DeviceInfo channelcount: ${deviceInfo[i].channelCounts[0]}`);
7043      console.info(`DeviceInfo channelmask: ${deviceInfo[i].channelMasks[0]}`);
7044    }
7045  }
7046});
7047```
7048### getCurrentOutputDevices<sup>10+</sup>
7049
7050getCurrentOutputDevices(): Promise&lt;AudioDeviceDescriptors&gt;
7051
7052获取音频流输出设备描述符。使用Promise异步回调。
7053
7054**系统能力:** SystemCapability.Multimedia.Audio.Device
7055
7056**返回值:**
7057
7058| 类型                | 说明                          |
7059| ------------------- | ----------------------------- |
7060| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt;| Promise对象,返回音频流的输出设备描述信息 |
7061
7062**示例:**
7063
7064```ts
7065import { BusinessError } from '@kit.BasicServicesKit';
7066
7067audioRenderer.getCurrentOutputDevices().then((deviceInfo: audio.AudioDeviceDescriptors) => {
7068  for (let i = 0; i < deviceInfo.length; i++) {
7069    console.info(`DeviceInfo id: ${deviceInfo[i].id}`);
7070    console.info(`DeviceInfo type: ${deviceInfo[i].deviceType}`);
7071    console.info(`DeviceInfo role: ${deviceInfo[i].deviceRole}`);
7072    console.info(`DeviceInfo name: ${deviceInfo[i].name}`);
7073    console.info(`DeviceInfo address: ${deviceInfo[i].address}`);
7074    console.info(`DeviceInfo samplerate: ${deviceInfo[i].sampleRates[0]}`);
7075    console.info(`DeviceInfo channelcount: ${deviceInfo[i].channelCounts[0]}`);
7076    console.info(`DeviceInfo channelmask: ${deviceInfo[i].channelMasks[0]}`);
7077  }
7078}).catch((err: BusinessError) => {
7079  console.error(`Get current output devices Fail: ${err}`);
7080});
7081```
7082
7083### getCurrentOutputDevicesSync<sup>10+</sup>
7084
7085getCurrentOutputDevicesSync(): AudioDeviceDescriptors
7086
7087获取音频流输出设备描述符,同步返回结果。
7088
7089**系统能力:** SystemCapability.Multimedia.Audio.Device
7090
7091**返回值:**
7092
7093| 类型                | 说明                          |
7094| ------------------- | ----------------------------- |
7095| [AudioDeviceDescriptors](#audiodevicedescriptors) | 返回音频流的输出设备描述信息 |
7096
7097**示例:**
7098
7099```ts
7100import { BusinessError } from '@kit.BasicServicesKit';
7101
7102try {
7103  let deviceInfo: audio.AudioDeviceDescriptors = audioRenderer.getCurrentOutputDevicesSync();
7104  for (let i = 0; i < deviceInfo.length; i++) {
7105    console.info(`DeviceInfo id: ${deviceInfo[i].id}`);
7106    console.info(`DeviceInfo type: ${deviceInfo[i].deviceType}`);
7107    console.info(`DeviceInfo role: ${deviceInfo[i].deviceRole}`);
7108    console.info(`DeviceInfo name: ${deviceInfo[i].name}`);
7109    console.info(`DeviceInfo address: ${deviceInfo[i].address}`);
7110    console.info(`DeviceInfo samplerate: ${deviceInfo[i].sampleRates[0]}`);
7111    console.info(`DeviceInfo channelcount: ${deviceInfo[i].channelCounts[0]}`);
7112    console.info(`DeviceInfo channelmask: ${deviceInfo[i].channelMasks[0]}`);
7113  }
7114} catch (err) {
7115  let error = err as BusinessError;
7116  console.error(`Get current output devices Fail: ${error}`);
7117}
7118```
7119### setChannelBlendMode<sup>11+</sup>
7120
7121setChannelBlendMode(mode: ChannelBlendMode): void
7122
7123设置单双声道混合模式。使用同步方式返回结果。
7124
7125**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7126
7127**参数:**
7128
7129| 参数名     | 类型                                | 必填 | 说明                                                     |
7130| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
7131| mode | [ChannelBlendMode](#channelblendmode11) | 是   | 声道混合模式类型。                                             |
7132
7133**错误码:**
7134
7135以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
7136
7137| 错误码ID | 错误信息 |
7138| ------- | --------------------------------------------|
7139| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
7140| 6800101 | Parameter verification failed. |
7141| 6800103 | Operation not permit at current state.    |
7142
7143**示例:**
7144
7145```ts
7146let mode = audio.ChannelBlendMode.MODE_DEFAULT;
7147
7148audioRenderer.setChannelBlendMode(mode);
7149console.info(`BlendMode: ${mode}`);
7150```
7151### setVolumeWithRamp<sup>11+</sup>
7152
7153setVolumeWithRamp(volume: number, duration: number): void
7154
7155设置音量渐变模式。使用同步方式返回结果。
7156
7157**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7158
7159**参数:**
7160
7161| 参数名     | 类型                                | 必填 | 说明                                                     |
7162| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
7163| volume     | number | 是   | 渐变目标音量值,音量范围为[0.0, 1.0]。                                             |
7164| duration     | number | 是   | 渐变持续时间,单位为ms。                                             |
7165
7166**错误码:**
7167
7168以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
7169
7170| 错误码ID | 错误信息 |
7171| ------- | --------------------------------------------|
7172| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
7173| 6800101 | Parameter verification failed. |
7174
7175**示例:**
7176
7177```ts
7178let volume = 0.5;
7179let duration = 1000;
7180
7181audioRenderer.setVolumeWithRamp(volume, duration);
7182console.info(`setVolumeWithRamp: ${volume}`);
7183```
7184
7185### setSilentModeAndMixWithOthers<sup>12+</sup>
7186
7187setSilentModeAndMixWithOthers(on: boolean): void
7188
7189设置静音并发播放模式。
7190
7191当设置为true,打开静音并发播放模式,系统将让此音频流静音播放,并且不会打断其它音频流。设置为false,将关闭静音并发播放,音频流可根据系统焦点策略抢占焦点。
7192
7193**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7194
7195**参数:**
7196
7197| 参数名 | 类型                                     | 必填 | 说明                   |
7198| ------ | ---------------------------------------- | ---- |----------------------|
7199| on | boolean | 是   | 打开/关闭静音并发播放模式,true打开,false关闭。 |
7200
7201**示例:**
7202
7203```ts
7204audioRenderer.setSilentModeAndMixWithOthers(true);
7205```
7206
7207### getSilentModeAndMixWithOthers<sup>12+</sup>
7208
7209getSilentModeAndMixWithOthers(): boolean
7210
7211获取静音并发播放模式。
7212
7213**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7214
7215**返回值:**
7216
7217| 类型                                              | 说明        |
7218| ------------------------------------------------- |-----------|
7219| boolean | 返回静音并发播放模式状态,true打开,false关闭。 |
7220
7221**示例:**
7222
7223```ts
7224let on = audioRenderer.getSilentModeAndMixWithOthers();
7225```
7226
7227### setDefaultOutputDevice<sup>12+</sup>
7228
7229setDefaultOutputDevice(deviceType: DeviceType): Promise&lt;void&gt;
7230
7231设置默认本机内置发声设备。使用Promise方式异步返回结果。
7232
7233本接口仅适用于[音频流类型](#streamusage)为语音消息、VoIP语音通话或者VoIP视频通话的场景使用,以及可选的设备类型为听筒、扬声器和系统默认设备。
7234
7235本接口允许在AudioRenderer创建以后的任何时间被调用,系统会记录应用设置的默认本机内置发声设备。在应用启动播放时,若有外接设备如蓝牙耳机/有线耳机接入,系统优先从外接设备发声;否则系统遵循应用设置的默认本机内置发声设备发声。
7236
7237**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7238
7239**参数:**
7240
7241| 参数名     | 类型             | 必填   | 说明                                                      |
7242| ---------- |----------------| ------ |---------------------------------------------------------|
7243| deviceType | [DeviceType](#devicetype) | 是     | 设备类型。<br>只支持:EARPIECE(听筒)、SPEAKER(扬声器)和DEFAULT(系统默认设备)。 |
7244
7245**返回值:**
7246
7247| 类型                | 说明                          |
7248| ------------------- | ----------------------------- |
7249| Promise&lt;void&gt; | Promise对象,无返回结果。 |
7250
7251**错误码:**
7252
7253以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
7254
7255| 错误码ID | 错误信息 |
7256| ------- | --------------------------------------------|
7257| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
7258| 6800101 | Parameter verification failed. |
7259| 6800103 | Operation not permit at current state.    |
7260
7261**示例:**
7262
7263```ts
7264import { BusinessError } from '@kit.BasicServicesKit';
7265
7266// 本接口允许在AudioRenderer创建以后的任何时间被调用。
7267// 未播放时调用,系统会记录应用设置的默认本机内置发声设备,当应用启动播放时从设置的默认本机内置发声设备发声。
7268// 正在播放时调用,在没有外接设备如蓝牙耳机/有线耳机,系统会立即切换到设置的默认本机内置发声设备发声;否则系统会先记录应用设置的默认本机内置发声设备,等外接设备移除后再切换到设置的默认本机内置发声设备发声。
7269audioRenderer.setDefaultOutputDevice(audio.DeviceType.SPEAKER).then(() => {
7270  console.info('setDefaultOutputDevice Success!');
7271}).catch((err: BusinessError) => {
7272  console.error(`setDefaultOutputDevice Fail: ${err}`);
7273});
7274```
7275
7276### on('audioInterrupt')<sup>9+</sup>
7277
7278on(type: 'audioInterrupt', callback: Callback\<InterruptEvent>): void
7279
7280监听音频中断事件(当音频焦点发生变化时触发),使用callback方式返回结果。
7281
7282AudioRenderer对象在start事件发生时会主动获取焦点,在pause、stop等事件发生时会主动释放焦点,不需要开发者主动发起获取焦点或释放焦点的申请。
7283
7284调用此方法,在AudioRenderer对象获取焦点失败或发生中断事件(如被其他音频打断等)时,会收到[InterruptEvent](#interruptevent9)。建议应用可根据InterruptEvent的信息完成进一步处理,更多信息可参考文档[处理音频焦点事件](../../media/audio/audio-playback-concurrency.md)。
7285
7286**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
7287
7288**参数:**
7289
7290| 参数名   | 类型                                         | 必填 | 说明                                                        |
7291| -------- | -------------------------------------------- | ---- | ----------------------------------------------------------- |
7292| type     | string                                       | 是   | 监听事件,固定为:'audioInterrupt'。 |
7293| callback | Callback\<[InterruptEvent](#interruptevent9)\> | 是   | 回调函数,返回播放中断时,应用接收的中断事件信息。 |
7294
7295**错误码:**
7296
7297以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
7298
7299| 错误码ID | 错误信息 |
7300| ------- | --------------------------------------------|
7301| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
7302| 6800101 | Parameter verification failed. |
7303
7304**示例:**
7305
7306```ts
7307import { audio } from '@kit.AudioKit';
7308
7309let isPlaying: boolean; // 标识符,表示是否正在渲染
7310let isDucked: boolean; // 标识符,表示是否被降低音量
7311onAudioInterrupt();
7312
7313async function onAudioInterrupt(){
7314  audioRenderer.on('audioInterrupt', (interruptEvent: audio.InterruptEvent) => {
7315    // 在发生音频打断事件时,audioRenderer收到interruptEvent回调,此处根据其内容做相应处理。
7316    // 1、可选:读取interruptEvent.forceType的类型,判断系统是否已强制执行相应操作。
7317    // 注:默认焦点策略下,INTERRUPT_HINT_RESUME为INTERRUPT_SHARE类型,其余hintType均为INTERRUPT_FORCE类型。因此对forceType可不做判断。
7318    // 2、必选:读取interruptEvent.hintType的类型,做出相应的处理。
7319    if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
7320      // 音频焦点事件已由系统强制执行,应用需更新自身状态及显示内容等
7321      switch (interruptEvent.hintType) {
7322        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
7323          // 音频流已被暂停,临时失去焦点,待可重获焦点时会收到resume对应的interruptEvent
7324          console.info('Force paused. Update playing status and stop writing');
7325          isPlaying = false; // 简化处理,代表应用切换至暂停状态的若干操作
7326          break;
7327        case audio.InterruptHint.INTERRUPT_HINT_STOP:
7328          // 音频流已被停止,永久失去焦点,若想恢复渲染,需用户主动触发
7329          console.info('Force stopped. Update playing status and stop writing');
7330          isPlaying = false; // 简化处理,代表应用切换至暂停状态的若干操作
7331          break;
7332        case audio.InterruptHint.INTERRUPT_HINT_DUCK:
7333          // 音频流已被降低音量渲染
7334          console.info('Force ducked. Update volume status');
7335          isDucked = true; // 简化处理,代表应用更新音量状态的若干操作
7336          break;
7337        case audio.InterruptHint.INTERRUPT_HINT_UNDUCK:
7338          // 音频流已被恢复正常音量渲染
7339          console.info('Force ducked. Update volume status');
7340          isDucked = false; // 简化处理,代表应用更新音量状态的若干操作
7341          break;
7342        default:
7343          console.info('Invalid interruptEvent');
7344          break;
7345      }
7346    } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
7347      // 音频焦点事件需由应用进行操作,应用可以自主选择如何处理该事件,建议应用遵从InterruptHint提示处理
7348      switch (interruptEvent.hintType) {
7349        case audio.InterruptHint.INTERRUPT_HINT_RESUME:
7350          // 建议应用继续渲染(说明音频流此前被强制暂停,临时失去焦点,现在可以恢复渲染)
7351          // 由于INTERRUPT_HINT_RESUME操作需要应用主动执行,系统无法强制,故INTERRUPT_HINT_RESUME事件一定为INTERRUPT_SHARE类型
7352          console.info('Resume force paused renderer or ignore');
7353          // 若选择继续渲染,需在此处主动执行开始渲染的若干操作
7354          break;
7355        default:
7356          console.info('Invalid interruptEvent');
7357          break;
7358      }
7359    }
7360  });
7361}
7362```
7363
7364### on('markReach')<sup>8+</sup>
7365
7366on(type: 'markReach', frame: number, callback: Callback&lt;number&gt;): void
7367
7368监听到达标记事件(当渲染的帧数到达frame参数的值时触发,仅调用一次),使用callback方式返回结果。
7369
7370举例说明,如果frame设置为100,当渲染帧数到达第100帧时,将上报信息。
7371
7372**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7373
7374**参数:**
7375
7376| 参数名   | 类型                     | 必填 | 说明                                      |
7377| :------- | :----------------------- | :--- | :---------------------------------------- |
7378| type     | string                   | 是   | 监听事件,固定为:'markReach'。 |
7379| frame    | number                   | 是   | 触发事件的帧数。该值必须大于0。         |
7380| callback | Callback\<number>         | 是   | 回调函数,返回frame参数的值。 |
7381
7382**示例:**
7383
7384```ts
7385audioRenderer.on('markReach', 1000, (position: number) => {
7386  if (position == 1000) {
7387    console.info('ON Triggered successfully');
7388  }
7389});
7390```
7391
7392
7393### off('markReach')<sup>8+</sup>
7394
7395off(type: 'markReach'): void
7396
7397取消监听到达标记事件。
7398
7399**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7400
7401**参数:**
7402
7403| 参数名 | 类型   | 必填 | 说明                                              |
7404| :----- | :----- | :--- | :------------------------------------------------ |
7405| type   | string | 是   | 监听事件,固定为:'markReach'。 |
7406
7407**示例:**
7408
7409```ts
7410audioRenderer.off('markReach');
7411```
7412
7413### on('periodReach')<sup>8+</sup>
7414
7415on(type: 'periodReach', frame: number, callback: Callback&lt;number&gt;): void
7416
7417监听到达标记事件(每当渲染的帧数达到frame参数的值时触发,即按周期上报信息),使用callback方式返回结果。
7418
7419举例说明,如果frame设置为10,每当渲染10帧数据时将上报信息,例如在第10帧、20帧、30帧,均会上报信息。
7420
7421**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7422
7423**参数:**
7424
7425| 参数名   | 类型                     | 必填 | 说明                                        |
7426| :------- | :----------------------- | :--- | :------------------------------------------ |
7427| type     | string                   | 是   | 监听事件,固定为:'periodReach'。 |
7428| frame    | number                   | 是   | 触发事件的帧数。该值必须大于 0。           |
7429| callback | Callback\<number>         | 是   | 回调函数,返回frame参数的值。 |
7430
7431**示例:**
7432
7433```ts
7434audioRenderer.on('periodReach', 1000, (position: number) => {
7435  if (position == 1000) {
7436    console.info('ON Triggered successfully');
7437  }
7438});
7439```
7440
7441### off('periodReach')<sup>8+</sup>
7442
7443off(type: 'periodReach'): void
7444
7445取消监听到达标记事件。
7446
7447**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7448
7449**参数:**
7450
7451| 参数名 | 类型   | 必填 | 说明                                                |
7452| :----- | :----- | :--- | :-------------------------------------------------- |
7453| type   | string | 是   | 监听事件,固定为:'periodReach'。 |
7454
7455**示例:**
7456
7457```ts
7458audioRenderer.off('periodReach');
7459```
7460
7461### on('stateChange')<sup>8+</sup>
7462
7463on(type: 'stateChange', callback: Callback<AudioState\>): void
7464
7465监听状态变化事件(当AudioRenderer的状态发生变化时触发),使用callback方式返回结果。
7466
7467**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7468
7469**参数:**
7470
7471| 参数名   | 类型                       | 必填 | 说明                                        |
7472| :------- | :------------------------- | :--- | :------------------------------------------ |
7473| type     | string                     | 是   | 监听事件,固定为:'stateChange'。 |
7474| callback | Callback\<[AudioState](#audiostate8)> | 是   | 回调函数,返回当前音频的状态。 |
7475
7476**示例:**
7477
7478```ts
7479audioRenderer.on('stateChange', (state: audio.AudioState) => {
7480  if (state == 1) {
7481    console.info('audio renderer state is: STATE_PREPARED');
7482  }
7483  if (state == 2) {
7484    console.info('audio renderer state is: STATE_RUNNING');
7485  }
7486});
7487```
7488
7489### on('outputDeviceChange')<sup>10+</sup>
7490
7491on(type: 'outputDeviceChange', callback: Callback\<AudioDeviceDescriptors>): void
7492
7493监听音频输出设备变化事件(当音频输出设备发生变化时触发),使用callback方式返回结果。
7494
7495**系统能力:** SystemCapability.Multimedia.Audio.Device
7496
7497**参数:**
7498
7499| 参数名   | 类型                       | 必填 | 说明                                        |
7500| :------- | :------------------------- | :--- | :------------------------------------------ |
7501| type     | string                     | 是   | 监听事件,固定为:'outputDeviceChange'。 |
7502| callback | Callback\<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 是   | 回调函数,返回当前音频流的输出设备描述信息。 |
7503
7504**错误码:**
7505
7506以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
7507
7508| 错误码ID | 错误信息 |
7509| ------- | --------------------------------------------|
7510| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
7511| 6800101 | Parameter verification failed. |
7512
7513**示例:**
7514
7515```ts
7516audioRenderer.on('outputDeviceChange', (deviceInfo: audio.AudioDeviceDescriptors) => {
7517  console.info(`DeviceInfo id: ${deviceInfo[0].id}`);
7518  console.info(`DeviceInfo name: ${deviceInfo[0].name}`);
7519  console.info(`DeviceInfo address: ${deviceInfo[0].address}`);
7520});
7521```
7522
7523### off('outputDeviceChange')<sup>10+</sup>
7524
7525off(type: 'outputDeviceChange', callback?: Callback\<AudioDeviceDescriptors>): void
7526
7527取消监听音频输出设备变化事件,使用callback方式返回结果。
7528
7529**系统能力:** SystemCapability.Multimedia.Audio.Device
7530
7531**参数:**
7532
7533| 参数名   | 类型                       | 必填 | 说明                                        |
7534| :------- | :------------------------- | :--- | :------------------------------------------ |
7535| type     | string                     | 是   | 监听事件,固定为:'outputDeviceChange'。 |
7536| callback | Callback\<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 否   | 回调函数,返回当前音频流的输出设备描述信息。 |
7537
7538**错误码:**
7539
7540以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
7541
7542| 错误码ID | 错误信息 |
7543| ------- | --------------------------------------------|
7544| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
7545| 6800101 | Parameter verification failed. |
7546
7547**示例:**
7548
7549```ts
7550// 取消该事件的所有监听
7551audioRenderer.off('outputDeviceChange');
7552
7553// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
7554let outputDeviceChangeCallback = (deviceInfo: audio.AudioDeviceDescriptors) => {
7555  console.info(`DeviceInfo id: ${deviceInfo[0].id}`);
7556  console.info(`DeviceInfo name: ${deviceInfo[0].name}`);
7557  console.info(`DeviceInfo address: ${deviceInfo[0].address}`);
7558};
7559
7560audioRenderer.on('outputDeviceChange', outputDeviceChangeCallback);
7561
7562audioRenderer.off('outputDeviceChange', outputDeviceChangeCallback);
7563```
7564
7565### on('outputDeviceChangeWithInfo')<sup>11+</sup>
7566
7567on(type: 'outputDeviceChangeWithInfo', callback: Callback\<AudioStreamDeviceChangeInfo>): void
7568
7569监听音频流输出设备变化及原因事件(当音频输出设备发生变化时触发),使用callback方式返回结果。
7570
7571**系统能力:** SystemCapability.Multimedia.Audio.Device
7572
7573**参数:**
7574
7575| 参数名   | 类型                                                                       | 必填 | 说明                                          |
7576| :------- |:-------------------------------------------------------------------------| :--- |:--------------------------------------------|
7577| type     | string                                                                   | 是   | 监听事件,固定为:'outputDeviceChangeWithInfo'。 |
7578| callback | Callback\<[AudioStreamDeviceChangeInfo](#audiostreamdevicechangeinfo11)> | 是   | 回调函数,返回当前音频流的输出设备描述信息及变化原因。 |
7579
7580**错误码:**
7581
7582以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
7583
7584| 错误码ID | 错误信息 |
7585| ------- | --------------------------------------------|
7586| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
7587| 6800101 | Parameter verification failed. |
7588
7589**示例:**
7590
7591```ts
7592audioRenderer.on('outputDeviceChangeWithInfo', (deviceChangeInfo: audio.AudioStreamDeviceChangeInfo) => {
7593  console.info(`DeviceInfo id: ${deviceChangeInfo.devices[0].id}`);
7594  console.info(`DeviceInfo name: ${deviceChangeInfo.devices[0].name}`);
7595  console.info(`DeviceInfo address: ${deviceChangeInfo.devices[0].address}`);
7596  console.info(`Device change reason: ${deviceChangeInfo.changeReason}`);
7597});
7598```
7599
7600### off('outputDeviceChangeWithInfo')<sup>11+</sup>
7601
7602off(type: 'outputDeviceChangeWithInfo', callback?: Callback\<AudioStreamDeviceChangeInfo>): void
7603
7604取消监听音频流输出设备变化及原因事件,使用callback方式返回结果。
7605
7606**系统能力:** SystemCapability.Multimedia.Audio.Device
7607
7608**参数:**
7609
7610| 参数名   | 类型                                                                       | 必填 | 说明                                          |
7611| :------- |:-------------------------------------------------------------------------| :--- |:--------------------------------------------|
7612| type     | string                                                                   | 是   | 监听事件,固定为:'outputDeviceChangeWithInfo'。 |
7613| callback | Callback\<[AudioStreamDeviceChangeInfo](#audiostreamdevicechangeinfo11)> | 否   | 回调函数,返回当前音频流的输出设备描述信息及变化原因。 |
7614
7615**错误码:**
7616
7617以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
7618
7619| 错误码ID | 错误信息 |
7620| ------- | --------------------------------------------|
7621| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
7622| 6800101 | Parameter verification failed. |
7623
7624**示例:**
7625
7626```ts
7627// 取消该事件的所有监听
7628audioRenderer.off('outputDeviceChangeWithInfo');
7629
7630// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
7631let outputDeviceChangeWithInfoCallback = (deviceChangeInfo: audio.AudioStreamDeviceChangeInfo) => {
7632  console.info(`DeviceInfo id: ${deviceChangeInfo.devices[0].id}`);
7633  console.info(`DeviceInfo name: ${deviceChangeInfo.devices[0].name}`);
7634  console.info(`DeviceInfo address: ${deviceChangeInfo.devices[0].address}`);
7635  console.info(`Device change reason: ${deviceChangeInfo.changeReason}`);
7636};
7637
7638audioRenderer.on('outputDeviceChangeWithInfo', outputDeviceChangeWithInfoCallback);
7639
7640audioRenderer.off('outputDeviceChangeWithInfo', outputDeviceChangeWithInfoCallback);
7641```
7642
7643### on('writeData')<sup>11+</sup>
7644
7645on(type: 'writeData', callback: AudioRendererWriteDataCallback): void
7646
7647监听音频数据写入回调事件(当需要写入音频数据时触发),使用 callback 方式返回结果。
7648
7649**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7650
7651**参数:**
7652
7653| 参数名   | 类型                             | 必填 | 说明                                  |
7654| :------- |:--------------------------------| :--- |:--------------------------------------|
7655| type     | string                           | 是   | 监听事件,固定为:'writeData'。 |
7656| callback | [AudioRendererWriteDataCallback](#audiorendererwritedatacallback12)   | 是   | 回调函数,入参代表应用接收待写入的数据缓冲区。<br>API version 11 不支持返回回调结果,从 API version 12 开始支持返回回调结果[AudioDataCallbackResult](#audiodatacallbackresult12)。        |
7657
7658**错误码:**
7659
7660以下错误码的详细介绍请参见 [Audio错误码](errorcode-audio.md)。
7661
7662| 错误码ID | 错误信息 |
7663| ------- | --------------------------------------------|
7664| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
7665| 6800101 | Parameter verification failed. |
7666
7667**示例:**
7668
7669```ts
7670import { BusinessError } from '@kit.BasicServicesKit';
7671import {fileIo as fs} from '@kit.CoreFileKit';
7672
7673class Options {
7674  offset?: number;
7675  length?: number;
7676}
7677
7678let bufferSize: number = 0;
7679let path = getContext().cacheDir;
7680// 确保该沙箱路径下存在该资源
7681let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
7682let file: fs.File = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
7683let writeDataCallback = (buffer: ArrayBuffer) => {
7684  let options: Options = {
7685    offset: bufferSize,
7686    length: buffer.byteLength
7687  };
7688
7689  try {
7690    fs.readSync(file.fd, buffer, options);
7691    bufferSize += buffer.byteLength;
7692    // API version 11 不支持返回回调结果,从 API version 12 开始支持返回回调结果
7693    return audio.AudioDataCallbackResult.VALID;
7694  } catch (error) {
7695    console.error('Error reading file:', error);
7696    // API version 11 不支持返回回调结果,从 API version 12 开始支持返回回调结果
7697    return audio.AudioDataCallbackResult.INVALID;
7698  }
7699};
7700
7701audioRenderer.on('writeData', writeDataCallback);
7702audioRenderer.start().then(() => {
7703  console.info('Renderer started');
7704}).catch((err: BusinessError) => {
7705  console.error(`ERROR: ${err}`);
7706});
7707```
7708
7709### off('writeData')<sup>11+</sup>
7710
7711off(type: 'writeData', callback?: AudioRendererWriteDataCallback): void
7712
7713取消监听音频数据写入回调事件,使用 callback 方式返回结果。
7714
7715**系统能力:** SystemCapability.Multimedia.Audio.Renderer
7716
7717**参数:**
7718
7719| 参数名   | 类型                             | 必填 | 说明                                  |
7720| :------- |:--------------------------------| :--- |:--------------------------------------|
7721| type     | string                           | 是   | 监听事件,固定为:'writeData'。 |
7722| callback | [AudioRendererWriteDataCallback](#audiorendererwritedatacallback12)   | 否   | 回调函数,入参代表应用接收待写入的数据缓冲区。<br>API version 11 不支持返回回调结果,从 API version 12 开始支持返回回调结果[AudioDataCallbackResult](#audiodatacallbackresult12)。 |
7723
7724**错误码:**
7725
7726以下错误码的详细介绍请参见 [Audio错误码](errorcode-audio.md)。
7727
7728| 错误码ID | 错误信息 |
7729| ------- | --------------------------------------------|
7730| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7731| 6800101 | Parameter verification failed. |
7732
7733**示例:**
7734
7735```ts
7736// 取消该事件的所有监听
7737audioRenderer.off('writeData');
7738
7739// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
7740let writeDataCallback = (data: ArrayBuffer) => {
7741    console.info(`write data: ${data}`);
7742};
7743
7744audioRenderer.on('writeData', writeDataCallback);
7745
7746audioRenderer.off('writeData', writeDataCallback);
7747```
7748
7749## AudioCapturer<sup>8+</sup>
7750
7751提供音频采集的相关接口。在调用AudioCapturer的接口前,需要先通过[createAudioCapturer](#audiocreateaudiocapturer8)创建实例。
7752
7753### 属性
7754
7755**系统能力:** SystemCapability.Multimedia.Audio.Capturer
7756
7757| 名称  | 类型                     | 可读 | 可写 | 说明             |
7758| :---- | :------------------------- | :--- | :--- | :--------------- |
7759| state<sup>8+</sup>  | [AudioState](#audiostate8) | 是 | 否   | 音频采集器状态。 |
7760
7761**示例:**
7762
7763```ts
7764import { audio } from '@kit.AudioKit';
7765
7766let state: audio.AudioState = audioCapturer.state;
7767```
7768
7769### getCapturerInfo<sup>8+</sup>
7770
7771getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void
7772
7773获取采集器信息。使用callback方式异步返回结果。
7774
7775**系统能力:** SystemCapability.Multimedia.Audio.Capturer
7776
7777**参数:**
7778
7779| 参数名   | 类型                              | 必填 | 说明                                 |
7780| :------- | :-------------------------------- | :--- | :----------------------------------- |
7781| callback | AsyncCallback<[AudioCapturerInfo](#audiocapturerinfo8)\> | 是   | 回调函数。当获取采集器信息成功,err为undefined,data为获取到的采集器信息;否则为错误对象。 |
7782
7783**示例:**
7784
7785```ts
7786import { BusinessError } from '@kit.BasicServicesKit';
7787
7788audioCapturer.getCapturerInfo((err: BusinessError, capturerInfo: audio.AudioCapturerInfo) => {
7789  if (err) {
7790    console.error('Failed to get capture info');
7791  } else {
7792    console.info('Capturer getCapturerInfo:');
7793    console.info(`Capturer source: ${capturerInfo.source}`);
7794    console.info(`Capturer flags: ${capturerInfo.capturerFlags}`);
7795  }
7796});
7797```
7798
7799
7800### getCapturerInfo<sup>8+</sup>
7801
7802getCapturerInfo(): Promise<AudioCapturerInfo\>
7803
7804获取采集器信息。使用Promise方式异步返回结果。
7805
7806**系统能力:** SystemCapability.Multimedia.Audio.Capturer
7807
7808**返回值:**
7809
7810| 类型                                              | 说明                                |
7811| :------------------------------------------------ | :---------------------------------- |
7812| Promise<[AudioCapturerInfo](#audiocapturerinfo8)\> | Promise对象,返回采集器信息。 |
7813
7814**示例:**
7815
7816```ts
7817import { BusinessError } from '@kit.BasicServicesKit';
7818
7819audioCapturer.getCapturerInfo().then((audioParamsGet: audio.AudioCapturerInfo) => {
7820  if (audioParamsGet != undefined) {
7821    console.info('AudioFrameworkRecLog: Capturer CapturerInfo:');
7822    console.info(`AudioFrameworkRecLog: Capturer SourceType: ${audioParamsGet.source}`);
7823    console.info(`AudioFrameworkRecLog: Capturer capturerFlags: ${audioParamsGet.capturerFlags}`);
7824  } else {
7825    console.info(`AudioFrameworkRecLog: audioParamsGet is : ${audioParamsGet}`);
7826    console.info('AudioFrameworkRecLog: audioParams getCapturerInfo are incorrect');
7827  }
7828}).catch((err: BusinessError) => {
7829  console.error(`AudioFrameworkRecLog: CapturerInfo :ERROR: ${err}`);
7830})
7831```
7832
7833### getCapturerInfoSync<sup>10+</sup>
7834
7835getCapturerInfoSync(): AudioCapturerInfo
7836
7837获取采集器信息,同步返回结果。
7838
7839**系统能力:** SystemCapability.Multimedia.Audio.Capturer
7840
7841**返回值:**
7842
7843| 类型                                              | 说明                                |
7844| :------------------------------------------------ | :---------------------------------- |
7845| [AudioCapturerInfo](#audiocapturerinfo8) | 返回采集器信息。 |
7846
7847**示例:**
7848
7849```ts
7850import { BusinessError } from '@kit.BasicServicesKit';
7851
7852try {
7853  let audioParamsGet: audio.AudioCapturerInfo = audioCapturer.getCapturerInfoSync();
7854  console.info(`AudioFrameworkRecLog: Capturer SourceType: ${audioParamsGet.source}`);
7855  console.info(`AudioFrameworkRecLog: Capturer capturerFlags: ${audioParamsGet.capturerFlags}`);
7856} catch (err) {
7857  let error = err as BusinessError;
7858  console.error(`AudioFrameworkRecLog: CapturerInfo :ERROR: ${error}`);
7859}
7860```
7861
7862### getStreamInfo<sup>8+</sup>
7863
7864getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
7865
7866获取采集器流信息。使用callback方式异步返回结果。
7867
7868**系统能力:** SystemCapability.Multimedia.Audio.Capturer
7869
7870**参数:**
7871
7872| 参数名   | 类型                                                 | 必填 | 说明                             |
7873| :------- | :--------------------------------------------------- | :--- | :------------------------------- |
7874| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | 是   | 回调函数。当获取采集器流信息成功,err为undefined,data为获取到的采集器流信息;否则为错误对象。 |
7875
7876**示例:**
7877
7878```ts
7879import { BusinessError } from '@kit.BasicServicesKit';
7880
7881audioCapturer.getStreamInfo((err: BusinessError, streamInfo: audio.AudioStreamInfo) => {
7882  if (err) {
7883    console.error('Failed to get stream info');
7884  } else {
7885    console.info('Capturer GetStreamInfo:');
7886    console.info(`Capturer sampling rate: ${streamInfo.samplingRate}`);
7887    console.info(`Capturer channel: ${streamInfo.channels}`);
7888    console.info(`Capturer format: ${streamInfo.sampleFormat}`);
7889    console.info(`Capturer encoding type: ${streamInfo.encodingType}`);
7890  }
7891});
7892```
7893
7894### getStreamInfo<sup>8+</sup>
7895
7896getStreamInfo(): Promise<AudioStreamInfo\>
7897
7898获取采集器流信息。使用Promise方式异步返回结果。
7899
7900**系统能力:** SystemCapability.Multimedia.Audio.Capturer
7901
7902**返回值:**
7903
7904| 类型                                           | 说明                            |
7905| :--------------------------------------------- | :------------------------------ |
7906| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise对象,返回流信息。 |
7907
7908**示例:**
7909
7910```ts
7911import { BusinessError } from '@kit.BasicServicesKit';
7912
7913audioCapturer.getStreamInfo().then((audioParamsGet: audio.AudioStreamInfo) => {
7914  console.info('getStreamInfo:');
7915  console.info(`sampleFormat: ${audioParamsGet.sampleFormat}`);
7916  console.info(`samplingRate: ${audioParamsGet.samplingRate}`);
7917  console.info(`channels: ${audioParamsGet.channels}`);
7918  console.info(`encodingType: ${audioParamsGet.encodingType}`);
7919}).catch((err: BusinessError) => {
7920  console.error(`getStreamInfo :ERROR: ${err}`);
7921});
7922```
7923
7924### getStreamInfoSync<sup>10+</sup>
7925
7926getStreamInfoSync(): AudioStreamInfo
7927
7928获取采集器流信息,同步返回结果。
7929
7930**系统能力:** SystemCapability.Multimedia.Audio.Capturer
7931
7932**返回值:**
7933
7934| 类型                                           | 说明                            |
7935| :--------------------------------------------- | :------------------------------ |
7936| [AudioStreamInfo](#audiostreaminfo8) | 返回流信息。 |
7937
7938**示例:**
7939
7940```ts
7941import { BusinessError } from '@kit.BasicServicesKit';
7942
7943try {
7944  let audioParamsGet: audio.AudioStreamInfo = audioCapturer.getStreamInfoSync();
7945  console.info(`sampleFormat: ${audioParamsGet.sampleFormat}`);
7946  console.info(`samplingRate: ${audioParamsGet.samplingRate}`);
7947  console.info(`channels: ${audioParamsGet.channels}`);
7948  console.info(`encodingType: ${audioParamsGet.encodingType}`);
7949} catch (err) {
7950  let error = err as BusinessError;
7951  console.error(`getStreamInfo :ERROR: ${error}`);
7952}
7953```
7954
7955### getAudioStreamId<sup>9+</sup>
7956
7957getAudioStreamId(callback: AsyncCallback<number\>): void
7958
7959获取音频流id,使用callback方式异步返回结果。
7960
7961**系统能力:** SystemCapability.Multimedia.Audio.Capturer
7962
7963**参数:**
7964
7965| 参数名   | 类型                                                 | 必填 | 说明                 |
7966| :------- | :--------------------------------------------------- | :--- | :------------------- |
7967| callback | AsyncCallback<number\> | 是   | 回调函数。当获取音频流id成功,err为undefined,data为获取到的音频流id;否则为错误对象。 |
7968
7969**示例:**
7970
7971```ts
7972import { BusinessError } from '@kit.BasicServicesKit';
7973
7974audioCapturer.getAudioStreamId((err: BusinessError, streamId: number) => {
7975  console.info(`audioCapturer GetStreamId: ${streamId}`);
7976});
7977```
7978
7979### getAudioStreamId<sup>9+</sup>
7980
7981getAudioStreamId(): Promise<number\>
7982
7983获取音频流id,使用Promise方式异步返回结果。
7984
7985**系统能力:** SystemCapability.Multimedia.Audio.Capturer
7986
7987**返回值:**
7988
7989| 类型             | 说明                   |
7990| :----------------| :--------------------- |
7991| Promise<number\> | Promise对象,返回音频流id。 |
7992
7993**示例:**
7994
7995```ts
7996import { BusinessError } from '@kit.BasicServicesKit';
7997
7998audioCapturer.getAudioStreamId().then((streamId: number) => {
7999  console.info(`audioCapturer getAudioStreamId: ${streamId}`);
8000}).catch((err: BusinessError) => {
8001  console.error(`ERROR: ${err}`);
8002});
8003```
8004
8005### getAudioStreamIdSync<sup>10+</sup>
8006
8007getAudioStreamIdSync(): number
8008
8009获取音频流id,同步返回结果。
8010
8011**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8012
8013**返回值:**
8014
8015| 类型             | 说明                   |
8016| :----------------| :--------------------- |
8017| number | 返回音频流id。 |
8018
8019**示例:**
8020
8021```ts
8022import { BusinessError } from '@kit.BasicServicesKit';
8023
8024try {
8025  let streamId: number = audioCapturer.getAudioStreamIdSync();
8026  console.info(`audioCapturer getAudioStreamIdSync: ${streamId}`);
8027} catch (err) {
8028  let error = err as BusinessError;
8029  console.error(`ERROR: ${error}`);
8030}
8031```
8032
8033### start<sup>8+</sup>
8034
8035start(callback: AsyncCallback<void\>): void
8036
8037启动音频采集器。使用callback方式异步返回结果。
8038
8039**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8040
8041**参数:**
8042
8043| 参数名   | 类型                 | 必填 | 说明                           |
8044| :------- | :------------------- | :--- | :----------------------------- |
8045| callback | AsyncCallback<void\> | 是   | Callback对象,成功表示启动音频采集器成功,异常将返回error对象:<br>错误码6800301,表示包含状态检查异常、焦点抢占失败、系统处理异常(具体错误查看系统日志)。 |
8046
8047**示例:**
8048
8049```ts
8050import { BusinessError } from '@kit.BasicServicesKit';
8051
8052audioCapturer.start((err: BusinessError) => {
8053  if (err) {
8054    console.error('Capturer start failed.');
8055  } else {
8056    console.info('Capturer start success.');
8057  }
8058});
8059```
8060
8061
8062### start<sup>8+</sup>
8063
8064start(): Promise<void\>
8065
8066启动音频采集器。使用Promise方式异步返回结果。
8067
8068**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8069
8070**返回值:**
8071
8072| 类型           | 说明                          |
8073| :------------- | :---------------------------- |
8074| Promise<void\> | Promise对象,成功表示启动音频采集器成功,异常将返回error对象:<br>错误码6800301,表示包含状态检查异常、焦点抢占失败、系统处理异常(具体错误查看系统日志)。 |
8075
8076**示例:**
8077
8078```ts
8079import { BusinessError } from '@kit.BasicServicesKit';
8080
8081audioCapturer.start().then(() => {
8082  console.info('AudioFrameworkRecLog: ---------START---------');
8083  console.info('AudioFrameworkRecLog: Capturer started: SUCCESS');
8084  console.info(`AudioFrameworkRecLog: AudioCapturer: STATE: ${audioCapturer.state}`);
8085  console.info('AudioFrameworkRecLog: Capturer started: SUCCESS');
8086  if ((audioCapturer.state == audio.AudioState.STATE_RUNNING)) {
8087    console.info('AudioFrameworkRecLog: AudioCapturer is in Running State');
8088  }
8089}).catch((err: BusinessError) => {
8090  console.error(`AudioFrameworkRecLog: Capturer start :ERROR : ${err}`);
8091});
8092```
8093
8094### stop<sup>8+</sup>
8095
8096stop(callback: AsyncCallback<void\>): void
8097
8098停止采集。使用callback方式异步返回结果。
8099
8100**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8101
8102**参数:**
8103
8104| 参数名   | 类型                 | 必填 | 说明                           |
8105| :------- | :------------------- | :--- | :----------------------------- |
8106| callback | AsyncCallback<void\> | 是   | 回调函数。当停止采集成功,err为undefined,否则为错误对象。 |
8107
8108**示例:**
8109
8110```ts
8111import { BusinessError } from '@kit.BasicServicesKit';
8112
8113audioCapturer.stop((err: BusinessError) => {
8114  if (err) {
8115    console.error('Capturer stop failed');
8116  } else {
8117    console.info('Capturer stopped.');
8118  }
8119});
8120```
8121
8122
8123### stop<sup>8+</sup>
8124
8125stop(): Promise<void\>
8126
8127停止采集。使用Promise方式异步返回结果。
8128
8129**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8130
8131**返回值:**
8132
8133| 类型           | 说明                          |
8134| :------------- | :---------------------------- |
8135| Promise<void\> | Promise对象,无返回结果。 |
8136
8137**示例:**
8138
8139```ts
8140import { BusinessError } from '@kit.BasicServicesKit';
8141
8142audioCapturer.stop().then(() => {
8143  console.info('AudioFrameworkRecLog: ---------STOP RECORD---------');
8144  console.info('AudioFrameworkRecLog: Capturer stopped: SUCCESS');
8145  if ((audioCapturer.state == audio.AudioState.STATE_STOPPED)){
8146    console.info('AudioFrameworkRecLog: State is Stopped:');
8147  }
8148}).catch((err: BusinessError) => {
8149  console.error(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
8150});
8151```
8152
8153### release<sup>8+</sup>
8154
8155release(callback: AsyncCallback<void\>): void
8156
8157释放采集器。使用callback方式异步返回结果。
8158
8159**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8160
8161**参数:**
8162
8163| 参数名   | 类型                 | 必填 | 说明                                |
8164| :------- | :------------------- | :--- | :---------------------------------- |
8165| callback | AsyncCallback<void\> | 是   | 回调函数。当释放采集器成功,err为undefined,否则为错误对象。 |
8166
8167**示例:**
8168
8169```ts
8170import { BusinessError } from '@kit.BasicServicesKit';
8171
8172audioCapturer.release((err: BusinessError) => {
8173  if (err) {
8174    console.error('capturer release failed');
8175  } else {
8176    console.info('capturer released.');
8177  }
8178});
8179```
8180
8181
8182### release<sup>8+</sup>
8183
8184release(): Promise<void\>
8185
8186释放采集器。使用Promise方式异步返回结果。
8187
8188**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8189
8190**返回值:**
8191
8192| 类型           | 说明                          |
8193| :------------- | :---------------------------- |
8194| Promise<void\> | Promise对象,无返回结果。 |
8195
8196**示例:**
8197
8198```ts
8199import { BusinessError } from '@kit.BasicServicesKit';
8200
8201audioCapturer.release().then(() => {
8202  console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
8203  console.info('AudioFrameworkRecLog: Capturer release : SUCCESS');
8204  console.info(`AudioFrameworkRecLog: AudioCapturer : STATE : ${audioCapturer.state}`);
8205}).catch((err: BusinessError) => {
8206  console.error(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
8207});
8208```
8209
8210### read<sup>8+(deprecated)</sup>
8211
8212read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void
8213
8214读入缓冲区。使用callback方式异步返回结果。
8215
8216> **说明:**
8217> 从 API version 8 开始支持,从 API version 11 开始废弃,建议使用AudioCapturer中的[on('readData')](#onreaddata11)替代。
8218
8219**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8220
8221**参数:**
8222
8223| 参数名         | 类型                        | 必填 | 说明                             |
8224| :------------- | :-------------------------- | :--- | :------------------------------- |
8225| size           | number                      | 是   | 读入的字节数。                   |
8226| isBlockingRead | boolean                     | 是   | 是否阻塞读操作 ,true阻塞,false不阻塞。                 |
8227| callback       | AsyncCallback<ArrayBuffer\> | 是   | 回调函数。当读入缓冲区成功,err为undefined,data为获取到的缓冲区;否则为错误对象。 |
8228
8229**示例:**
8230
8231```ts
8232import { BusinessError } from '@kit.BasicServicesKit';
8233
8234let bufferSize: number = 0;
8235
8236audioCapturer.getBufferSize().then((data: number) => {
8237  console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ${data}`);
8238  bufferSize = data;
8239}).catch((err: BusinessError) => {
8240  console.error(`AudioFrameworkRecLog: getBufferSize: ERROR: ${err}`);
8241});
8242
8243audioCapturer.read(bufferSize, true, (err: BusinessError, buffer: ArrayBuffer) => {
8244  if (!err) {
8245    console.info('Success in reading the buffer data');
8246  }
8247});
8248```
8249
8250### read<sup>8+(deprecated)</sup>
8251
8252read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
8253
8254读入缓冲区。使用Promise方式异步返回结果。
8255
8256> **说明:**
8257> 从 API version 8 开始支持,从 API version 11 开始废弃,建议使用AudioCapturer中的[on('readData')](#onreaddata11)替代。
8258
8259**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8260
8261**参数:**
8262
8263| 参数名         | 类型    | 必填 | 说明             |
8264| :------------- | :------ | :--- | :--------------- |
8265| size           | number  | 是   | 读入的字节数。   |
8266| isBlockingRead | boolean | 是   | 是否阻塞读操作 ,true阻塞,false不阻塞。 |
8267
8268**返回值:**
8269
8270| 类型                  | 说明                                                   |
8271| :-------------------- | :----------------------------------------------------- |
8272| Promise<ArrayBuffer\> | Promise对象,返回读取的缓冲区数据。 |
8273
8274**示例:**
8275
8276```ts
8277import { BusinessError } from '@kit.BasicServicesKit';
8278
8279let bufferSize: number = 0;
8280
8281audioCapturer.getBufferSize().then((data: number) => {
8282  console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ${data}`);
8283  bufferSize = data;
8284}).catch((err: BusinessError) => {
8285  console.error(`AudioFrameworkRecLog: getBufferSize: ERROR ${err}`);
8286});
8287console.info(`Buffer size: ${bufferSize}`);
8288
8289audioCapturer.read(bufferSize, true).then((buffer: ArrayBuffer) => {
8290  console.info('buffer read successfully');
8291}).catch((err: BusinessError) => {
8292  console.error(`ERROR : ${err}`);
8293});
8294```
8295
8296### getAudioTime<sup>8+</sup>
8297
8298getAudioTime(callback: AsyncCallback<number\>): void
8299
8300获取录制到当前位置时的时间戳(从1970年1月1日开始),单位为纳秒。使用callback方式异步返回结果。
8301
8302**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8303
8304**参数:**
8305
8306| 参数名   | 类型                   | 必填 | 说明                           |
8307| :------- | :--------------------- | :--- | :----------------------------- |
8308| callback | AsyncCallback<number\> | 是   | 回调函数。当获取时间戳成功,err为undefined,data为获取到的时间戳;否则为错误对象。 |
8309
8310**示例:**
8311
8312```ts
8313import { BusinessError } from '@kit.BasicServicesKit';
8314
8315audioCapturer.getAudioTime((err: BusinessError, timestamp: number) => {
8316  console.info(`Current timestamp: ${timestamp}`);
8317});
8318```
8319
8320### getAudioTime<sup>8+</sup>
8321
8322getAudioTime(): Promise<number\>
8323
8324获取录制到当前位置时的时间戳(从1970年1月1日开始),单位为纳秒。使用Promise方式异步返回结果。
8325
8326**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8327
8328**返回值:**
8329
8330| 类型             | 说明                          |
8331| :--------------- | :---------------------------- |
8332| Promise<number\> | Promise对象,返回时间戳(从1970年1月1日开始),单位为纳秒。 |
8333
8334**示例:**
8335
8336```ts
8337import { BusinessError } from '@kit.BasicServicesKit';
8338
8339audioCapturer.getAudioTime().then((audioTime: number) => {
8340  console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTime : Success ${audioTime}`);
8341}).catch((err: BusinessError) => {
8342  console.error(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
8343});
8344```
8345
8346### getAudioTimeSync<sup>10+</sup>
8347
8348getAudioTimeSync(): number
8349
8350获取录制到当前位置时的时间戳(从1970年1月1日开始),单位为纳秒。同步返回结果。
8351
8352**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8353
8354**返回值:**
8355
8356| 类型             | 说明                          |
8357| :--------------- | :---------------------------- |
8358| number | 返回时间戳。 |
8359
8360**示例:**
8361
8362```ts
8363import { BusinessError } from '@kit.BasicServicesKit';
8364
8365try {
8366  let audioTime: number = audioCapturer.getAudioTimeSync();
8367  console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTimeSync : Success ${audioTime}`);
8368} catch (err) {
8369  let error = err as BusinessError;
8370  console.error(`AudioFrameworkRecLog: AudioCapturer getAudioTimeSync : ERROR : ${error}`);
8371}
8372```
8373
8374### getBufferSize<sup>8+</sup>
8375
8376getBufferSize(callback: AsyncCallback<number\>): void
8377
8378获取采集器合理的最小缓冲区大小。使用callback方式异步返回结果。
8379
8380**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8381
8382**参数:**
8383
8384| 参数名   | 类型                   | 必填 | 说明                                 |
8385| :------- | :--------------------- | :--- | :----------------------------------- |
8386| callback | AsyncCallback<number\> | 是   | 回调函数。当获取采集器合理的最小缓冲区大小成功,err为undefined,data为获取到的采集器合理的最小缓冲区大小;否则为错误对象。 |
8387
8388**示例:**
8389
8390```ts
8391import { BusinessError } from '@kit.BasicServicesKit';
8392
8393audioCapturer.getBufferSize((err: BusinessError, bufferSize: number) => {
8394  if (!err) {
8395    console.info(`BufferSize : ${bufferSize}`);
8396    audioCapturer.read(bufferSize, true).then((buffer: ArrayBuffer) => {
8397      console.info(`Buffer read is ${buffer.byteLength}`);
8398    }).catch((err: BusinessError) => {
8399      console.error(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
8400    });
8401  }
8402});
8403```
8404
8405### getBufferSize<sup>8+</sup>
8406
8407getBufferSize(): Promise<number\>
8408
8409获取采集器合理的最小缓冲区大小。使用Promise方式异步返回结果。
8410
8411**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8412
8413**返回值:**
8414
8415| 类型             | 说明                                |
8416| :--------------- | :---------------------------------- |
8417| Promise<number\> | Promise对象,返回缓冲区大小。 |
8418
8419**示例:**
8420
8421```ts
8422import { BusinessError } from '@kit.BasicServicesKit';
8423
8424let bufferSize: number = 0;
8425
8426audioCapturer.getBufferSize().then((data: number) => {
8427  console.info(`AudioFrameworkRecLog: getBufferSize :SUCCESS ${data}`);
8428  bufferSize = data;
8429}).catch((err: BusinessError) => {
8430  console.error(`AudioFrameworkRecLog: getBufferSize :ERROR : ${err}`);
8431});
8432```
8433
8434### getBufferSizeSync<sup>10+</sup>
8435
8436getBufferSizeSync(): number
8437
8438获取采集器合理的最小缓冲区大小,同步返回结果。
8439
8440**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8441
8442**返回值:**
8443
8444| 类型             | 说明                                |
8445| :--------------- | :---------------------------------- |
8446| number | 返回缓冲区大小。 |
8447
8448**示例:**
8449
8450```ts
8451import { BusinessError } from '@kit.BasicServicesKit';
8452
8453let bufferSize: number = 0;
8454
8455try {
8456  bufferSize = audioCapturer.getBufferSizeSync();
8457  console.info(`AudioFrameworkRecLog: getBufferSizeSync :SUCCESS ${bufferSize}`);
8458} catch (err) {
8459  let error = err as BusinessError;
8460  console.error(`AudioFrameworkRecLog: getBufferSizeSync :ERROR : ${error}`);
8461}
8462```
8463
8464### getCurrentInputDevices<sup>11+</sup>
8465
8466getCurrentInputDevices(): AudioDeviceDescriptors
8467
8468获取录音流输入设备描述符。使用同步方式返回结果。
8469
8470**系统能力:** SystemCapability.Multimedia.Audio.Device
8471
8472**返回值:**
8473
8474| 类型                   | 说明                                                   |
8475| ---------------------- | ------------------------------------------------------ |
8476| [AudioDeviceDescriptors](#audiodevicedescriptors)            | 同步接口,返回设备属性数组类型数据。 |
8477
8478**示例:**
8479
8480```ts
8481let deviceDescriptors: audio.AudioDeviceDescriptors = audioCapturer.getCurrentInputDevices();
8482console.info(`Device id: ${deviceDescriptors[0].id}`);
8483console.info(`Device type: ${deviceDescriptors[0].deviceType}`);
8484console.info(`Device role: ${deviceDescriptors[0].deviceRole}`);
8485console.info(`Device name: ${deviceDescriptors[0].name}`);
8486console.info(`Device address: ${deviceDescriptors[0].address}`);
8487console.info(`Device samplerates: ${deviceDescriptors[0].sampleRates[0]}`);
8488console.info(`Device channelcounts: ${deviceDescriptors[0].channelCounts[0]}`);
8489console.info(`Device channelmask: ${deviceDescriptors[0].channelMasks[0]}`);
8490if (deviceDescriptors[0].encodingTypes) {
8491  console.info(`Device encodingTypes: ${deviceDescriptors[0].encodingTypes[0]}`);
8492}
8493```
8494
8495### getCurrentAudioCapturerChangeInfo<sup>11+</sup>
8496
8497getCurrentAudioCapturerChangeInfo(): AudioCapturerChangeInfo
8498
8499获取录音流配置。使用同步方式返回结果。
8500
8501**系统能力:** SystemCapability.Multimedia.Audio.Device
8502
8503**返回值:**
8504
8505| 类型             | 说明                                |
8506| :--------------- | :---------------------------------- |
8507| [AudioCapturerChangeInfo](#audiocapturerchangeinfo9) | 同步接口,返回描述音频采集器更改信息。 |
8508
8509**示例:**
8510
8511```ts
8512let info: audio.AudioCapturerChangeInfo = audioCapturer.getCurrentAudioCapturerChangeInfo();
8513console.info(`Info streamId: ${info.streamId}`);
8514console.info(`Info source: ${info.capturerInfo.source}`);
8515console.info(`Info capturerFlags: ${info.capturerInfo.capturerFlags}`);
8516console.info(`Info muted: ${info.muted}`);
8517console.info(`Info type: ${info.deviceDescriptors[0].deviceType}`);
8518console.info(`Info role: ${info.deviceDescriptors[0].deviceRole}`);
8519console.info(`Info name: ${info.deviceDescriptors[0].name}`);
8520console.info(`Info address: ${info.deviceDescriptors[0].address}`);
8521console.info(`Info samplerates: ${info.deviceDescriptors[0].sampleRates[0]}`);
8522console.info(`Info channelcounts: ${info.deviceDescriptors[0].channelCounts[0]}`);
8523console.info(`Info channelmask: ${info.deviceDescriptors[0].channelMasks[0]}`);
8524if (info.deviceDescriptors[0].encodingTypes) {
8525  console.info(`Device encodingTypes: ${info.deviceDescriptors[0].encodingTypes[0]}`);
8526}
8527```
8528
8529### on('audioInterrupt')<sup>10+</sup>
8530
8531on(type: 'audioInterrupt', callback: Callback\<InterruptEvent>): void
8532
8533监听音频中断事件(当音频焦点发生变化时触发),使用callback方式返回结果。
8534
8535AudioCapturer对象在start事件发生时会主动获取焦点,在pause、stop等事件发生时会主动释放焦点,不需要开发者主动发起获取焦点或释放焦点的申请。
8536
8537调用此方法,在AudioCapturer对象获取焦点失败或发生中断事件(如被其他音频打断等)时,会收到[InterruptEvent](#interruptevent9)。建议应用可根据InterruptEvent的信息完成进一步处理,更多信息可参考文档[处理音频焦点事件](../../media/audio/audio-playback-concurrency.md)。
8538
8539**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
8540
8541**参数:**
8542
8543| 参数名   | 类型                                         | 必填 | 说明                                                         |
8544| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
8545| type     | string                                       | 是   | 监听事件,固定为:'audioInterrupt'。 |
8546| callback | Callback\<[InterruptEvent](#interruptevent9)\> | 是   | 回调函数,返回录制中断时,应用接收的中断事件信息。 |
8547
8548**错误码:**
8549
8550以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
8551
8552| 错误码ID | 错误信息 |
8553| ------- | --------------------------------------------|
8554| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
8555| 6800101 | Parameter verification failed. |
8556
8557**示例:**
8558
8559```ts
8560import { audio } from '@kit.AudioKit';
8561
8562let isCapturing: boolean; // 标识符,表示是否正在采集
8563onAudioInterrupt();
8564
8565async function onAudioInterrupt(){
8566  audioCapturer.on('audioInterrupt', (interruptEvent: audio.InterruptEvent) => {
8567    // 在发生音频打断事件时,audioCapturer收到interruptEvent回调,此处根据其内容做相应处理。
8568    // 1、可选:读取interruptEvent.forceType的类型,判断系统是否已强制执行相应操作。
8569    // 注:默认焦点策略下,INTERRUPT_HINT_RESUME为INTERRUPT_SHARE类型,其余hintType均为INTERRUPT_FORCE类型。因此对forceType可不做判断。
8570    // 2、必选:读取interruptEvent.hintType的类型,做出相应的处理。
8571    if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
8572      // 音频焦点事件已由系统强制执行,应用需更新自身状态及显示内容等
8573      switch (interruptEvent.hintType) {
8574        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
8575          // 音频流已被暂停,临时失去焦点,待可重获焦点时会收到resume对应的interruptEvent
8576          console.info('Force paused. Update capturing status and stop reading');
8577          isCapturing = false; // 简化处理,代表应用切换至暂停状态的若干操作
8578          break;
8579        case audio.InterruptHint.INTERRUPT_HINT_STOP:
8580          // 音频流已被停止,永久失去焦点,若想恢复采集,需用户主动触发
8581          console.info('Force stopped. Update capturing status and stop reading');
8582          isCapturing = false; // 简化处理,代表应用切换至暂停状态的若干操作
8583          break;
8584        default:
8585          console.info('Invalid interruptEvent');
8586          break;
8587      }
8588    } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
8589      // 音频焦点事件需由应用进行操作,应用可以自主选择如何处理该事件,建议应用遵从InterruptHint提示处理
8590      switch (interruptEvent.hintType) {
8591        case audio.InterruptHint.INTERRUPT_HINT_RESUME:
8592          // 建议应用继续采集(说明音频流此前被强制暂停,临时失去焦点,现在可以恢复采集)
8593          // 由于INTERRUPT_HINT_RESUME操作需要应用主动执行,系统无法强制,故INTERRUPT_HINT_RESUME事件一定为INTERRUPT_SHARE类型
8594          console.info('Resume force paused renderer or ignore');
8595          // 若选择继续采集,需在此处主动执行开始采集的若干操作
8596          break;
8597        default:
8598          console.info('Invalid interruptEvent');
8599          break;
8600      }
8601    }
8602  });
8603}
8604```
8605
8606### off('audioInterrupt')<sup>10+</sup>
8607
8608off(type: 'audioInterrupt'): void
8609
8610取消监听音频中断事件。
8611
8612**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
8613
8614**参数:**
8615
8616| 参数名   | 类型                                         | 必填 | 说明                                                         |
8617| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
8618| type     | string                                       | 是   | 监听事件,固定为:'audioInterrupt'。 |
8619
8620**错误码:**
8621
8622以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
8623
8624| 错误码ID | 错误信息 |
8625| ------- | --------------------------------------------|
8626| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
8627| 6800101 | Parameter verification failed. |
8628
8629**示例:**
8630
8631```ts
8632audioCapturer.off('audioInterrupt');
8633```
8634
8635### on('inputDeviceChange')<sup>11+</sup>
8636
8637on(type: 'inputDeviceChange', callback: Callback\<AudioDeviceDescriptors>): void
8638
8639监听音频输入设备变化事件(当音频输入设备发生变化时触发),使用callback方式返回结果。
8640
8641**系统能力:** SystemCapability.Multimedia.Audio.Device
8642
8643**参数:**
8644
8645| 参数名   | 类型                       | 必填 | 说明                                        |
8646| :------- | :------------------------- | :--- | :------------------------------------------ |
8647| type     | string                     | 是   | 监听事件,固定为:'inputDeviceChange'。 |
8648| callback | Callback\<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 是   | 回调函数,返回监听的音频输入设备变化(返回数据为切换后的设备信息)。 |
8649
8650**错误码:**
8651
8652以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
8653
8654| 错误码ID | 错误信息 |
8655| ------- | --------------------------------------------|
8656| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
8657| 6800101 | Parameter verification failed. |
8658
8659**示例:**
8660
8661```ts
8662audioCapturer.on('inputDeviceChange', (deviceChangeInfo: audio.AudioDeviceDescriptors) => {
8663  console.info(`inputDevice id: ${deviceChangeInfo[0].id}`);
8664  console.info(`inputDevice deviceRole: ${deviceChangeInfo[0].deviceRole}`);
8665  console.info(`inputDevice deviceType: ${deviceChangeInfo[0].deviceType}`);
8666});
8667```
8668### off('inputDeviceChange')<sup>11+</sup>
8669
8670off(type: 'inputDeviceChange', callback?: Callback\<AudioDeviceDescriptors>): void
8671
8672取消监听音频输入设备更改事件,使用callback方式返回结果。
8673
8674**系统能力:** SystemCapability.Multimedia.Audio.Device
8675
8676**参数:**
8677
8678| 参数名   | 类型                       | 必填 | 说明                                       |
8679| :------- | :------------------------- | :--- |:-----------------------------------------|
8680| type     | string                     | 是   | 监听事件,固定为:'inputDeviceChange'。       |
8681| callback | Callback\<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 否   | 回调函数,返回监听的音频输入设备信息。 |
8682
8683**错误码:**
8684
8685以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
8686
8687| 错误码ID | 错误信息 |
8688| ------- | --------------------------------------------|
8689| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
8690| 6800101 | Parameter verification failed. |
8691
8692**示例:**
8693
8694```ts
8695// 取消该事件的所有监听
8696audioCapturer.off('inputDeviceChange');
8697
8698// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
8699let inputDeviceChangeCallback = (deviceChangeInfo: audio.AudioDeviceDescriptors) => {
8700  console.info(`inputDevice id: ${deviceChangeInfo[0].id}`);
8701  console.info(`inputDevice deviceRole: ${deviceChangeInfo[0].deviceRole}`);
8702  console.info(`inputDevice deviceType: ${deviceChangeInfo[0].deviceType}`);
8703};
8704
8705audioCapturer.on('inputDeviceChange', inputDeviceChangeCallback);
8706
8707audioCapturer.off('inputDeviceChange', inputDeviceChangeCallback);
8708```
8709
8710### on('audioCapturerChange')<sup>11+</sup>
8711
8712on(type: 'audioCapturerChange', callback: Callback\<AudioCapturerChangeInfo>): void
8713
8714监听录音流配置变化事件(当音频录制流状态变化、设备变化时触发),使用callback方式返回结果。订阅内部是异步实现,是非精确回调,在录音流配置变化的同时注册回调,收到的返回结果存在变化可能性。
8715
8716**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8717
8718**参数:**
8719
8720| 参数名   | 类型                       | 必填 | 说明                                        |
8721| :------- | :------------------------- | :--- | :------------------------------------------ |
8722| type     | string                     | 是   | 监听事件,固定为:'audioCapturerChange'。 |
8723| callback | Callback\<[AudioCapturerChangeInfo](#audiocapturerchangeinfo9)> | 是   | 回调函数,录音流配置或状态变化时返回监听的录音流当前配置和状态信息。 |
8724
8725**错误码:**
8726
8727以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
8728
8729| 错误码ID | 错误信息 |
8730| ------- | --------------------------------------------|
8731| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
8732| 6800101 | Parameter verification failed. |
8733
8734**示例:**
8735
8736```ts
8737audioCapturer.on('audioCapturerChange', (capturerChangeInfo: audio.AudioCapturerChangeInfo) => {
8738  console.info(`audioCapturerChange id: ${capturerChangeInfo[0].id}`);
8739  console.info(`audioCapturerChange deviceRole: ${capturerChangeInfo[0].deviceRole}`);
8740  console.info(`audioCapturerChange deviceType: ${capturerChangeInfo[0].deviceType}`);
8741});
8742```
8743
8744### off('audioCapturerChange')<sup>11+</sup>
8745
8746off(type: 'audioCapturerChange', callback?: Callback\<AudioCapturerChangeInfo>): void
8747
8748取消监听录音流配置变化事件,使用callback方式返回结果。
8749
8750**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8751
8752**参数:**
8753
8754| 参数名   | 类型                       | 必填 | 说明                                        |
8755| :------- | :------------------------- | :--- | :------------------------------------------ |
8756| type     | string                     | 是   | 监听事件,固定为:'audioCapturerChange'。 |
8757| callback | Callback\<[AudioCapturerChangeInfo](#audiocapturerchangeinfo9)> | 否   | 回调函数,返回取消监听的录音流配置或状态变化。 |
8758
8759**错误码:**
8760
8761以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
8762
8763| 错误码ID | 错误信息 |
8764| ------- | --------------------------------------------|
8765| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
8766| 6800101 | Parameter verification failed. |
8767
8768**示例:**
8769
8770```ts
8771// 取消该事件的所有监听
8772audioCapturer.off('audioCapturerChange');
8773
8774// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
8775let audioCapturerChangeCallback = (capturerChangeInfo: audio.AudioCapturerChangeInfo) => {
8776  console.info(`audioCapturerChange id: ${capturerChangeInfo[0].id}`);
8777  console.info(`audioCapturerChange deviceRole: ${capturerChangeInfo[0].deviceRole}`);
8778  console.info(`audioCapturerChange deviceType: ${capturerChangeInfo[0].deviceType}`);
8779};
8780
8781audioCapturer.on('audioCapturerChange', audioCapturerChangeCallback);
8782
8783audioCapturer.off('audioCapturerChange', audioCapturerChangeCallback);
8784```
8785
8786### on('markReach')<sup>8+</sup>
8787
8788on(type: 'markReach', frame: number, callback: Callback&lt;number&gt;): void
8789
8790监听标记到达事件(当采集的帧数达到frame参数的值时触发,仅调用一次),使用callback方式返回结果。
8791
8792举例说明,如果frame设置为100,当采集帧数到达第100帧时,将上报信息。
8793
8794**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8795
8796**参数:**
8797
8798| 参数名   | 类型                     | 必填 | 说明                                       |
8799| :------- | :----------------------  | :--- | :----------------------------------------- |
8800| type     | string                   | 是   | 监听事件,固定为:'markReach'。  |
8801| frame    | number                   | 是   | 触发事件的帧数。该值必须大于0。           |
8802| callback | Callback\<number>         | 是   | 回调函数,返回frame参数的值。 |
8803
8804**示例:**
8805
8806```ts
8807audioCapturer.on('markReach', 1000, (position: number) => {
8808  if (position == 1000) {
8809    console.info('ON Triggered successfully');
8810  }
8811});
8812```
8813
8814### off('markReach')<sup>8+</sup>
8815
8816off(type: 'markReach'): void
8817
8818取消监听标记到达事件。
8819
8820**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8821
8822**参数:**
8823
8824| 参数名 | 类型   | 必填 | 说明                                          |
8825| :----- | :----- | :--- | :-------------------------------------------- |
8826| type   | string | 是   | 监听事件,固定为:'markReach'。 |
8827
8828**示例:**
8829
8830```ts
8831audioCapturer.off('markReach');
8832```
8833
8834### on('periodReach')<sup>8+</sup>
8835
8836on(type: 'periodReach', frame: number, callback: Callback&lt;number&gt;): void
8837
8838监听到达标记事件(当采集的帧数达到frame参数的值时触发,即按周期上报信息),使用callback方式返回结果。
8839
8840举例说明,如果frame设置为10,每当采集10帧数据时将上报信息,例如在第10帧、20帧、30帧,均会上报信息。
8841
8842**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8843
8844**参数:**
8845
8846| 参数名   | 类型                     | 必填 | 说明                                        |
8847| :------- | :----------------------- | :--- | :------------------------------------------ |
8848| type     | string                   | 是   | 监听事件,固定为:'periodReach'。 |
8849| frame    | number                   | 是   | 触发事件的帧数。该值必须大于0。            |
8850| callback | Callback\<number>         | 是   |回调函数,返回frame参数的值。    |
8851
8852**示例:**
8853
8854```ts
8855audioCapturer.on('periodReach', 1000, (position: number) => {
8856  if (position == 1000) {
8857    console.info('ON Triggered successfully');
8858  }
8859});
8860```
8861
8862### off('periodReach')<sup>8+</sup>
8863
8864off(type: 'periodReach'): void
8865
8866取消监听标记到达事件。
8867
8868**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8869
8870**参数:**
8871
8872| 参数名 | 类型   | 必填 | 说明                                            |
8873| :----- | :----- | :--- | :---------------------------------------------- |
8874| type   | string | 是  | 监听事件,固定为:'periodReach'。 |
8875
8876**示例:**
8877
8878```ts
8879audioCapturer.off('periodReach');
8880```
8881
8882### on('stateChange')<sup>8+</sup>
8883
8884on(type: 'stateChange', callback: Callback<AudioState\>): void
8885
8886监听状态变化事件(当AudioCapturer状态发生变化时触发),使用callback方式返回结果。
8887
8888**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8889
8890**参数:**
8891
8892| 参数名   | 类型                       | 必填 | 说明                                        |
8893| :------- | :------------------------- | :--- | :------------------------------------------ |
8894| type     | string                     | 是   | 监听事件,固定为:'stateChange'。 |
8895| callback | Callback\<[AudioState](#audiostate8)> | 是   | 回调函数,返回当前音频的状态。 |
8896
8897**示例:**
8898
8899```ts
8900audioCapturer.on('stateChange', (state: audio.AudioState) => {
8901  if (state == 1) {
8902    console.info('audio capturer state is: STATE_PREPARED');
8903  }
8904  if (state == 2) {
8905    console.info('audio capturer state is: STATE_RUNNING');
8906  }
8907});
8908```
8909
8910### on('readData')<sup>11+</sup>
8911
8912on(type: 'readData', callback: Callback\<ArrayBuffer>): void
8913
8914监听音频数据读入回调事件(当需要读取音频流数据时触发),使用callback方式返回结果。
8915
8916**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8917
8918**参数:**
8919
8920| 参数名   | 类型                     | 必填 | 说明                        |
8921| :------- |:-----------------------| :--- |:--------------------------|
8922| type     | string                 | 是   | 监听事件,固定为:'readData'。 |
8923| callback | Callback\<ArrayBuffer> | 是   | 回调函数,返回读到的数据缓冲区。            |
8924
8925**错误码:**
8926
8927以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
8928
8929| 错误码ID | 错误信息 |
8930| ------- | --------------------------------------------|
8931| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
8932| 6800101 | Parameter verification failed. |
8933
8934**示例:**
8935
8936```ts
8937import { BusinessError } from '@kit.BasicServicesKit';
8938import { fileIo as fs } from '@kit.CoreFileKit';
8939
8940class Options {
8941  offset?: number;
8942  length?: number;
8943}
8944
8945let bufferSize: number = 0;
8946let path = getContext().cacheDir;
8947// 确保该沙箱路径下存在该资源
8948let filePath = path + '/StarWars10s-2C-48000-4SW.pcm';
8949let file: fs.File = fs.openSync(filePath, fs.OpenMode.READ_WRITE);
8950let readDataCallback = (buffer: ArrayBuffer) => {
8951  let options: Options = {
8952    offset: bufferSize,
8953    length: buffer.byteLength
8954  };
8955  fs.writeSync(file.fd, buffer, options);
8956  bufferSize += buffer.byteLength;
8957}
8958
8959audioCapturer.on('readData', readDataCallback);
8960
8961audioCapturer.start((err: BusinessError) => {
8962  if (err) {
8963    console.error('Capturer start failed.');
8964  } else {
8965    console.info('Capturer start success.');
8966  }
8967});
8968```
8969
8970### off('readData')<sup>11+</sup>
8971
8972off(type: 'readData', callback?: Callback\<ArrayBuffer>): void
8973
8974取消监听音频数据读入回调事件,使用callback方式返回结果。
8975
8976**系统能力:** SystemCapability.Multimedia.Audio.Capturer
8977
8978**参数:**
8979
8980| 参数名   | 类型                     | 必填 | 说明                                         |
8981| :------- |:-----------------------| :--- |:-------------------------------------------|
8982| type     | string                 | 是   | 监听事件,固定为:'readData'。                 |
8983| callback | Callback\<ArrayBuffer> | 否   | 回调函数,返回读到的数据缓冲区。                            |
8984
8985**错误码:**
8986
8987以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
8988
8989| 错误码ID | 错误信息 |
8990| ------- | --------------------------------------------|
8991| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
8992| 6800101 | Parameter verification failed. |
8993
8994**示例:**
8995
8996```ts
8997// 取消该事件的所有监听
8998audioCapturer.off('readData');
8999
9000// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听
9001let readDataCallback = (data: ArrayBuffer) => {
9002    console.info(`read data: ${data}`);
9003};
9004
9005audioCapturer.on('readData', readDataCallback);
9006
9007audioCapturer.off('readData', readDataCallback);
9008```
9009
9010### getOverflowCount<sup>12+</sup>
9011
9012getOverflowCount(): Promise&lt;number&gt;
9013
9014获取当前录制音频流的过载音频帧数量。使用Promise异步回调。
9015
9016**系统能力:** SystemCapability.Multimedia.Audio.Capturer
9017
9018**返回值:**
9019
9020| 类型                | 说明                          |
9021| ------------------- | ----------------------------- |
9022| Promise&lt;number&gt;| Promise对象,返回音频流的过载音频帧数量。|
9023
9024**示例:**
9025
9026```ts
9027import { BusinessError } from '@kit.BasicServicesKit';
9028
9029audioCapturer.getOverflowCount().then((value: number) => {
9030  console.info(`Get overflow count Success! ${value}`);
9031}).catch((err: BusinessError) => {
9032  console.error(`Get overflow count Fail: ${err}`);
9033});
9034```
9035
9036### getOverflowCountSync<sup>12+</sup>
9037
9038getOverflowCountSync(): number
9039
9040获取当前录制音频流的过载音频帧数量,同步返回数据。
9041
9042**系统能力:** SystemCapability.Multimedia.Audio.Capturer
9043
9044**返回值:**
9045
9046| 类型                | 说明                          |
9047| ------------------- | ----------------------------- |
9048| number| 返回音频流的过载音频帧数量。|
9049
9050**示例:**
9051
9052```ts
9053import { BusinessError } from '@kit.BasicServicesKit';
9054
9055try {
9056  let value: number = audioCapturer.getOverflowCountSync();
9057  console.info(`Get overflow count Success! ${value}`);
9058} catch (err) {
9059  let error = err as BusinessError;
9060  console.error(`Get overflow count Fail: ${error}`);
9061}
9062```
9063
9064## ActiveDeviceType<sup>(deprecated)</sup>
9065
9066枚举,活跃设备类型。
9067
9068> **说明:**
9069>
9070> 从 API version 9 开始废弃,建议使用[CommunicationDeviceType](#communicationdevicetype9)替代。
9071
9072**系统能力:** SystemCapability.Multimedia.Audio.Device
9073
9074| 名称          |  值     | 说明                                                 |
9075| ------------- | ------ | ---------------------------------------------------- |
9076| SPEAKER       | 2      | 扬声器。                                             |
9077| BLUETOOTH_SCO | 7      | 蓝牙设备SCO(Synchronous Connection Oriented)连接。 |
9078
9079## InterruptActionType<sup>(deprecated)</sup>
9080
9081枚举,中断事件返回类型。
9082
9083> **说明:**
9084>
9085> 从 API version 7 开始支持,从 API version 9 开始废弃。无替代接口,与中断事件配套使用。
9086
9087**系统能力:** SystemCapability.Multimedia.Audio.Renderer
9088
9089| 名称           |  值     | 说明               |
9090| -------------- | ------ | ------------------ |
9091| TYPE_ACTIVATED | 0      | 表示触发焦点事件。 |
9092| TYPE_INTERRUPT | 1      | 表示音频打断事件。 |
9093
9094## AudioInterrupt<sup>(deprecated)</sup>
9095
9096音频监听事件传入的参数。
9097
9098> **说明:**
9099>
9100> 从 API version 7 开始支持,从 API version 9 开始废弃。无替代接口,与中断事件配套使用。
9101
9102**系统能力:** SystemCapability.Multimedia.Audio.Renderer
9103
9104| 名称            | 类型                        | 必填 | 说明                                                         |
9105| --------------- | --------------------------- | ----| ------------------------------------------------------------ |
9106| streamUsage     | [StreamUsage](#streamusage) | 是  | 音频流使用类型。                                             |
9107| contentType     | [ContentType](#contenttypedeprecated) | 是  | 音频打断媒体类型。                                           |
9108| pauseWhenDucked | boolean                     | 是  | 音频打断时是否可以暂停音频播放(true表示音频播放可以在音频打断期间暂停,false表示相反)。 |
9109
9110## InterruptAction<sup>(deprecated)</sup>
9111
9112音频打断/获取焦点事件的回调方法。
9113
9114> **说明:**
9115>
9116> 从 API version 7 开始支持,从 API version 9 开始废弃。建议使用[InterruptEvent](#interruptevent9)替代。
9117
9118**系统能力:** SystemCapability.Multimedia.Audio.Renderer
9119
9120| 名称       | 类型                                        | 必填 | 说明                                                         |
9121| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
9122| actionType | [InterruptActionType](#interruptactiontypedeprecated) | 是   | 事件返回类型。TYPE_ACTIVATED为焦点触发事件,TYPE_INTERRUPT为音频打断事件。 |
9123| type       | [InterruptType](#interrupttype)             | 否   | 打断事件类型。                                               |
9124| hint       | [InterruptHint](#interrupthint)             | 否   | 打断事件提示。                                               |
9125| activated  | boolean                                     | 否   | 获得/释放焦点。true表示焦点获取/释放成功,false表示焦点获得/释放失败。 |
9126