• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Interface (AudioRoutingManager)
2<!--Kit: Audio Kit-->
3<!--Subsystem: Multimedia-->
4<!--Owner: @songshenke-->
5<!--Designer: @caixuejiang; @hao-liangfei; @zhanganxiang-->
6<!--Tester: @Filger-->
7<!--Adviser: @zengyawen-->
8
9> **说明:**
10>
11> - 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
12> - 本Interface首批接口从API version 9开始支持。
13
14音频路由管理。
15
16在使用AudioRoutingManager的接口之前,需先通过[getRoutingManager](arkts-apis-audio-AudioManager.md#getroutingmanager9)获取AudioRoutingManager实例。
17
18## 导入模块
19
20```ts
21import { audio } from '@kit.AudioKit';
22```
23
24## getDevices<sup>9+</sup>
25
26getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
27
28获取音频设备列表。使用callback异步回调。
29
30**系统能力:** SystemCapability.Multimedia.Audio.Device
31
32**参数:**
33
34| 参数名     | 类型                                                         | 必填 | 说明                 |
35| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
36| deviceFlag | [DeviceFlag](arkts-apis-audio-e.md#deviceflag)                                    | 是   | 音频设备类型。     |
37| callback   | AsyncCallback&lt;[AudioDeviceDescriptors](arkts-apis-audio-t.md#audiodevicedescriptors)&gt; | 是   | 回调函数。当获取音频设备列表成功,err为undefined,data为获取到的音频设备列表;否则为错误对象。 |
38
39**示例:**
40
41```ts
42import { BusinessError } from '@kit.BasicServicesKit';
43
44audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err: BusinessError, audioDeviceDescriptors: audio.AudioDeviceDescriptors) => {
45  if (err) {
46    console.error(`Failed to get devices. Code: ${err.code}, message: ${err.message}`);
47  } else {
48    console.info(`Succeeded in getting devices, AudioDeviceDescriptors: ${JSON.stringify(audioDeviceDescriptors)}.`);
49  }
50});
51```
52
53## getDevices<sup>9+</sup>
54
55getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
56
57获取音频设备列表。使用Promise异步回调。
58
59**系统能力:** SystemCapability.Multimedia.Audio.Device
60
61**参数:**
62
63| 参数名     | 类型                      | 必填 | 说明             |
64| ---------- | ------------------------- | ---- | ---------------- |
65| deviceFlag | [DeviceFlag](arkts-apis-audio-e.md#deviceflag) | 是   | 音频设备类型。 |
66
67**返回值:**
68
69| 类型                                                         | 说明                      |
70| ------------------------------------------------------------ | ------------------------- |
71| Promise&lt;[AudioDeviceDescriptors](arkts-apis-audio-t.md#audiodevicedescriptors)&gt; | Promise对象,返回设备列表。 |
72
73**示例:**
74
75```ts
76import { BusinessError } from '@kit.BasicServicesKit';
77
78audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((audioDeviceDescriptors: audio.AudioDeviceDescriptors) => {
79  console.info(`Succeeded in getting devices, AudioDeviceDescriptors: ${JSON.stringify(audioDeviceDescriptors)}.`);
80}).catch((err: BusinessError) => {
81  console.error(`Failed to get devices. Code: ${err.code}, message: ${err.message}`);
82});
83```
84
85## getDevicesSync<sup>10+</sup>
86
87getDevicesSync(deviceFlag: DeviceFlag): AudioDeviceDescriptors
88
89获取音频设备列表。同步返回结果。
90
91**系统能力:** SystemCapability.Multimedia.Audio.Device
92
93**参数:**
94
95| 参数名     | 类型                      | 必填 | 说明             |
96| ---------- | ------------------------- | ---- | ---------------- |
97| deviceFlag | [DeviceFlag](arkts-apis-audio-e.md#deviceflag) | 是   | 音频设备类型。 |
98
99**返回值:**
100
101| 类型                                                         | 说明                      |
102| ------------------------------------------------------------ | ------------------------- |
103| [AudioDeviceDescriptors](arkts-apis-audio-t.md#audiodevicedescriptors) | 返回设备列表。 |
104
105**错误码:**
106
107以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
108
109| 错误码ID | 错误信息 |
110| ------- | --------------------------------------------|
111| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
112| 6800101 | Parameter verification failed. |
113
114**示例:**
115
116```ts
117import { BusinessError } from '@kit.BasicServicesKit';
118
119try {
120  let audioDeviceDescriptors = audioRoutingManager.getDevicesSync(audio.DeviceFlag.OUTPUT_DEVICES_FLAG);
121  console.info(`Succeeded in getting devices, AudioDeviceDescriptors: ${JSON.stringify(audioDeviceDescriptors)}.`);
122} catch (err) {
123  let error = err as BusinessError;
124  console.error(`Failed to get devices. Code: ${error.code}, message: ${error.message}`);
125}
126```
127
128## isMicBlockDetectionSupported<sup>13+</sup>
129
130isMicBlockDetectionSupported(): Promise&lt;boolean&gt;
131
132获取当前设备是否支持麦克风状态检测。使用Promise异步回调。
133
134**系统能力:** SystemCapability.Multimedia.Audio.Device
135
136**返回值:**
137
138| 类型                   | 说明                                                         |
139| ---------------------- | ------------------------------------------------------------ |
140| Promise&lt;boolean&gt; | Promise对象。返回true表示支持;返回false表示不支持。 |
141
142**示例:**
143
144```ts
145audioRoutingManager.isMicBlockDetectionSupported().then((value: boolean) => {
146  console.info(`Query whether microphone block detection is supported on current device result is ${value}.`);
147});
148```
149
150## on('micBlockStatusChanged')<sup>13+</sup>
151
152on(type: 'micBlockStatusChanged', callback: Callback<DeviceBlockStatusInfo\>): void
153
154监听麦克风堵塞状态变化事件。使用callback异步回调。
155
156使用此功能前,请查询设备是否支持检测。应用在使用麦克风录音时,若麦克风堵塞状态发生变化,将触发该事件。目前此检测功能仅支持麦克风位于本地设备上。
157
158**系统能力:** SystemCapability.Multimedia.Audio.Device
159
160**参数:**
161
162| 参数名   | 类型                                                 | 必填 | 说明                                       |
163| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
164| type     | string                                               | 是   | 事件回调类型,支持的事件为'micBlockStatusChanged',当麦克风堵塞状态发生变化时,触发该事件。 |
165| callback | Callback<[DeviceBlockStatusInfo](arkts-apis-audio-i.md#deviceblockstatusinfo13)\> | 是   | 回调函数,返回麦克风被堵塞状态和设备信息。 |
166
167**错误码:**
168
169以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
170
171| 错误码ID | 错误信息 |
172| ------- | --------------------------------------------|
173| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
174| 6800101 | Parameter verification failed. |
175
176**示例:**
177
178```ts
179// 在使用此功能之前,应先查询当前设备是否支持检测。
180audioRoutingManager.isMicBlockDetectionSupported().then((value: boolean) => {
181  console.info(`Query whether microphone block detection is supported on current device result is ${value}.`);
182  if (value) {
183    audioRoutingManager.on('micBlockStatusChanged', (micBlockStatusChanged: audio.DeviceBlockStatusInfo) => {
184      console.info(`block status : ${micBlockStatusChanged.blockStatus} `);
185    });
186  }
187});
188```
189
190## off('micBlockStatusChanged')<sup>13+</sup>
191
192off(type: 'micBlockStatusChanged', callback?: Callback<DeviceBlockStatusInfo\>): void
193
194取消监听麦克风堵塞状态变化事件。使用callback异步回调。
195
196**系统能力:** SystemCapability.Multimedia.Audio.Device
197
198**参数:**
199
200| 参数名   | 类型                                                | 必填 | 说明                                       |
201| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
202| type     | string                                              | 是   | 事件回调类型,支持的事件为'micBlockStatusChanged',当取消监听音频麦克风是否被堵塞变化事件时,触发该事件。 |
203| callback | Callback<[DeviceBlockStatusInfo](arkts-apis-audio-i.md#deviceblockstatusinfo13)\> | 否   | 回调函数,返回麦克风被堵塞状态和设备信息。|
204
205**错误码:**
206
207以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
208
209| 错误码ID | 错误信息 |
210| ------- | --------------------------------------------|
211| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
212| 6800101 | Parameter verification failed. |
213
214**示例:**
215
216```ts
217// 取消该事件的所有监听。
218audioRoutingManager.off('micBlockStatusChanged');
219
220// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听。
221let micBlockStatusCallback = (micBlockStatusChanged: audio.DeviceBlockStatusInfo) => {
222  console.info(`block status : ${micBlockStatusChanged.blockStatus} `);
223};
224
225audioRoutingManager.on('micBlockStatusChanged', micBlockStatusCallback);
226
227audioRoutingManager.off('micBlockStatusChanged', micBlockStatusCallback);
228```
229
230## on('deviceChange')<sup>9+</sup>
231
232on(type: 'deviceChange', deviceFlag: DeviceFlag, callback: Callback<DeviceChangeAction\>): void
233
234监听音频设备连接状态变化事件(当音频设备连接状态发生变化时触发)。使用callback异步回调。
235
236**系统能力:** SystemCapability.Multimedia.Audio.Device
237
238**参数:**
239
240| 参数名   | 类型                                                 | 必填 | 说明                      |
241| :------- | :--------------------------------------------------- | :--- |:------------------------|
242| type     | string                                               | 是   | 事件回调类型,支持的事件为'deviceChange',当音频设备连接状态发生变化时,触发该事件。 |
243| deviceFlag | [DeviceFlag](arkts-apis-audio-e.md#deviceflag)                                    | 是   | 音频设备类型。              |
244| callback | Callback<[DeviceChangeAction](arkts-apis-audio-i.md#devicechangeaction)\> | 是   | 回调函数,返回设备更新详情。          |
245
246**错误码:**
247
248以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
249
250| 错误码ID | 错误信息 |
251| ------- | --------------------------------------------|
252| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
253| 6800101 | Parameter verification failed. |
254
255**示例:**
256
257```ts
258audioRoutingManager.on('deviceChange', audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (deviceChanged: audio.DeviceChangeAction) => {
259  console.info('device change type : ' + deviceChanged.type);
260  console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
261  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole);
262  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType);
263});
264```
265
266## off('deviceChange')<sup>9+</sup>
267
268off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void
269
270取消监听音频设备连接状态变化事件。使用callback异步回调。
271
272**系统能力:** SystemCapability.Multimedia.Audio.Device
273
274**参数:**
275
276| 参数名   | 类型                                                | 必填 | 说明                                       |
277| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
278| type     | string                                              | 是   | 事件回调类型,支持的事件为'deviceChange',当取消监听音频设备连接变化事件时,触发该事件。 |
279| callback | Callback<[DeviceChangeAction](arkts-apis-audio-i.md#devicechangeaction)> | 否   | 回调函数,返回设备更新详情。 |
280
281**错误码:**
282
283以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
284
285| 错误码ID | 错误信息 |
286| ------- | --------------------------------------------|
287| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
288| 6800101 | Parameter verification failed. |
289
290**示例:**
291
292```ts
293// 取消该事件的所有监听。
294audioRoutingManager.off('deviceChange');
295
296// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听。
297let deviceChangeCallback = (deviceChanged: audio.DeviceChangeAction) => {
298  console.info('device change type : ' + deviceChanged.type);
299  console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
300  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole);
301  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType);
302};
303
304audioRoutingManager.on('deviceChange', audio.DeviceFlag.OUTPUT_DEVICES_FLAG, deviceChangeCallback);
305
306audioRoutingManager.off('deviceChange', deviceChangeCallback);
307```
308
309## setCommunicationDevice<sup>9+</sup>
310
311setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
312
313设置通信设备激活状态。使用callback异步回调。
314
315该接口由于功能设计变化,将在后续版本废弃,不建议开发者使用。
316
317推荐使用AVSession提供的[设备切换组件](../../media/avsession/using-switch-call-devices.md),实现通话设备切换。
318
319**系统能力:** SystemCapability.Multimedia.Audio.Communication
320
321**参数:**
322
323| 参数名     | 类型                                  | 必填 | 说明                      |
324| ---------- | ------------------------------------- | ---- |-------------------------|
325| deviceType | [CommunicationDeviceType](arkts-apis-audio-e.md#communicationdevicetype9) | 是   | 音频设备类型。                 |
326| active     | boolean                               | 是   | 是否设置设备为激活状态。true表示激活,false表示未激活。 |
327| callback   | AsyncCallback&lt;void&gt;             | 是   | 回调函数。当设置通信设备激活状态成功,err为undefined,否则为错误对象。 |
328
329**示例:**
330
331```ts
332import { BusinessError } from '@kit.BasicServicesKit';
333
334audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true, (err: BusinessError) => {
335  if (err) {
336    console.error(`Failed to set the active status of the device. ${err}`);
337    return;
338  }
339  console.info('Callback invoked to indicate that the device is set to the active status.');
340});
341```
342
343## getAvailableDevices<sup>12+</sup>
344
345getAvailableDevices(deviceUsage: DeviceUsage): AudioDeviceDescriptors
346
347获取音频可选设备列表。同步返回结果。
348
349**系统能力:** SystemCapability.Multimedia.Audio.Device
350
351**参数:**
352
353| 参数名     | 类型                      | 必填 | 说明             |
354| ---------- | ------------------------- | ---- | ---------------- |
355| deviceUsage| [DeviceUsage](arkts-apis-audio-e.md#deviceusage12) | 是   | 音频设备类型(根据用途分类)。 |
356
357**返回值:**
358
359| 类型                                                         | 说明                      |
360| ------------------------------------------------------------ | ------------------------- |
361| [AudioDeviceDescriptors](arkts-apis-audio-t.md#audiodevicedescriptors) | 返回设备列表。 |
362
363**错误码:**
364
365以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
366
367| 错误码ID | 错误信息 |
368| ------- | --------------------------------------------|
369| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
370| 6800101 | Parameter verification failed. |
371
372**示例:**
373
374```ts
375import { BusinessError } from '@kit.BasicServicesKit';
376
377try {
378  let data: audio.AudioDeviceDescriptors = audioRoutingManager.getAvailableDevices(audio.DeviceUsage.MEDIA_OUTPUT_DEVICES);
379  console.info('Succeeded in doing getAvailableDevices.');
380} catch (err) {
381  let error = err as BusinessError;
382   console.error(`Failed to getAvailableDevices. Code: ${error.code}, message: ${error.message}`);
383}
384```
385
386## on('availableDeviceChange')<sup>12+</sup>
387
388on(type: 'availableDeviceChange', deviceUsage: DeviceUsage, callback: Callback<DeviceChangeAction\>): void
389
390监听音频可选设备连接状态变化事件(当音频可选设备连接状态发生变化时触发)。使用callback异步回调。
391
392**系统能力:** SystemCapability.Multimedia.Audio.Device
393
394**参数:**
395
396| 参数名   | 类型                                                 | 必填 | 说明                                       |
397| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
398| type     | string                                               | 是   | 事件回调类型,支持的事件为'availableDeviceChange',当音频可选设备连接状态发生变化时,触发该事件。 |
399| deviceUsage | [DeviceUsage](arkts-apis-audio-e.md#deviceusage12)                       | 是   | 音频设备类型(根据用途分类)。     |
400| callback | Callback<[DeviceChangeAction](arkts-apis-audio-i.md#devicechangeaction)\> | 是   | 回调函数,返回设备更新详情。 |
401
402**错误码:**
403
404以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
405
406| 错误码ID | 错误信息 |
407| ------- | --------------------------------------------|
408| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
409| 6800101 | Parameter verification failed. |
410
411**示例:**
412
413```ts
414audioRoutingManager.on('availableDeviceChange', audio.DeviceUsage.MEDIA_OUTPUT_DEVICES, (deviceChanged: audio.DeviceChangeAction) => {
415  console.info('device change type : ' + deviceChanged.type);
416  console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
417  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole);
418  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType);
419});
420```
421
422## off('availableDeviceChange')<sup>12+</sup>
423
424off(type: 'availableDeviceChange', callback?: Callback<DeviceChangeAction\>): void
425
426取消监听音频可选设备连接状态变化事件。使用callback异步回调。
427
428**系统能力:** SystemCapability.Multimedia.Audio.Device
429
430**参数:**
431
432| 参数名   | 类型                                                | 必填 | 说明                                       |
433| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
434| type     | string                                              | 是   | 事件回调类型,支持的事件为'availableDeviceChange',当取消监听音频可选设备连接变化事件时,触发该事件。 |
435| callback | Callback<[DeviceChangeAction](arkts-apis-audio-i.md#devicechangeaction)> | 否   | 回调函数,返回可选设备更新详情。 |
436
437**错误码:**
438
439以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
440
441| 错误码ID | 错误信息 |
442| ------- | --------------------------------------------|
443| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
444| 6800101 | Parameter verification failed. |
445
446**示例:**
447
448```ts
449// 取消该事件的所有监听。
450audioRoutingManager.off('availableDeviceChange');
451
452// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听。
453let availableDeviceChangeCallback = (deviceChanged: audio.DeviceChangeAction) => {
454  console.info('device change type : ' + deviceChanged.type);
455  console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
456  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole);
457  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType);
458};
459
460audioRoutingManager.on('availableDeviceChange', audio.DeviceUsage.MEDIA_OUTPUT_DEVICES, availableDeviceChangeCallback);
461
462audioRoutingManager.off('availableDeviceChange', availableDeviceChangeCallback);
463```
464
465## setCommunicationDevice<sup>9+</sup>
466
467setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean): Promise&lt;void&gt;
468
469设置通信设备激活状态。使用Promise异步回调。
470
471该接口由于功能设计变化,将在后续版本废弃,不建议开发者使用。
472
473推荐开发者使用AVSession提供的[设备切换组件](../../media/avsession/using-switch-call-devices.md),实现通话设备切换。
474
475**系统能力:** SystemCapability.Multimedia.Audio.Communication
476
477**参数:**
478
479| 参数名     | 类型                                                   | 必填 | 说明               |
480| ---------- | ----------------------------------------------------- | ---- | ------------------ |
481| deviceType | [CommunicationDeviceType](arkts-apis-audio-e.md#communicationdevicetype9)  | 是   | 活跃音频设备类型。 |
482| active     | boolean                                               | 是   | 是否设置设备为激活状态。true表示激活,false表示未激活。     |
483
484**返回值:**
485
486| 类型                | 说明                            |
487| ------------------- | ------------------------------- |
488| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
489
490**示例:**
491
492```ts
493audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true).then(() => {
494  console.info('Promise returned to indicate that the device is set to the active status.');
495});
496```
497
498## isCommunicationDeviceActive<sup>9+</sup>
499
500isCommunicationDeviceActive(deviceType: CommunicationDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
501
502获取指定通信设备的激活状态。使用callback异步回调。
503
504**系统能力:** SystemCapability.Multimedia.Audio.Communication
505
506**参数:**
507
508| 参数名     | 类型                                                  | 必填 | 说明                     |
509| ---------- | ---------------------------------------------------- | ---- | ------------------------ |
510| deviceType | [CommunicationDeviceType](arkts-apis-audio-e.md#communicationdevicetype9) | 是   | 活跃音频设备类型。       |
511| callback   | AsyncCallback&lt;boolean&gt;                         | 是   | 回调函数。当获取指定通信设备的激活状态成功,err为undefined,data为true表示激活,false表示未激活;否则为错误对象。 |
512
513**示例:**
514
515```ts
516import { BusinessError } from '@kit.BasicServicesKit';
517
518audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER, (err: BusinessError, value: boolean) => {
519  if (err) {
520    console.error(`Failed to obtain the active status of the device. ${err}`);
521    return;
522  }
523  console.info('Callback invoked to indicate that the active status of the device is obtained.');
524});
525```
526
527## isCommunicationDeviceActive<sup>9+</sup>
528
529isCommunicationDeviceActive(deviceType: CommunicationDeviceType): Promise&lt;boolean&gt;
530
531获取指定通信设备的激活状态。使用Promise异步回调。
532
533**系统能力:** SystemCapability.Multimedia.Audio.Communication
534
535**参数:**
536
537| 参数名     | 类型                                                  | 必填 | 说明               |
538| ---------- | ---------------------------------------------------- | ---- | ------------------ |
539| deviceType | [CommunicationDeviceType](arkts-apis-audio-e.md#communicationdevicetype9) | 是   | 活跃音频设备类型。 |
540
541**返回值:**
542
543| 类型                   | 说明                             |
544| ---------------------- | ------------------------------- |
545| Promise&lt;boolean&gt; | Promise对象。返回true表示设备已激活;返回false表示设备未激活。 |
546
547**示例:**
548
549```ts
550audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER).then((value: boolean) => {
551  console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
552});
553```
554
555## isCommunicationDeviceActiveSync<sup>10+</sup>
556
557isCommunicationDeviceActiveSync(deviceType: CommunicationDeviceType): boolean
558
559获取指定通信设备的激活状态。同步返回结果。
560
561**系统能力:** SystemCapability.Multimedia.Audio.Communication
562
563**参数:**
564
565| 参数名     | 类型                                                  | 必填 | 说明               |
566| ---------- | ---------------------------------------------------- | ---- | ------------------ |
567| deviceType | [CommunicationDeviceType](arkts-apis-audio-e.md#communicationdevicetype9) | 是   | 活跃音频设备类型。 |
568
569**返回值:**
570
571| 类型                   | 说明                             |
572| ---------------------- | ------------------------------- |
573| boolean | 设备是否处于激活状态。true表示处于激活状态,false表示处于未激活状态。 |
574
575**错误码:**
576
577以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
578
579| 错误码ID | 错误信息 |
580| ------- | --------------------------------------------|
581| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
582| 6800101 | Parameter verification failed. |
583
584**示例:**
585
586```ts
587import { BusinessError } from '@kit.BasicServicesKit';
588
589try {
590  let value: boolean = audioRoutingManager.isCommunicationDeviceActiveSync(audio.CommunicationDeviceType.SPEAKER);
591  console.info(`Indicate that the active status of the device is obtained ${value}.`);
592} catch (err) {
593  let error = err as BusinessError;
594  console.error(`Failed to obtain the active status of the device ${error}.`);
595}
596```
597
598## getPreferOutputDeviceForRendererInfo<sup>10+</sup>
599
600getPreferOutputDeviceForRendererInfo(rendererInfo: AudioRendererInfo, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
601
602根据音频信息,返回优先级最高的输出设备。使用callback异步回调。
603
604**系统能力:** SystemCapability.Multimedia.Audio.Device
605
606**参数:**
607
608| 参数名                       | 类型                                                         | 必填 | 说明                      |
609| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
610| rendererInfo                | [AudioRendererInfo](arkts-apis-audio-i.md#audiorendererinfo8)                     | 是   | 音频渲染器信息。             |
611| callback                    | AsyncCallback&lt;[AudioDeviceDescriptors](arkts-apis-audio-t.md#audiodevicedescriptors)&gt;  | 是   | 回调函数。当获取优先级最高的输出设备成功,err为undefined,data为获取到的优先级最高的输出设备信息;否则为错误对象。 |
612
613**错误码:**
614
615以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
616
617| 错误码ID | 错误信息                                           |
618| ------- |--------------------------------------------------|
619| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
620| 6800101 | Parameter verification failed. Return by callback. |
621| 6800301 | System error. Return by callback.                |
622
623**示例:**
624```ts
625import { BusinessError } from '@kit.BasicServicesKit';
626
627let rendererInfo: audio.AudioRendererInfo = {
628  usage: audio.StreamUsage.STREAM_USAGE_MUSIC, // 音频流使用类型:音乐。根据业务场景配置,参考StreamUsage。
629  rendererFlags: 0 // 音频渲染器标志。
630};
631
632audioRoutingManager.getPreferOutputDeviceForRendererInfo(rendererInfo, (err: BusinessError, audioDeviceDescriptors: audio.AudioDeviceDescriptors) => {
633  if (err) {
634    console.error(`Failed to get prefer output device for renderer info. Code: ${err.code}, message: ${err.message}`);
635  } else {
636    console.info(`Succeeded in getting prefer output device for renderer info, AudioDeviceDescriptors: ${JSON.stringify(audioDeviceDescriptors)}.`);
637  }
638});
639```
640
641## getPreferOutputDeviceForRendererInfo<sup>10+</sup>
642getPreferOutputDeviceForRendererInfo(rendererInfo: AudioRendererInfo): Promise&lt;AudioDeviceDescriptors&gt;
643
644根据音频信息,返回优先级最高的输出设备。使用Promise异步回调。
645
646**系统能力:** SystemCapability.Multimedia.Audio.Device
647
648**参数:**
649
650| 参数名                 | 类型                                                         | 必填 | 说明                      |
651| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
652| rendererInfo          | [AudioRendererInfo](arkts-apis-audio-i.md#audiorendererinfo8)                     | 是   | 音频渲染器信息。            |
653
654**返回值:**
655
656| 类型                  | 说明                         |
657| --------------------- | --------------------------- |
658| Promise&lt;[AudioDeviceDescriptors](arkts-apis-audio-t.md#audiodevicedescriptors)&gt;   | Promise对象,返回优先级最高的输出设备信息。 |
659
660**错误码:**
661
662以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
663
664| 错误码ID | 错误信息                                          |
665| ------- |-------------------------------------------------|
666| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
667| 6800101 | Parameter verification failed. Return by promise. |
668| 6800301 | System error. Return by promise.                |
669
670**示例:**
671
672```ts
673import { BusinessError } from '@kit.BasicServicesKit';
674
675let rendererInfo: audio.AudioRendererInfo = {
676  usage: audio.StreamUsage.STREAM_USAGE_MUSIC, // 音频流使用类型:音乐。根据业务场景配置,参考StreamUsage。
677  rendererFlags: 0 // 音频渲染器标志。
678};
679
680audioRoutingManager.getPreferOutputDeviceForRendererInfo(rendererInfo).then((audioDeviceDescriptors: audio.AudioDeviceDescriptors) => {
681  console.info(`Succeeded in getting prefer output device for renderer info, AudioDeviceDescriptors: ${JSON.stringify(audioDeviceDescriptors)}.`);
682}).catch((err: BusinessError) => {
683  console.error(`Failed to get prefer output device for renderer info. Code: ${err.code}, message: ${err.message}`);
684})
685```
686
687## getPreferredOutputDeviceForRendererInfoSync<sup>10+</sup>
688getPreferredOutputDeviceForRendererInfoSync(rendererInfo: AudioRendererInfo): AudioDeviceDescriptors
689
690根据音频信息,返回优先级最高的输出设备。同步返回结果。
691
692**系统能力:** SystemCapability.Multimedia.Audio.Device
693
694**参数:**
695
696| 参数名                 | 类型                                                         | 必填 | 说明                      |
697| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
698| rendererInfo          | [AudioRendererInfo](arkts-apis-audio-i.md#audiorendererinfo8)                     | 是   | 音频渲染器信息。            |
699
700**返回值:**
701
702| 类型                  | 说明                         |
703| --------------------- | --------------------------- |
704| [AudioDeviceDescriptors](arkts-apis-audio-t.md#audiodevicedescriptors)   | 返回优先级最高的输出设备信息。 |
705
706**错误码:**
707
708以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
709
710| 错误码ID | 错误信息                     |
711| ------- |--------------------------|
712| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
713| 6800101 | Parameter verification failed. |
714
715**示例:**
716
717```ts
718import { BusinessError } from '@kit.BasicServicesKit';
719
720let rendererInfo: audio.AudioRendererInfo = {
721  usage: audio.StreamUsage.STREAM_USAGE_MUSIC, // 音频流使用类型:音乐。根据业务场景配置,参考StreamUsage。
722  rendererFlags: 0 // 音频渲染器标志。
723};
724
725try {
726  let audioDeviceDescriptors = audioRoutingManager.getPreferredOutputDeviceForRendererInfoSync(rendererInfo);
727  console.info(`Succeeded in getting prefer output device for renderer info, AudioDeviceDescriptors: ${JSON.stringify(audioDeviceDescriptors)}.`);
728} catch (err) {
729  let error = err as BusinessError;
730  console.error(`Failed to get prefer output device for renderer info. Code: ${error.code}, message: ${error.message}`);
731}
732```
733
734## on('preferOutputDeviceChangeForRendererInfo')<sup>10+</sup>
735
736on(type: 'preferOutputDeviceChangeForRendererInfo', rendererInfo: AudioRendererInfo, callback: Callback<AudioDeviceDescriptors\>): void
737
738监听最高优先级输出设备变化事件(当最高优先级输出设备发生变化时触发)。使用callback异步回调。
739
740**系统能力:** SystemCapability.Multimedia.Audio.Device
741
742**参数:**
743
744| 参数名   | 类型                                                 | 必填 | 说明                                                      |
745| :------- | :--------------------------------------------------- | :--- |:--------------------------------------------------------|
746| type     | string | 是   | 事件回调类型,支持的事件为'preferOutputDeviceChangeForRendererInfo',当最高优先级输出设备发生变化时,触发该事件。|
747| rendererInfo  | [AudioRendererInfo](arkts-apis-audio-i.md#audiorendererinfo8)        | 是   | 音频渲染器信息。                                                |
748| callback | Callback<[AudioDeviceDescriptors](arkts-apis-audio-t.md#audiodevicedescriptors)\> | 是   | 回调函数,返回优先级最高的输出设备信息。 |
749
750**错误码:**
751
752以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
753
754| 错误码ID | 错误信息 |
755| ------- | --------------------------------------------|
756| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
757| 6800101 | Parameter verification failed. |
758
759**示例:**
760
761```ts
762let rendererInfo: audio.AudioRendererInfo = {
763  usage: audio.StreamUsage.STREAM_USAGE_MUSIC, // 音频流使用类型:音乐。根据业务场景配置,参考StreamUsage。
764  rendererFlags: 0 // 音频渲染器标志。
765};
766
767audioRoutingManager.on('preferOutputDeviceChangeForRendererInfo', rendererInfo, (audioDeviceDescriptors: audio.AudioDeviceDescriptors) => {
768  console.info(`Succeeded in using on function, AudioDeviceDescriptors: ${JSON.stringify(audioDeviceDescriptors)}.`);
769});
770```
771
772## off('preferOutputDeviceChangeForRendererInfo')<sup>10+</sup>
773
774off(type: 'preferOutputDeviceChangeForRendererInfo', callback?: Callback<AudioDeviceDescriptors\>): void
775
776取消监听最高优先级输出音频设备变化事件。使用callback异步回调。
777
778**系统能力:** SystemCapability.Multimedia.Audio.Device
779
780**参数:**
781
782| 参数名   | 类型                                                | 必填 | 说明                                       |
783| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
784| type     | string | 是   | 事件回调类型,支持的事件为'preferOutputDeviceChangeForRendererInfo',当取消监听最高优先级输出音频设备变化事件时,触发该事件。 |
785| callback | Callback<[AudioDeviceDescriptors](arkts-apis-audio-t.md#audiodevicedescriptors)> | 否   | 回调函数,返回优先级最高的输出设备信息。 |
786
787**错误码:**
788
789以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
790
791| 错误码ID | 错误信息 |
792| ------- | --------------------------------------------|
793| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
794| 6800101 | Parameter verification failed. |
795
796**示例:**
797
798```ts
799// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听。
800// 当订阅了多个该事件的监听时,可通过 audioRoutingManager.off('preferOutputDeviceChangeForRendererInfo'); 取消该事件的所有监听。
801let preferOutputDeviceChangeForRendererInfoCallback = (audioDeviceDescriptors: audio.AudioDeviceDescriptors) => {
802  console.info(`Succeeded in using on or off function, AudioDeviceDescriptors: ${JSON.stringify(audioDeviceDescriptors)}.`);
803};
804let rendererInfo: audio.AudioRendererInfo = {
805  usage: audio.StreamUsage.STREAM_USAGE_MUSIC, // 音频流使用类型:音乐。根据业务场景配置,参考StreamUsage。
806  rendererFlags: 0 // 音频渲染器标志。
807};
808
809audioRoutingManager.on('preferOutputDeviceChangeForRendererInfo', rendererInfo, preferOutputDeviceChangeForRendererInfoCallback);
810
811audioRoutingManager.off('preferOutputDeviceChangeForRendererInfo', preferOutputDeviceChangeForRendererInfoCallback);
812```
813
814## getPreferredInputDeviceForCapturerInfo<sup>10+</sup>
815
816getPreferredInputDeviceForCapturerInfo(capturerInfo: AudioCapturerInfo, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
817
818根据音频信息,返回优先级最高的输入设备。使用callback异步回调。
819
820**系统能力:** SystemCapability.Multimedia.Audio.Device
821
822**参数:**
823
824| 参数名                       | 类型                                                         | 必填 | 说明                      |
825| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
826| capturerInfo                | [AudioCapturerInfo](arkts-apis-audio-i.md#audiocapturerinfo8)                     | 是   | 音频采集器信息。             |
827| callback                    | AsyncCallback&lt;[AudioDeviceDescriptors](arkts-apis-audio-t.md#audiodevicedescriptors)&gt;  | 是   | 回调函数。当获取优先级最高的输入设备成功,err为undefined,data为获取到的优先级最高的输入设备信息;否则为错误对象。 |
828
829**错误码:**
830
831以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
832
833| 错误码ID | 错误信息 |
834| ------- | --------------------------------------------|
835| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
836| 6800101 | Parameter verification failed. Return by callback.|
837| 6800301 | System error. Return by callback. |
838
839**示例:**
840```ts
841import { BusinessError } from '@kit.BasicServicesKit';
842
843let capturerInfo: audio.AudioCapturerInfo = {
844  source: audio.SourceType.SOURCE_TYPE_MIC, // 音源类型:Mic音频源。根据业务场景配置,参考SourceType。
845  capturerFlags: 0 // 音频采集器标志。
846};
847
848audioRoutingManager.getPreferredInputDeviceForCapturerInfo(capturerInfo, (err: BusinessError, audioDeviceDescriptors: audio.AudioDeviceDescriptors) => {
849  if (err) {
850    console.error(`Failed to get preferred input device for capturer info. Code: ${err.code}, message: ${err.message}`);
851  } else {
852    console.info(`Succeeded in getting preferred input device for capturer info, AudioDeviceDescriptors: ${JSON.stringify(audioDeviceDescriptors)}.`);
853  }
854});
855```
856
857## getPreferredInputDeviceForCapturerInfo<sup>10+</sup>
858
859getPreferredInputDeviceForCapturerInfo(capturerInfo: AudioCapturerInfo): Promise&lt;AudioDeviceDescriptors&gt;
860
861根据音频信息,返回优先级最高的输入设备。使用Promise异步回调。
862
863**系统能力:** SystemCapability.Multimedia.Audio.Device
864
865**参数:**
866
867| 参数名                 | 类型                                                         | 必填 | 说明                      |
868| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
869| capturerInfo          | [AudioCapturerInfo](arkts-apis-audio-i.md#audiocapturerinfo8)                     | 是   | 音频采集器信息。            |
870
871**返回值:**
872
873| 类型                  | 说明                         |
874| --------------------- | --------------------------- |
875| Promise&lt;[AudioDeviceDescriptors](arkts-apis-audio-t.md#audiodevicedescriptors)&gt;   | Promise对象,返回优先级最高的输入设备信息。 |
876
877**错误码:**
878
879以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
880
881| 错误码ID | 错误信息 |
882| ------- | --------------------------------------------|
883| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
884| 6800101 | Parameter verification failed. Return by promise. |
885| 6800301 | System error. Return by promise. |
886
887**示例:**
888
889```ts
890import { BusinessError } from '@kit.BasicServicesKit';
891
892let capturerInfo: audio.AudioCapturerInfo = {
893  source: audio.SourceType.SOURCE_TYPE_MIC, // 音源类型:Mic音频源。根据业务场景配置,参考SourceType。
894  capturerFlags: 0 // 音频采集器标志。
895};
896
897audioRoutingManager.getPreferredInputDeviceForCapturerInfo(capturerInfo).then((audioDeviceDescriptors: audio.AudioDeviceDescriptors) => {
898  console.info(`Succeeded in getting preferred input device for capturer info, AudioDeviceDescriptors: ${JSON.stringify(audioDeviceDescriptors)}.`);
899}).catch((err: BusinessError) => {
900  console.error(`Failed to get preferred input device for capturer info. Code: ${err.code}, message: ${err.message}`);
901});
902```
903
904## getPreferredInputDeviceForCapturerInfoSync<sup>10+</sup>
905
906getPreferredInputDeviceForCapturerInfoSync(capturerInfo: AudioCapturerInfo): AudioDeviceDescriptors
907
908根据音频信息,返回优先级最高的输入设备。同步返回结果。
909
910**系统能力:** SystemCapability.Multimedia.Audio.Device
911
912**参数:**
913
914| 参数名                 | 类型                                                         | 必填 | 说明                      |
915| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
916| capturerInfo          | [AudioCapturerInfo](arkts-apis-audio-i.md#audiocapturerinfo8)                     | 是   | 音频采集器信息。            |
917
918**返回值:**
919
920| 类型                  | 说明                         |
921| --------------------- | --------------------------- |
922| [AudioDeviceDescriptors](arkts-apis-audio-t.md#audiodevicedescriptors)   | 返回优先级最高的输入设备信息。 |
923
924**错误码:**
925
926以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
927
928| 错误码ID | 错误信息 |
929| ------- | --------------------------------------------|
930| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
931| 6800101 | Parameter verification failed. |
932
933**示例:**
934
935```ts
936import { BusinessError } from '@kit.BasicServicesKit';
937
938let capturerInfo: audio.AudioCapturerInfo = {
939  source: audio.SourceType.SOURCE_TYPE_MIC, // 音源类型:Mic音频源。根据业务场景配置,参考SourceType。
940  capturerFlags: 0 // 音频采集器标志。
941};
942
943try {
944  let audioDeviceDescriptors = audioRoutingManager.getPreferredInputDeviceForCapturerInfoSync(capturerInfo);
945  console.info(`Succeeded in getting preferred input device for capturer info, AudioDeviceDescriptors: ${JSON.stringify(audioDeviceDescriptors)}.`);
946} catch (err) {
947  let error = err as BusinessError;
948  console.error(`Failed to get preferred input device for capturer info. Code: ${error.code}, message: ${error.message}`);
949}
950```
951
952## on('preferredInputDeviceChangeForCapturerInfo')<sup>10+</sup>
953
954on(type: 'preferredInputDeviceChangeForCapturerInfo', capturerInfo: AudioCapturerInfo, callback: Callback<AudioDeviceDescriptors\>): void
955
956监听最高优先级输入设备变化事件(当最高优先级输入设备发生变化时触发)。使用callback异步回调。
957
958**系统能力:** SystemCapability.Multimedia.Audio.Device
959
960**参数:**
961
962| 参数名   | 类型                                                 | 必填 | 说明                                       |
963| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
964| type     | string | 是   | 事件回调类型,支持的事件为'preferredInputDeviceChangeForCapturerInfo',当最高优先级输入设备发生变化时,触发该事件。 |
965| capturerInfo  | [AudioCapturerInfo](arkts-apis-audio-i.md#audiocapturerinfo8)        | 是   | 音频采集器信息。              |
966| callback | Callback<[AudioDeviceDescriptors](arkts-apis-audio-t.md#audiodevicedescriptors)\> | 是   | 回调函数,返回优先级最高的输入设备信息。 |
967
968**错误码:**
969
970以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
971
972| 错误码ID | 错误信息 |
973| ------- | --------------------------------------------|
974| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
975| 6800101 | Parameter verification failed. |
976
977**示例:**
978
979```ts
980let capturerInfo: audio.AudioCapturerInfo = {
981  source: audio.SourceType.SOURCE_TYPE_MIC, // 音源类型:Mic音频源。根据业务场景配置,参考SourceType。
982  capturerFlags: 0 // 音频采集器标志。
983};
984
985audioRoutingManager.on('preferredInputDeviceChangeForCapturerInfo', capturerInfo, (audioDeviceDescriptors: audio.AudioDeviceDescriptors) => {
986  console.info(`Succeeded in using on function, AudioDeviceDescriptors: ${JSON.stringify(audioDeviceDescriptors)}.`);
987});
988```
989
990## off('preferredInputDeviceChangeForCapturerInfo')<sup>10+</sup>
991
992off(type: 'preferredInputDeviceChangeForCapturerInfo', callback?: Callback<AudioDeviceDescriptors\>): void
993
994取消监听最高优先级输入音频设备变化事件。使用callback异步回调。
995
996**系统能力:** SystemCapability.Multimedia.Audio.Device
997
998**参数:**
999
1000| 参数名   | 类型                                                | 必填 | 说明                                       |
1001| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
1002| type     | string | 是   | 事件回调类型,支持的事件为'preferredInputDeviceChangeForCapturerInfo',当取消监听最高优先级输入音频设备变化事件时,触发该事件。 |
1003| callback | Callback<[AudioDeviceDescriptors](arkts-apis-audio-t.md#audiodevicedescriptors)> | 否   | 回调函数,返回优先级最高的输入设备信息。 |
1004
1005**错误码:**
1006
1007以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
1008
1009| 错误码ID | 错误信息 |
1010| ------- | --------------------------------------------|
1011| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
1012| 6800101 | Parameter verification failed. |
1013
1014**示例:**
1015
1016```ts
1017// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听。
1018// 当订阅了多个该事件的监听时,可通过 audioRoutingManager.off('preferredInputDeviceChangeForCapturerInfo'); 取消该事件的所有监听。
1019let preferredInputDeviceChangeForCapturerInfoCallback = (audioDeviceDescriptors: audio.AudioDeviceDescriptors) => {
1020  console.info(`Succeeded in using on or off function, AudioDeviceDescriptors: ${JSON.stringify(audioDeviceDescriptors)}.`);
1021};
1022let capturerInfo: audio.AudioCapturerInfo = {
1023  source: audio.SourceType.SOURCE_TYPE_MIC, // 音源类型:Mic音频源。根据业务场景配置,参考SourceType。
1024  capturerFlags: 0 // 音频采集器标志。
1025};
1026
1027audioRoutingManager.on('preferredInputDeviceChangeForCapturerInfo', capturerInfo, preferredInputDeviceChangeForCapturerInfoCallback);
1028
1029audioRoutingManager.off('preferredInputDeviceChangeForCapturerInfo', preferredInputDeviceChangeForCapturerInfoCallback);
1030```
1031