• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Interface (AudioStreamManager)
2
3> **NOTE**
4>
5> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
6> - The initial APIs of this interface are supported since API version 9.
7
8This interface implements audio stream management.
9
10Before calling any API in AudioStreamManager, you must use [getStreamManager](arkts-apis-audio-AudioManager.md#getstreammanager9) to obtain an AudioStreamManager instance.
11
12## Modules to Import
13
14```ts
15import { audio } from '@kit.AudioKit';
16```
17
18## getCurrentAudioRendererInfoArray<sup>9+</sup>
19
20getCurrentAudioRendererInfoArray(callback: AsyncCallback&lt;AudioRendererChangeInfoArray&gt;): void
21
22Obtains the information about this audio renderer. This API uses an asynchronous callback to return the result.
23
24**System capability**: SystemCapability.Multimedia.Audio.Renderer
25
26**Parameters**
27
28| Name    | Type                                | Mandatory    | Description                        |
29| -------- | ----------------------------------- | -------- | --------------------------- |
30| callback | AsyncCallback<[AudioRendererChangeInfoArray](arkts-apis-audio-t.md#audiorendererchangeinfoarray9)> | Yes    | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the audio renderer information obtained; otherwise, **err** is an error object.|
31
32**Example**
33
34```ts
35import { BusinessError } from '@kit.BasicServicesKit';
36
37audioStreamManager.getCurrentAudioRendererInfoArray(async (err: BusinessError, AudioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray) => {
38  console.info('getCurrentAudioRendererInfoArray **** Get Callback Called ****');
39  if (err) {
40    console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`);
41  } else {
42    if (AudioRendererChangeInfoArray != null) {
43      for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
44        let AudioRendererChangeInfo: audio.AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
45        console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
46        console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
47        console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
48        console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
49        for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
50          console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
51          console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
52          console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
53          console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
54          console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
55          console.info(`SampleRate: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
56          console.info(`ChannelCount: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
57          console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
58        }
59      }
60    }
61  }
62});
63```
64
65## getCurrentAudioRendererInfoArray<sup>9+</sup>
66
67getCurrentAudioRendererInfoArray(): Promise&lt;AudioRendererChangeInfoArray&gt;
68
69Obtains the information about this audio renderer. This API uses a promise to return the result.
70
71**System capability**: SystemCapability.Multimedia.Audio.Renderer
72
73**Return value**
74
75| Type                                                                             | Description                                   |
76| ---------------------------------------------------------------------------------| --------------------------------------- |
77| Promise<[AudioRendererChangeInfoArray](arkts-apis-audio-t.md#audiorendererchangeinfoarray9)>          | Promise used to return the audio renderer information.     |
78
79**Example**
80
81```ts
82import { BusinessError } from '@kit.BasicServicesKit';
83
84async function getCurrentAudioRendererInfoArray(){
85  await audioStreamManager.getCurrentAudioRendererInfoArray().then((AudioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray) => {
86    console.info(`getCurrentAudioRendererInfoArray ######### Get Promise is called ##########`);
87    if (AudioRendererChangeInfoArray != null) {
88      for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
89        let AudioRendererChangeInfo: audio.AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
90        console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
91        console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
92        console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
93        console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
94        for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
95          console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
96          console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
97          console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
98          console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
99          console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
100          console.info(`SampleRate: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
101          console.info(`ChannelCount: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
102          console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
103        }
104      }
105    }
106  }).catch((err: BusinessError) => {
107    console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`);
108  });
109}
110```
111## getCurrentAudioRendererInfoArraySync<sup>10+</sup>
112
113getCurrentAudioRendererInfoArraySync(): AudioRendererChangeInfoArray
114
115Obtains the information about this audio renderer. This API returns the result synchronously.
116
117**System capability**: SystemCapability.Multimedia.Audio.Renderer
118
119**Return value**
120
121| Type                                                                             | Description                                   |
122| ---------------------------------------------------------------------------------| --------------------------------------- |
123| [AudioRendererChangeInfoArray](arkts-apis-audio-t.md#audiorendererchangeinfoarray9)          | Audio renderer information.     |
124
125**Example**
126
127```ts
128import { BusinessError } from '@kit.BasicServicesKit';
129
130try {
131  let audioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray = audioStreamManager.getCurrentAudioRendererInfoArraySync();
132  console.info(`getCurrentAudioRendererInfoArraySync success.`);
133  if (audioRendererChangeInfoArray != null) {
134    for (let i = 0; i < audioRendererChangeInfoArray.length; i++) {
135      let AudioRendererChangeInfo: audio.AudioRendererChangeInfo = audioRendererChangeInfoArray[i];
136      console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
137      console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
138      console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
139      console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
140      for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
141        console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
142        console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
143        console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
144        console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
145        console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
146        console.info(`SampleRate: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
147        console.info(`ChannelCount: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
148        console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
149      }
150    }
151  }
152} catch (err) {
153  let error = err as BusinessError;
154  console.error(`getCurrentAudioRendererInfoArraySync :ERROR: ${error}`);
155}
156```
157
158## getCurrentAudioCapturerInfoArray<sup>9+</sup>
159
160getCurrentAudioCapturerInfoArray(callback: AsyncCallback&lt;AudioCapturerChangeInfoArray&gt;): void
161
162Obtains the information about this audio capturer. This API uses an asynchronous callback to return the result.
163
164**System capability**: SystemCapability.Multimedia.Audio.Renderer
165
166**Parameters**
167
168| Name       | Type                                | Mandatory     | Description                                                     |
169| ---------- | ----------------------------------- | --------- | -------------------------------------------------------- |
170| callback   | AsyncCallback<[AudioCapturerChangeInfoArray](arkts-apis-audio-t.md#audiocapturerchangeinfoarray9)> | Yes   | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the audio capturer information obtained; otherwise, **err** is an error object.|
171
172**Example**
173
174```ts
175import { BusinessError } from '@kit.BasicServicesKit';
176
177audioStreamManager.getCurrentAudioCapturerInfoArray(async (err: BusinessError, AudioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray) => {
178  console.info('getCurrentAudioCapturerInfoArray **** Get Callback Called ****');
179  if (err) {
180    console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
181  } else {
182    if (AudioCapturerChangeInfoArray != null) {
183      for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
184        console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
185        console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
186        console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
187        for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
188          console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
189          console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
190          console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
191          console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
192          console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
193          console.info(`SampleRate: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
194          console.info(`ChannelCount: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
195          console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
196        }
197      }
198    }
199  }
200});
201```
202
203## getCurrentAudioCapturerInfoArray<sup>9+</sup>
204
205getCurrentAudioCapturerInfoArray(): Promise&lt;AudioCapturerChangeInfoArray&gt;
206
207Obtains the information about this audio capturer. This API uses a promise to return the result.
208
209**System capability**: SystemCapability.Multimedia.Audio.Renderer
210
211**Return value**
212
213| Type                                                                        | Description                                |
214| -----------------------------------------------------------------------------| ----------------------------------- |
215| Promise<[AudioCapturerChangeInfoArray](arkts-apis-audio-t.md#audiocapturerchangeinfoarray9)>      | Promise used to return the audio capturer information. |
216
217**Example**
218
219```ts
220import { BusinessError } from '@kit.BasicServicesKit';
221
222async function getCurrentAudioCapturerInfoArray(){
223  await audioStreamManager.getCurrentAudioCapturerInfoArray().then((AudioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray) => {
224    console.info('getCurrentAudioCapturerInfoArray **** Get Promise Called ****');
225    if (AudioCapturerChangeInfoArray != null) {
226      for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
227        console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
228        console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
229        console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
230        for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
231          console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
232          console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
233          console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
234          console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
235          console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
236          console.info(`SampleRate: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
237          console.info(`ChannelCount: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
238          console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
239        }
240      }
241    }
242  }).catch((err: BusinessError) => {
243    console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
244  });
245}
246```
247
248## getCurrentAudioCapturerInfoArraySync<sup>10+</sup>
249
250getCurrentAudioCapturerInfoArraySync(): AudioCapturerChangeInfoArray
251
252Obtains the information about this audio capturer. This API returns the result synchronously.
253
254**System capability**: SystemCapability.Multimedia.Audio.Capturer
255
256**Return value**
257
258| Type                                                                        | Description                                |
259| -----------------------------------------------------------------------------| ----------------------------------- |
260| [AudioCapturerChangeInfoArray](arkts-apis-audio-t.md#audiocapturerchangeinfoarray9)      | Audio capturer information. |
261
262**Example**
263
264```ts
265import { BusinessError } from '@kit.BasicServicesKit';
266
267try {
268  let audioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray = audioStreamManager.getCurrentAudioCapturerInfoArraySync();
269  console.info('getCurrentAudioCapturerInfoArraySync success.');
270  if (audioCapturerChangeInfoArray != null) {
271    for (let i = 0; i < audioCapturerChangeInfoArray.length; i++) {
272      console.info(`StreamId for ${i} is: ${audioCapturerChangeInfoArray[i].streamId}`);
273      console.info(`Source for ${i} is: ${audioCapturerChangeInfoArray[i].capturerInfo.source}`);
274      console.info(`Flag  ${i} is: ${audioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
275      for (let j = 0; j < audioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
276        console.info(`Id: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
277        console.info(`Type: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
278        console.info(`Role: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
279        console.info(`Name: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
280        console.info(`Address: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
281        console.info(`SampleRate: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
282        console.info(`ChannelCount: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
283        console.info(`ChannelMask: ${i} : ${audioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
284      }
285    }
286  }
287} catch (err) {
288  let error = err as BusinessError;
289  console.error(`getCurrentAudioCapturerInfoArraySync ERROR: ${error}`);
290}
291```
292
293## on('audioRendererChange')<sup>9+</sup>
294
295on(type: 'audioRendererChange', callback: Callback&lt;AudioRendererChangeInfoArray&gt;): void
296
297Subscribes to the audio renderer change event, which is triggered when the audio playback stream status or device is changed. This API uses an asynchronous callback to return the result.
298
299**System capability**: SystemCapability.Multimedia.Audio.Renderer
300
301**Parameters**
302
303| Name     | Type       | Mandatory     | Description                                                                    |
304| -------- | ---------- | --------- | ------------------------------------------------------------------------ |
305| type     | string     | Yes       | Event type. The event **'audioRendererChange'** is triggered when the audio playback stream status or device is changed.|
306| callback | Callback<[AudioRendererChangeInfoArray](arkts-apis-audio-t.md#audiorendererchangeinfoarray9)> | Yes |  Callback used to return the audio renderer information.|
307
308**Error codes**
309
310For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Audio Error Codes](errorcode-audio.md).
311
312| ID| Error Message|
313| ------- | --------------------------------------------|
314| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
315| 6800101 | Parameter verification failed. |
316
317**Example**
318
319```ts
320audioStreamManager.on('audioRendererChange',  (audioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray) => {
321  for (let i = 0; i < audioRendererChangeInfoArray.length; i++) {
322    let audioRendererChangeInfo: audio.AudioRendererChangeInfo = audioRendererChangeInfoArray[i];
323    console.info(`## RendererChange on is called for ${i} ##`);
324    console.info(`StreamId for ${i} is: ${audioRendererChangeInfo.streamId}`);
325    console.info(`Content ${i} is: ${audioRendererChangeInfo.rendererInfo.content}`);
326    console.info(`Stream ${i} is: ${audioRendererChangeInfo.rendererInfo.usage}`);
327    console.info(`Flag ${i} is: ${audioRendererChangeInfo.rendererInfo.rendererFlags}`);
328    for (let j = 0;j < audioRendererChangeInfo.deviceDescriptors.length; j++) {
329      console.info(`Id: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].id}`);
330      console.info(`Type: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
331      console.info(`Role: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
332      console.info(`Name: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].name}`);
333      console.info(`Address: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].address}`);
334      console.info(`SampleRate: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
335      console.info(`ChannelCount: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
336      console.info(`ChannelMask: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
337    }
338  }
339});
340```
341
342## off('audioRendererChange')<sup>9+</sup>
343
344off(type: 'audioRendererChange', callback?: Callback&lt;AudioRendererChangeInfoArray&gt;): void
345
346Unsubscribes from the audio renderer change event. This API uses an asynchronous callback to return the result.
347
348**System capability**: SystemCapability.Multimedia.Audio.Renderer
349
350**Parameters**
351
352| Name    | Type    | Mandatory| Description             |
353| -------- | ------- |----| ---------------- |
354| type     | string  | Yes | Event type. The event **'audioRendererChange'** is triggered when the audio playback stream status or device is changed.|
355| callback<sup>18+</sup> | Callback<[AudioRendererChangeInfoArray](arkts-apis-audio-t.md#audiorendererchangeinfoarray9)> | No |  Callback used to return the audio renderer information.|
356
357**Error codes**
358
359For details about the error codes, see [Audio Error Codes](errorcode-audio.md).
360
361| ID| Error Message                    |
362| ------- |--------------------------|
363| 6800101 | Parameter verification failed. |
364
365**Example**
366
367```ts
368// Cancel all subscriptions to the event.
369audioStreamManager.off('audioRendererChange');
370
371// For the same event, if the callback parameter passed to the off API is the same as that passed to the on API, the off API cancels the subscription registered with the specified callback parameter.
372let audioRendererChangeCallback = (audioRendererChangeInfoArray: audio.AudioRendererChangeInfoArray) => {
373  for (let i = 0; i < audioRendererChangeInfoArray.length; i++) {
374    let audioRendererChangeInfo: audio.AudioRendererChangeInfo = audioRendererChangeInfoArray[i];
375    console.info(`## RendererChange on is called for ${i} ##`);
376    console.info(`StreamId for ${i} is: ${audioRendererChangeInfo.streamId}`);
377    console.info(`Content ${i} is: ${audioRendererChangeInfo.rendererInfo.content}`);
378    console.info(`Stream ${i} is: ${audioRendererChangeInfo.rendererInfo.usage}`);
379    console.info(`Flag ${i} is: ${audioRendererChangeInfo.rendererInfo.rendererFlags}`);
380    for (let j = 0;j < audioRendererChangeInfo.deviceDescriptors.length; j++) {
381      console.info(`Id: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].id}`);
382      console.info(`Type: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
383      console.info(`Role: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
384      console.info(`Name: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].name}`);
385      console.info(`Address: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].address}`);
386      console.info(`SampleRate: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
387      console.info(`ChannelCount: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
388      console.info(`ChannelMask: ${i} : ${audioRendererChangeInfo.deviceDescriptors[j].channelMasks[0]}`);
389    }
390  }
391};
392
393audioStreamManager.on('audioRendererChange', audioRendererChangeCallback);
394
395audioStreamManager.off('audioRendererChange', audioRendererChangeCallback);
396```
397
398## on('audioCapturerChange')<sup>9+</sup>
399
400on(type: 'audioCapturerChange', callback: Callback&lt;AudioCapturerChangeInfoArray&gt;): void
401
402Subscribes to the audio capturer change event, which is triggered when the audio recording stream status or device is changed. This API uses an asynchronous callback to return the result.
403
404**System capability**: SystemCapability.Multimedia.Audio.Capturer
405
406**Parameters**
407
408| Name    | Type    | Mandatory     | Description                                                                                         |
409| -------- | ------- | --------- | ---------------------------------------------------------------------- |
410| type     | string  | Yes       | Event type. The event **'audioCapturerChange'** is triggered when the audio recording stream status or device is changed.|
411| callback | Callback<[AudioCapturerChangeInfoArray](arkts-apis-audio-t.md#audiocapturerchangeinfoarray9)> | Yes    | Callback used to return the audio capturer information.|
412
413**Error codes**
414
415For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Audio Error Codes](errorcode-audio.md).
416
417| ID| Error Message|
418| ------- | --------------------------------------------|
419| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
420| 6800101 | Parameter verification failed. |
421
422**Example**
423
424```ts
425audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray) =>  {
426  for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
427    console.info(`## CapChange on is called for element ${i} ##`);
428    console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
429    console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
430    console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
431    for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
432      console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
433      console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
434      console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
435      console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
436      console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
437      console.info(`SampleRate: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
438      console.info(`ChannelCount: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
439      console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
440    }
441  }
442});
443```
444
445## off('audioCapturerChange')<sup>9+</sup>
446
447off(type: 'audioCapturerChange', callback?: Callback&lt;AudioCapturerChangeInfoArray&gt;): void
448
449Unsubscribes from the audio capturer change event. This API uses an asynchronous callback to return the result.
450
451**System capability**: SystemCapability.Multimedia.Audio.Capturer
452
453**Parameters**
454
455| Name      | Type    | Mandatory| Description                                                         |
456| -------- | -------- | --- | ------------------------------------------------------------- |
457| type     | string   |Yes  | Event type. The event **'audioCapturerChange'** is triggered when the audio capturer is changed.|
458| callback<sup>18+</sup> | Callback<[AudioCapturerChangeInfoArray](arkts-apis-audio-t.md#audiocapturerchangeinfoarray9)> | No| Callback used to return the audio capturer information.|
459
460**Error codes**
461
462For details about the error codes, see [Audio Error Codes](errorcode-audio.md).
463
464| ID| Error Message|
465| ------- | --------------------------------------------|
466| 6800101 | Parameter verification failed. |
467
468**Example**
469
470```ts
471audioStreamManager.off('audioCapturerChange');
472// Cancel all subscriptions to the event.
473audioStreamManager.off('audioCapturerChange');
474
475// For the same event, if the callback parameter passed to the off API is the same as that passed to the on API, the off API cancels the subscription registered with the specified callback parameter.
476let audioCapturerChangeCallback = (AudioCapturerChangeInfoArray: audio.AudioCapturerChangeInfoArray) =>  {
477  for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
478    console.info(`## CapChange on is called for element ${i} ##`);
479    console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
480    console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
481    console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
482    for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
483      console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
484      console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
485      console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
486      console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
487      console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
488      console.info(`SampleRate: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
489      console.info(`ChannelCount: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
490      console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks[0]}`);
491    }
492  }
493};
494
495audioStreamManager.on('audioCapturerChange', audioCapturerChangeCallback);
496
497audioStreamManager.off('audioCapturerChange', audioCapturerChangeCallback);
498```
499
500## isActive<sup>(deprecated)</sup>
501
502isActive(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
503
504Checks whether a stream is active. This API uses an asynchronous callback to return the result.
505
506> **NOTE**
507>
508> This API is supported since API version 9 and deprecated since API version 20. You are advised to use [isStreamActive](arkts-apis-audio-AudioStreamManager.md#isstreamactive20) instead.
509
510**System capability**: SystemCapability.Multimedia.Audio.Renderer
511
512**Parameters**
513
514| Name    | Type                               | Mandatory| Description                                             |
515| ---------- | ----------------------------------- | ---- | ------------------------------------------------- |
516| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes  | Audio stream types.                                     |
517| callback   | AsyncCallback&lt;boolean&gt;        | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true** if the stream is active or **false** if not active; otherwise, **err** is an error object.|
518
519**Example**
520
521```ts
522import { BusinessError } from '@kit.BasicServicesKit';
523
524audioStreamManager.isActive(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => {
525if (err) {
526  console.error(`Failed to obtain the active status of the stream. ${err}`);
527  return;
528}
529  console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`);
530});
531```
532
533## isActive<sup>(deprecated)</sup>
534
535isActive(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
536
537Checks whether a stream is active. This API uses a promise to return the result.
538
539> **NOTE**
540>
541> This API is supported since API version 9 and deprecated since API version 20. You are advised to use [isStreamActive](arkts-apis-audio-AudioStreamManager.md#isstreamactive20) instead.
542
543**System capability**: SystemCapability.Multimedia.Audio.Renderer
544
545**Parameters**
546
547| Name    | Type                               | Mandatory| Description        |
548| ---------- | ----------------------------------- | ---- | ------------ |
549| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes  | Audio stream types.|
550
551**Return value**
552
553| Type                  | Description                                                    |
554| ---------------------- | -------------------------------------------------------- |
555| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the stream is active, and **false** means the opposite.|
556
557**Example**
558
559```ts
560audioStreamManager.isActive(audio.AudioVolumeType.MEDIA).then((value: boolean) => {
561  console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`);
562});
563```
564
565## isActiveSync<sup>(deprecated)</sup>
566
567isActiveSync(volumeType: AudioVolumeType): boolean
568
569Checks whether a stream is active. This API returns the result synchronously.
570
571> **NOTE**
572>
573> This API is supported since API version 10 and deprecated since API version 20. You are advised to use [isStreamActive](arkts-apis-audio-AudioStreamManager.md#isstreamactive20) instead.
574
575**System capability**: SystemCapability.Multimedia.Audio.Renderer
576
577**Parameters**
578
579| Name    | Type                               | Mandatory| Description        |
580| ---------- | ----------------------------------- | ---- | ------------ |
581| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes  | Audio stream types.|
582
583**Return value**
584
585| Type                  | Description                                                    |
586| ---------------------- | -------------------------------------------------------- |
587| boolean | Check result. The value **true** means that the stream is active, and **false** means the opposite.|
588
589**Error codes**
590
591For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Audio Error Codes](errorcode-audio.md).
592
593| ID| Error Message|
594| ------- | --------------------------------------------|
595| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
596| 6800101 | Parameter verification failed. |
597
598**Example**
599
600```ts
601import { BusinessError } from '@kit.BasicServicesKit';
602
603try {
604  let value: boolean = audioStreamManager.isActiveSync(audio.AudioVolumeType.MEDIA);
605  console.info(`Indicate that the active status of the stream is obtained ${value}.`);
606} catch (err) {
607  let error = err as BusinessError;
608  console.error(`Failed to obtain the active status of the stream ${error}.`);
609}
610```
611
612## isStreamActive<sup>20+</sup>
613
614isStreamActive(streamUsage: StreamUsage): boolean
615
616Checks whether a stream is active. This API returns the result synchronously.
617
618**System capability**: SystemCapability.Multimedia.Audio.Renderer
619
620**Parameters**
621
622| Name    | Type                               | Mandatory| Description        |
623| ---------- | ----------------------------------- | ---- | ------------ |
624| streamUsage | [StreamUsage](arkts-apis-audio-e.md#streamusage) | Yes  | Audio stream usage.|
625
626**Return value**
627
628| Type                  | Description                                                    |
629| ---------------------- | -------------------------------------------------------- |
630| boolean | Check result. The value **true** means that the stream is active, and **false** means the opposite.|
631
632**Error codes**
633
634For details about the error codes, see [Audio Error Codes](errorcode-audio.md).
635
636| ID| Error Message|
637| ------- | --------------------------------------------|
638| 6800101 | Parameter verification failed. |
639
640**Example**
641
642```ts
643import { BusinessError } from '@kit.BasicServicesKit';
644
645try {
646  let value: boolean = audioStreamManager.isStreamActive(audio.StreamUsage.STREAM_USAGE_MUSIC);
647  console.info(`Indicate that the active status of the stream is obtained ${value}.`);
648} catch (err) {
649  let error = err as BusinessError;
650  console.error(`Failed to obtain the active status of the stream ${error}.`);
651}
652```
653
654## getAudioEffectInfoArray<sup>10+</sup>
655
656getAudioEffectInfoArray(usage: StreamUsage, callback: AsyncCallback&lt;AudioEffectInfoArray&gt;): void
657
658Obtains information about the audio effect mode in use. This API uses an asynchronous callback to return the result.
659
660**System capability**: SystemCapability.Multimedia.Audio.Renderer
661
662**Parameters**
663
664| Name   | Type                               | Mandatory    | Description                        |
665| -------- | ----------------------------------- | -------- | --------------------------- |
666| usage    | [StreamUsage](arkts-apis-audio-e.md#streamusage)                                    | Yes    |  Audio stream usage.               |
667| callback | AsyncCallback<[AudioEffectInfoArray](arkts-apis-audio-AudioStreamManager.md#getaudioeffectinfoarray10)> | Yes    | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the information about the audio effect mode obtained; otherwise, **err** is an error object.|
668
669**Error codes**
670
671For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Audio Error Codes](errorcode-audio.md).
672
673| ID| Error Message|
674| ------- | --------------------------------------------|
675| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
676| 6800101 | Parameter verification failed. Return by callback.|
677
678**Example**
679
680```ts
681import { BusinessError } from '@kit.BasicServicesKit';
682
683audioStreamManager.getAudioEffectInfoArray(audio.StreamUsage.STREAM_USAGE_MUSIC, async (err: BusinessError, audioEffectInfoArray: audio.AudioEffectInfoArray) => {
684  console.info('getAudioEffectInfoArray **** Get Callback Called ****');
685  if (err) {
686    console.error(`getAudioEffectInfoArray :ERROR: ${err}`);
687    return;
688  } else {
689    console.info(`The effect modes are: ${audioEffectInfoArray}`);
690  }
691});
692```
693
694## getAudioEffectInfoArray<sup>10+</sup>
695
696getAudioEffectInfoArray(usage: StreamUsage): Promise&lt;AudioEffectInfoArray&gt;
697
698Obtains information about the audio effect mode in use. This API uses a promise to return the result.
699
700**System capability**: SystemCapability.Multimedia.Audio.Renderer
701
702**Parameters**
703
704| Name   | Type                               | Mandatory    | Description                        |
705| -------- | ----------------------------------- | -------- | --------------------------- |
706| usage    | [StreamUsage](arkts-apis-audio-e.md#streamusage)         | Yes    |  Audio stream usage.              |
707
708**Return value**
709
710| Type                                                                     | Description                                   |
711| --------------------------------------------------------------------------| --------------------------------------- |
712| Promise<[AudioEffectInfoArray](arkts-apis-audio-AudioStreamManager.md#getaudioeffectinfoarray10)>                  | Promise used to return the information about the audio effect mode obtained.     |
713
714**Error codes**
715
716For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Audio Error Codes](errorcode-audio.md).
717
718| ID| Error Message|
719| ------- | --------------------------------------------|
720| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
721| 6800101 | Parameter verification failed. Return by promise. |
722
723**Example**
724
725```ts
726import { BusinessError } from '@kit.BasicServicesKit';
727
728audioStreamManager.getAudioEffectInfoArray(audio.StreamUsage.STREAM_USAGE_MUSIC).then((audioEffectInfoArray: audio.AudioEffectInfoArray) => {
729  console.info('getAudioEffectInfoArray ######### Get Promise is called ##########');
730  console.info(`The effect modes are: ${audioEffectInfoArray}`);
731}).catch((err: BusinessError) => {
732  console.error(`getAudioEffectInfoArray :ERROR: ${err}`);
733});
734```
735
736## getAudioEffectInfoArraySync<sup>10+</sup>
737
738getAudioEffectInfoArraySync(usage: StreamUsage): AudioEffectInfoArray
739
740Obtains information about the audio effect mode in use. This API returns the result synchronously.
741
742**System capability**: SystemCapability.Multimedia.Audio.Renderer
743
744**Parameters**
745
746| Name   | Type                               | Mandatory    | Description                        |
747| -------- | ----------------------------------- | -------- | --------------------------- |
748| usage    | [StreamUsage](arkts-apis-audio-e.md#streamusage)         | Yes    |  Audio stream usage.              |
749
750**Return value**
751
752| Type                                                                     | Description                                   |
753| --------------------------------------------------------------------------| --------------------------------------- |
754| [AudioEffectInfoArray](arkts-apis-audio-AudioStreamManager.md#getaudioeffectinfoarray10)                  | Information about the audio effect mode.     |
755
756**Error codes**
757
758For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Audio Error Codes](errorcode-audio.md).
759
760| ID| Error Message|
761| ------- | --------------------------------------------|
762| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
763| 6800101 | Parameter verification failed. |
764
765**Example**
766
767```ts
768import { BusinessError } from '@kit.BasicServicesKit';
769
770try {
771  let audioEffectInfoArray: audio.AudioEffectInfoArray = audioStreamManager.getAudioEffectInfoArraySync(audio.StreamUsage.STREAM_USAGE_MUSIC);
772  console.info(`The effect modes are: ${audioEffectInfoArray}`);
773} catch (err) {
774  let error = err as BusinessError;
775  console.error(`getAudioEffectInfoArraySync ERROR: ${error}`);
776}
777```
778
779## isAcousticEchoCancelerSupported<sup>20+</sup>
780
781isAcousticEchoCancelerSupported(sourceType: SourceType): boolean
782
783Checks whether the specified audio source type supports echo cancellation.
784
785**System capability**: SystemCapability.Multimedia.Audio.Capturer
786
787**Parameters**
788
789| Name   | Type                               | Mandatory    | Description                        |
790| -------- | ----------------------------------- | -------- | --------------------------- |
791| sourceType    | [SourceType](arkts-apis-audio-e.md#sourcetype8)         | Yes    |  Audio source type.              |
792
793**Return value**
794
795| Type                                                                     | Description                                   |
796| --------------------------------------------------------------------------| --------------------------------------- |
797|  boolean     | Check result. The value **true** means that echo cancellation is supported, and **false** means the opposite.       |
798
799**Error codes**
800
801For details about the error codes, see [Audio Error Codes](errorcode-audio.md).
802
803| ID| Error Message|
804| ------- | --------------------------------------------|
805| 6800101 | Parameter verification failed. |
806
807**Example**
808
809```ts
810import { BusinessError } from '@kit.BasicServicesKit';
811
812try {
813  let isSupportAEC = audioStreamManager.isAcousticEchoCancelerSupported(audio.SourceType.SOURCE_TYPE_LIVE);
814  console.info(`[AEC Support] SourceType: ${audio.SourceType.SOURCE_TYPE_LIVE}, Status: ${isSupportAEC}`);
815} catch (err) {
816  let error = err as BusinessError;
817  console.error(`isAcousticEchoCancelerSupported ERROR: ${error}`);
818}
819```
820
821## isAudioLoopbackSupported<sup>20+</sup>
822
823isAudioLoopbackSupported(mode: AudioLoopbackMode): boolean
824
825Checks whether the current system supports the specified audio loopback mode.
826
827**System capability**: SystemCapability.Multimedia.Audio.Capturer
828
829**Parameters**
830
831| Name   | Type                               | Mandatory    | Description                        |
832| -------- | ----------------------------------- | -------- | --------------------------- |
833| mode     | [AudioLoopbackMode](arkts-apis-audio-e.md#audioloopbackmode20)         | Yes    |  Audio loopback mode.              |
834
835**Return value**
836
837| Type                                                                     | Description                                   |
838| --------------------------------------------------------------------------| --------------------------------------- |
839|  boolean     | Check result. The value **true** is returned if the audio loopback mode is supported, and **false** is returned otherwise.       |
840
841**Error codes**
842
843For details about the error codes, see [Audio Error Codes](errorcode-audio.md).
844
845| ID| Error Message|
846| ------- | --------------------------------------------|
847| 6800101 | Parameter verification failed.              |
848
849**Example**
850
851```ts
852import { BusinessError } from '@kit.BasicServicesKit';
853
854try {
855  let isSupported = audioStreamManager.isAudioLoopbackSupported(audio.AudioLoopbackMode.HARDWARE);
856  console.info(`[Audio loopback Support] mode: ${audio.AudioLoopbackMode.HARDWARE}, Status: ${isSupported}`);
857} catch (err) {
858  let error = err as BusinessError;
859  console.error(`isAudioLoopbackSupported ERROR: ${error}`);
860}
861```
862
863## isRecordingAvailable<sup>20+</sup>
864
865isRecordingAvailable(capturerInfo: AudioCapturerInfo): boolean
866
867Checks whether recording can be started based on the audio source type in the audio capturer information.
868
869**System capability**: SystemCapability.Multimedia.Audio.Capturer
870
871**Parameters**
872
873| Name   | Type                               | Mandatory    | Description                        |
874| -------- | ----------------------------------- | -------- | --------------------------- |
875| capturerInfo | [AudioCapturerInfo](arkts-apis-audio-i.md#audiocapturerinfo8) | Yes| Audio capturer information.|
876
877**Return value**
878
879| Type         | Description                                   |
880| ------------ | --------------------------------------- |
881|  boolean     | Check result. The value **true** is returned if recording can be started, and **false** is returned otherwise.<br>This API checks whether the specified audio source type in the capturer information can acquire focus. It should be called before starting audio recording to avoid conflicts with existing recording streams.|
882
883**Error codes**
884
885For details about the error codes, see [Audio Error Codes](errorcode-audio.md).
886
887| ID| Error Message|
888| ------- | --------------------------------------------|
889| 6800101 | Parameter verification failed.              |
890
891**Example**
892```ts
893import { BusinessError } from '@kit.BasicServicesKit';
894
895let audioStreamInfo: audio.AudioStreamInfo = {
896  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000,
897  channels: audio.AudioChannel.CHANNEL_2,
898  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
899  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
900};
901
902let audioCapturerInfo: audio.AudioCapturerInfo = {
903  source: audio.SourceType.SOURCE_TYPE_MIC,
904  capturerFlags: 0
905};
906
907let audioCapturerOptions: audio.AudioCapturerOptions = {
908  streamInfo: audioStreamInfo,
909  capturerInfo: audioCapturerInfo
910};
911
912audio.createAudioCapturer(audioCapturerOptions, (err, data) => {
913  if (err) {
914    console.error(`AudioCapturer Created : Error: ${err}`);
915  } else {
916    console.info('AudioCapturer Created : Success : SUCCESS');
917    let audioCapturer = data;
918    try {
919      let isAvailable = audioStreamManager.isRecordingAvailable(audioCapturerInfo);
920      console.info(`[Recording Available] Status: ${isAvailable}`);
921    } catch (err) {
922      let error = err as BusinessError;
923      console.error(`isRecordingAvailable ERROR: ${error}`);
924    }
925  }
926});
927```
928