js-apis-audio.md 181.8 KB
Newer Older
Z
zengyawen 已提交
1
# 音频管理
2

J
jiao_yanlin 已提交
3
音频管理提供管理音频的一些基础能力,包括对音频音量、音频设备的管理,以及对音频数据的采集和渲染等。 
Z
zengyawen 已提交
4 5 6 7

该模块提供以下音频相关的常用功能:

- [AudioManager](#audiomanager):音频管理。
L
lwx1059628 已提交
8
- [AudioRenderer](#audiorenderer8):音频渲染,用于播放PCM(Pulse Code Modulation)音频数据。
9
- [AudioCapturer](#audiocapturer8):音频采集,用于录制PCM音频数据。
Z
zengyawen 已提交
10

11 12 13
>  **说明:**
>  本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

Z
zengyawen 已提交
14
## 导入模块
M
mamingshuai 已提交
15

J
jiao_yanlin 已提交
16
```js
M
mamingshuai 已提交
17 18 19
import audio from '@ohos.multimedia.audio';
```

20 21
## 常量

22
**系统接口:** 该接口为系统接口
23 24

**系统能力:** SystemCapability.Multimedia.Audio.Device
25

26 27 28 29 30 31 32 33 34 35 36
| 名称  | 类型                     | 可读 | 可写 | 说明               |
| ----- | -------------------------- | ---- | ---- | ------------------ |
| LOCAL_NETWORK_ID<sup>9+</sup> | string | 是   | 否   | 本地设备网络id。 |

**示例:**

```js
import audio from '@ohos.multimedia.audio';

const localNetworkId = audio.LOCAL_NETWORK_ID;
```
Z
zengyawen 已提交
37

Z
zengyawen 已提交
38
## audio.getAudioManager
Z
zengyawen 已提交
39 40

getAudioManager(): AudioManager
M
mamingshuai 已提交
41 42 43

获取音频管理器。

Z
zengyawen 已提交
44 45
**系统能力:** SystemCapability.Multimedia.Audio.Core

M
mamingshuai 已提交
46
**返回值:**
47

Z
zengyawen 已提交
48 49
| 类型                          | 说明         |
| ----------------------------- | ------------ |
Z
zengyawen 已提交
50
| [AudioManager](#audiomanager) | 音频管理类。 |
M
mamingshuai 已提交
51 52

**示例:**
J
jiao_yanlin 已提交
53
```js
M
mamingshuai 已提交
54 55 56
var audioManager = audio.getAudioManager();
```

57 58
## audio.getStreamManager<sup>9+</sup>

59
getStreamManager(callback: AsyncCallback\<AudioStreamManager>): void
60

61 62 63 64
获取音频流管理器实例。使用callback方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Core

65 66
**参数:**

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| 参数名   | 类型                                                       | 必填 | 说明             |
| -------- | --------------------------------------------------------- | ---- | ---------------- |
| callback | AsyncCallback<[AudioStreamManager](#audiostreammanager9)> | 是   | 返回音频流管理器实例。 |

**示例:**

```js
audio.getStreamManager((err, data) => {
  if (err) {
    console.error(`getStreamManager : Error: ${err.message}`);
  } else {
    console.info('getStreamManager : Success : SUCCESS');
    let audioStreamManager = data;
  }
});
```

## audio.getStreamManager<sup>9+</sup>

getStreamManager(): Promise<AudioStreamManager\>

获取音频流管理器实例。使用Promise方式异步返回结果。
89

90
**系统能力:** SystemCapability.Multimedia.Audio.Core
91

92
**返回值:**
93

94 95
| 类型                                                | 说明             |
| ---------------------------------------------------- | ---------------- |
96
| Promise<[AudioStreamManager](#audiostreammanager9)> | 返回音频流管理器实例。 |
97

98
**示例:**
99

J
jiao_yanlin 已提交
100
```js
101 102 103 104 105 106 107 108
var audioStreamManager;
audio.getStreamManager().then((data) => {
  audioStreamManager = data;
  console.info('getStreamManager: Success!');
}).catch((err) => {
  console.error(`getStreamManager: ERROR : ${err.message}`);
});

109 110
```

Z
zengyawen 已提交
111 112
## audio.createAudioRenderer<sup>8+</sup>

M
magekkkk 已提交
113
createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\<AudioRenderer>): void
Z
zengyawen 已提交
114

115
获取音频渲染器。使用callback方式异步返回结果。
Z
zengyawen 已提交
116 117 118

**系统能力:** SystemCapability.Multimedia.Audio.Renderer

119
**参数:**
Z
zengyawen 已提交
120

H
update  
HelloCrease 已提交
121 122 123
| 参数名   | 类型                                            | 必填 | 说明             |
| -------- | ----------------------------------------------- | ---- | ---------------- |
| options  | [AudioRendererOptions](#audiorendereroptions8)  | 是   | 配置渲染器。     |
M
magekkkk 已提交
124
| callback | AsyncCallback<[AudioRenderer](#audiorenderer8)> | 是   | 音频渲染器对象。 |
L
lwx1059628 已提交
125 126 127

**示例:**

J
jiao_yanlin 已提交
128
```js
L
lwx1059628 已提交
129
import audio from '@ohos.multimedia.audio';
L
lwx1059628 已提交
130
var audioStreamInfo = {
J
jiao_yanlin 已提交
131 132 133 134
  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
  channels: audio.AudioChannel.CHANNEL_1,
  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
L
lwx1059628 已提交
135 136 137
}

var audioRendererInfo = {
J
jiao_yanlin 已提交
138 139
  content: audio.ContentType.CONTENT_TYPE_SPEECH,
  usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
J
jiao_yanlin 已提交
140
  rendererFlags: 0
L
lwx1059628 已提交
141 142 143
}

var audioRendererOptions = {
J
jiao_yanlin 已提交
144 145
  streamInfo: audioStreamInfo,
  rendererInfo: audioRendererInfo
L
lwx1059628 已提交
146 147 148
}

audio.createAudioRenderer(audioRendererOptions,(err, data) => {
J
jiao_yanlin 已提交
149
  if (err) {
J
jiao_yanlin 已提交
150
    console.error(`AudioRenderer Created: Error: ${err.message}`);
J
jiao_yanlin 已提交
151
  } else {
152
    console.info('AudioRenderer Created: Success: SUCCESS');
J
jiao_yanlin 已提交
153 154
    let audioRenderer = data;
  }
L
lwx1059628 已提交
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
});
```

## audio.createAudioRenderer<sup>8+</sup>

createAudioRenderer(options: AudioRendererOptions): Promise<AudioRenderer\>

获取音频渲染器。使用Promise方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Renderer

**参数:**

| 参数名  | 类型                                           | 必填 | 说明         |
| :------ | :--------------------------------------------- | :--- | :----------- |
| options | [AudioRendererOptions](#audiorendereroptions8) | 是   | 配置渲染器。 |

**返回值:**

| 类型                                      | 说明             |
| ----------------------------------------- | ---------------- |
176
| Promise<[AudioRenderer](#audiorenderer8)> | 音频渲染器对象。 |
Z
zengyawen 已提交
177 178 179

**示例:**

J
jiao_yanlin 已提交
180
```js
L
lwx1059628 已提交
181 182
import audio from '@ohos.multimedia.audio';

Z
zengyawen 已提交
183
var audioStreamInfo = {
J
jiao_yanlin 已提交
184 185 186 187
  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
  channels: audio.AudioChannel.CHANNEL_1,
  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
Z
zengyawen 已提交
188 189 190
}

var audioRendererInfo = {
J
jiao_yanlin 已提交
191 192
  content: audio.ContentType.CONTENT_TYPE_SPEECH,
  usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
J
jiao_yanlin 已提交
193
  rendererFlags: 0
Z
zengyawen 已提交
194 195 196
}

var audioRendererOptions = {
J
jiao_yanlin 已提交
197 198
  streamInfo: audioStreamInfo,
  rendererInfo: audioRendererInfo
Z
zengyawen 已提交
199 200
}

L
lwx1059628 已提交
201 202
var audioRenderer;
audio.createAudioRenderer(audioRendererOptions).then((data) => {
J
jiao_yanlin 已提交
203
  audioRenderer = data;
204
  console.info('AudioFrameworkRenderLog: AudioRenderer Created : Success : Stream Type: SUCCESS');
L
lwx1059628 已提交
205
}).catch((err) => {
206
  console.error(`AudioFrameworkRenderLog: AudioRenderer Created : ERROR : ${err.message}`);
L
lwx1059628 已提交
207
});
Z
zengyawen 已提交
208
```
Z
zengyawen 已提交
209

L
lwx1059628 已提交
210 211 212 213 214 215 216 217 218 219
## audio.createAudioCapturer<sup>8+</sup>

createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback<AudioCapturer\>): void

获取音频采集器。使用callback方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**参数:**

H
update  
HelloCrease 已提交
220 221
| 参数名   | 类型                                            | 必填 | 说明             |
| :------- | :---------------------------------------------- | :--- | :--------------- |
Z
zengyawen 已提交
222
| options  | [AudioCapturerOptions](#audiocaptureroptions8)  | 是   | 配置音频采集器。 |
M
magekkkk 已提交
223
| callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | 是   | 音频采集器对象。 |
L
lwx1059628 已提交
224 225 226

**示例:**

J
jiao_yanlin 已提交
227
```js
L
lwx1059628 已提交
228
import audio from '@ohos.multimedia.audio';
L
lwx1059628 已提交
229
var audioStreamInfo = {
J
jiao_yanlin 已提交
230 231 232 233
  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
  channels: audio.AudioChannel.CHANNEL_2,
  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
L
lwx1059628 已提交
234 235 236
}

var audioCapturerInfo = {
J
jiao_yanlin 已提交
237
  source: audio.SourceType.SOURCE_TYPE_MIC,
J
jiao_yanlin 已提交
238
  capturerFlags: 0
L
lwx1059628 已提交
239 240 241
}

var audioCapturerOptions = {
J
jiao_yanlin 已提交
242 243
  streamInfo: audioStreamInfo,
  capturerInfo: audioCapturerInfo
L
lwx1059628 已提交
244 245
}

J
jiao_yanlin 已提交
246
audio.createAudioCapturer(audioCapturerOptions, (err, data) => {
J
jiao_yanlin 已提交
247 248
  if (err) {
    console.error(`AudioCapturer Created : Error: ${err.message}`);
J
jiao_yanlin 已提交
249
  } else {
250
    console.info('AudioCapturer Created : Success : SUCCESS');
J
jiao_yanlin 已提交
251 252
    let audioCapturer = data;
  }
L
lwx1059628 已提交
253 254 255 256 257 258 259 260 261 262 263 264 265
});
```

## audio.createAudioCapturer<sup>8+</sup>

createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\>

获取音频采集器。使用promise 方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**参数:**

Z
zengyawen 已提交
266 267 268
| 参数名  | 类型                                           | 必填 | 说明             |
| :------ | :--------------------------------------------- | :--- | :--------------- |
| options | [AudioCapturerOptions](#audiocaptureroptions8) | 是   | 配置音频采集器。 |
L
lwx1059628 已提交
269 270 271 272 273

**返回值:**

| 类型                                      | 说明           |
| ----------------------------------------- | -------------- |
M
magekkkk 已提交
274
| Promise<[AudioCapturer](#audiocapturer8)> | 音频采集器对象 |
L
lwx1059628 已提交
275 276 277

**示例:**

J
jiao_yanlin 已提交
278
```js
L
lwx1059628 已提交
279 280
import audio from '@ohos.multimedia.audio';

L
lwx1059628 已提交
281
var audioStreamInfo = {
J
jiao_yanlin 已提交
282 283 284 285
  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
  channels: audio.AudioChannel.CHANNEL_2,
  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
L
lwx1059628 已提交
286 287 288
}

var audioCapturerInfo = {
J
jiao_yanlin 已提交
289
  source: audio.SourceType.SOURCE_TYPE_MIC,
J
jiao_yanlin 已提交
290
  capturerFlags: 0
L
lwx1059628 已提交
291 292 293
}

var audioCapturerOptions = {
J
jiao_yanlin 已提交
294 295
  streamInfo: audioStreamInfo,
  capturerInfo: audioCapturerInfo
L
lwx1059628 已提交
296 297
}

L
lwx1059628 已提交
298
var audioCapturer;
R
rahul 已提交
299
audio.createAudioCapturer(audioCapturerOptions).then((data) => {
J
jiao_yanlin 已提交
300
  audioCapturer = data;
301
  console.info('AudioCapturer Created : Success : Stream Type: SUCCESS');
L
lwx1059628 已提交
302
}).catch((err) => {
303
  console.error(`AudioCapturer Created : ERROR : ${err.message}`);
L
lwx1059628 已提交
304
});
L
lwx1059628 已提交
305 306
```

Z
zengyawen 已提交
307
## AudioVolumeType
M
mamingshuai 已提交
308

309
枚举,音频流类型。
M
mamingshuai 已提交
310

Z
zengyawen 已提交
311 312 313 314 315 316 317 318
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Volume

| 名称                         | 默认值 | 描述       |
| ---------------------------- | ------ | ---------- |
| VOICE_CALL<sup>8+</sup>      | 0      | 语音电话。 |
| RINGTONE                     | 2      | 铃声。     |
| MEDIA                        | 3      | 媒体。     |
| VOICE_ASSISTANT<sup>8+</sup> | 9      | 语音助手。 |
319
| ALL<sup>9+</sup>             | 100    | 所有公共音频流。<br/>此接口为系统接口,三方应用不支持调用。|
Z
zengyawen 已提交
320

321
## InterruptMode<sup>9+</sup>
322

323
枚举,焦点模型。
324

325
**系统能力:** SystemCapability.Multimedia.Audio.Core
326 327 328

| 名称                         | 默认值 | 描述       |
| ---------------------------- | ------ | ---------- |
329 330
| SHARE_MODE      | 0      | 共享焦点模式。 |
| INDEPENDENT_MODE| 1      | 独立焦点模式。     |
331

Z
zengyawen 已提交
332
## DeviceFlag
M
mamingshuai 已提交
333

334
枚举,可获取的设备种类。
M
mamingshuai 已提交
335

Z
zengyawen 已提交
336 337 338 339
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Device

| 名称                | 默认值 | 描述       |
| ------------------- | ------ | ---------- |
340
| NONE_DEVICES_FLAG<sup>9+</sup>   | 0      | 无         |
Z
zengyawen 已提交
341 342 343
| OUTPUT_DEVICES_FLAG | 1      | 输出设备。 |
| INPUT_DEVICES_FLAG  | 2      | 输入设备。 |
| ALL_DEVICES_FLAG    | 3      | 所有设备。 |
344 345 346
| DISTRIBUTED_OUTPUT_DEVICES_FLAG<sup>9+</sup> | 4   | 分布式输出设备。  |
| DISTRIBUTED_INPUT_DEVICES_FLAG<sup>9+</sup>  | 8   | 分布式输入设备。  |
| ALL_DISTRIBUTED_DEVICES_FLAG<sup>9+</sup>    | 12  | 分布式输入和输出设备。  |
Z
zengyawen 已提交
347 348 349


## DeviceRole
M
mamingshuai 已提交
350

351
枚举,设备角色。
M
mamingshuai 已提交
352

Z
zengyawen 已提交
353 354 355 356 357 358
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Device

| 名称          | 默认值 | 描述           |
| ------------- | ------ | -------------- |
| INPUT_DEVICE  | 1      | 输入设备角色。 |
| OUTPUT_DEVICE | 2      | 输出设备角色。 |
M
mamingshuai 已提交
359 360


Z
zengyawen 已提交
361 362 363
## DeviceType

枚举,设备类型。
M
magekkkk 已提交
364

Z
zengyawen 已提交
365 366
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Device

H
update  
HelloCrease 已提交
367 368 369 370 371 372 373 374 375 376 377
| 名称             | 默认值 | 描述                                                      |
| ---------------- | ------ | --------------------------------------------------------- |
| INVALID          | 0      | 无效设备。                                                |
| EARPIECE         | 1      | 听筒。                                                    |
| SPEAKER          | 2      | 扬声器。                                                  |
| WIRED_HEADSET    | 3      | 有线耳机,带麦克风。                                      |
| WIRED_HEADPHONES | 4      | 有线耳机,无麦克风。                                      |
| BLUETOOTH_SCO    | 7      | 蓝牙设备SCO(Synchronous Connection Oriented)连接。      |
| BLUETOOTH_A2DP   | 8      | 蓝牙设备A2DP(Advanced Audio Distribution Profile)连接。 |
| MIC              | 15     | 麦克风。                                                  |
| USB_HEADSET      | 22     | USB耳机,带麦克风。                                       |
378
| DEFAULT          | 1000   | 默认设备类型。                                            |
M
magekkkk 已提交
379

Z
zengyawen 已提交
380
## ActiveDeviceType
M
magekkkk 已提交
381

Z
zengyawen 已提交
382
枚举,活跃设备类型。
M
magekkkk 已提交
383

Z
zengyawen 已提交
384 385 386 387 388 389
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Device

| 名称          | 默认值 | 描述                                                 |
| ------------- | ------ | ---------------------------------------------------- |
| SPEAKER       | 2      | 扬声器。                                             |
| BLUETOOTH_SCO | 7      | 蓝牙设备SCO(Synchronous Connection Oriented)连接。 |
M
mamingshuai 已提交
390

Z
zengyawen 已提交
391
## AudioRingMode
392 393 394

枚举,铃声模式。

Z
zengyawen 已提交
395 396 397 398 399 400 401 402 403 404 405 406 407 408
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Communication

| 名称                | 默认值 | 描述       |
| ------------------- | ------ | ---------- |
| RINGER_MODE_SILENT  | 0      | 静音模式。 |
| RINGER_MODE_VIBRATE | 1      | 震动模式。 |
| RINGER_MODE_NORMAL  | 2      | 响铃模式。 |

## AudioSampleFormat<sup>8+</sup>

枚举,音频采样格式。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Core

409 410 411 412 413 414 415 416
| 名称                                | 默认值 | 描述                       |
| ---------------------------------- | ------ | -------------------------- |
| SAMPLE_FORMAT_INVALID              | -1     | 无效格式。                 |
| SAMPLE_FORMAT_U8                   | 0      | 无符号8位整数。            |
| SAMPLE_FORMAT_S16LE                | 1      | 带符号的16位整数,小尾数。 |
| SAMPLE_FORMAT_S24LE                | 2      | 带符号的24位整数,小尾数。 <br>由于系统限制,该采样格式仅部分设备支持,请根据实际情况使用。|
| SAMPLE_FORMAT_S32LE                | 3      | 带符号的32位整数,小尾数。 <br>由于系统限制,该采样格式仅部分设备支持,请根据实际情况使用。|
| SAMPLE_FORMAT_F32LE<sup>9+</sup>   | 4      | 带符号的32位整数,小尾数。 <br>由于系统限制,该采样格式仅部分设备支持,请根据实际情况使用。|
Z
zengyawen 已提交
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459

## AudioChannel<sup>8+</sup>

枚举, 音频声道。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Core

| 名称      | 默认值   | 描述     |
| --------- | -------- | -------- |
| CHANNEL_1 | 0x1 << 0 | 单声道。 |
| CHANNEL_2 | 0x1 << 1 | 双声道。 |

## AudioSamplingRate<sup>8+</sup>

枚举,音频采样率。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Core

| 名称              | 默认值 | 描述            |
| ----------------- | ------ | --------------- |
| SAMPLE_RATE_8000  | 8000   | 采样率为8000。  |
| SAMPLE_RATE_11025 | 11025  | 采样率为11025。 |
| SAMPLE_RATE_12000 | 12000  | 采样率为12000。 |
| SAMPLE_RATE_16000 | 16000  | 采样率为16000。 |
| SAMPLE_RATE_22050 | 22050  | 采样率为22050。 |
| SAMPLE_RATE_24000 | 24000  | 采样率为24000。 |
| SAMPLE_RATE_32000 | 32000  | 采样率为32000。 |
| SAMPLE_RATE_44100 | 44100  | 采样率为44100。 |
| SAMPLE_RATE_48000 | 48000  | 采样率为48000。 |
| SAMPLE_RATE_64000 | 64000  | 采样率为64000。 |
| SAMPLE_RATE_96000 | 96000  | 采样率为96000。 |

## AudioEncodingType<sup>8+</sup>

枚举,音频编码类型。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Core

| 名称                  | 默认值 | 描述      |
| --------------------- | ------ | --------- |
| ENCODING_TYPE_INVALID | -1     | 无效。    |
| ENCODING_TYPE_RAW     | 0      | PCM编码。 |

L
lwx1059628 已提交
460
## ContentType
Z
zengyawen 已提交
461 462 463 464 465

枚举,音频内容类型。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Core

L
lwx1059628 已提交
466 467 468 469 470 471 472 473
| 名称                               | 默认值 | 描述       |
| ---------------------------------- | ------ | ---------- |
| CONTENT_TYPE_UNKNOWN               | 0      | 未知类型。 |
| CONTENT_TYPE_SPEECH                | 1      | 语音。     |
| CONTENT_TYPE_MUSIC                 | 2      | 音乐。     |
| CONTENT_TYPE_MOVIE                 | 3      | 电影。     |
| CONTENT_TYPE_SONIFICATION          | 4      | 加密类型。 |
| CONTENT_TYPE_RINGTONE<sup>8+</sup> | 5      | 铃声。     |
Z
zengyawen 已提交
474

L
lwx1059628 已提交
475
## StreamUsage
Z
zengyawen 已提交
476 477 478 479 480 481 482 483 484 485

枚举,音频流使用类型。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Core

| 名称                               | 默认值 | 描述       |
| ---------------------------------- | ------ | ---------- |
| STREAM_USAGE_UNKNOWN               | 0      | 未知类型。 |
| STREAM_USAGE_MEDIA                 | 1      | 音频。     |
| STREAM_USAGE_VOICE_COMMUNICATION   | 2      | 语音通信。 |
L
lwx1059628 已提交
486
| STREAM_USAGE_NOTIFICATION_RINGTONE | 6      | 通知铃声。 |
Z
zengyawen 已提交
487

488
## FocusType<sup>9+</sup>
489

490
表示焦点类型的枚举。
491

492
**系统能力:**: SystemCapability.Multimedia.Audio.Core
493

494 495 496
| 名称                               | 默认值  | 描述                            |
| ---------------------------------- | ------ | ------------------------------- |
| FOCUS_TYPE_RECORDING               | 0      |  在录制场景使用,可打断其他音频。  |
497 498


Z
zengyawen 已提交
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
## AudioState<sup>8+</sup>

枚举,音频状态。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Core

| 名称           | 默认值 | 描述             |
| -------------- | ------ | ---------------- |
| STATE_INVALID  | -1     | 无效状态。       |
| STATE_NEW      | 0      | 创建新实例状态。 |
| STATE_PREPARED | 1      | 准备状态。       |
| STATE_RUNNING  | 2      | 可运行状态。     |
| STATE_STOPPED  | 3      | 停止状态。       |
| STATE_RELEASED | 4      | 释放状态。       |
| STATE_PAUSED   | 5      | 暂停状态。       |

## AudioRendererRate<sup>8+</sup>

L
lwx1059628 已提交
517
枚举,音频渲染速度。
Z
zengyawen 已提交
518 519 520 521 522 523 524 525 526

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer

| 名称               | 默认值 | 描述       |
| ------------------ | ------ | ---------- |
| RENDER_RATE_NORMAL | 0      | 正常速度。 |
| RENDER_RATE_DOUBLE | 1      | 2倍速。    |
| RENDER_RATE_HALF   | 2      | 0.5倍数。  |

L
lwx1059628 已提交
527
## InterruptType
Z
zengyawen 已提交
528 529 530 531

枚举,中断类型。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
532

Z
zengyawen 已提交
533 534 535 536 537
| 名称                 | 默认值 | 描述                   |
| -------------------- | ------ | ---------------------- |
| INTERRUPT_TYPE_BEGIN | 1      | 音频播放中断事件开始。 |
| INTERRUPT_TYPE_END   | 2      | 音频播放中断事件结束。 |

L
lwx1059628 已提交
538
## InterruptForceType<sup>9+</sup>
Z
zengyawen 已提交
539 540 541 542 543 544 545 546 547 548

枚举,强制打断类型。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer

| 名称            | 默认值 | 描述                                 |
| --------------- | ------ | ------------------------------------ |
| INTERRUPT_FORCE | 0      | 由系统进行操作,强制打断音频播放。   |
| INTERRUPT_SHARE | 1      | 由应用进行操作,可以选择打断或忽略。 |

L
lwx1059628 已提交
549
## InterruptHint
Z
zengyawen 已提交
550 551 552 553 554

枚举,中断提示。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer

L
lwx1059628 已提交
555 556 557 558 559 560 561 562
| 名称                               | 默认值 | 描述                                         |
| ---------------------------------- | ------ | -------------------------------------------- |
| INTERRUPT_HINT_NONE<sup>8+</sup>   | 0      | 无提示。                                     |
| INTERRUPT_HINT_RESUME              | 1      | 提示音频恢复。                               |
| INTERRUPT_HINT_PAUSE               | 2      | 提示音频暂停。                               |
| INTERRUPT_HINT_STOP                | 3      | 提示音频停止。                               |
| INTERRUPT_HINT_DUCK                | 4      | 提示音频躲避。(躲避:音量减弱,而不会停止) |
| INTERRUPT_HINT_UNDUCK<sup>8+</sup> | 5      | 提示音量恢复。                               |
Z
zengyawen 已提交
563

564 565 566 567 568 569
## InterruptActionType

枚举,中断事件返回类型。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer

H
update  
HelloCrease 已提交
570 571 572 573
| 名称           | 默认值 | 描述               |
| -------------- | ------ | ------------------ |
| TYPE_ACTIVATED | 0      | 表示触发焦点事件。 |
| TYPE_INTERRUPT | 1      | 表示音频打断事件。 |
574

Z
zengyawen 已提交
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
## AudioStreamInfo<sup>8+</sup>

音频流信息。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Core

| 名称         | 类型                                     | 必填 | 说明               |
| ------------ | ---------------------------------------- | ---- | ------------------ |
| samplingRate | [AudioSamplingRate](#audiosamplingrate8) | 是   | 音频文件的采样率。 |
| channels     | [AudioChannel](#audiochannel8)           | 是   | 音频文件的通道数。 |
| sampleFormat | [AudioSampleFormat](#audiosampleformat8) | 是   | 音频采样格式。     |
| encodingType | [AudioEncodingType](#audioencodingtype8) | 是   | 音频编码格式。     |

## AudioRendererInfo<sup>8+</sup>

L
lwx1059628 已提交
590
音频渲染器信息。
Z
zengyawen 已提交
591 592 593

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Core

L
lwx1059628 已提交
594 595
| 名称          | 类型                        | 必填 | 说明             |
| ------------- | --------------------------- | ---- | ---------------- |
Z
zengyawen 已提交
596
| content       | [ContentType](#contenttype) | 是   | 媒体类型。       |
L
lwx1059628 已提交
597 598
| usage         | [StreamUsage](#streamusage) | 是   | 音频流使用类型。 |
| rendererFlags | number                      | 是   | 音频渲染器标志。 |
Z
zengyawen 已提交
599 600 601

## AudioRendererOptions<sup>8+</sup>

L
lwx1059628 已提交
602
音频渲染器选项信息。
Z
zengyawen 已提交
603 604 605 606 607 608

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer

| 名称         | 类型                                     | 必填 | 说明             |
| ------------ | ---------------------------------------- | ---- | ---------------- |
| streamInfo   | [AudioStreamInfo](#audiostreaminfo8)     | 是   | 表示音频流信息。 |
L
lwx1059628 已提交
609
| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | 是   | 表示渲染器信息。 |
Z
zengyawen 已提交
610

L
lwx1059628 已提交
611
## InterruptEvent<sup>9+</sup>
Z
zengyawen 已提交
612 613 614 615 616 617 618

播放中断时,应用接收的中断事件。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer

| 名称      | 类型                                       | 必填 | 说明                                 |
| --------- | ------------------------------------------ | ---- | ------------------------------------ |
L
lwx1059628 已提交
619 620 621
| eventType | [InterruptType](#interrupttype)            | 是   | 中断事件类型,开始或是结束。         |
| forceType | [InterruptForceType](#interruptforcetype9) | 是   | 操作是由系统执行或是由应用程序执行。 |
| hintType  | [InterruptHint](#interrupthint)            | 是   | 中断提示。                           |
Z
zengyawen 已提交
622

623 624 625 626 627 628
## AudioInterrupt

音频监听事件传入的参数。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer

H
update  
HelloCrease 已提交
629 630 631 632 633
| 名称            | 类型                        | 必填 | 说明                                                         |
| --------------- | --------------------------- | ---- | ------------------------------------------------------------ |
| streamUsage     | [StreamUsage](#streamusage) | 是   | 音频流使用类型。                                             |
| contentType     | [ContentType](#contenttype) | 是   | 音频打断媒体类型。                                           |
| pauseWhenDucked | boolean                     | 是   | 音频打断时是否可以暂停音频播放(true表示音频播放可以在音频打断期间暂停,false表示相反)。 |
634 635 636 637 638 639 640

## InterruptAction

音频打断/获取焦点事件的回调方法。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer

H
update  
HelloCrease 已提交
641 642 643 644
| 名称       | 类型                                        | 必填 | 说明                                                         |
| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
| actionType | [InterruptActionType](#interruptactiontype) | 是   | 事件返回类型。TYPE_ACTIVATED为焦点触发事件,TYPE_INTERRUPT为音频打断事件。 |
| type       | [InterruptType](#interrupttype)             | 否   | 打断事件类型。                                               |
Z
zengyawen 已提交
645
| hint       | [InterruptHint](#interrupthint)              | 否   | 打断事件提示。                                               |
H
update  
HelloCrease 已提交
646
| activated  | boolean                                     | 否   | 获得/释放焦点。true表示焦点获取/释放成功,false表示焦点获得/释放失败。 |
647

Z
zengyawen 已提交
648 649 650 651
## VolumeEvent<sup>8+</sup>

音量改变时,应用接收的事件。

652
**系统接口:** 该接口为系统接口
L
lwx1059628 已提交
653

Z
zengyawen 已提交
654 655 656 657 658 659 660
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Volume

| 名称       | 类型                                | 必填 | 说明                                                     |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
| volume     | number                              | 是   | 音量等级,可设置范围通过getMinVolume和getMaxVolume获取。 |
| updateUi   | boolean                             | 是   | 在UI中显示音量变化。                                     |
W
wangtao 已提交
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
| volumeGroupId<sup>9+</sup>   | number            | 是   | 音量组id。可用于getGroupManager入参                      |
| networkId<sup>9+</sup>    | string               | 是   | 网络id。                                                |

## ConnectType<sup>9+</sup>

枚举,设备连接类型。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Device

| 名称                            | 默认值 | 描述                   |
| :------------------------------ | :----- | :--------------------- |
| CONNECT_TYPE_LOCAL              | 1      | 本地设备。         |
| CONNECT_TYPE_DISTRIBUTED        | 2      | 分布式设备。            |

## VolumeGroupInfo<sup>9+</sup>

音量组信息。

679
**系统接口:** 该接口为系统接口
W
wangtao 已提交
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Volume

| 名称                        | 类型                       | 可读 | 可写 | 说明       |
| -------------------------- | -------------------------- | ---- | ---- | ---------- |
| networkId<sup>9+</sup>     | string                     | 是   | 否   | 组网络id。  |
| groupId<sup>9+</sup>       | number                     | 是   | 否   | 组设备组id。 |
| mappingId<sup>9+</sup>     | number                     | 是   | 否   | 组映射id。 |
| groupName<sup>9+</sup>     | number                     | 是   | 否   | 组名。 |
| ConnectType<sup>9+</sup>   | [ConnectType](#connecttype9)| 是   | 否   | 连接设备类型。 |

## VolumeGroupInfos<sup>9+</sup>

音量组信息,数组类型,为[VolumeGroupInfo](#volumegroupinfo9)的数组,只读。

695
**系统接口:** 该接口为系统接口
W
wangtao 已提交
696 697 698 699 700 701 702 703 704 705 706 707 708 709

**系统能力:** SystemCapability.Multimedia.Audio.Volume

**示例:**

```js
import audio from '@ohos.multimedia.audio';

async function getVolumeGroupInfos(){
  let volumegroupinfos = await audio.getAudioManager().getVolumeGroups(audio.LOCAL_NETWORK_ID);
  console.info('Promise returned to indicate that the volumeGroup list is obtained.'+JSON.stringify(volumegroupinfos))
}
getVolumeGroupInfos();
```
Z
zengyawen 已提交
710

L
lwx1059628 已提交
711 712 713 714
## DeviceChangeAction

描述设备连接状态变化和设备信息。

715
**系统能力:** SystemCapability.Multimedia.Audio.Device
L
lwx1059628 已提交
716 717 718

| 名称              | 类型                                              | 必填 | 说明               |
| :---------------- | :------------------------------------------------ | :--- | :----------------- |
719 720
| type              | [DeviceChangeType](#devicechangetype)             | 是   | 设备连接状态变化。 |
| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | 是   | 设备信息。         |
L
lwx1059628 已提交
721 722 723 724 725 726 727 728 729 730 731 732

## DeviceChangeType

枚举,设备连接状态变化。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Device

| 名称       | 默认值 | 描述           |
| :--------- | :----- | :------------- |
| CONNECT    | 0      | 设备连接。     |
| DISCONNECT | 1      | 断开设备连接。 |

Z
zengyawen 已提交
733 734 735 736 737 738 739 740 741
## AudioCapturerOptions<sup>8+</sup>

音频采集器选项信息。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Capturer

| 名称         | 类型                                    | 必填 | 说明             |
| ------------ | --------------------------------------- | ---- | ---------------- |
| streamInfo   | [AudioStreamInfo](#audiostreaminfo8)    | 是   | 表示音频流信息。 |
Z
zengyawen 已提交
742
| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo) | 是   | 表示采集器信息。 |
Z
zengyawen 已提交
743

L
lwx1059628 已提交
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
## AudioCapturerInfo<sup>8+</sup><a name="audiocapturerinfo"></a>

描述音频采集器信息。

**系统能力:** SystemCapability.Multimedia.Audio.Core

| 名称          | 类型                      | 必填 | 说明             |
| :------------ | :------------------------ | :--- | :--------------- |
| source        | [SourceType](#sourcetype) | 是   | 音源类型。       |
| capturerFlags | number                    | 是   | 音频采集器标志。 |

## SourceType<sup>8+</sup><a name="sourcetype"></a>

枚举,音源类型。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Core

Z
update  
zengyawen 已提交
761 762 763 764 765
| 名称                            | 默认值 | 描述                   |
| :------------------------------ | :----- | :--------------------- |
| SOURCE_TYPE_INVALID             | -1     | 无效的音频源。         |
| SOURCE_TYPE_MIC                 | 0      | Mic音频源。            |
| SOURCE_TYPE_VOICE_COMMUNICATION | 7      | 语音通话场景的音频源。 |
L
lwx1059628 已提交
766 767 768 769 770 771 772

## AudioScene<sup>8+</sup><a name="audioscene"></a>

枚举,音频场景。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Communication

Z
zengyawen 已提交
773 774 775
| 名称                   | 默认值 | 描述                                          |
| :--------------------- | :----- | :-------------------------------------------- |
| AUDIO_SCENE_DEFAULT    | 0      | 默认音频场景。                                |
776 777
| AUDIO_SCENE_RINGING    | 1      | 响铃模式。<br/>此接口为系统接口,三方应用不支持调用。 |
| AUDIO_SCENE_PHONE_CALL | 2      | 电话模式。<br/>此接口为系统接口,三方应用不支持调用。 |
Z
zengyawen 已提交
778
| AUDIO_SCENE_VOICE_CHAT | 3      | 语音聊天模式。                                |
L
lwx1059628 已提交
779

W
wangtao 已提交
780

Z
zengyawen 已提交
781
## AudioManager
M
mamingshuai 已提交
782

Z
zengyawen 已提交
783
管理音频音量和音频设备。在调用AudioManager的接口前,需要先通过[getAudioManager](#audiogetaudiomanager)创建实例。
M
mamingshuai 已提交
784

785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
### getRoutingManager<sup>9+</sup>

getRoutingManager(callback: AsyncCallback&lt;AudioRoutingManager&gt;): void

获取AudioRoutingManager对象,使用callback方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Device

**参数:**

| 参数名     | 类型                                                              | 必填 | 说明                               |
| ---------- | ---------------------------------------------------------------- | ---- | --------------------------------- |
| callback   | AsyncCallback&lt;[AudioRoutingManager](#audioroutingmanager9)&gt; | 是   | 回调,返回AudioRoutingManager对象。 |

**示例:**
```js
await audioManager.getRoutingManager((err,callback) => {
  if (err) {
    console.error(`Result ERROR: ${err.message}`);
  }
  console.info('getRoutingManager Callback SUCCESS.');
  var audioRoutingManager;
  audioRoutingManager = callback;
});
```

### getRoutingManager<sup>9+</sup>

getRoutingManager(): Promise&lt;AudioRoutingManager&gt;

获取AudioRoutingManager对象,使用Promise方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Device

**返回值:**

| 类型                                                        | 说明                                    |
| ----------------------------------------------------------- | --------------------------------------- |
| Promise&lt;[AudioRoutingManager](#audioroutingmanager9)&gt;  | Promise回调返回AudioRoutingManager对象。 |

**示例:**
```js
await audioManager.getRoutingManager().then((value) => {
  var routingManager = value;
  console.info('getRoutingManager Promise SUCCESS.');
}).catch((err) => {
  console.error(`Result ERROR: ${err.message}`);
});
```

Z
zengyawen 已提交
835 836 837
### setVolume

setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&lt;void&gt;): void
M
mamingshuai 已提交
838

Z
zengyawen 已提交
839
设置指定流的音量,使用callback方式异步返回结果。
M
mamingshuai 已提交
840

841 842 843
**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY

仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
844

Z
zengyawen 已提交
845 846
**系统能力:** SystemCapability.Multimedia.Audio.Volume

M
mamingshuai 已提交
847 848
**参数:**

Z
zengyawen 已提交
849 850 851 852 853
| 参数名     | 类型                                | 必填 | 说明                                                     |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
| volume     | number                              | 是   | 音量等级,可设置范围通过getMinVolume和getMaxVolume获取。 |
| callback   | AsyncCallback&lt;void&gt;           | 是   | 回调表示成功还是失败。                                   |
854

M
mamingshuai 已提交
855 856
**示例:**

J
jiao_yanlin 已提交
857
```js
L
lwx1059628 已提交
858
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
J
jiao_yanlin 已提交
859
  if (err) {
860
    console.error(`Failed to set the volume. ${err.message}`);
J
jiao_yanlin 已提交
861 862
    return;
  }
863
  console.info('Callback invoked to indicate a successful volume setting.');
L
lwx1059628 已提交
864
});
M
mamingshuai 已提交
865 866
```

Z
zengyawen 已提交
867 868 869
### setVolume

setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
M
mamingshuai 已提交
870

Z
zengyawen 已提交
871
设置指定流的音量,使用Promise方式异步返回结果。
M
mamingshuai 已提交
872

873 874 875
**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY

仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
876

Z
zengyawen 已提交
877 878
**系统能力:** SystemCapability.Multimedia.Audio.Volume

M
mamingshuai 已提交
879 880
**参数:**

Z
zengyawen 已提交
881 882 883 884
| 参数名     | 类型                                | 必填 | 说明                                                     |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
| volume     | number                              | 是   | 音量等级,可设置范围通过getMinVolume和getMaxVolume获取。 |
M
mamingshuai 已提交
885 886 887

**返回值:**

Z
zengyawen 已提交
888 889
| 类型                | 说明                          |
| ------------------- | ----------------------------- |
Z
zengyawen 已提交
890
| Promise&lt;void&gt; | Promise回调表示成功还是失败。 |
M
mamingshuai 已提交
891 892 893

**示例:**

J
jiao_yanlin 已提交
894
```js
A
AOL 已提交
895
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
896
  console.info('Promise returned to indicate a successful volume setting.');
L
lwx1059628 已提交
897
});
M
mamingshuai 已提交
898 899
```

Z
zengyawen 已提交
900 901 902
### getVolume

getVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
M
mamingshuai 已提交
903

Z
zengyawen 已提交
904
获取指定流的音量,使用callback方式异步返回结果。
M
mamingshuai 已提交
905

Z
zengyawen 已提交
906 907
**系统能力:** SystemCapability.Multimedia.Audio.Volume

M
mamingshuai 已提交
908 909
**参数:**

Z
zengyawen 已提交
910 911 912 913
| 参数名     | 类型                                | 必填 | 说明               |
| ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。       |
| callback   | AsyncCallback&lt;number&gt;         | 是   | 回调返回音量大小。 |
914

M
mamingshuai 已提交
915 916
**示例:**

J
jiao_yanlin 已提交
917
```js
918
audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
J
jiao_yanlin 已提交
919
  if (err) {
920
    console.error(`Failed to obtain the volume. ${err.message}`);
J
jiao_yanlin 已提交
921 922
    return;
  }
923
  console.info('Callback invoked to indicate that the volume is obtained.');
L
lwx1059628 已提交
924
});
M
mamingshuai 已提交
925 926
```

Z
zengyawen 已提交
927 928 929
### getVolume

getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
M
mamingshuai 已提交
930

Z
zengyawen 已提交
931
获取指定流的音量,使用Promise方式异步返回结果。
M
mamingshuai 已提交
932

Z
zengyawen 已提交
933 934
**系统能力:** SystemCapability.Multimedia.Audio.Volume

M
mamingshuai 已提交
935 936
**参数:**

Z
zengyawen 已提交
937 938 939
| 参数名     | 类型                                | 必填 | 说明         |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
M
mamingshuai 已提交
940 941 942

**返回值:**

Z
zengyawen 已提交
943 944
| 类型                  | 说明                      |
| --------------------- | ------------------------- |
Z
zengyawen 已提交
945
| Promise&lt;number&gt; | Promise回调返回音量大小。 |
M
mamingshuai 已提交
946 947 948

**示例:**

J
jiao_yanlin 已提交
949
```js
A
AOL 已提交
950
audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
951
  console.info(`Promise returned to indicate that the volume is obtained ${value} .`);
L
lwx1059628 已提交
952
});
M
mamingshuai 已提交
953 954
```

Z
zengyawen 已提交
955 956 957
### getMinVolume

getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
M
mamingshuai 已提交
958

Z
zengyawen 已提交
959
获取指定流的最小音量,使用callback方式异步返回结果。
M
mamingshuai 已提交
960

Z
zengyawen 已提交
961 962
**系统能力:** SystemCapability.Multimedia.Audio.Volume

M
mamingshuai 已提交
963 964
**参数:**

Z
zengyawen 已提交
965 966 967 968
| 参数名     | 类型                                | 必填 | 说明               |
| ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。       |
| callback   | AsyncCallback&lt;number&gt;         | 是   | 回调返回最小音量。 |
969

M
mamingshuai 已提交
970 971
**示例:**

J
jiao_yanlin 已提交
972
```js
Z
zengyawen 已提交
973
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
J
jiao_yanlin 已提交
974
  if (err) {
975
    console.error(`Failed to obtain the minimum volume. ${err.message}`);
J
jiao_yanlin 已提交
976 977
    return;
  }
978
  console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
L
lwx1059628 已提交
979
});
M
mamingshuai 已提交
980 981
```

Z
zengyawen 已提交
982 983 984
### getMinVolume

getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
M
mamingshuai 已提交
985

Z
zengyawen 已提交
986
获取指定流的最小音量,使用Promise方式异步返回结果。
M
mamingshuai 已提交
987

Z
zengyawen 已提交
988 989
**系统能力:** SystemCapability.Multimedia.Audio.Volume

M
mamingshuai 已提交
990 991
**参数:**

Z
zengyawen 已提交
992 993 994
| 参数名     | 类型                                | 必填 | 说明         |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
M
mamingshuai 已提交
995 996 997

**返回值:**

Z
zengyawen 已提交
998 999
| 类型                  | 说明                      |
| --------------------- | ------------------------- |
Z
zengyawen 已提交
1000
| Promise&lt;number&gt; | Promise回调返回最小音量。 |
M
mamingshuai 已提交
1001 1002 1003

**示例:**

J
jiao_yanlin 已提交
1004
```js
A
AOL 已提交
1005
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
1006
  console.info(`Promised returned to indicate that the minimum volume is obtained. ${value}`);
L
lwx1059628 已提交
1007
});
M
mamingshuai 已提交
1008 1009
```

Z
zengyawen 已提交
1010 1011 1012
### getMaxVolume

getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
M
mamingshuai 已提交
1013

Z
zengyawen 已提交
1014
获取指定流的最大音量,使用callback方式异步返回结果。
M
mamingshuai 已提交
1015

Z
zengyawen 已提交
1016 1017
**系统能力:** SystemCapability.Multimedia.Audio.Volume

M
mamingshuai 已提交
1018 1019
**参数:**

Z
zengyawen 已提交
1020 1021 1022 1023
| 参数名     | 类型                                | 必填 | 说明                   |
| ---------- | ----------------------------------- | ---- | ---------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。           |
| callback   | AsyncCallback&lt;number&gt;         | 是   | 回调返回最大音量大小。 |
1024

M
mamingshuai 已提交
1025 1026
**示例:**

J
jiao_yanlin 已提交
1027
```js
1028
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
J
jiao_yanlin 已提交
1029
  if (err) {
1030
    console.error(`Failed to obtain the maximum volume. ${err.message}`);
J
jiao_yanlin 已提交
1031 1032
    return;
  }
1033
  console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`);
L
lwx1059628 已提交
1034
});
M
mamingshuai 已提交
1035 1036
```

Z
zengyawen 已提交
1037 1038 1039
### getMaxVolume

getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
M
mamingshuai 已提交
1040

Z
zengyawen 已提交
1041
获取指定流的最大音量,使用Promise方式异步返回结果。
M
mamingshuai 已提交
1042

Z
zengyawen 已提交
1043 1044
**系统能力:** SystemCapability.Multimedia.Audio.Volume

M
mamingshuai 已提交
1045 1046
**参数:**

Z
zengyawen 已提交
1047 1048 1049
| 参数名     | 类型                                | 必填 | 说明         |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
M
mamingshuai 已提交
1050 1051 1052

**返回值:**

Z
zengyawen 已提交
1053 1054
| 类型                  | 说明                          |
| --------------------- | ----------------------------- |
Z
zengyawen 已提交
1055
| Promise&lt;number&gt; | Promise回调返回最大音量大小。 |
M
mamingshuai 已提交
1056 1057 1058

**示例:**

J
jiao_yanlin 已提交
1059
```js
A
AOL 已提交
1060
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
1061
  console.info('Promised returned to indicate that the maximum volume is obtained.');
L
lwx1059628 已提交
1062
});
Z
zengyawen 已提交
1063 1064
```

Z
zengyawen 已提交
1065
### mute
Z
zengyawen 已提交
1066 1067

mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
Z
zengyawen 已提交
1068

Z
zengyawen 已提交
1069
设置指定音量流静音,使用callback方式异步返回结果。
Z
zengyawen 已提交
1070

1071 1072 1073
**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY

仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
1074

Z
zengyawen 已提交
1075 1076
**系统能力:** SystemCapability.Multimedia.Audio.Volume

Z
zengyawen 已提交
1077 1078
**参数:**

Z
zengyawen 已提交
1079 1080 1081 1082 1083
| 参数名     | 类型                                | 必填 | 说明                                  |
| ---------- | ----------------------------------- | ---- | ------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                          |
| mute       | boolean                             | 是   | 静音状态,true为静音,false为非静音。 |
| callback   | AsyncCallback&lt;void&gt;           | 是   | 回调表示成功还是失败。                |
1084

Z
zengyawen 已提交
1085 1086
**示例:**

J
jiao_yanlin 已提交
1087
```js
1088
audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
J
jiao_yanlin 已提交
1089
  if (err) {
1090
    console.error(`Failed to mute the stream. ${err.message}`);
J
jiao_yanlin 已提交
1091 1092
    return;
  }
1093
  console.info('Callback invoked to indicate that the stream is muted.');
L
lwx1059628 已提交
1094
});
1095 1096
```

Z
zengyawen 已提交
1097
### mute
Z
zengyawen 已提交
1098 1099

mute(volumeType: AudioVolumeType, mute: boolean): Promise&lt;void&gt;
1100

Z
zengyawen 已提交
1101
设置指定音量流静音,使用Promise方式异步返回结果。
1102

1103 1104 1105
**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY

仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
1106

Z
zengyawen 已提交
1107 1108
**系统能力:** SystemCapability.Multimedia.Audio.Volume

1109 1110
**参数:**

Z
zengyawen 已提交
1111 1112 1113 1114
| 参数名     | 类型                                | 必填 | 说明                                  |
| ---------- | ----------------------------------- | ---- | ------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                          |
| mute       | boolean                             | 是   | 静音状态,true为静音,false为非静音。 |
1115 1116 1117

**返回值:**

Z
zengyawen 已提交
1118 1119
| 类型                | 说明                          |
| ------------------- | ----------------------------- |
Z
zengyawen 已提交
1120
| Promise&lt;void&gt; | Promise回调表示成功还是失败。 |
1121 1122 1123

**示例:**

Z
zengyawen 已提交
1124

J
jiao_yanlin 已提交
1125
```js
A
AOL 已提交
1126
audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
1127
  console.info('Promise returned to indicate that the stream is muted.');
L
lwx1059628 已提交
1128
});
1129 1130 1131
```


Z
zengyawen 已提交
1132
### isMute
1133

Z
zengyawen 已提交
1134
isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
1135

Z
zengyawen 已提交
1136
获取指定音量流是否被静音,使用callback方式异步返回结果。
1137

Z
zengyawen 已提交
1138 1139
**系统能力:** SystemCapability.Multimedia.Audio.Volume

Z
zengyawen 已提交
1140
**参数:**
1141

Z
zengyawen 已提交
1142 1143 1144 1145
| 参数名     | 类型                                | 必填 | 说明                                            |
| ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                    |
| callback   | AsyncCallback&lt;boolean&gt;        | 是   | 回调返回流静音状态,true为静音,false为非静音。 |
1146 1147 1148

**示例:**

J
jiao_yanlin 已提交
1149
```js
1150
audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
J
jiao_yanlin 已提交
1151
  if (err) {
1152
    console.error(`Failed to obtain the mute status. ${err.message}`);
J
jiao_yanlin 已提交
1153 1154
    return;
  }
1155
  console.info(`Callback invoked to indicate that the mute status of the stream is obtained. ${value}`);
L
lwx1059628 已提交
1156
});
Z
zengyawen 已提交
1157 1158
```

Z
zengyawen 已提交
1159

Z
zengyawen 已提交
1160
### isMute
Z
zengyawen 已提交
1161 1162

isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
Z
zengyawen 已提交
1163

Z
zengyawen 已提交
1164
获取指定音量流是否被静音,使用Promise方式异步返回结果。
Z
zengyawen 已提交
1165

Z
zengyawen 已提交
1166 1167
**系统能力:** SystemCapability.Multimedia.Audio.Volume

Z
zengyawen 已提交
1168 1169
**参数:**

Z
zengyawen 已提交
1170 1171 1172
| 参数名     | 类型                                | 必填 | 说明         |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
Z
zengyawen 已提交
1173 1174 1175

**返回值:**

Z
zengyawen 已提交
1176 1177
| 类型                   | 说明                                                   |
| ---------------------- | ------------------------------------------------------ |
Z
zengyawen 已提交
1178
| Promise&lt;boolean&gt; | Promise回调返回流静音状态,true为静音,false为非静音。 |
M
mamingshuai 已提交
1179

Z
zengyawen 已提交
1180 1181
**示例:**

J
jiao_yanlin 已提交
1182
```js
A
AOL 已提交
1183
audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
1184
  console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`);
L
lwx1059628 已提交
1185
});
Z
zengyawen 已提交
1186 1187
```

Z
zengyawen 已提交
1188
### isActive
Z
zengyawen 已提交
1189 1190

isActive(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
Z
zengyawen 已提交
1191

Z
zengyawen 已提交
1192
获取指定音量流是否为活跃状态,使用callback方式异步返回结果。
1193

Z
zengyawen 已提交
1194 1195
**系统能力:** SystemCapability.Multimedia.Audio.Volume

1196 1197
**参数:**

Z
zengyawen 已提交
1198 1199 1200 1201
| 参数名     | 类型                                | 必填 | 说明                                              |
| ---------- | ----------------------------------- | ---- | ------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                      |
| callback   | AsyncCallback&lt;boolean&gt;        | 是   | 回调返回流的活跃状态,true为活跃,false为不活跃。 |
1202 1203 1204

**示例:**

J
jiao_yanlin 已提交
1205
```js
1206
audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
J
jiao_yanlin 已提交
1207
  if (err) {
1208
    console.error(`Failed to obtain the active status of the stream. ${err.message}`);
J
jiao_yanlin 已提交
1209 1210
    return;
  }
1211
  console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`);
L
lwx1059628 已提交
1212
});
1213 1214
```

Z
zengyawen 已提交
1215
### isActive
Z
zengyawen 已提交
1216 1217

isActive(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
1218

Z
zengyawen 已提交
1219
获取指定音量流是否为活跃状态,使用Promise方式异步返回结果。
1220

Z
zengyawen 已提交
1221 1222
**系统能力:** SystemCapability.Multimedia.Audio.Volume

1223 1224
**参数:**

Z
zengyawen 已提交
1225 1226 1227
| 参数名     | 类型                                | 必填 | 说明         |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
1228 1229 1230

**返回值:**

Z
zengyawen 已提交
1231 1232
| 类型                   | 说明                                                     |
| ---------------------- | -------------------------------------------------------- |
Z
zengyawen 已提交
1233
| Promise&lt;boolean&gt; | Promise回调返回流的活跃状态,true为活跃,false为不活跃。 |
Z
zengyawen 已提交
1234

1235 1236
**示例:**

J
jiao_yanlin 已提交
1237
```js
A
AOL 已提交
1238
audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
1239
  console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`);
L
lwx1059628 已提交
1240
});
1241 1242
```

Z
zengyawen 已提交
1243
### setRingerMode
Z
zengyawen 已提交
1244 1245

setRingerMode(mode: AudioRingMode, callback: AsyncCallback&lt;void&gt;): void
1246

Z
zengyawen 已提交
1247
设置铃声模式,使用callback方式异步返回结果。
1248

1249 1250 1251
**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY

仅在静音和非静音状态切换时需要该权限。
1252

Z
zengyawen 已提交
1253 1254
**系统能力:** SystemCapability.Multimedia.Audio.Communication

1255 1256
**参数:**

Z
zengyawen 已提交
1257 1258 1259 1260
| 参数名   | 类型                            | 必填 | 说明                     |
| -------- | ------------------------------- | ---- | ------------------------ |
| mode     | [AudioRingMode](#audioringmode) | 是   | 音频铃声模式。           |
| callback | AsyncCallback&lt;void&gt;       | 是   | 回调返回设置成功或失败。 |
1261 1262 1263

**示例:**

J
jiao_yanlin 已提交
1264
```js
1265
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
J
jiao_yanlin 已提交
1266
  if (err) {
1267
    console.error(`Failed to set the ringer mode.​ ${err.message}`);
J
jiao_yanlin 已提交
1268 1269
    return;
  }
1270
  console.info('Callback invoked to indicate a successful setting of the ringer mode.');
L
lwx1059628 已提交
1271
});
1272 1273
```

Z
zengyawen 已提交
1274
### setRingerMode
Z
zengyawen 已提交
1275 1276

setRingerMode(mode: AudioRingMode): Promise&lt;void&gt;
1277

Z
zengyawen 已提交
1278
设置铃声模式,使用Promise方式异步返回结果。
1279

1280 1281 1282
**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY

仅在静音和非静音状态切换时需要该权限。
1283

Z
zengyawen 已提交
1284 1285
**系统能力:** SystemCapability.Multimedia.Audio.Communication

1286 1287
**参数:**

Z
zengyawen 已提交
1288 1289 1290
| 参数名 | 类型                            | 必填 | 说明           |
| ------ | ------------------------------- | ---- | -------------- |
| mode   | [AudioRingMode](#audioringmode) | 是   | 音频铃声模式。 |
1291 1292 1293

**返回值:**

Z
zengyawen 已提交
1294 1295
| 类型                | 说明                            |
| ------------------- | ------------------------------- |
Z
zengyawen 已提交
1296
| Promise&lt;void&gt; | Promise回调返回设置成功或失败。 |
1297 1298 1299

**示例:**

J
jiao_yanlin 已提交
1300
```js
A
AOL 已提交
1301
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
1302
  console.info('Promise returned to indicate a successful setting of the ringer mode.');
L
lwx1059628 已提交
1303
});
1304 1305 1306
```


Z
zengyawen 已提交
1307
### getRingerMode
1308

Z
zengyawen 已提交
1309
getRingerMode(callback: AsyncCallback&lt;AudioRingMode&gt;): void
1310

Z
zengyawen 已提交
1311
获取铃声模式,使用callback方式异步返回结果。
1312

Z
zengyawen 已提交
1313 1314
**系统能力:** SystemCapability.Multimedia.Audio.Communication

Z
zengyawen 已提交
1315
**参数:**
1316

Z
zengyawen 已提交
1317 1318 1319
| 参数名   | 类型                                                 | 必填 | 说明                     |
| -------- | ---------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback&lt;[AudioRingMode](#audioringmode)&gt; | 是   | 回调返回系统的铃声模式。 |
1320 1321 1322

**示例:**

J
jiao_yanlin 已提交
1323
```js
1324
audioManager.getRingerMode((err, value) => {
J
jiao_yanlin 已提交
1325
  if (err) {
1326
    console.error(`Failed to obtain the ringer mode.​ ${err.message}`);
J
jiao_yanlin 已提交
1327 1328
    return;
  }
1329
  console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`);
L
lwx1059628 已提交
1330
});
1331 1332 1333
```


Z
zengyawen 已提交
1334
### getRingerMode
1335

Z
zengyawen 已提交
1336
getRingerMode(): Promise&lt;AudioRingMode&gt;
1337

Z
zengyawen 已提交
1338
获取铃声模式,使用Promise方式异步返回结果。
1339

Z
zengyawen 已提交
1340 1341
**系统能力:** SystemCapability.Multimedia.Audio.Communication

1342 1343
**返回值:**

Z
zengyawen 已提交
1344 1345
| 类型                                           | 说明                            |
| ---------------------------------------------- | ------------------------------- |
1346
| Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise回调返回系统的铃声模式。 |
1347 1348 1349

**示例:**

J
jiao_yanlin 已提交
1350
```js
A
AOL 已提交
1351
audioManager.getRingerMode().then((value) => {
1352
  console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`);
L
lwx1059628 已提交
1353
});
1354 1355
```

Z
zengyawen 已提交
1356
### setAudioParameter
Z
zengyawen 已提交
1357 1358

setAudioParameter(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
1359

Z
zengyawen 已提交
1360
音频参数设置,使用callback方式异步返回结果。
1361

1362
本接口的使用场景为根据硬件设备支持能力扩展音频配置。在不同的设备平台上,所支持的音频参数会存在差异。示例代码内使用样例参数,实际支持的音频配置参数见具体设备平台的资料描述。
1363

1364 1365
**需要权限:** ohos.permission.MODIFY_AUDIO_SETTINGS

Z
zengyawen 已提交
1366 1367
**系统能力:** SystemCapability.Multimedia.Audio.Core

1368 1369
**参数:**

Z
zengyawen 已提交
1370 1371 1372 1373 1374
| 参数名   | 类型                      | 必填 | 说明                     |
| -------- | ------------------------- | ---- | ------------------------ |
| key      | string                    | 是   | 被设置的音频参数的键。   |
| value    | string                    | 是   | 被设置的音频参数的值。   |
| callback | AsyncCallback&lt;void&gt; | 是   | 回调返回设置成功或失败。 |
1375 1376 1377

**示例:**

J
jiao_yanlin 已提交
1378
```js
1379
audioManager.setAudioParameter('key_example', 'value_example', (err) => {
J
jiao_yanlin 已提交
1380
  if (err) {
1381
    console.error(`Failed to set the audio parameter. ${err.message}`);
J
jiao_yanlin 已提交
1382 1383
    return;
  }
1384
  console.info('Callback invoked to indicate a successful setting of the audio parameter.');
L
lwx1059628 已提交
1385
});
1386 1387
```

Z
zengyawen 已提交
1388
### setAudioParameter
Z
zengyawen 已提交
1389 1390

setAudioParameter(key: string, value: string): Promise&lt;void&gt;
1391

Z
zengyawen 已提交
1392
音频参数设置,使用Promise方式异步返回结果。
1393

1394
本接口的使用场景为根据硬件设备支持能力扩展音频配置。在不同的设备平台上,所支持的音频参数会存在差异。示例代码内使用样例参数,实际支持的音频配置参数见具体设备平台的资料描述。
1395

1396 1397
**需要权限:** ohos.permission.MODIFY_AUDIO_SETTINGS

Z
zengyawen 已提交
1398 1399
**系统能力:** SystemCapability.Multimedia.Audio.Core

1400 1401
**参数:**

Z
zengyawen 已提交
1402 1403 1404 1405
| 参数名 | 类型   | 必填 | 说明                   |
| ------ | ------ | ---- | ---------------------- |
| key    | string | 是   | 被设置的音频参数的键。 |
| value  | string | 是   | 被设置的音频参数的值。 |
1406 1407 1408

**返回值:**

Z
zengyawen 已提交
1409 1410
| 类型                | 说明                            |
| ------------------- | ------------------------------- |
Z
zengyawen 已提交
1411
| Promise&lt;void&gt; | Promise回调返回设置成功或失败。 |
1412 1413 1414

**示例:**

J
jiao_yanlin 已提交
1415
```js
1416
audioManager.setAudioParameter('key_example', 'value_example').then(() => {
1417
  console.info('Promise returned to indicate a successful setting of the audio parameter.');
L
lwx1059628 已提交
1418
});
1419 1420
```

Z
zengyawen 已提交
1421
### getAudioParameter
Z
zengyawen 已提交
1422 1423

getAudioParameter(key: string, callback: AsyncCallback&lt;string&gt;): void
1424

Z
zengyawen 已提交
1425
获取指定音频参数值,使用callback方式异步返回结果。
1426

1427
本接口的使用场景为根据硬件设备支持能力扩展音频配置。在不同的设备平台上,所支持的音频参数会存在差异。示例代码内使用样例参数,实际支持的音频配置参数见具体设备平台的资料描述。
1428

Z
zengyawen 已提交
1429 1430
**系统能力:** SystemCapability.Multimedia.Audio.Core

1431 1432
**参数:**

Z
zengyawen 已提交
1433 1434 1435 1436
| 参数名   | 类型                        | 必填 | 说明                         |
| -------- | --------------------------- | ---- | ---------------------------- |
| key      | string                      | 是   | 待获取的音频参数的键。       |
| callback | AsyncCallback&lt;string&gt; | 是   | 回调返回获取的音频参数的值。 |
1437 1438 1439

**示例:**

J
jiao_yanlin 已提交
1440
```js
1441
audioManager.getAudioParameter('key_example', (err, value) => {
J
jiao_yanlin 已提交
1442
  if (err) {
1443
    console.error(`Failed to obtain the value of the audio parameter. ${err.message}`);
J
jiao_yanlin 已提交
1444 1445
    return;
  }
1446
  console.info(`Callback invoked to indicate that the value of the audio parameter is obtained ${value}.`);
L
lwx1059628 已提交
1447
});
1448 1449
```

Z
zengyawen 已提交
1450
### getAudioParameter
Z
zengyawen 已提交
1451 1452

getAudioParameter(key: string): Promise&lt;string&gt;
1453

Z
zengyawen 已提交
1454
获取指定音频参数值,使用Promise方式异步返回结果。
1455

1456
本接口的使用场景为根据硬件设备支持能力扩展音频配置。在不同的设备平台上,所支持的音频参数会存在差异。示例代码内使用样例参数,实际支持的音频配置参数见具体设备平台的资料描述。
1457

Z
zengyawen 已提交
1458 1459
**系统能力:** SystemCapability.Multimedia.Audio.Core

1460 1461
**参数:**

Z
zengyawen 已提交
1462 1463 1464
| 参数名 | 类型   | 必填 | 说明                   |
| ------ | ------ | ---- | ---------------------- |
| key    | string | 是   | 待获取的音频参数的键。 |
1465 1466 1467

**返回值:**

Z
zengyawen 已提交
1468 1469
| 类型                  | 说明                                |
| --------------------- | ----------------------------------- |
Z
zengyawen 已提交
1470
| Promise&lt;string&gt; | Promise回调返回获取的音频参数的值。 |
1471 1472 1473

**示例:**

J
jiao_yanlin 已提交
1474
```js
1475
audioManager.getAudioParameter('key_example').then((value) => {
1476
  console.info(`Promise returned to indicate that the value of the audio parameter is obtained ${value}.`);
L
lwx1059628 已提交
1477
});
1478 1479
```

Z
zengyawen 已提交
1480 1481 1482
### getDevices

getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
1483

Z
zengyawen 已提交
1484
获取音频设备列表,使用callback方式异步返回结果。
1485

Z
zengyawen 已提交
1486 1487
**系统能力:** SystemCapability.Multimedia.Audio.Device

1488 1489
**参数:**

Z
zengyawen 已提交
1490 1491 1492 1493
| 参数名     | 类型                                                         | 必填 | 说明                 |
| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
| deviceFlag | [DeviceFlag](#deviceflag)                                    | 是   | 设备类型的flag。     |
| callback   | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | 是   | 回调,返回设备列表。 |
1494 1495

**示例:**
J
jiao_yanlin 已提交
1496
```js
A
AOL 已提交
1497
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
J
jiao_yanlin 已提交
1498
  if (err) {
1499
    console.error(`Failed to obtain the device list. ${err.message}`);
J
jiao_yanlin 已提交
1500 1501
    return;
  }
1502
  console.info('Callback invoked to indicate that the device list is obtained.');
L
lwx1059628 已提交
1503
});
1504 1505
```

Z
zengyawen 已提交
1506 1507
### getDevices

A
AOL 已提交
1508
getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
1509

Z
zengyawen 已提交
1510
获取音频设备列表,使用Promise方式异步返回结果。
1511

Z
zengyawen 已提交
1512 1513
**系统能力:** SystemCapability.Multimedia.Audio.Device

1514 1515
**参数:**

Z
zengyawen 已提交
1516 1517 1518
| 参数名     | 类型                      | 必填 | 说明             |
| ---------- | ------------------------- | ---- | ---------------- |
| deviceFlag | [DeviceFlag](#deviceflag) | 是   | 设备类型的flag。 |
1519 1520 1521

**返回值:**

Z
zengyawen 已提交
1522 1523
| 类型                                                         | 说明                      |
| ------------------------------------------------------------ | ------------------------- |
Z
zengyawen 已提交
1524
| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise回调返回设备列表。 |
1525 1526 1527

**示例:**

J
jiao_yanlin 已提交
1528
```js
A
AOL 已提交
1529
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
1530
  console.info('Promise returned to indicate that the device list is obtained.');
L
lwx1059628 已提交
1531
});
1532 1533
```

Z
zengyawen 已提交
1534
### setDeviceActive
Z
zengyawen 已提交
1535

A
AOL 已提交
1536
setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
1537

Z
zengyawen 已提交
1538
设置设备激活状态,使用callback方式异步返回结果。
1539

Z
zengyawen 已提交
1540 1541
**系统能力:** SystemCapability.Multimedia.Audio.Device

1542 1543
**参数:**

H
update  
HelloCrease 已提交
1544 1545 1546 1547 1548
| 参数名     | 类型                                  | 必填 | 说明                     |
| ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | 是   | 活跃音频设备类型。       |
| active     | boolean                               | 是   | 设备激活状态。           |
| callback   | AsyncCallback&lt;void&gt;             | 是   | 回调返回设置成功或失败。 |
1549 1550 1551

**示例:**

J
jiao_yanlin 已提交
1552
```js
R
rahul 已提交
1553
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err) => {
J
jiao_yanlin 已提交
1554
  if (err) {
1555
    console.error(`Failed to set the active status of the device. ${err.message}`);
J
jiao_yanlin 已提交
1556 1557
    return;
  }
1558
  console.info('Callback invoked to indicate that the device is set to the active status.');
L
lwx1059628 已提交
1559
});
1560 1561
```

Z
zengyawen 已提交
1562
### setDeviceActive
Z
zengyawen 已提交
1563

A
AOL 已提交
1564
setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise&lt;void&gt;
1565

Z
zengyawen 已提交
1566
设置设备激活状态,使用Promise方式异步返回结果。
1567

Z
zengyawen 已提交
1568 1569
**系统能力:** SystemCapability.Multimedia.Audio.Device

1570 1571
**参数:**

H
update  
HelloCrease 已提交
1572 1573
| 参数名     | 类型                                  | 必填 | 说明               |
| ---------- | ------------------------------------- | ---- | ------------------ |
A
AOL 已提交
1574
| deviceType | [ActiveDeviceType](#activedevicetype) | 是   | 活跃音频设备类型。 |
H
update  
HelloCrease 已提交
1575
| active     | boolean                               | 是   | 设备激活状态。     |
1576 1577 1578

**返回值:**

Z
zengyawen 已提交
1579 1580
| 类型                | 说明                            |
| ------------------- | ------------------------------- |
Z
zengyawen 已提交
1581
| Promise&lt;void&gt; | Promise回调返回设置成功或失败。 |
1582 1583 1584

**示例:**

Z
zengyawen 已提交
1585

J
jiao_yanlin 已提交
1586
```js
R
rahul 已提交
1587
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => {
1588
  console.info('Promise returned to indicate that the device is set to the active status.');
L
lwx1059628 已提交
1589
});
1590 1591
```

Z
zengyawen 已提交
1592
### isDeviceActive
Z
zengyawen 已提交
1593

A
AOL 已提交
1594
isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
1595

Z
zengyawen 已提交
1596
获取指定设备的激活状态,使用callback方式异步返回结果。
1597

Z
zengyawen 已提交
1598 1599
**系统能力:** SystemCapability.Multimedia.Audio.Device

1600 1601
**参数:**

H
update  
HelloCrease 已提交
1602 1603 1604 1605
| 参数名     | 类型                                  | 必填 | 说明                     |
| ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | 是   | 活跃音频设备类型。       |
| callback   | AsyncCallback&lt;boolean&gt;          | 是   | 回调返回设备的激活状态。 |
1606 1607 1608

**示例:**

J
jiao_yanlin 已提交
1609
```js
R
rahul 已提交
1610
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err, value) => {
J
jiao_yanlin 已提交
1611
  if (err) {
1612
    console.error(`Failed to obtain the active status of the device. ${err.message}`);
J
jiao_yanlin 已提交
1613 1614
    return;
  }
1615
  console.info('Callback invoked to indicate that the active status of the device is obtained.');
L
lwx1059628 已提交
1616
});
1617 1618
```

Z
zengyawen 已提交
1619

Z
zengyawen 已提交
1620
### isDeviceActive
Z
zengyawen 已提交
1621

A
AOL 已提交
1622
isDeviceActive(deviceType: ActiveDeviceType): Promise&lt;boolean&gt;
1623

Z
zengyawen 已提交
1624
获取指定设备的激活状态,使用Promise方式异步返回结果。
1625

Z
zengyawen 已提交
1626 1627
**系统能力:** SystemCapability.Multimedia.Audio.Device

1628 1629
**参数:**

H
update  
HelloCrease 已提交
1630 1631
| 参数名     | 类型                                  | 必填 | 说明               |
| ---------- | ------------------------------------- | ---- | ------------------ |
A
AOL 已提交
1632
| deviceType | [ActiveDeviceType](#activedevicetype) | 是   | 活跃音频设备类型。 |
1633 1634 1635

**返回值:**

Z
zengyawen 已提交
1636 1637
| Type                   | Description                     |
| ---------------------- | ------------------------------- |
Z
zengyawen 已提交
1638
| Promise&lt;boolean&gt; | Promise回调返回设备的激活状态。 |
1639 1640 1641

**示例:**

J
jiao_yanlin 已提交
1642
```js
R
rahul 已提交
1643
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value) => {
1644
  console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
L
lwx1059628 已提交
1645
});
1646 1647
```

Z
zengyawen 已提交
1648
### setMicrophoneMute
Z
zengyawen 已提交
1649 1650

setMicrophoneMute(mute: boolean, callback: AsyncCallback&lt;void&gt;): void
1651

Z
zengyawen 已提交
1652
设置麦克风静音状态,使用callback方式异步返回结果。
1653

1654 1655
**需要权限:** ohos.permission.MICROPHONE

Z
zengyawen 已提交
1656 1657
**系统能力:** SystemCapability.Multimedia.Audio.Device

1658 1659
**参数:**

Z
zengyawen 已提交
1660 1661 1662 1663
| 参数名   | 类型                      | 必填 | 说明                                          |
| -------- | ------------------------- | ---- | --------------------------------------------- |
| mute     | boolean                   | 是   | 待设置的静音状态,true为静音,false为非静音。 |
| callback | AsyncCallback&lt;void&gt; | 是   | 回调返回设置成功或失败。                      |
1664 1665 1666

**示例:**

J
jiao_yanlin 已提交
1667
```js
1668
audioManager.setMicrophoneMute(true, (err) => {
J
jiao_yanlin 已提交
1669
  if (err) {
1670
    console.error(`Failed to mute the microphone. ${err.message}`);
J
jiao_yanlin 已提交
1671 1672
    return;
  }
1673
  console.info('Callback invoked to indicate that the microphone is muted.');
L
lwx1059628 已提交
1674
});
1675 1676
```

Z
zengyawen 已提交
1677
### setMicrophoneMute
Z
zengyawen 已提交
1678 1679

setMicrophoneMute(mute: boolean): Promise&lt;void&gt;
1680

Z
zengyawen 已提交
1681
设置麦克风静音状态,使用Promise方式异步返回结果。
1682

1683 1684
**需要权限:** ohos.permission.MICROPHONE

Z
zengyawen 已提交
1685 1686
**系统能力:** SystemCapability.Multimedia.Audio.Device

1687 1688
**参数:**

Z
zengyawen 已提交
1689 1690 1691
| 参数名 | 类型    | 必填 | 说明                                          |
| ------ | ------- | ---- | --------------------------------------------- |
| mute   | boolean | 是   | 待设置的静音状态,true为静音,false为非静音。 |
1692 1693 1694

**返回值:**

Z
zengyawen 已提交
1695 1696
| 类型                | 说明                            |
| ------------------- | ------------------------------- |
Z
zengyawen 已提交
1697
| Promise&lt;void&gt; | Promise回调返回设置成功或失败。 |
1698 1699 1700

**示例:**

J
jiao_yanlin 已提交
1701
```js
A
AOL 已提交
1702
audioManager.setMicrophoneMute(true).then(() => {
1703
  console.info('Promise returned to indicate that the microphone is muted.');
L
lwx1059628 已提交
1704
});
1705 1706
```

Z
zengyawen 已提交
1707
### isMicrophoneMute
Z
zengyawen 已提交
1708 1709

isMicrophoneMute(callback: AsyncCallback&lt;boolean&gt;): void
1710

Z
zengyawen 已提交
1711
获取麦克风静音状态,使用callback方式异步返回结果。
1712

1713 1714
**需要权限:** ohos.permission.MICROPHONE

Z
zengyawen 已提交
1715 1716
**系统能力:** SystemCapability.Multimedia.Audio.Device

1717 1718
**参数:**

Z
zengyawen 已提交
1719 1720 1721
| 参数名   | 类型                         | 必填 | 说明                                                    |
| -------- | ---------------------------- | ---- | ------------------------------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调返回系统麦克风静音状态,true为静音,false为非静音。 |
1722 1723 1724

**示例:**

J
jiao_yanlin 已提交
1725
```js
1726
audioManager.isMicrophoneMute((err, value) => {
J
jiao_yanlin 已提交
1727
  if (err) {
1728
    console.error(`Failed to obtain the mute status of the microphone. ${err.message}`);
J
jiao_yanlin 已提交
1729 1730
    return;
  }
1731
  console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`);
L
lwx1059628 已提交
1732
});
1733 1734
```

Z
zengyawen 已提交
1735
### isMicrophoneMute
1736

Z
zengyawen 已提交
1737
isMicrophoneMute(): Promise&lt;boolean&gt;
1738

Z
zengyawen 已提交
1739
获取麦克风静音状态,使用Promise方式异步返回结果。
1740

1741 1742
**需要权限:** ohos.permission.MICROPHONE

Z
zengyawen 已提交
1743 1744
**系统能力:** SystemCapability.Multimedia.Audio.Device

1745 1746
**返回值:**

Z
zengyawen 已提交
1747 1748
| 类型                   | 说明                                                         |
| ---------------------- | ------------------------------------------------------------ |
Z
zengyawen 已提交
1749
| Promise&lt;boolean&gt; | Promise回调返回系统麦克风静音状态,true为静音,false为非静音。 |
1750 1751 1752

**示例:**

Z
zengyawen 已提交
1753

J
jiao_yanlin 已提交
1754
```js
A
AOL 已提交
1755
audioManager.isMicrophoneMute().then((value) => {
1756
  console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`);
L
lwx1059628 已提交
1757
});
1758 1759
```

L
lwx1059628 已提交
1760
### on('volumeChange')<sup>8+</sup>
Z
zengyawen 已提交
1761 1762 1763 1764 1765

on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void

监听系统音量变化事件。

1766
**系统接口:** 该接口为系统接口
L
lwx1059628 已提交
1767

1768 1769
目前此订阅接口在单进程多AudioManager实例的使用场景下,仅最后一个实例的订阅生效,其他实例的订阅会被覆盖(即使最后一个实例没有进行订阅),因此推荐使用单一AudioManager实例进行开发。

Z
zengyawen 已提交
1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780
**系统能力:** SystemCapability.Multimedia.Audio.Volume

**参数:**

| 参数名   | 类型                                   | 必填 | 说明                                                         |
| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                                 | 是   | 事件回调类型,支持的事件为:'volumeChange'(系统音量变化事件,检测到系统音量改变时,触发该事件)。 |
| callback | Callback<[VolumeEvent](#volumeevent8)> | 是   | 回调方法。                                                   |

**示例:**

J
jiao_yanlin 已提交
1781
```js
Z
zengyawen 已提交
1782
audioManager.on('volumeChange', (volumeEvent) => {
1783 1784 1785
  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
  console.info(`Volume level: ${volumeEvent.volume} `);
  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
L
lwx1059628 已提交
1786
});
Z
zengyawen 已提交
1787 1788
```

L
lwx1059628 已提交
1789
### on('ringerModeChange')<sup>8+</sup>
Z
zengyawen 已提交
1790

A
AOL 已提交
1791
on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void
Z
zengyawen 已提交
1792 1793 1794

监听铃声模式变化事件。

1795
**系统接口:** 该接口为系统接口
L
lwx1059628 已提交
1796

Z
zengyawen 已提交
1797 1798 1799 1800 1801 1802 1803 1804
**系统能力:** SystemCapability.Multimedia.Audio.Communication

**参数:**

| 参数名   | 类型                                      | 必填 | 说明                                                         |
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                                    | 是   | 事件回调类型,支持的事件为:'ringerModeChange'(铃声模式变化事件,检测到铃声模式改变时,触发该事件)。 |
| callback | Callback<[AudioRingMode](#audioringmode)> | 是   | 回调方法。                                                   |
Z
zengyawen 已提交
1805

L
lwx1059628 已提交
1806 1807
**示例:**

J
jiao_yanlin 已提交
1808
```js
L
lwx1059628 已提交
1809
audioManager.on('ringerModeChange', (ringerMode) => {
1810
  console.info(`Updated ringermode: ${ringerMode}`);
L
lwx1059628 已提交
1811 1812 1813
});
```

L
lwx1059628 已提交
1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826
### on('deviceChange')

on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void

设备更改。音频设备连接状态变化。

**系统能力:** SystemCapability.Multimedia.Audio.Device

**参数:**

| 参数名   | 类型                                                 | 必填 | 说明                                       |
| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
| type     | string                                               | 是   | 订阅的事件的类型。支持事件:'deviceChange' |
1827
| callback | Callback<[DeviceChangeAction](#devicechangeaction)\> | 是   | 获取设备更新详情。                         |
L
lwx1059628 已提交
1828 1829 1830

**示例:**

J
jiao_yanlin 已提交
1831
```js
L
lwx1059628 已提交
1832
audioManager.on('deviceChange', (deviceChanged) => {
1833 1834 1835 1836
  console.info(`device change type : ${deviceChanged.type} `);
  console.info(`device descriptor size : ${deviceChanged.deviceDescriptors.length} `);
  console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceRole} `);
  console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceType} `);
L
lwx1059628 已提交
1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852
});
```

### off('deviceChange')

off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void

取消订阅音频设备连接变化事件。

**系统能力:** SystemCapability.Multimedia.Audio.Device

**参数:**

| 参数名   | 类型                                                | 必填 | 说明                                       |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
| type     | string                                              | 是   | 订阅的事件的类型。支持事件:'deviceChange' |
1853
| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | 否   | 获取设备更新详情。                         |
L
lwx1059628 已提交
1854 1855 1856

**示例:**

J
jiao_yanlin 已提交
1857
```js
L
lwx1059628 已提交
1858
audioManager.off('deviceChange', (deviceChanged) => {
1859
  console.info('Should be no callback.');
L
lwx1059628 已提交
1860 1861 1862
});
```

1863 1864 1865 1866 1867 1868 1869 1870 1871 1872
### on('interrupt')

on(type: 'interrupt', interrupt: AudioInterrupt, callback: Callback\<InterruptAction>): void

请求焦点并开始监听音频打断事件(当应用程序的音频被另一个播放事件中断,回调通知此应用程序)

**系统能力:** SystemCapability.Multimedia.Audio.Renderer

**参数:**

H
update  
HelloCrease 已提交
1873 1874 1875 1876 1877
| 参数名    | 类型                                          | 必填 | 说明                                                         |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type      | string                                        | 是   | 音频打断事件回调类型,支持的事件为:'interrupt'(多应用之间第二个应用会打断第一个应用,触发该事件)。 |
| interrupt | AudioInterrupt                                | 是   | 音频打断事件类型的参数。                                     |
| callback  | Callback<[InterruptAction](#interruptaction)> | 是   | 音频打断事件回调方法。                                       |
1878 1879 1880

**示例:**

J
jiao_yanlin 已提交
1881
```js
1882
var interAudioInterrupt = {
J
jiao_yanlin 已提交
1883 1884 1885
  streamUsage:2,
  contentType:0,
  pauseWhenDucked:true
1886
};
R
rahul 已提交
1887
audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
J
jiao_yanlin 已提交
1888
  if (InterruptAction.actionType === 0) {
1889 1890
    console.info('An event to gain the audio focus starts.');
    console.info(`Focus gain event: ${InterruptAction} `);
J
jiao_yanlin 已提交
1891 1892
  }
  if (InterruptAction.actionType === 1) {
1893 1894
    console.info('An audio interruption event starts.');
    console.info(`Audio interruption event: ${InterruptAction} `);
J
jiao_yanlin 已提交
1895
  }
1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908
});
```

### off('interrupt')

off(type: 'interrupt', interrupt: AudioInterrupt, callback?: Callback\<InterruptAction>): void

取消监听音频打断事件(删除监听事件,取消打断)

**系统能力:** SystemCapability.Multimedia.Audio.Renderer

**参数:**

H
update  
HelloCrease 已提交
1909 1910 1911 1912 1913
| 参数名    | 类型                                          | 必填 | 说明                                                         |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type      | string                                        | 是   | 音频打断事件回调类型,支持的事件为:'interrupt'(多应用之间第二个应用会打断第一个应用,触发该事件)。 |
| interrupt | AudioInterrupt                                | 是   | 音频打断事件类型的参数。                                     |
| callback  | Callback<[InterruptAction](#interruptaction)> | 否   | 音频打断事件回调方法。                                       |
1914 1915 1916

**示例:**

J
jiao_yanlin 已提交
1917
```js
1918
var interAudioInterrupt = {
J
jiao_yanlin 已提交
1919 1920 1921
  streamUsage:2,
  contentType:0,
  pauseWhenDucked:true
1922
};
R
rahul 已提交
1923
audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
J
jiao_yanlin 已提交
1924
  if (InterruptAction.actionType === 0) {
1925 1926
      console.info('An event to release the audio focus starts.');
      console.info(`Focus release event: ${InterruptAction} `);
J
jiao_yanlin 已提交
1927
  }
1928 1929 1930
});
```

L
lwx1059628 已提交
1931 1932 1933 1934 1935 1936
### setAudioScene<sup>8+</sup>

setAudioScene\(scene: AudioScene, callback: AsyncCallback<void\>\): void

设置音频场景模式,使用callback方式异步返回结果。

1937
**系统接口:** 该接口为系统接口
L
lwx1059628 已提交
1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949

**系统能力:** SystemCapability.Multimedia.Audio.Communication

**参数:**

| 参数名   | 类型                                 | 必填 | 说明                 |
| :------- | :----------------------------------- | :--- | :------------------- |
| scene    | <a href="#audioscene">AudioScene</a> | 是   | 音频场景模式。       |
| callback | AsyncCallback<void\>                 | 是   | 用于返回结果的回调。 |

**示例:**

J
jiao_yanlin 已提交
1950
```js
L
lwx1059628 已提交
1951
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => {
J
jiao_yanlin 已提交
1952
  if (err) {
1953
    console.error(`Failed to set the audio scene mode.​ ${err.message}`);
J
jiao_yanlin 已提交
1954 1955
    return;
  }
1956
  console.info('Callback invoked to indicate a successful setting of the audio scene mode.');
L
lwx1059628 已提交
1957 1958 1959 1960 1961 1962 1963 1964 1965
});
```

### setAudioScene<sup>8+</sup>

setAudioScene\(scene: AudioScene\): Promise<void\>

设置音频场景模式,使用Promise方式返回异步结果。

1966
**系统接口:** 该接口为系统接口
L
lwx1059628 已提交
1967

Z
zengyawen 已提交
1968
**系统能力:** SystemCapability.Multimedia.Audio.Communication
L
lwx1059628 已提交
1969

Z
zengyawen 已提交
1970
**参数:**
L
lwx1059628 已提交
1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983

| 参数名 | 类型                                 | 必填 | 说明           |
| :----- | :----------------------------------- | :--- | :------------- |
| scene  | <a href="#audioscene">AudioScene</a> | 是   | 音频场景模式。 |

**返回值:**

| 类型           | 说明                 |
| :------------- | :------------------- |
| Promise<void\> | 用于返回结果的回调。 |

**示例:**

J
jiao_yanlin 已提交
1984
```js
R
rahul 已提交
1985
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => {
1986
  console.info('Promise returned to indicate a successful setting of the audio scene mode.');
L
lwx1059628 已提交
1987
}).catch ((err) => {
1988
  console.error(`Failed to set the audio scene mode ${err.message}`);
L
lwx1059628 已提交
1989 1990 1991 1992 1993 1994 1995 1996 1997
});
```

### getAudioScene<sup>8+</sup>

getAudioScene\(callback: AsyncCallback<AudioScene\>\): void

获取音频场景模式,使用callback方式返回异步结果。

Z
zengyawen 已提交
1998
**系统能力:** SystemCapability.Multimedia.Audio.Communication
L
lwx1059628 已提交
1999 2000 2001 2002 2003 2004 2005 2006 2007

**参数:**

| 参数名   | 类型                                                | 必填 | 说明                         |
| :------- | :-------------------------------------------------- | :--- | :--------------------------- |
| callback | AsyncCallback<<a href="#audioscene">AudioScene</a>> | 是   | 用于返回音频场景模式的回调。 |

**示例:**

J
jiao_yanlin 已提交
2008
```js
L
lwx1059628 已提交
2009
audioManager.getAudioScene((err, value) => {
J
jiao_yanlin 已提交
2010
  if (err) {
2011
    console.error(`Failed to obtain the audio scene mode.​ ${err.message}`);
J
jiao_yanlin 已提交
2012 2013
    return;
  }
2014
  console.info(`Callback invoked to indicate that the audio scene mode is obtained ${value}.`);
L
lwx1059628 已提交
2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034
});
```


### getAudioScene<sup>8+</sup>

getAudioScene\(\): Promise<AudioScene\>

获取音频场景模式,使用Promise方式返回异步结果。

**系统能力:** SystemCapability.Multimedia.Audio.Communication

**返回值:**

| 类型                                          | 说明                         |
| :-------------------------------------------- | :--------------------------- |
| Promise<<a href="#audioscene">AudioScene</a>> | 用于返回音频场景模式的回调。 |

**示例:**

J
jiao_yanlin 已提交
2035
```js
L
lwx1059628 已提交
2036
audioManager.getAudioScene().then((value) => {
2037
  console.info(`Promise returned to indicate that the audio scene mode is obtained ${value}.`);
L
lwx1059628 已提交
2038
}).catch ((err) => {
2039
  console.error(`Failed to obtain the audio scene mode ${err.message}`);
L
lwx1059628 已提交
2040 2041 2042
});
```

W
wangtao 已提交
2043 2044 2045 2046 2047 2048
### getVolumeGroups<sup>9+</sup>

getVolumeGroups(networkId: string, callback: AsyncCallback<VolumeGroupInfos\>\): void

获取音量组信息列表,使用callback方式异步返回结果。

2049
**系统接口:** 该接口为系统接口
W
wangtao 已提交
2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076

**系统能力:** SystemCapability.Multimedia.Audio.Volume

**参数:**

| 参数名     | 类型                                                         | 必填 | 说明                 |
| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
| networkId | string                                    | 是   | 设备的网络id。本地设备audio.LOCAL_NETWORK_ID ,也可以通过getRoutingManager().getDevices()获取全部networkId。    |
| callback   | AsyncCallback&lt;[VolumeGroupInfos](#volumegroupinfos9)&gt; | 是   | 回调,返回音量组信息列表。 |

**示例:**
```js
audioManager.getVolumeGroups(audio.LOCAL_NETWORK_ID, (err, value) => {
  if (err) {
    console.error(`Failed to obtain the volume group infos list. ${err.message}`);
    return;
  }
  console.info('Callback invoked to indicate that the volume group infos list is obtained.');
});
```

### getVolumeGroups<sup>9+</sup>

getVolumeGroups(networkId: string\): Promise<VolumeGroupInfos\>

获取音量组信息列表,使用promise方式异步返回结果。

2077
**系统接口:** 该接口为系统接口
W
wangtao 已提交
2078 2079 2080 2081 2082 2083 2084 2085 2086

**系统能力:** SystemCapability.Multimedia.Audio.Volume

**参数:**

| 参数名     | 类型                                                         | 必填 | 说明                 |
| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
| networkId | string                                    | 是   | 设备的网络id。本地设备audio.LOCAL_NETWORK_ID ,也可以通过getRoutingManager().getDevices()获取全部networkId。    |

2087 2088 2089 2090 2091 2092
**返回值:**

| 类型                | 说明                          |
| ------------------- | ----------------------------- |
| Promise&lt;[VolumeGroupInfos](#volumegroupinfos9)&gt; | 音量组信息列表。 |

W
wangtao 已提交
2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107
**示例:**

```js
async function getVolumeGroupInfos(){
  let volumegroupinfos = await audio.getAudioManager().getVolumeGroups(audio.LOCAL_NETWORK_ID);
  console.info('Promise returned to indicate that the volumeGroup list is obtained.'+JSON.stringify(volumegroupinfos))
}
```

### getGroupManager<sup>9+</sup>

getGroupManager(groupId: number, callback: AsyncCallback<AudioGroupManager\>\): void

获取音频组管理器,使用callback方式异步返回结果。

2108
**系统接口:** 该接口为系统接口
W
wangtao 已提交
2109 2110 2111 2112 2113 2114 2115 2116

**系统能力:** SystemCapability.Multimedia.Audio.Volume

**参数:**

| 参数名     | 类型                                                         | 必填 | 说明                 |
| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
| networkId | string                                    | 是   | 设备的网络id。     |
2117
| callback   | AsyncCallback&lt; [AudioGroupManager](#audiogroupmanager9) &gt; | 是   | 回调,返回一个音量组实例。 |
W
wangtao 已提交
2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143

**示例:**

```js
async function getGroupManager(){
  let value = await audioManager.getVolumeGroups(audio.LOCAL_NETWORK_ID);
  if (value.length > 0) {
    let groupid = value[0].groupId;
    audioManager.getGroupManager(groupid, (err, value) => {
      if (err) {
        console.error(`Failed to obtain the volume group infos list. ${err.message}`);
        return;
      }
      audioGroupManager = value
      console.info('Callback invoked to indicate that the volume group infos list is obtained.');
    });
  }
}
```

### getGroupManager<sup>9+</sup>

getGroupManager(groupId: number\): Promise<AudioGroupManager\>

获取音频组管理器,使用promise方式异步返回结果。

2144
**系统接口:** 该接口为系统接口
W
wangtao 已提交
2145 2146 2147 2148 2149

**系统能力:** SystemCapability.Multimedia.Audio.Volume

**参数:**

2150 2151
| 参数名     | 类型                                      | 必填 | 说明              |
| ---------- | ---------------------------------------- | ---- | -------------- -- |
W
wangtao 已提交
2152 2153
| networkId | string                                    | 是   | 设备的网络id。     |

2154 2155 2156 2157 2158 2159
**返回值:**

| 类型                | 说明                          |
| ------------------- | ----------------------------- |
| Promise&lt; [AudioGroupManager](#audiogroupmanager9) &gt; | 音量组实例。 |

W
wangtao 已提交
2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175
**示例:**

```js
async function getGroupManager(){
  let value = await audioManager.getVolumeGroups(audio.LOCAL_NETWORK_ID);
  if (value.length > 0) {
    let groupid = value[0].groupId;
    let audioGroupManager = await audioManager.getGroupManager(audio.LOCAL_NETWORK_ID)
    console.info('Callback invoked to indicate that the volume group infos list is obtained.');
  }
}
```

## AudioGroupManager<sup>9+</sup>
管理音频组音量。在调用AudioGroupManager的接口前,需要先通过 [getGroupManager](#getgroupmanager9) 创建实例。

2176
**系统接口:** 该接口为系统接口
W
wangtao 已提交
2177 2178 2179 2180 2181 2182 2183 2184 2185

**系统能力:** SystemCapability.Multimedia.Audio.Volume

### setVolume<sup>9+</sup>

setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&lt;void&gt;): void

设置指定流的音量,使用callback方式异步返回结果。

2186 2187 2188
**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY

仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
W
wangtao 已提交
2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217

**系统能力:** SystemCapability.Multimedia.Audio.Volume

**参数:**

| 参数名     | 类型                                | 必填 | 说明                                                     |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
| volume     | number                              | 是   | 音量等级,可设置范围通过getMinVolume和getMaxVolume获取。 |
| callback   | AsyncCallback&lt;void&gt;           | 是   | 回调表示成功还是失败。                                   |

**示例:**

```js
audioGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
  if (err) {
    console.error(`Failed to set the volume. ${err.message}`);
    return;
  }
  console.log(`Callback invoked to indicate a successful volume setting.`);
});
```

### setVolume<sup>9+</sup>

setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;

设置指定流的音量,使用Promise方式异步返回结果。

2218 2219 2220
**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY

仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
W
wangtao 已提交
2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415

**系统能力:** SystemCapability.Multimedia.Audio.Volume

**参数:**

| 参数名     | 类型                                | 必填 | 说明                                                     |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
| volume     | number                              | 是   | 音量等级,可设置范围通过getMinVolume和getMaxVolume获取。 |

**返回值:**

| 类型                | 说明                          |
| ------------------- | ----------------------------- |
| Promise&lt;void&gt; | Promise回调表示成功还是失败。 |

**示例:**

```js
audioGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
  console.log(`Promise returned to indicate a successful volume setting.`);
});
```

### getVolume<sup>9+</sup>

getVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void

获取指定流的音量,使用callback方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Volume

**参数:**

| 参数名     | 类型                                | 必填 | 说明               |
| ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。       |
| callback   | AsyncCallback&lt;number&gt;         | 是   | 回调返回音量大小。 |

**示例:**

```js
audioGroupManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
  if (err) {
    console.error(`Failed to obtain the volume. ${err.message}`);
    return;
  }
  console.log(`Callback invoked to indicate that the volume is obtained.`);
});
```

### getVolume<sup>9+</sup>

getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;

获取指定流的音量,使用Promise方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Volume

**参数:**

| 参数名     | 类型                                | 必填 | 说明         |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |

**返回值:**

| 类型                  | 说明                      |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise回调返回音量大小。 |

**示例:**

```js
audioGroupManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
  console.log(`Promise returned to indicate that the volume is obtained.` + value);
});
```

### getMinVolume<sup>9+</sup>

getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void

获取指定流的最小音量,使用callback方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Volume

**参数:**

| 参数名     | 类型                                | 必填 | 说明               |
| ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。       |
| callback   | AsyncCallback&lt;number&gt;         | 是   | 回调返回最小音量。 |

**示例:**

```js
audioGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
  if (err) {
    console.error(`Failed to obtain the minimum volume. ${err.message}`);
    return;
  }
  console.log(`Callback invoked to indicate that the minimum volume is obtained.` + value);
});
```

### getMinVolume<sup>9+</sup>

getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;

获取指定流的最小音量,使用Promise方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Volume

**参数:**

| 参数名     | 类型                                | 必填 | 说明         |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |

**返回值:**

| 类型                  | 说明                      |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise回调返回最小音量。 |

**示例:**

```js
audioGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
  console.log(`Promised returned to indicate that the minimum volume is obtained.` + value);
});
```

### getMaxVolume<sup>9+</sup>

getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void

获取指定流的最大音量,使用callback方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Volume

**参数:**

| 参数名     | 类型                                | 必填 | 说明                   |
| ---------- | ----------------------------------- | ---- | ---------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。           |
| callback   | AsyncCallback&lt;number&gt;         | 是   | 回调返回最大音量大小。 |

**示例:**

```js
audioGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
  if (err) {
    console.error(`Failed to obtain the maximum volume. ${err.message}`);
    return;
  }
  console.log(`Callback invoked to indicate that the maximum volume is obtained.` + value);
});
```

### getMaxVolume<sup>9+</sup>

getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;

获取指定流的最大音量,使用Promise方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Volume

**参数:**

| 参数名     | 类型                                | 必填 | 说明         |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |

**返回值:**

| 类型                  | 说明                          |
| --------------------- | ----------------------------- |
| Promise&lt;number&gt; | Promise回调返回最大音量大小。 |

**示例:**

```js
audioGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
  console.log(`Promised returned to indicate that the maximum volume is obtained.`);
});
```

### mute<sup>9+</sup>

mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void

设置指定音量流静音,使用callback方式异步返回结果。

2416 2417 2418
**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY

仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
W
wangtao 已提交
2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447

**系统能力:** SystemCapability.Multimedia.Audio.Volume

**参数:**

| 参数名     | 类型                                | 必填 | 说明                                  |
| ---------- | ----------------------------------- | ---- | ------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                          |
| mute       | boolean                             | 是   | 静音状态,true为静音,false为非静音。 |
| callback   | AsyncCallback&lt;void&gt;           | 是   | 回调表示成功还是失败。                |

**示例:**

```js
audioGroupManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
  if (err) {
    console.error(`Failed to mute the stream. ${err.message}`);
    return;
  }
  console.log(`Callback invoked to indicate that the stream is muted.`);
});
```

### mute<sup>9+</sup>

mute(volumeType: AudioVolumeType, mute: boolean): Promise&lt;void&gt;

设置指定音量流静音,使用Promise方式异步返回结果。

2448 2449 2450
**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY

仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
W
wangtao 已提交
2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529

**系统能力:** SystemCapability.Multimedia.Audio.Volume

**参数:**

| 参数名     | 类型                                | 必填 | 说明                                  |
| ---------- | ----------------------------------- | ---- | ------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                          |
| mute       | boolean                             | 是   | 静音状态,true为静音,false为非静音。 |

**返回值:**

| 类型                | 说明                          |
| ------------------- | ----------------------------- |
| Promise&lt;void&gt; | Promise回调表示成功还是失败。 |

**示例:**

```js
audioGroupManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
  console.log(`Promise returned to indicate that the stream is muted.`);
});
```

### isMute<sup>9+</sup>

isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void

获取指定音量流是否被静音,使用callback方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Volume

**参数:**

| 参数名     | 类型                                | 必填 | 说明                                            |
| ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                    |
| callback   | AsyncCallback&lt;boolean&gt;        | 是   | 回调返回流静音状态,true为静音,false为非静音。 |

**示例:**

```js
audioGroupManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
  if (err) {
    console.error(`Failed to obtain the mute status. ${err.message}`);
    return;
  }
  console.log(`Callback invoked to indicate that the mute status of the stream is obtained.` + value);
});
```

### isMute<sup>9+</sup>

isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt;

获取指定音量流是否被静音,使用Promise方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Volume

**参数:**

| 参数名     | 类型                                | 必填 | 说明         |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |

**返回值:**

| 类型                   | 说明                                                   |
| ---------------------- | ------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise回调返回流静音状态,true为静音,false为非静音。 |

**示例:**

```js
audioGroupManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
  console.log(`Promise returned to indicate that the mute status of the stream is obtained.` + value);
});
```

2530 2531
## AudioStreamManager<sup>9+</sup>

2532
管理音频流。在使用AudioStreamManager的API前,需要使用[getStreamManager](#audiogetstreammanager9)获取AudioStreamManager实例。
2533 2534 2535

### getCurrentAudioRendererInfoArray<sup>9+</sup>

2536
getCurrentAudioRendererInfoArray(callback: AsyncCallback&lt;AudioRendererChangeInfoArray&gt;): void
2537

2538
获取当前音频渲染器的信息。使用callback异步回调。
2539 2540 2541

**系统能力**: SystemCapability.Multimedia.Audio.Renderer

2542
**参数:**
2543 2544 2545

| 名称     | 类型                                 | 必填     | 说明                         |
| -------- | ----------------------------------- | -------- | --------------------------- |
2546
| callback | AsyncCallback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | 是     |  回调函数,返回当前音频渲染器的信息。 |
2547

2548
**示例:**
J
jiao_yanlin 已提交
2549 2550

```js
J
jiao_yanlin 已提交
2551 2552 2553 2554 2555 2556 2557 2558 2559 2560
let audioStreamManager;
audio.getStreamManager((err, data) => {
  if (err) {
    console.error(`getStreamManager : Error: ${err.message}`);
  } else {
    console.info('getStreamManager : Success : SUCCESS');
    audioStreamManager = data;
  }
});

2561
audioStreamManager.getCurrentAudioRendererInfoArray(async (err, AudioRendererChangeInfoArray) => {
2562
  console.info('getCurrentAudioRendererInfoArray **** Get Callback Called ****');
J
jiao_yanlin 已提交
2563
  if (err) {
2564
    console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err.message}`);
J
jiao_yanlin 已提交
2565 2566 2567
  } else {
    if (AudioRendererChangeInfoArray != null) {
      for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
J
jiao_yanlin 已提交
2568
        let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
2569 2570 2571 2572 2573 2574
        console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
        console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`);
        console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
        console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
        console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`); 
        console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`);  
J
jiao_yanlin 已提交
2575
        for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
2576 2577 2578 2579 2580 2581 2582 2583
          console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
          console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
          console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
          console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
          console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
          console.info(`SampleRates: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
          console.info(`ChannelCount ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
          console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks}`);
2584
        }
J
jiao_yanlin 已提交
2585
      }
2586
    }
J
jiao_yanlin 已提交
2587
  }
2588 2589 2590 2591 2592
});
```

### getCurrentAudioRendererInfoArray<sup>9+</sup>

2593
getCurrentAudioRendererInfoArray(): Promise&lt;AudioRendererChangeInfoArray&gt;
2594

2595
获取当前音频渲染器的信息。使用Promise异步回调。
2596

2597
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
2598

2599
**返回值:**
2600 2601 2602

| 类型                                                                              | 说明                                    |
| ---------------------------------------------------------------------------------| --------------------------------------- |
2603
| Promise<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)>          | Promise对象,返回当前音频渲染器信息。      |
2604

2605
**示例:**
J
jiao_yanlin 已提交
2606 2607

```js
J
jiao_yanlin 已提交
2608 2609 2610 2611 2612 2613 2614 2615 2616 2617
let audioStreamManager;
audio.getStreamManager((err, data) => {
  if (err) {
    console.error(`getStreamManager : Error: ${err.message}`);
  } else {
    console.info('getStreamManager : Success : SUCCESS');
    audioStreamManager = data;
  }
});

2618
await audioStreamManager.getCurrentAudioRendererInfoArray().then( function (AudioRendererChangeInfoArray) {
2619
  console.info(`getCurrentAudioRendererInfoArray ######### Get Promise is called ##########`);
J
jiao_yanlin 已提交
2620 2621
  if (AudioRendererChangeInfoArray != null) {
    for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
J
jiao_yanlin 已提交
2622
      let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637
      console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
      console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`);
      console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
      console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
      console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`); 
      console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`);  
      for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
        console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
        console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
        console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
        console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
        console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
        console.info(`SampleRates: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
        console.info(`ChannelCount ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
        console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks}`);
J
jiao_yanlin 已提交
2638
      }
2639
    }
J
jiao_yanlin 已提交
2640
  }
2641
}).catch((err) => {
2642
  console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err.message}`);
2643 2644 2645 2646 2647
});
```

### getCurrentAudioCapturerInfoArray<sup>9+</sup>

2648
getCurrentAudioCapturerInfoArray(callback: AsyncCallback&lt;AudioCapturerChangeInfoArray&gt;): void
2649

2650
获取当前音频采集器的信息。使用callback异步回调。
2651

2652
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
2653

2654
**参数:**
2655 2656 2657

| 名称       | 类型                                 | 必填      | 说明                                                      |
| ---------- | ----------------------------------- | --------- | -------------------------------------------------------- |
2658
| callback   | AsyncCallback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | 是    | 回调函数,返回当前音频采集器的信息。 |
2659

2660
**示例:**
J
jiao_yanlin 已提交
2661 2662

```js
J
jiao_yanlin 已提交
2663 2664 2665 2666 2667 2668 2669 2670 2671 2672
let audioStreamManager;
audio.getStreamManager((err, data) => {
  if (err) {
    console.error(`getStreamManager : Error: ${err.message}`);
  } else {
    console.info('getStreamManager : Success : SUCCESS');
    audioStreamManager = data;
  }
});

2673
audioStreamManager.getCurrentAudioCapturerInfoArray(async (err, AudioCapturerChangeInfoArray) => {
2674
  console.info('getCurrentAudioCapturerInfoArray **** Get Callback Called ****');
J
jiao_yanlin 已提交
2675
  if (err) {
2676
    console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err.message}`);
J
jiao_yanlin 已提交
2677
  } else {
J
jiao_yanlin 已提交
2678 2679
    if (AudioCapturerChangeInfoArray != null) {
      for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
2680 2681 2682 2683 2684
        console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
        console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
        console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
        console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
        console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);  
J
jiao_yanlin 已提交
2685
        for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
2686 2687 2688 2689 2690 2691 2692 2693
          console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
          console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
          console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
          console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
          console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
          console.info(`SampleRates: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
          console.info(`ChannelCounts ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
          console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
2694
        }
J
jiao_yanlin 已提交
2695
      }
2696
    }
J
jiao_yanlin 已提交
2697
  }
2698 2699 2700 2701 2702
});
```

### getCurrentAudioCapturerInfoArray<sup>9+</sup>

2703
getCurrentAudioCapturerInfoArray(): Promise&lt;AudioCapturerChangeInfoArray&gt;
2704

2705
获取当前音频采集器的信息。使用Promise异步回调。
2706

2707
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
2708

2709
**返回值:**
2710

2711 2712 2713
| 类型                                                                         | 说明                                 |
| -----------------------------------------------------------------------------| ----------------------------------- |
| Promise<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)>      | Promise对象,返回当前音频渲染器信息。  |
2714

2715
**示例:**
J
jiao_yanlin 已提交
2716 2717

```js
J
jiao_yanlin 已提交
2718 2719 2720 2721 2722 2723 2724 2725 2726 2727
let audioStreamManager;
audio.getStreamManager((err, data) => {
  if (err) {
    console.error(`getStreamManager : Error: ${err.message}`);
  } else {
    console.info('getStreamManager : Success : SUCCESS');
    audioStreamManager = data;
  }
});

2728
await audioStreamManager.getCurrentAudioCapturerInfoArray().then( function (AudioCapturerChangeInfoArray) {
2729
  console.info('getCurrentAudioCapturerInfoArray **** Get Promise Called ****');
J
jiao_yanlin 已提交
2730 2731
  if (AudioCapturerChangeInfoArray != null) {
    for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
2732 2733 2734 2735 2736
      console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
      console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
      console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
      console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
      console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);  
J
jiao_yanlin 已提交
2737
      for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
2738 2739 2740 2741 2742 2743 2744 2745
        console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
        console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
        console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
        console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
        console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
        console.info(`SampleRates: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
        console.info(`ChannelCounts ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
        console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
J
jiao_yanlin 已提交
2746
      }
2747
    }
J
jiao_yanlin 已提交
2748
  }
2749
}).catch((err) => {
2750
  console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err.message}`);
2751 2752 2753 2754 2755
});
```

### on('audioRendererChange')<sup>9+</sup>

2756
on(type: "audioRendererChange", callback: Callback&lt;AudioRendererChangeInfoArray&gt;): void
2757 2758 2759

监听音频渲染器更改事件。

2760
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
2761

2762
**参数:**
2763

2764 2765 2766
| 名称     | 类型        | 必填      | 说明                                                                     |
| -------- | ---------- | --------- | ------------------------------------------------------------------------ |
| type     | string     | 是        | 事件类型,支持的事件`'audioRendererChange'`:当音频渲染器发生更改时触发。     |
2767
| callback | Callback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | 是  |  回调函数。        |
2768

2769
**示例:**
J
jiao_yanlin 已提交
2770 2771

```js
J
jiao_yanlin 已提交
2772 2773 2774 2775 2776 2777 2778 2779 2780 2781
let audioStreamManager;
audio.getStreamManager((err, data) => {
  if (err) {
    console.error(`getStreamManager : Error: ${err.message}`);
  } else {
    console.info('getStreamManager : Success : SUCCESS');
    audioStreamManager = data;
  }
});

2782
audioStreamManager.on('audioRendererChange',  (AudioRendererChangeInfoArray) => {
J
jiao_yanlin 已提交
2783
  for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
J
jiao_yanlin 已提交
2784
    let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800
    console.info(`## RendererChange on is called for ${i} ##`);
    console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
    console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`);
    console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
    console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
    console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`); 
    console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`);  
    for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
      console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
      console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
      console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
      console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
      console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
      console.info(`SampleRates: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
      console.info(`ChannelCount ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
      console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks}`);
2801
    }
J
jiao_yanlin 已提交
2802
  }
2803 2804 2805 2806 2807 2808 2809
});
```

### off('audioRendererChange')<sup>9+</sup>

off(type: "audioRendererChange");

2810
取消监听音频渲染器更改事件。
2811

2812
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
2813

2814
**参数:**
2815 2816 2817

| 名称     | 类型     | 必填 | 说明              |
| -------- | ------- | ---- | ---------------- |
2818
| type     | string  | 是   | 事件类型,支持的事件`'audioRendererChange'`:音频渲染器更改事件。 |
2819

2820
**示例:**
J
jiao_yanlin 已提交
2821 2822

```js
J
jiao_yanlin 已提交
2823 2824 2825 2826 2827 2828 2829 2830 2831 2832
let audioStreamManager;
audio.getStreamManager((err, data) => {
  if (err) {
    console.error(`getStreamManager : Error: ${err.message}`);
  } else {
    console.info('getStreamManager : Success : SUCCESS');
    audioStreamManager = data;
  }
});

2833
audioStreamManager.off('audioRendererChange');
2834
console.info('######### RendererChange Off is called #########');
2835 2836 2837 2838
```

### on('audioCapturerChange')<sup>9+</sup>

2839
on(type: "audioCapturerChange", callback: Callback&lt;AudioCapturerChangeInfoArray&gt;): void
2840

2841
监听音频采集器更改事件。
2842

2843
**系统能力:** SystemCapability.Multimedia.Audio.Capturer
2844

2845
**参数:**
2846 2847

| 名称     | 类型     | 必填      | 说明                                                                                           |
2848
| -------- | ------- | --------- | ----------------------------------------------------------------------- |
2849
| type     | string  | 是        | 事件类型,支持的事件`'audioCapturerChange'`:当音频采集器发生更改时触发。     |
2850
| callback | Callback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | 是     | 回调函数。   |
2851

2852
**示例:**
J
jiao_yanlin 已提交
2853 2854

```js
J
jiao_yanlin 已提交
2855 2856 2857 2858 2859 2860 2861 2862 2863 2864
let audioStreamManager;
audio.getStreamManager((err, data) => {
  if (err) {
    console.error(`getStreamManager : Error: ${err.message}`);
  } else {
    console.info('getStreamManager : Success : SUCCESS');
    audioStreamManager = data;
  }
});

2865
audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) =>  {
J
jiao_yanlin 已提交
2866
  for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
2867 2868 2869 2870 2871 2872 2873
    console.info(`## CapChange on is called for element ${i} ##');
    console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
    console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
    console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
    console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
    console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);  
    var devDescriptor = AudioCapturerChangeInfoArray[i].deviceDescriptors;
J
jiao_yanlin 已提交
2874
    for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
2875 2876 2877 2878 2879 2880 2881 2882
      console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
      console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
      console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
      console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
      console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
      console.info(`SampleRates: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
      console.info(`ChannelCounts ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
      console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
2883
    }
J
jiao_yanlin 已提交
2884
  }
2885 2886 2887 2888 2889 2890 2891
});
```

### off('audioCapturerChange')<sup>9+</sup>

off(type: "audioCapturerChange");

2892
取消监听音频采集器更改事件。
2893

2894
**系统能力:** SystemCapability.Multimedia.Audio.Capturer
2895

2896
**参数:**
2897

2898 2899 2900
| 名称      | 类型     | 必填 | 说明                                                          |
| -------- | -------- | --- | ------------------------------------------------------------- |
| type     | string   |是   | 事件类型,支持的事件`'audioCapturerChange'`:音频采集器更改事件。 |
2901

2902
**示例:**
J
jiao_yanlin 已提交
2903 2904

```js
J
jiao_yanlin 已提交
2905 2906 2907 2908 2909 2910 2911 2912 2913 2914
let audioStreamManager;
audio.getStreamManager((err, data) => {
  if (err) {
    console.error(`getStreamManager : Error: ${err.message}`);
  } else {
    console.info('getStreamManager : Success : SUCCESS');
    audioStreamManager = data;
  }
});

2915
audioStreamManager.off('audioCapturerChange');
2916
console.info('######### CapturerChange Off is called #########');
2917 2918 2919

```

2920 2921 2922 2923
## AudioRoutingManager<sup>9+</sup>

音频路由管理。在使用AudioRoutingManager的接口前,需要使用[getRoutingManager](#getroutingmanager9)获取AudioRoutingManager实例。

2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057
### getDevices<sup>9+</sup>

getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void

获取音频设备列表,使用callback方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Device

**参数:**

| 参数名     | 类型                                                         | 必填 | 说明                 |
| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
| deviceFlag | [DeviceFlag](#deviceflag)                                    | 是   | 设备类型的flag。     |
| callback   | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | 是   | 回调,返回设备列表。 |

**示例:**

```js
audioManager.getRoutingManager((err,AudioRoutingManager)=>{
  if (err) {
    console.error(`AudioFrameworkTest:Callback:failed to get RoutingManager ${err.message}`);
  }
  else {
    AudioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
      if (err) {
        console.error(`Failed to obtain the device list. ${err.message}`);
        return;
      }
      console.log(`Callback invoked to indicate that the device list is obtained.`);
    });
  }
})
```

### getDevices<sup>9+</sup>

getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;

获取音频设备列表,使用Promise方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Device

**参数:**

| 参数名     | 类型                      | 必填 | 说明             |
| ---------- | ------------------------- | ---- | ---------------- |
| deviceFlag | [DeviceFlag](#deviceflag) | 是   | 设备类型的flag。 |

**返回值:**

| 类型                                                         | 说明                      |
| ------------------------------------------------------------ | ------------------------- |
| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise回调返回设备列表。 |

**示例:**

```js
audioManager.getRoutingManager((err,AudioRoutingManager)=>{
  if (err) {
    console.error(`AudioFrameworkTest:Callback:failed to get RoutingManager ${err.message}`);
  }
  else {
    AudioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
      console.log(`Promise returned to indicate that the device list is obtained.`);
    });
  }
});
```

### on<sup>9+</sup>

on(type: 'deviceChange', deviceFlag: DeviceFlag,, callback: Callback<DeviceChangeAction\>): void

设备更改。音频设备连接状态变化。

**系统能力:** SystemCapability.Multimedia.Audio.Device

**参数:**

| 参数名   | 类型                                                 | 必填 | 说明                                       |
| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
| type     | string                                               | 是   | 订阅的事件的类型。支持事件:'deviceChange' |
| deviceFlag | [DeviceFlag](#deviceflag)                                    | 是   | 设备类型的flag。     |
| callback | Callback<[DeviceChangeAction](#devicechangeaction)\> | 是   | 获取设备更新详情。                         |

**示例:**

```js
audioManager.getRoutingManager((err,AudioRoutingManager)=>{
  if (err) {
    console.error(`AudioFrameworkTest:Callback:failed to get RoutingManager ${err.message}`);
  }
  else {
    AudioRoutingManager.on('deviceChange', audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (deviceChanged) => {
      console.info('device change type : ' + deviceChanged.type);
      console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
      console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole);
      console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType);
    });
  }
});
```

### off<sup>9+</sup>

off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void

取消订阅音频设备连接变化事件。

**系统能力:** SystemCapability.Multimedia.Audio.Device

**参数:**

| 参数名   | 类型                                                | 必填 | 说明                                       |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
| type     | string                                              | 是   | 订阅的事件的类型。支持事件:'deviceChange' |
| deviceFlag | [DeviceFlag](#deviceflag)                                    | 是   | 设备类型的flag。     |
| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | 否   | 获取设备更新详情。                         |

**示例:**

```js
audioManager.getRoutingManager((err,AudioRoutingManager)=>{
  if (err) {
    console.error(`AudioFrameworkTest:Callback:failed to get RoutingManager ${err.message}`);
  }
  else {
    AudioRoutingManager.off('deviceChange', audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (deviceChanged) => {
      console.log('Should be no callback.');
    });
  }
});
```

3058 3059
### selectOutputDevice<sup>9+</sup>

3060
selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
3061 3062 3063

选择音频输出设备,当前只能选择一个输出设备,使用callback方式异步返回结果。该接口为系统应用接口。

3064
**系统接口:** 该接口为系统接口
3065

3066 3067 3068 3069 3070 3071
**系统能力:** SystemCapability.Multimedia.Audio.Device

**参数:**

| 参数名                       | 类型                                                         | 必填 | 说明                      |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
3072
| outputAudioDevices          | [AudioDeviceDescriptors](#audiodevicedescriptors)            | 是   | 输出设备类。               |
3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095
| callback                    | AsyncCallback&lt;void&gt;                                    | 是   | 回调,返回获取输出设备结果。 |

**示例:**
```js
let outputAudioDeviceDescriptor = [{
  "deviceRole":audio.DeviceRole.OUTPUT_DEVICE,
  "networkId":audio.LOCAL_NETWORK_ID,
  "interruptGroupId":1,
  "volumeGroupId":1 }];
var audioRoutingManager;
await audioManager.getRoutingManager().then((value) => {
  audioRoutingManager = value;
  audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor, (err) => {
    if (err) {
      console.error(`Result ERROR: ${err.message}`);
    } else {
      console.info('Select output devices result callback: SUCCESS'); }
  });
});
```

### selectOutputDevice<sup>9+</sup>

3096 3097
selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;

3098
**系统接口:** 该接口为系统接口
3099 3100 3101 3102 3103 3104 3105 3106 3107

选择音频输出设备,当前只能选择一个输出设备,使用Promise方式异步返回结果。该接口为系统应用接口。

**系统能力:** SystemCapability.Multimedia.Audio.Device

**参数:**

| 参数名                       | 类型                                                         | 必填 | 说明                      |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
3108
| outputAudioDevices          | [AudioDeviceDescriptors](#audiodevicedescriptors)            | 是   | 输出设备类。               |
3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136

**返回值:**

| 类型                  | 说明                         |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise返回选择输出设备结果。 |

**示例:**

```js
let outputAudioDeviceDescriptor =[{
  "deviceRole":audio.DeviceRole.OUTPUT_DEVICE,
  "networkId":audio.LOCAL_NETWORK_ID,
  "interruptGroupId":1,
  "volumeGroupId":1 }];
var audioRoutingManager;
await audioManager.getRoutingManager().then((value) => {
  audioRoutingManager = value;
  audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor).then(() => {
    console.info('Select output devices result promise: SUCCESS');
  }).catch((err) => {
    console.error(`Result ERROR: ${err.message}`);
  });
});
```

### selectOutputDeviceByFilter<sup>9+</sup>

3137 3138
selectOutputDeviceByFilter(audiorendererfilter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void

3139
**系统接口:** 该接口为系统接口
3140 3141 3142 3143 3144 3145 3146 3147 3148 3149

根据过滤条件,选择音频输出设备,当前只能选择一个输出设备,使用callback方式异步返回结果。该接口为系统应用接口。

**系统能力:** SystemCapability.Multimedia.Audio.Device

**参数:**

| 参数名                       | 类型                                                         | 必填 | 说明                      |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| audiorendererfilter         | [AudioRendererFilter](#audiorendererfilter9)                 | 是   | 过滤条件类。               |
3150
| outputAudioDevices          | [AudioDeviceDescriptors](#audiodevicedescriptors)            | 是   | 输出设备类。               |
3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180
| callback                    | AsyncCallback&lt;void&gt;                                    | 是   | 回调,返回获取输出设备结果。 |

**示例:**
```js
let outputAudioRendererFilter = {
  "uid":20010041,
  "rendererInfo": {
    "contentType":audio.ContentType.CONTENT_TYPE_MUSIC,
    "streamUsage":audio.StreamUsage.STREAM_USAGE_MEDIA,
    "rendererFlags":0 },
  "rendererId":0 };
let outputAudioDeviceDescriptor = [{
  "deviceRole":audio.DeviceRole.OUTPUT_DEVICE,
  "networkId":audio.LOCAL_NETWORK_ID,
  "interruptGroupId":1,
  "volumeGroupId":1 }];
var audioRoutingManager;
await audioManager.getRoutingManager().then((value) => {
  audioRoutingManager = value;
  audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor, (err) => {
    if (err) {
      console.error(`Result ERROR: ${err.message}`);
    } else {
      console.info('Select output devices by filter result callback: SUCCESS'); }
  });
});
```

### selectOutputDeviceByFilter<sup>9+</sup>

3181 3182
selectOutputDeviceByFilter(audiorendererfilter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;

3183
**系统接口:** 该接口为系统接口
3184 3185 3186 3187 3188 3189 3190 3191 3192 3193

根据过滤条件,选择音频输出设备,当前只能选择一个输出设备,使用Promise方式异步返回结果。该接口为系统应用接口。

**系统能力:** SystemCapability.Multimedia.Audio.Device

**参数:**

| 参数名                        | 类型                                                         | 必填 | 说明                      |
| ---------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| audiorendererfilter          | [AudioRendererFilter](#audiorendererfilter9)                 | 是   | 过滤条件类。               |
3194
| outputAudioDevices         | [AudioDeviceDescriptors](#audiodevicedescriptors)            | 是   | 输出设备类。               |
3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227

**返回值:**

| 类型                  | 说明                         |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise返回选择输出设备结果。 |

**示例:**

```js
let outputAudioRendererFilter = {
  "uid":20010041,
  "rendererInfo": {
    "contentType":audio.ContentType.CONTENT_TYPE_MUSIC,
    "streamUsage":audio.StreamUsage.STREAM_USAGE_MEDIA,
    "rendererFlags":0 },
  "rendererId":0 };
let outputAudioDeviceDescriptor = [{
  "deviceRole":audio.DeviceRole.OUTPUT_DEVICE,
  "networkId":audio.LOCAL_NETWORK_ID,
  "interruptGroupId":1,
  "volumeGroupId":1 }];
var audioRoutingManager;
await audioManager.getRoutingManager().then((value) => {
  audioRoutingManager = value;
  audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor).then(() => {
    console.info('Select output devices by filter result promise: SUCCESS');
  }).catch((err) => {
    console.error(`Result ERROR: ${err.message}`);
  })
});
```

3228 3229 3230 3231 3232 3233 3234 3235 3236
## AudioRendererChangeInfo<sup>9+</sup>

描述音频渲染器更改信息。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer

| 名称               | 类型                                       | 可读 | 可写 | 说明                          |
| -------------------| ----------------------------------------- | ---- | ---- | ---------------------------- |
| streamId           | number                                    | 是   | 否   | 音频流唯一id。                |
J
jiao_yanlin 已提交
3237
| clientUid          | number                                    | 是   | 否   | 音频渲染器客户端应用程序的Uid。<br/>此接口为系统接口,三方应用不支持调用。 |
3238
| rendererInfo       | [AudioRendererInfo](#audiorendererinfo8)  | 是   | 否   | 音频渲染器信息。               |
J
jiao_yanlin 已提交
3239
| rendererState      | [AudioState](#audiostate)                 | 是   | 否   | 音频状态。<br/>此接口为系统接口,三方应用不支持调用。|
3240

3241 3242 3243 3244
## AudioRendererChangeInfoArray<sup>9+</sup>

AudioRenderChangeInfo数组,只读。

3245
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
3246

3247 3248
**示例:**

J
jiao_yanlin 已提交
3249
```js
3250 3251 3252 3253
import audio from '@ohos.multimedia.audio';

var audioStreamManager;
var audioStreamManagerCB;
3254
var resultFlag = false;
3255 3256

await audioManager.getStreamManager().then(async function (data) {
J
jiao_yanlin 已提交
3257
  audioStreamManager = data;
3258
  console.info('Get AudioStream Manager : Success');
3259
}).catch((err) => {
3260
  console.error(`Get AudioStream Manager : ERROR : ${err.message}`);
3261 3262 3263
});

audioManager.getStreamManager((err, data) => {
J
jiao_yanlin 已提交
3264
  if (err) {
3265
    console.error(`Get AudioStream Manager : ERROR : ${err.message}`);
J
jiao_yanlin 已提交
3266
  } else {
J
jiao_yanlin 已提交
3267
    audioStreamManagerCB = data;
3268
    console.info('Get AudioStream Manager : Success');
J
jiao_yanlin 已提交
3269 3270
  }
});
3271 3272

audioStreamManagerCB.on('audioRendererChange',  (AudioRendererChangeInfoArray) => {
J
jiao_yanlin 已提交
3273
  for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
3274 3275 3276 3277 3278 3279 3280
    console.info(`## RendererChange on is called for ${i} ##`);
    console.info(`StreamId for ${i} is: ${AudioRendererChangeInfoArray[i].streamId}`);
    console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfoArray[i].clientUid}`);
    console.info(`Content for ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.content}`);
    console.info(`Stream for ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.usage}`);
    console.info(`Flag ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.rendererFlags}`);
    console.info(`State for ${i} is: ${AudioRendererChangeInfoArray[i].rendererState}`);
J
jiao_yanlin 已提交
3281
  	var devDescriptor = AudioRendererChangeInfoArray[i].deviceDescriptors;
J
jiao_yanlin 已提交
3282
  	for (let j = 0; j < AudioRendererChangeInfoArray[i].deviceDescriptors.length; j++) {
3283 3284 3285 3286 3287 3288 3289 3290
  	  console.info(`Id: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].id}`);
  	  console.info(`Type: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
  	  console.info(`Role: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
  	  console.info(`Name: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].name}`);
  	  console.info(`Addr: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].address}`);
  	  console.info(`SR: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
  	  console.info(`C ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
  	  console.info(`CM: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
J
jiao_yanlin 已提交
3291 3292 3293
  	}
    if (AudioRendererChangeInfoArray[i].rendererState == 1 && devDescriptor != null) {
      resultFlag = true;
3294
      console.info(`ResultFlag for ${i} is: ${resultFlag}`);
3295
    }
J
jiao_yanlin 已提交
3296
  }
3297 3298 3299 3300 3301
});
```

## AudioCapturerChangeInfo<sup>9+</sup>

3302
描述音频采集器更改信息。
3303 3304 3305 3306 3307 3308

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Capturer

| 名称               | 类型                                       | 可读 | 可写 | 说明                          |
| -------------------| ----------------------------------------- | ---- | ---- | ---------------------------- |
| streamId           | number                                    | 是   | 否   | 音频流唯一id。                |
3309 3310
| clientUid          | number                                    | 是   | 否   | 音频采集器客户端应用程序的Uid。<br/>此接口为系统接口,三方应用不支持调用。 |
| capturerInfo       | [AudioCapturerInfo](#audiocapturerinfo8)   | 是   | 否   | 音频采集器信息。               |
J
jiao_yanlin 已提交
3311
| capturerState      | [AudioState](#audiostate)                 | 是   | 否   | 音频状态。<br/>此接口为系统接口,三方应用不支持调用。|
3312

3313 3314 3315 3316 3317 3318
## AudioCapturerChangeInfoArray<sup>9+</sup>

AudioCapturerChangeInfo数组,只读。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

3319 3320
**示例:**

J
jiao_yanlin 已提交
3321
```js
3322 3323 3324
import audio from '@ohos.multimedia.audio';

const audioManager = audio.getAudioManager();
3325
var resultFlag = false;
3326
audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) =>  {
J
jiao_yanlin 已提交
3327
  for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
3328 3329 3330 3331 3332 3333
    console.info(`## CapChange on is called for element ${i} ##`);
    console.info(`StrId for  ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
    console.info(`CUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
    console.info(`Src for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
    console.info(`Flag ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
    console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);
J
jiao_yanlin 已提交
3334
    var devDescriptor = AudioCapturerChangeInfoArray[i].deviceDescriptors;
J
jiao_yanlin 已提交
3335
    for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
3336 3337 3338 3339 3340 3341 3342 3343
      console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
      console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
      console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
      console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
      console.info(`Addr: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
      console.info(`SR: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
      console.info(`C ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
      console.info(`CM ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
3344
    }
J
jiao_yanlin 已提交
3345 3346
    if (AudioCapturerChangeInfoArray[i].capturerState == 1 && devDescriptor != null) {
      resultFlag = true;
3347 3348
      console.info(`ResultFlag for element ${i} is: ${resultFlag}`);
    }
J
jiao_yanlin 已提交
3349
  }
3350 3351 3352
});
```

Z
zengyawen 已提交
3353
## AudioDeviceDescriptor
3354 3355 3356

描述音频设备。

Z
zengyawen 已提交
3357
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Device
Z
zengyawen 已提交
3358

3359 3360 3361 3362 3363 3364 3365 3366 3367 3368
| 名称                          | 类型                       | 可读 | 可写 | 说明       |
| ----------------------------- | -------------------------- | ---- | ---- | ---------- |
| deviceRole                    | [DeviceRole](#devicerole)  | 是   | 否   | 设备角色。 |
| deviceType                    | [DeviceType](#devicetype)  | 是   | 否   | 设备类型。 |
| id<sup>9+</sup>               | number                     | 是   | 否   | 设备id。  |
| name<sup>9+</sup>             | string                     | 是   | 否   | 设备名称。 |
| address<sup>9+</sup>          | string                     | 是   | 否   | 设备地址。 |
| sampleRates<sup>9+</sup>      | Array&lt;number&gt;        | 是   | 否   | 支持的采样率。 |
| channelCounts<sup>9+</sup>    | Array&lt;number&gt;        | 是   | 否   | 支持的通道数。 |
| channelMasks<sup>9+</sup>     | Array&lt;number&gt;        | 是   | 否   | 支持的通道掩码。 |
3369 3370 3371
| networkId<sup>9+</sup>        | string                     | 是   | 否   | 设备组网的ID。<br/>此接口为系统接口,三方应用不支持调用。 |
| interruptGroupId<sup>9+</sup> | number                     | 是   | 否   | 设备所处的焦点组ID。<br/>此接口为系统接口,三方应用不支持调用。 |
| volumeGroupId<sup>9+</sup>    | number                     | 是   | 否   | 设备所处的音量组ID。<br/>此接口为系统接口,三方应用不支持调用。 |
Z
zengyawen 已提交
3372 3373

## AudioDeviceDescriptors
M
mamingshuai 已提交
3374

H
update  
HelloCrease 已提交
3375
设备属性数组类型,为[AudioDeviceDescriptor](#audiodevicedescriptor)的数组,只读。
Z
zengyawen 已提交
3376 3377 3378

**示例:**

J
jiao_yanlin 已提交
3379
```js
L
lwx1059628 已提交
3380 3381 3382
import audio from '@ohos.multimedia.audio';

function displayDeviceProp(value) {
J
jiao_yanlin 已提交
3383 3384
  deviceRoleValue = value.deviceRole;
  deviceTypeValue = value.deviceType;
Z
zengyawen 已提交
3385 3386
}

L
lwx1059628 已提交
3387 3388 3389 3390
var deviceRoleValue = null;
var deviceTypeValue = null;
const promise = audio.getAudioManager().getDevices(1);
promise.then(function (value) {
3391
  console.info('AudioFrameworkTest: Promise: getDevices OUTPUT_DEVICES_FLAG');
J
jiao_yanlin 已提交
3392 3393
  value.forEach(displayDeviceProp);
  if (deviceTypeValue != null && deviceRoleValue != null){
3394
    console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  PASS');
J
jiao_yanlin 已提交
3395
  } else {
3396
    console.error('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  FAIL');
J
jiao_yanlin 已提交
3397
  }
L
lwx1059628 已提交
3398
});
Z
zengyawen 已提交
3399 3400
```

3401 3402 3403 3404
## AudioRendererFilter<sup>9+</sup>

过滤条件类。在调用selectOutputDeviceByFilter接口前,需要先创建AudioRendererFilter实例。

3405
**系统接口:** 该接口为系统接口
3406

3407 3408 3409 3410
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Device

| 名称          | 类型                                     | 必填  | 说明          |
| -------------| ---------------------------------------- | ---- | -------------- |
3411 3412 3413
| uid          | number                                   |  是  | 表示应用ID。<br> 系统能力:SystemCapability.Multimedia.Audio.Core|
| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) |  否  | 表示渲染器信息。<br> 系统能力:SystemCapability.Multimedia.Audio.Renderer|
| rendererId   | number                                   |  否  | 音频流唯一id。<br> 系统能力:SystemCapability.Multimedia.Audio.Renderer|
3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426

**示例:**

```js
let outputAudioRendererFilter = {
  "uid":20010041,
  "rendererInfo": {
    "contentType":audio.ContentType.CONTENT_TYPE_MUSIC,
    "streamUsage":audio.StreamUsage.STREAM_USAGE_MEDIA,
    "rendererFlags":0 },
  "rendererId":0 };
```

Z
zengyawen 已提交
3427 3428
## AudioRenderer<sup>8+</sup>

L
lwx1059628 已提交
3429 3430
提供音频渲染的相关接口。在调用AudioRenderer的接口前,需要先通过[createAudioRenderer](#audiocreateaudiorenderer8)创建实例。

3431
### 属性
Z
zengyawen 已提交
3432

3433
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3434

3435
| 名称  | 类型                     | 可读 | 可写 | 说明               |
Z
zengyawen 已提交
3436
| ----- | -------------------------- | ---- | ---- | ------------------ |
3437
| state<sup>8+</sup> | [AudioState](#audiostate8) | 是   | 否   | 音频渲染器的状态。 |
Z
zengyawen 已提交
3438 3439 3440

**示例:**

J
jiao_yanlin 已提交
3441
```js
Z
zengyawen 已提交
3442 3443 3444 3445 3446 3447 3448
var state = audioRenderer.state;
```

### getRendererInfo<sup>8+</sup>

getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void

L
lwx1059628 已提交
3449
获取当前被创建的音频渲染器的信息,使用callback方式异步返回结果。
Z
zengyawen 已提交
3450

3451
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3452 3453 3454

**参数:**

L
lwx1059628 已提交
3455 3456 3457
| 参数名   | 类型                                                     | 必填 | 说明                   |
| :------- | :------------------------------------------------------- | :--- | :--------------------- |
| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | 是   | 返回音频渲染器的信息。 |
Z
zengyawen 已提交
3458 3459 3460

**示例:**

J
jiao_yanlin 已提交
3461
```js
L
lwx1059628 已提交
3462
audioRenderer.getRendererInfo((err, rendererInfo) => {
3463 3464 3465 3466
  console.info('Renderer GetRendererInfo:');
  console.info(`Renderer content: ${rendererInfo.content}`);
  console.info(`Renderer usage: ${rendererInfo.usage}`);
  console.info(`Renderer flags: ${rendererInfo.rendererFlags}`);
L
lwx1059628 已提交
3467
});
Z
zengyawen 已提交
3468 3469 3470 3471 3472 3473
```

### getRendererInfo<sup>8+</sup>

getRendererInfo(): Promise<AudioRendererInfo\>

L
lwx1059628 已提交
3474
获取当前被创建的音频渲染器的信息,使用Promise方式异步返回结果。
Z
zengyawen 已提交
3475

3476
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3477 3478 3479 3480 3481

**返回值:**

| 类型                                               | 说明                            |
| -------------------------------------------------- | ------------------------------- |
L
lwx1059628 已提交
3482
| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise用于返回音频渲染器信息。 |
Z
zengyawen 已提交
3483 3484 3485

**示例:**

J
jiao_yanlin 已提交
3486
```js
L
lwx1059628 已提交
3487
audioRenderer.getRendererInfo().then((rendererInfo) => {
3488 3489 3490 3491
  console.info('Renderer GetRendererInfo:');
  console.info(`Renderer content: ${rendererInfo.content}`);
  console.info(`Renderer usage: ${rendererInfo.usage}`);
  console.info(`Renderer flags: ${rendererInfo.rendererFlags}`)
L
lwx1059628 已提交
3492
}).catch((err) => {
3493
  console.error(`AudioFrameworkRenderLog: RendererInfo :ERROR: ${err.message}`);
L
lwx1059628 已提交
3494
});
Z
zengyawen 已提交
3495 3496 3497 3498 3499 3500 3501 3502
```

### getStreamInfo<sup>8+</sup>

getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void

获取音频流信息,使用callback方式异步返回结果。

3503
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3504 3505 3506 3507 3508 3509 3510 3511 3512

**参数:**

| 参数名   | 类型                                                 | 必填 | 说明                 |
| :------- | :--------------------------------------------------- | :--- | :------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | 是   | 回调返回音频流信息。 |

**示例:**

J
jiao_yanlin 已提交
3513
```js
L
lwx1059628 已提交
3514
audioRenderer.getStreamInfo((err, streamInfo) => {
3515 3516 3517 3518 3519
  console.info('Renderer GetStreamInfo:');
  console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
  console.info(`Renderer channel: ${streamInfo.channels}`);
  console.info(`Renderer format: ${streamInfo.sampleFormat}`);
  console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
L
lwx1059628 已提交
3520
});
Z
zengyawen 已提交
3521 3522 3523 3524 3525 3526 3527 3528
```

### getStreamInfo<sup>8+</sup>

getStreamInfo(): Promise<AudioStreamInfo\>

获取音频流信息,使用Promise方式异步返回结果。

3529
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3530 3531 3532 3533 3534 3535 3536 3537 3538

**返回值:**

| 类型                                           | 说明                   |
| :--------------------------------------------- | :--------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise返回音频流信息. |

**示例:**

J
jiao_yanlin 已提交
3539
```js
L
lwx1059628 已提交
3540
audioRenderer.getStreamInfo().then((streamInfo) => {
3541 3542 3543 3544 3545
  console.info('Renderer GetStreamInfo:');
  console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
  console.info(`Renderer channel: ${streamInfo.channels}`);
  console.info(`Renderer format: ${streamInfo.sampleFormat}`);
  console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
L
lwx1059628 已提交
3546
}).catch((err) => {
3547
  console.error(`ERROR: ${err.message}`);
L
lwx1059628 已提交
3548
});
Z
zengyawen 已提交
3549 3550 3551 3552 3553 3554
```

### start<sup>8+</sup>

start(callback: AsyncCallback<void\>): void

L
lwx1059628 已提交
3555
启动音频渲染器。使用callback方式异步返回结果。
Z
zengyawen 已提交
3556

3557
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3558 3559 3560 3561 3562 3563 3564 3565 3566

**参数:**

| 参数名   | 类型                 | 必填 | 说明       |
| -------- | -------------------- | ---- | ---------- |
| callback | AsyncCallback\<void> | 是   | 回调函数。 |

**示例:**

J
jiao_yanlin 已提交
3567
```js
L
lwx1059628 已提交
3568
audioRenderer.start((err) => {
J
jiao_yanlin 已提交
3569
  if (err) {
3570
    console.error('Renderer start failed.');
J
jiao_yanlin 已提交
3571
  } else {
3572
    console.info('Renderer start success.');
J
jiao_yanlin 已提交
3573
  }
L
lwx1059628 已提交
3574
});
Z
zengyawen 已提交
3575 3576 3577 3578 3579 3580
```

### start<sup>8+</sup>

start(): Promise<void\>

L
lwx1059628 已提交
3581
启动音频渲染器。使用Promise方式异步返回结果。
Z
zengyawen 已提交
3582

3583
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3584 3585 3586 3587 3588 3589 3590 3591 3592

**返回值:**

| 类型           | 说明                      |
| -------------- | ------------------------- |
| Promise\<void> | Promise方式异步返回结果。 |

**示例:**

J
jiao_yanlin 已提交
3593
```js
L
lwx1059628 已提交
3594
audioRenderer.start().then(() => {
3595
  console.info('Renderer started');
L
lwx1059628 已提交
3596
}).catch((err) => {
3597
  console.error(`ERROR: ${err.message}`);
L
lwx1059628 已提交
3598
});
Z
zengyawen 已提交
3599 3600 3601 3602 3603 3604
```

### pause<sup>8+</sup>

pause(callback: AsyncCallback\<void>): void

L
lwx1059628 已提交
3605
暂停渲染。使用callback方式异步返回结果。
Z
zengyawen 已提交
3606

3607
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3608 3609 3610 3611 3612 3613 3614 3615 3616

**参数:**

| 参数名   | 类型                 | 必填 | 说明             |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | 是   | 返回回调的结果。 |

**示例:**

J
jiao_yanlin 已提交
3617
```js
L
lwx1059628 已提交
3618
audioRenderer.pause((err) => {
J
jiao_yanlin 已提交
3619
  if (err) {
3620
    console.error('Renderer pause failed');
J
jiao_yanlin 已提交
3621
  } else {
3622
    console.info('Renderer paused.');
J
jiao_yanlin 已提交
3623
  }
L
lwx1059628 已提交
3624
});
Z
zengyawen 已提交
3625 3626 3627 3628 3629 3630
```

### pause<sup>8+</sup>

pause(): Promise\<void>

L
lwx1059628 已提交
3631
暂停渲染。使用Promise方式异步返回结果。
Z
zengyawen 已提交
3632

3633
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3634 3635 3636 3637 3638 3639 3640 3641 3642

**返回值:**

| 类型           | 说明                      |
| -------------- | ------------------------- |
| Promise\<void> | Promise方式异步返回结果。 |

**示例:**

J
jiao_yanlin 已提交
3643
```js
L
lwx1059628 已提交
3644
audioRenderer.pause().then(() => {
3645
  console.info('Renderer paused');
L
lwx1059628 已提交
3646
}).catch((err) => {
3647
  console.error(`ERROR: ${err.message}`);
L
lwx1059628 已提交
3648
});
Z
zengyawen 已提交
3649 3650 3651 3652 3653 3654
```

### drain<sup>8+</sup>

drain(callback: AsyncCallback\<void>): void

L
lwx1059628 已提交
3655
检查缓冲区是否已被耗尽。使用callback方式异步返回结果。
Z
zengyawen 已提交
3656

3657
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3658 3659 3660 3661 3662 3663 3664 3665 3666

**参数:**

| 参数名   | 类型                 | 必填 | 说明             |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | 是   | 返回回调的结果。 |

**示例:**

J
jiao_yanlin 已提交
3667
```js
L
lwx1059628 已提交
3668
audioRenderer.drain((err) => {
J
jiao_yanlin 已提交
3669
  if (err) {
3670
    console.error('Renderer drain failed');
J
jiao_yanlin 已提交
3671
  } else {
3672
    console.info('Renderer drained.');
J
jiao_yanlin 已提交
3673
  }
L
lwx1059628 已提交
3674
});
Z
zengyawen 已提交
3675 3676 3677 3678 3679 3680
```

### drain<sup>8+</sup>

drain(): Promise\<void>

L
lwx1059628 已提交
3681
检查缓冲区是否已被耗尽。使用Promise方式异步返回结果。
Z
zengyawen 已提交
3682

3683
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3684 3685 3686 3687 3688 3689 3690 3691 3692

**返回值:**

| 类型           | 说明                      |
| -------------- | ------------------------- |
| Promise\<void> | Promise方式异步返回结果。 |

**示例:**

J
jiao_yanlin 已提交
3693
```js
L
lwx1059628 已提交
3694
audioRenderer.drain().then(() => {
3695
  console.info('Renderer drained successfully');
L
lwx1059628 已提交
3696
}).catch((err) => {
3697
  console.error(`ERROR: ${err.message}`);
L
lwx1059628 已提交
3698
});
Z
zengyawen 已提交
3699 3700 3701 3702 3703 3704
```

### stop<sup>8+</sup>

stop(callback: AsyncCallback\<void>): void

L
lwx1059628 已提交
3705
停止渲染。使用callback方式异步返回结果。
Z
zengyawen 已提交
3706

3707
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3708 3709 3710 3711 3712 3713 3714 3715 3716

**参数:**

| 参数名   | 类型                 | 必填 | 说明             |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | 是   | 返回回调的结果。 |

**示例:**

J
jiao_yanlin 已提交
3717
```js
L
lwx1059628 已提交
3718
audioRenderer.stop((err) => {
J
jiao_yanlin 已提交
3719
  if (err) {
3720
    console.error('Renderer stop failed');
J
jiao_yanlin 已提交
3721
  } else {
3722
    console.info('Renderer stopped.');
J
jiao_yanlin 已提交
3723
  }
L
lwx1059628 已提交
3724
});
Z
zengyawen 已提交
3725 3726 3727 3728 3729 3730
```

### stop<sup>8+</sup>

stop(): Promise\<void>

L
lwx1059628 已提交
3731
停止渲染。使用Promise方式异步返回结果。
Z
zengyawen 已提交
3732

3733
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3734 3735 3736 3737 3738 3739 3740 3741 3742

**返回值:**

| 类型           | 说明                      |
| -------------- | ------------------------- |
| Promise\<void> | Promise方式异步返回结果。 |

**示例:**

J
jiao_yanlin 已提交
3743
```js
L
lwx1059628 已提交
3744
audioRenderer.stop().then(() => {
3745
  console.info('Renderer stopped successfully');
L
lwx1059628 已提交
3746
}).catch((err) => {
3747
  console.error(`ERROR: ${err.message}`);
L
lwx1059628 已提交
3748
});
Z
zengyawen 已提交
3749 3750 3751 3752 3753 3754
```

### release<sup>8+</sup>

release(callback: AsyncCallback\<void>): void

L
lwx1059628 已提交
3755
释放音频渲染器。使用callback方式异步返回结果。
Z
zengyawen 已提交
3756

3757
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3758 3759 3760 3761 3762 3763 3764 3765 3766

**参数:**

| 参数名   | 类型                 | 必填 | 说明             |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | 是   | 返回回调的结果。 |

**示例:**

J
jiao_yanlin 已提交
3767
```js
L
lwx1059628 已提交
3768
audioRenderer.release((err) => {
J
jiao_yanlin 已提交
3769
  if (err) {
3770
    console.error('Renderer release failed');
J
jiao_yanlin 已提交
3771
  } else {
3772
    console.info('Renderer released.');
J
jiao_yanlin 已提交
3773
  }
L
lwx1059628 已提交
3774
});
Z
zengyawen 已提交
3775 3776 3777 3778 3779 3780 3781 3782
```

### release<sup>8+</sup>

release(): Promise\<void>

释放渲染器。使用Promise方式异步返回结果。

3783
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3784 3785 3786 3787 3788 3789 3790 3791 3792

**返回值:**

| 类型           | 说明                      |
| -------------- | ------------------------- |
| Promise\<void> | Promise方式异步返回结果。 |

**示例:**

J
jiao_yanlin 已提交
3793
```js
L
lwx1059628 已提交
3794
audioRenderer.release().then(() => {
3795
  console.info('Renderer released successfully');
L
lwx1059628 已提交
3796
}).catch((err) => {
3797
  console.error(`ERROR: ${err.message}`);
L
lwx1059628 已提交
3798
});
Z
zengyawen 已提交
3799 3800 3801 3802 3803 3804 3805 3806
```

### write<sup>8+</sup>

write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void

写入缓冲区。使用callback方式异步返回结果。

3807
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3808 3809 3810 3811 3812 3813 3814 3815 3816 3817

**参数:**

| 参数名   | 类型                   | 必填 | 说明                                                |
| -------- | ---------------------- | ---- | --------------------------------------------------- |
| buffer   | ArrayBuffer            | 是   | 要写入缓冲区的数据。                                |
| callback | AsyncCallback\<number> | 是   | 回调如果成功,返回写入的字节数,否则返回errorcode。 |

**示例:**

J
jiao_yanlin 已提交
3818
```js
L
lwx1059628 已提交
3819 3820
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';
R
rahul 已提交
3821
import featureAbility from '@ohos.ability.featureAbility'
L
lwx1059628 已提交
3822

R
rahul 已提交
3823
var audioStreamInfo = {
J
jiao_yanlin 已提交
3824 3825 3826 3827
  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000,
  channels: audio.AudioChannel.CHANNEL_2,
  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S32LE,
  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
R
rahul 已提交
3828 3829 3830
}

var audioRendererInfo = {
J
jiao_yanlin 已提交
3831 3832
  content: audio.ContentType.CONTENT_TYPE_SPEECH,
  usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION
J
jiao_yanlin 已提交
3833
  rendererFlags: 0
R
rahul 已提交
3834 3835 3836
}

var audioRendererOptions = {
J
jiao_yanlin 已提交
3837 3838
  streamInfo: audioStreamInfo,
  rendererInfo: audioRendererInfo
R
rahul 已提交
3839 3840 3841
}
var audioRenderer;
audio.createAudioRenderer(audioRendererOptions).then((data)=> {
J
jiao_yanlin 已提交
3842
  audioRenderer = data;
3843
  console.info('AudioFrameworkRenderLog: AudioRenderer Created: SUCCESS');
J
jiao_yanlin 已提交
3844
  }).catch((err) => {
3845
  console.error(`AudioFrameworkRenderLog: AudioRenderer Created: ERROR: ${err.message}`);
J
jiao_yanlin 已提交
3846
  });
R
rahul 已提交
3847 3848
var bufferSize;
audioRenderer.getBufferSize().then((data)=> {
3849
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
J
jiao_yanlin 已提交
3850 3851
  bufferSize = data;
  }).catch((err) => {
3852
  console.error.(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err.message}`);
J
jiao_yanlin 已提交
3853
  });
3854
console.info(`Buffer size: ${bufferSize}`);
R
rahul 已提交
3855 3856
var context = featureAbility.getContext();
var path = await context.getCacheDir();
3857
var filePath = path + '/StarWars10s-2C-48000-4SW.wav';
Z
zengyawen 已提交
3858 3859 3860
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
L
lwx1059628 已提交
3861
audioRenderer.write(buf, (err, writtenbytes) => {
J
jiao_yanlin 已提交
3862
  if (writtenbytes < 0) {
3863
    console.error('write failed.');
J
jiao_yanlin 已提交
3864
  } else {
3865
    console.info(`Actual written bytes: ${writtenbytes}`);
J
jiao_yanlin 已提交
3866
  }
L
lwx1059628 已提交
3867
});
Z
zengyawen 已提交
3868 3869 3870 3871 3872 3873 3874 3875
```

### write<sup>8+</sup>

write(buffer: ArrayBuffer): Promise\<number>

写入缓冲区。使用Promise方式异步返回结果。

3876
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3877 3878 3879 3880 3881 3882 3883 3884 3885

**返回值:**

| 类型             | 说明                                                         |
| ---------------- | ------------------------------------------------------------ |
| Promise\<number> | Promise返回结果,如果成功,返回写入的字节数,否则返回errorcode。 |

**示例:**

J
jiao_yanlin 已提交
3886
```js
L
lwx1059628 已提交
3887 3888
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';
R
rahul 已提交
3889 3890 3891
import featureAbility from '@ohos.ability.featureAbility'

var audioStreamInfo = {
J
jiao_yanlin 已提交
3892 3893 3894 3895
  samplingRate:audio.AudioSamplingRate.SAMPLE_RATE_48000,
  channels:audio.AudioChannel.CHANNEL_2,
  sampleFormat:audio.AudioSampleFormat.SAMPLE_FORMAT_S32LE,
  encodingType:audio.AudioEncodingType.ENCODING_TYPE_RAW
R
rahul 已提交
3896 3897 3898
}

var audioRendererInfo = {
J
jiao_yanlin 已提交
3899 3900
  content: audio.ContentType.CONTENT_TYPE_SPEECH,
  usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
J
jiao_yanlin 已提交
3901
  rendererFlags: 0
R
rahul 已提交
3902
}
L
lwx1059628 已提交
3903

R
rahul 已提交
3904
var audioRendererOptions = {
J
jiao_yanlin 已提交
3905 3906
  streamInfo: audioStreamInfo,
  rendererInfo: audioRendererInfo
R
rahul 已提交
3907 3908 3909
}
var audioRenderer;
audio.createAudioRenderer(audioRendererOptions).then((data) => {
J
jiao_yanlin 已提交
3910
  audioRenderer = data;
3911
  console.info('AudioFrameworkRenderLog: AudioRenderer Created: SUCCESS');
J
jiao_yanlin 已提交
3912
  }).catch((err) => {
3913
  console.error(`AudioFrameworkRenderLog: AudioRenderer Created: ERROR: ${err.message}`);
J
jiao_yanlin 已提交
3914
  });
R
rahul 已提交
3915 3916
var bufferSize;
audioRenderer.getBufferSize().then((data) => {
3917
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
J
jiao_yanlin 已提交
3918 3919
  bufferSize = data;
  }).catch((err) => {
3920
  console.info(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err.message}`);
J
jiao_yanlin 已提交
3921
  });
3922
console.info(`BufferSize: ${bufferSize}`);
R
rahul 已提交
3923 3924
var context = featureAbility.getContext();
var path = await context.getCacheDir();
L
lwx1059628 已提交
3925
var filePath = 'data/StarWars10s-2C-48000-4SW.wav';
Z
zengyawen 已提交
3926 3927 3928
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
L
lwx1059628 已提交
3929
audioRenderer.write(buf).then((writtenbytes) => {
J
jiao_yanlin 已提交
3930
  if (writtenbytes < 0) {
3931
      console.error('write failed.');
J
jiao_yanlin 已提交
3932
  } else {
3933
      console.info(`Actual written bytes: ${writtenbytes}`);
J
jiao_yanlin 已提交
3934
  }
L
lwx1059628 已提交
3935
}).catch((err) => {
3936
    console.error(`ERROR: ${err.message}`);
L
lwx1059628 已提交
3937
});
Z
zengyawen 已提交
3938 3939 3940 3941 3942 3943
```

### getAudioTime<sup>8+</sup>

getAudioTime(callback: AsyncCallback\<number>): void

L
lwx1059628 已提交
3944
获取时间戳(从 1970 年 1 月 1 日开始)。使用callback方式异步返回结果。
Z
zengyawen 已提交
3945

3946
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3947 3948 3949 3950 3951 3952 3953 3954 3955

**参数:**

| 参数名   | 类型                   | 必填 | 说明             |
| -------- | ---------------------- | ---- | ---------------- |
| callback | AsyncCallback\<number> | 是   | 回调返回时间戳。 |

**示例:**

J
jiao_yanlin 已提交
3956
```js
L
lwx1059628 已提交
3957
audioRenderer.getAudioTime((err, timestamp) => {
3958
  console.info(`Current timestamp: ${timestamp}`);
L
lwx1059628 已提交
3959
});
Z
zengyawen 已提交
3960 3961 3962 3963 3964 3965
```

### getAudioTime<sup>8+</sup>

getAudioTime(): Promise\<number>

L
lwx1059628 已提交
3966
获取时间戳(从 1970 年 1 月 1 日开始)。使用Promise方式异步返回结果。
Z
zengyawen 已提交
3967

3968
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3969 3970 3971 3972 3973 3974 3975 3976 3977

**返回值:**

| 类型             | 描述                    |
| ---------------- | ----------------------- |
| Promise\<number> | Promise回调返回时间戳。 |

**示例:**

J
jiao_yanlin 已提交
3978
```js
L
lwx1059628 已提交
3979
audioRenderer.getAudioTime().then((timestamp) => {
3980
  console.info(`Current timestamp: ${timestamp}`);
L
lwx1059628 已提交
3981
}).catch((err) => {
3982
  console.error(`ERROR: ${err.message}`);
L
lwx1059628 已提交
3983
});
Z
zengyawen 已提交
3984 3985 3986 3987 3988 3989
```

### getBufferSize<sup>8+</sup>

getBufferSize(callback: AsyncCallback\<number>): void

L
lwx1059628 已提交
3990
获取音频渲染器的最小缓冲区大小。使用callback方式异步返回结果。
Z
zengyawen 已提交
3991

3992
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
3993 3994 3995 3996 3997 3998 3999 4000 4001

**参数:**

| 参数名   | 类型                   | 必填 | 说明                 |
| -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback\<number> | 是   | 回调返回缓冲区大小。 |

**示例:**

J
jiao_yanlin 已提交
4002
```js
R
rahul 已提交
4003
var bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
J
jiao_yanlin 已提交
4004
  if (err) {
4005
    console.error('getBufferSize error');
J
jiao_yanlin 已提交
4006
  }
L
lwx1059628 已提交
4007
});
Z
zengyawen 已提交
4008 4009 4010 4011 4012 4013
```

### getBufferSize<sup>8+</sup>

getBufferSize(): Promise\<number>

L
lwx1059628 已提交
4014
获取音频渲染器的最小缓冲区大小。使用Promise方式异步返回结果。
Z
zengyawen 已提交
4015

4016
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
4017 4018 4019 4020 4021 4022 4023 4024 4025

**返回值:**

| 类型             | 说明                        |
| ---------------- | --------------------------- |
| Promise\<number> | promise回调返回缓冲区大小。 |

**示例:**

J
jiao_yanlin 已提交
4026
```js
R
rahul 已提交
4027 4028 4029 4030
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';

var audioStreamInfo = {
J
jiao_yanlin 已提交
4031 4032 4033 4034
  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000,
  channels: audio.AudioChannel.CHANNEL_2,
  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S32LE,
  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
R
rahul 已提交
4035 4036 4037
}

var audioRendererInfo = {
J
jiao_yanlin 已提交
4038 4039
  content: audio.ContentType.CONTENT_TYPE_SPEECH,
  usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
J
jiao_yanlin 已提交
4040
  rendererFlags: 0
R
rahul 已提交
4041 4042 4043
}

var audioRendererOptions = {
J
jiao_yanlin 已提交
4044 4045
  streamInfo: audioStreamInfo,
  rendererInfo: audioRendererInfo
R
rahul 已提交
4046 4047 4048
}
var audioRenderer;
audio.createAudioRenderer(audioRendererOptions).then((data) => {
J
jiao_yanlin 已提交
4049 4050 4051
  audioRenderer = data;
  console.info('AudioFrameworkRenderLog: AudioRenderer Created: SUCCESS');
  }).catch((err) => {
4052
  console.info(`AudioFrameworkRenderLog: AudioRenderer Created: ERROR: ${err.message}`);
J
jiao_yanlin 已提交
4053
  });
R
rahul 已提交
4054
var bufferSize;
R
rahul 已提交
4055
audioRenderer.getBufferSize().then((data) => {
4056
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
J
jiao_yanlin 已提交
4057
  bufferSize = data;
L
lwx1059628 已提交
4058
}).catch((err) => {
4059
  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err.message}`);
L
lwx1059628 已提交
4060
});
Z
zengyawen 已提交
4061 4062 4063 4064 4065 4066
```

### setRenderRate<sup>8+</sup>

setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\<void>): void

L
lwx1059628 已提交
4067
设置音频渲染速率。使用callback方式异步返回结果。
Z
zengyawen 已提交
4068

4069
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
4070 4071 4072 4073 4074

**参数:**

| 参数名   | 类型                                     | 必填 | 说明                     |
| -------- | ---------------------------------------- | ---- | ------------------------ |
L
lwx1059628 已提交
4075
| rate     | [AudioRendererRate](#audiorendererrate8) | 是   | 渲染的速率。             |
Z
zengyawen 已提交
4076 4077 4078 4079
| callback | AsyncCallback\<void>                     | 是   | 用于返回执行结果的回调。 |

**示例:**

J
jiao_yanlin 已提交
4080
```js
L
lwx1059628 已提交
4081
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => {
J
jiao_yanlin 已提交
4082
  if (err) {
4083
    console.error('Failed to set params');
J
jiao_yanlin 已提交
4084
  } else {
4085
    console.info('Callback invoked to indicate a successful render rate setting.');
J
jiao_yanlin 已提交
4086
  }
L
lwx1059628 已提交
4087
});
Z
zengyawen 已提交
4088 4089 4090 4091 4092 4093
```

### setRenderRate<sup>8+</sup>

setRenderRate(rate: AudioRendererRate): Promise\<void>

L
lwx1059628 已提交
4094
设置音频渲染速率。使用Promise方式异步返回结果。
Z
zengyawen 已提交
4095

4096
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
4097 4098 4099 4100 4101

**参数:**

| 参数名 | 类型                                     | 必填 | 说明         |
| ------ | ---------------------------------------- | ---- | ------------ |
L
lwx1059628 已提交
4102
| rate   | [AudioRendererRate](#audiorendererrate8) | 是   | 渲染的速率。 |
Z
zengyawen 已提交
4103 4104 4105 4106 4107 4108 4109 4110 4111

**返回值:**

| 类型           | 说明                      |
| -------------- | ------------------------- |
| Promise\<void> | Promise用于返回执行结果。 |

**示例:**

J
jiao_yanlin 已提交
4112
```js
L
lwx1059628 已提交
4113
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
4114
  console.info('setRenderRate SUCCESS');
L
lwx1059628 已提交
4115
}).catch((err) => {
4116
  console.error(`ERROR: ${err.message}`);
L
lwx1059628 已提交
4117
});
Z
zengyawen 已提交
4118 4119 4120 4121 4122 4123
```

### getRenderRate<sup>8+</sup>

getRenderRate(callback: AsyncCallback\<AudioRendererRate>): void

L
lwx1059628 已提交
4124
获取当前渲染速率。使用callback方式异步返回结果。
Z
zengyawen 已提交
4125

4126
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
4127 4128 4129 4130 4131

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明               |
| -------- | ------------------------------------------------------- | ---- | ------------------ |
L
lwx1059628 已提交
4132
| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | 是   | 回调返回渲染速率。 |
Z
zengyawen 已提交
4133 4134 4135

**示例:**

J
jiao_yanlin 已提交
4136
```js
L
lwx1059628 已提交
4137
audioRenderer.getRenderRate((err, renderrate) => {
4138
  console.info(`getRenderRate: ${renderrate}`);
L
lwx1059628 已提交
4139
});
Z
zengyawen 已提交
4140 4141 4142 4143 4144 4145
```

### getRenderRate<sup>8+</sup>

getRenderRate(): Promise\<AudioRendererRate>

L
lwx1059628 已提交
4146
获取当前渲染速率。使用Promise方式异步返回结果。
Z
zengyawen 已提交
4147

4148
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
4149 4150 4151 4152 4153

**返回值:**

| 类型                                              | 说明                      |
| ------------------------------------------------- | ------------------------- |
L
lwx1059628 已提交
4154
| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise回调返回渲染速率。 |
Z
zengyawen 已提交
4155 4156 4157

**示例:**

J
jiao_yanlin 已提交
4158
```js
L
lwx1059628 已提交
4159
audioRenderer.getRenderRate().then((renderRate) => {
4160
  console.info(`getRenderRate: ${renderRate}`);
L
lwx1059628 已提交
4161
}).catch((err) => {
4162
  console.error(`ERROR: ${err.message}`);
L
lwx1059628 已提交
4163
});
Z
zengyawen 已提交
4164
```
4165 4166
### setInterruptMode<sup>9+</sup>

4167
setInterruptMode(mode: InterruptMode): Promise&lt;void&gt;
4168

4169
设置应用的焦点模型。使用Promise异步回调。
4170 4171 4172 4173 4174

**系统能力:** SystemCapability.Multimedia.Audio.Renderer

**参数:**

4175 4176
| 参数名     | 类型                                | 必填   | 说明        |
| ---------- | ---------------------------------- | ------ | ---------- |
4177
| mode       | [InterruptMode](#interruptmode9)    | 是     | 焦点模型。  |
4178 4179 4180 4181 4182

**返回值:**

| 类型                | 说明                          |
| ------------------- | ----------------------------- |
4183
| Promise&lt;void&gt; | 以Promise对象返回结果,设置成功时返回undefined,否则返回error。 |
4184 4185

**示例:**
Z
zengyawen 已提交
4186

J
jiao_yanlin 已提交
4187
```js
J
jiao_yanlin 已提交
4188
var audioStreamInfo = {
J
jiao_yanlin 已提交
4189 4190 4191 4192
  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000,
  channels: audio.AudioChannel.CHANNEL_1,
  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
J
jiao_yanlin 已提交
4193 4194
}
var audioRendererInfo = {
J
jiao_yanlin 已提交
4195 4196 4197
  content: audio.ContentType.CONTENT_TYPE_MUSIC,
  usage: audio.StreamUsage.STREAM_USAGE_MEDIA,
  rendererFlags: 0
J
jiao_yanlin 已提交
4198 4199
}
var audioRendererOptions = {
J
jiao_yanlin 已提交
4200 4201
  streamInfo: audioStreamInfo,
  rendererInfo: audioRendererInfo
J
jiao_yanlin 已提交
4202 4203 4204 4205
}
let audioRenderer = await audio.createAudioRenderer(audioRendererOptions);
let mode = 0;
audioRenderer.setInterruptMode(mode).then(data=>{
4206 4207 4208
  console.info('setInterruptMode Success!');
}).catch((err) => {
  console.error(`setInterruptMode Fail: ${err.message}`);
4209
});
Z
zhujie81 已提交
4210 4211 4212
```
### setInterruptMode<sup>9+</sup>

4213
setInterruptMode(mode: InterruptMode, callback: AsyncCallback\<void>): void
Z
zhujie81 已提交
4214

Z
zhujie81 已提交
4215
设置应用的焦点模型。使用Callback回调返回执行结果。
Z
zhujie81 已提交
4216 4217 4218 4219

**系统能力:** SystemCapability.Multimedia.Audio.Renderer

**参数:**
4220

4221 4222
| 参数名   | 类型                                | 必填   | 说明            |
| ------- | ----------------------------------- | ------ | -------------- |
4223
|mode     | [InterruptMode](#interruptmode9)     | 是     | 焦点模型。|
4224
|callback | AsyncCallback\<void>                 | 是     |回调返回执行结果。|
Z
zengyawen 已提交
4225

Z
zhujie81 已提交
4226 4227
**示例:**

J
jiao_yanlin 已提交
4228
```js
J
jiao_yanlin 已提交
4229
var audioStreamInfo = {
J
jiao_yanlin 已提交
4230 4231 4232 4233
  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000,
  channels: audio.AudioChannel.CHANNEL_1,
  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
J
jiao_yanlin 已提交
4234 4235
}
var audioRendererInfo = {
J
jiao_yanlin 已提交
4236 4237 4238
  content: audio.ContentType.CONTENT_TYPE_MUSIC,
  usage: audio.StreamUsage.STREAM_USAGE_MEDIA,
  rendererFlags: 0
J
jiao_yanlin 已提交
4239 4240
}
var audioRendererOptions = {
J
jiao_yanlin 已提交
4241 4242
  streamInfo: audioStreamInfo,
  rendererInfo: audioRendererInfo
J
jiao_yanlin 已提交
4243 4244 4245
}
let audioRenderer = await audio.createAudioRenderer(audioRendererOptions);
let mode = 1;
J
jiao_yanlin 已提交
4246
audioRenderer.setInterruptMode(mode, (err, data)=>{
J
jiao_yanlin 已提交
4247
  if(err){
4248
    console.error(`setInterruptMode Fail: ${err.message}`);
J
jiao_yanlin 已提交
4249
  }
4250
  console.info('setInterruptMode Success!');
4251
});
4252
```
L
lwx1059628 已提交
4253
### on('interrupt')<sup>9+</sup>
Z
zengyawen 已提交
4254 4255 4256 4257 4258

on(type: 'interrupt', callback: Callback\<InterruptEvent>): void

监听音频中断事件。使用callback获取中断事件。

4259
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
Z
zengyawen 已提交
4260 4261 4262 4263 4264 4265

**参数:**

| 参数名   | 类型                                         | 必填 | 说明                                                         |
| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                                       | 是   | 事件回调类型,支持的事件为:'interrupt'(中断事件被触发,音频播放被中断。) |
L
lwx1059628 已提交
4266
| callback | Callback<[InterruptEvent](#interruptevent9)> | 是   | 被监听的中断事件的回调。                                     |
Z
zengyawen 已提交
4267 4268 4269

**示例:**

J
jiao_yanlin 已提交
4270
```js
R
rahul 已提交
4271 4272 4273
var isPlay;
var started;
audioRenderer.on('interrupt', async(interruptEvent) => {
J
jiao_yanlin 已提交
4274 4275 4276
  if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
    switch (interruptEvent.hintType) {
      case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
4277
        console.info('Force paused. Stop writing');
J
jiao_yanlin 已提交
4278 4279 4280
        isPlay = false;
        break;
      case audio.InterruptHint.INTERRUPT_HINT_STOP:
4281
        console.info('Force stopped. Stop writing');
J
jiao_yanlin 已提交
4282 4283 4284 4285 4286 4287
        isPlay = false;
        break;
    }
  } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
    switch (interruptEvent.hintType) {
      case audio.InterruptHint.INTERRUPT_HINT_RESUME:
4288
        console.info('Resume force paused renderer or ignore');
J
jiao_yanlin 已提交
4289
        await audioRenderer.start().then(async function () {
4290
          console.info('AudioInterruptMusic: renderInstant started :SUCCESS ');
J
jiao_yanlin 已提交
4291 4292
          started = true;
        }).catch((err) => {
4293
          console.error(`AudioInterruptMusic: renderInstant start :ERROR : ${err.message}`);
J
jiao_yanlin 已提交
4294 4295 4296 4297
          started = false;
        });
        if (started) {
          isPlay = true;
4298
          console.info(`AudioInterruptMusic Renderer started : isPlay : ${isPlay}`);
J
jiao_yanlin 已提交
4299
        } else {
4300
          console.error('AudioInterruptMusic Renderer start failed');
Z
zengyawen 已提交
4301
        }
J
jiao_yanlin 已提交
4302 4303
        break;
      case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
4304
        console.info('Choose to pause or ignore');
J
jiao_yanlin 已提交
4305 4306
        if (isPlay == true) {
          isPlay == false;
4307
          console.info('AudioInterruptMusic: Media PAUSE : TRUE');
J
jiao_yanlin 已提交
4308
        } else {
J
jiao_yanlin 已提交
4309
          isPlay = true;
4310
          console.info('AudioInterruptMusic: Media PLAY : TRUE');
Z
zengyawen 已提交
4311
        }
J
jiao_yanlin 已提交
4312
        break;
Z
zengyawen 已提交
4313
    }
J
jiao_yanlin 已提交
4314
  }
L
lwx1059628 已提交
4315
});
Z
zengyawen 已提交
4316 4317
```

L
lwx1059628 已提交
4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335
### on('markReach')<sup>8+</sup>

on(type: 'markReach', frame: number, callback: (position: number) => {}): void

订阅到达标记的事件。 当渲染的帧数达到 frame 参数的值时,回调被调用。

**系统能力:** SystemCapability.Multimedia.Audio.Renderer

**参数:**

| 参数名   | 类型                     | 必填 | 说明                                      |
| :------- | :----------------------- | :--- | :---------------------------------------- |
| type     | string                   | 是   | 事件回调类型,支持的事件为:'markReach'。 |
| frame    | number                   | 是   | 触发事件的帧数。 该值必须大于 0。         |
| callback | (position: number) => {} | 是   | 触发事件时调用的回调。                    |

**示例:**

J
jiao_yanlin 已提交
4336
```js
L
lwx1059628 已提交
4337
audioRenderer.on('markReach', 1000, (position) => {
J
jiao_yanlin 已提交
4338
  if (position == 1000) {
4339
    console.info('ON Triggered successfully');
J
jiao_yanlin 已提交
4340
  }
L
lwx1059628 已提交
4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360
});
```


### off('markReach') <sup>8+</sup>

off(type: 'markReach'): void

取消订阅标记事件。

**系统能力:** SystemCapability.Multimedia.Audio.Renderer

**参数:**

| 参数名 | 类型   | 必填 | 说明                                              |
| :----- | :----- | :--- | :------------------------------------------------ |
| type   | string | 是   | 要取消订阅事件的类型。支持的事件为:'markReach'。 |

**示例:**

J
jiao_yanlin 已提交
4361
```js
L
lwx1059628 已提交
4362 4363 4364 4365
audioRenderer.off('markReach');
```

### on('periodReach') <sup>8+</sup>
Z
zengyawen 已提交
4366

L
lwx1059628 已提交
4367
on(type: "periodReach", frame: number, callback: (position: number) => {}): void
Z
zengyawen 已提交
4368

L
lwx1059628 已提交
4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382
订阅到达标记的事件。 当渲染的帧数达到 frame 参数的值时,回调被循环调用。

**系统能力:** SystemCapability.Multimedia.Audio.Renderer

**参数:**

| 参数名   | 类型                     | 必填 | 说明                                        |
| :------- | :----------------------- | :--- | :------------------------------------------ |
| type     | string                   | 是   | 事件回调类型,支持的事件为:'periodReach'。 |
| frame    | number                   | 是   | 触发事件的帧数。 该值必须大于 0。           |
| callback | (position: number) => {} | 是   | 触发事件时调用的回调。                      |

**示例:**

J
jiao_yanlin 已提交
4383
```js
L
lwx1059628 已提交
4384
audioRenderer.on('periodReach', 1000, (position) => {
J
jiao_yanlin 已提交
4385
  if (position == 1000) {
4386
    console.info('ON Triggered successfully');
J
jiao_yanlin 已提交
4387
  }
L
lwx1059628 已提交
4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406
});
```

### off('periodReach') <sup>8+</sup>

off(type: 'periodReach'): void

取消订阅标记事件。

**系统能力:** SystemCapability.Multimedia.Audio.Renderer

**参数:**

| 参数名 | 类型   | 必填 | 说明                                                |
| :----- | :----- | :--- | :-------------------------------------------------- |
| type   | string | 是   | 要取消订阅事件的类型。支持的事件为:'periodReach'。 |

**示例:**

J
jiao_yanlin 已提交
4407
```js
L
lwx1059628 已提交
4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423
audioRenderer.off('periodReach')
```

### on('stateChange') <sup>8+</sup>

on(type: 'stateChange', callback: Callback<AudioState\>): void

订阅监听状态变化。

**系统能力:** SystemCapability.Multimedia.Audio.Renderer

**参数:**

| 参数名   | 类型                       | 必填 | 说明                                        |
| :------- | :------------------------- | :--- | :------------------------------------------ |
| type     | string                     | 是   | 事件回调类型,支持的事件为:'stateChange'。 |
Z
zengyawen 已提交
4424
| callback | [AudioState](#audiostate8) | 是   | 返回监听的状态。                            |
L
lwx1059628 已提交
4425 4426 4427

**示例:**

J
jiao_yanlin 已提交
4428
```js
L
lwx1059628 已提交
4429
audioRenderer.on('stateChange', (state) => {
J
jiao_yanlin 已提交
4430
  if (state == 1) {
4431
    console.info('audio renderer state is: STATE_PREPARED');
J
jiao_yanlin 已提交
4432 4433
  }
  if (state == 2) {
4434
    console.info('audio renderer state is: STATE_RUNNING');
J
jiao_yanlin 已提交
4435
  }
L
lwx1059628 已提交
4436 4437 4438 4439 4440 4441 4442
});
```

## AudioCapturer<sup>8+</sup>

提供音频采集的相关接口。在调用AudioCapturer的接口前,需要先通过[createAudioCapturer](#audiocreateaudiocapturer8)创建实例。

4443
### 属性
L
lwx1059628 已提交
4444 4445 4446

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

4447
| 名称  | 类型                     | 可读 | 可写 | 说明             |
L
lwx1059628 已提交
4448
| :---- | :------------------------- | :--- | :--- | :--------------- |
4449
| state<sup>8+</sup>  | [AudioState](#audiostate8) | 是 | 否   | 音频采集器状态。 |
L
lwx1059628 已提交
4450 4451 4452

**示例:**

J
jiao_yanlin 已提交
4453
```js
L
lwx1059628 已提交
4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472
var state = audioCapturer.state;
```

### getCapturerInfo<sup>8+</sup>

getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void

获取采集器信息。使用callback方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**参数:**

| 参数名   | 类型                              | 必填 | 说明                                 |
| :------- | :-------------------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<AudioCapturerInfo\> | 是   | 使用callback方式异步返回采集器信息。 |

**示例:**

J
jiao_yanlin 已提交
4473
```js
L
lwx1059628 已提交
4474
audioCapturer.getCapturerInfo((err, capturerInfo) => {
J
jiao_yanlin 已提交
4475
  if (err) {
4476
    console.error('Failed to get capture info');
J
jiao_yanlin 已提交
4477
  } else {
4478 4479 4480
    console.info('Capturer getCapturerInfo:');
    console.info(`Capturer source: ${capturerInfo.source}`);
    console.info(`Capturer flags: ${capturerInfo.capturerFlags}`);
J
jiao_yanlin 已提交
4481
  }
L
lwx1059628 已提交
4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501
});
```


### getCapturerInfo<sup>8+</sup>

getCapturerInfo(): Promise<AudioCapturerInfo\>

获取采集器信息。使用Promise方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**返回值:**

| 类型                                              | 说明                                |
| :------------------------------------------------ | :---------------------------------- |
| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | 使用Promise方式异步返回采集器信息。 |

**示例:**

J
jiao_yanlin 已提交
4502
```js
L
lwx1059628 已提交
4503
audioCapturer.getCapturerInfo().then((audioParamsGet) => {
J
jiao_yanlin 已提交
4504
  if (audioParamsGet != undefined) {
4505 4506 4507
    console.info('AudioFrameworkRecLog: Capturer CapturerInfo:');
    console.info(`AudioFrameworkRecLog: Capturer SourceType: ${audioParamsGet.source}`);
    console.info(`AudioFrameworkRecLog: Capturer capturerFlags: ${audioParamsGet.capturerFlags}`);
J
jiao_yanlin 已提交
4508
  } else {
4509 4510
    console.info(`AudioFrameworkRecLog: audioParamsGet is : ${audioParamsGet}`);
    console.info('AudioFrameworkRecLog: audioParams getCapturerInfo are incorrect');
J
jiao_yanlin 已提交
4511
  }
L
lwx1059628 已提交
4512
}).catch((err) => {
4513
  console.error(`AudioFrameworkRecLog: CapturerInfo :ERROR: ${err.message}`);
L
lwx1059628 已提交
4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526
});
```

### getStreamInfo<sup>8+</sup>

getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void

获取采集器流信息。使用callback方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**参数:**

Z
zengyawen 已提交
4527 4528 4529
| 参数名   | 类型                                                 | 必填 | 说明                             |
| :------- | :--------------------------------------------------- | :--- | :------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | 是   | 使用callback方式异步返回流信息。 |
L
lwx1059628 已提交
4530 4531 4532

**示例:**

J
jiao_yanlin 已提交
4533
```js
L
lwx1059628 已提交
4534
audioCapturer.getStreamInfo((err, streamInfo) => {
J
jiao_yanlin 已提交
4535
  if (err) {
4536
    console.error('Failed to get stream info');
J
jiao_yanlin 已提交
4537
  } else {
4538 4539 4540 4541 4542
    console.info('Capturer GetStreamInfo:');
    console.info(`Capturer sampling rate: ${streamInfo.samplingRate}`);
    console.info(`Capturer channel: ${streamInfo.channels}`);
    console.info(`Capturer format: ${streamInfo.sampleFormat}`);
    console.info(`Capturer encoding type: ${streamInfo.encodingType}`);
J
jiao_yanlin 已提交
4543
  }
L
lwx1059628 已提交
4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556
});
```

### getStreamInfo<sup>8+</sup>

getStreamInfo(): Promise<AudioStreamInfo\>

获取采集器流信息。使用Promise方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**返回值:**

Z
zengyawen 已提交
4557 4558 4559
| 类型                                           | 说明                            |
| :--------------------------------------------- | :------------------------------ |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | 使用Promise方式异步返回流信息。 |
L
lwx1059628 已提交
4560 4561 4562

**示例:**

J
jiao_yanlin 已提交
4563
```js
L
lwx1059628 已提交
4564
audioCapturer.getStreamInfo().then((audioParamsGet) => {
4565 4566 4567 4568 4569
  console.info('getStreamInfo:');
  console.info(`sampleFormat: ${audioParamsGet.sampleFormat}`);
  console.info(`samplingRate: ${audioParamsGet.samplingRate}`);
  console.info(`channels: ${audioParamsGet.channels}`);
  console.info(`encodingType: ${audioParamsGet.encodingType}`);
L
lwx1059628 已提交
4570
}).catch((err) => {
4571
  console.error(`getStreamInfo :ERROR: ${err.message}`);
L
lwx1059628 已提交
4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582
});
```

### start<sup>8+</sup>

start(callback: AsyncCallback<void\>): void

启动音频采集器。使用callback方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

4583
**参数:**
L
lwx1059628 已提交
4584 4585 4586 4587 4588 4589 4590

| 参数名   | 类型                 | 必填 | 说明                           |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | 是   | 使用callback方式异步返回结果。 |

**示例:**

J
jiao_yanlin 已提交
4591
```js
L
lwx1059628 已提交
4592
audioCapturer.start((err) => {
J
jiao_yanlin 已提交
4593
  if (err) {
4594
    console.error('Capturer start failed.');
J
jiao_yanlin 已提交
4595
  } else {
4596
    console.info('Capturer start success.');
J
jiao_yanlin 已提交
4597
  }
L
lwx1059628 已提交
4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617
});
```


### start<sup>8+</sup>

start(): Promise<void\>

启动音频采集器。使用Promise方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**返回值:**

| 类型           | 说明                          |
| :------------- | :---------------------------- |
| Promise<void\> | 使用Promise方式异步返回结果。 |

**示例:**

J
jiao_yanlin 已提交
4618
```js
R
rahul 已提交
4619 4620 4621 4622
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';

var audioStreamInfo = {
J
jiao_yanlin 已提交
4623 4624 4625 4626
  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
  channels: audio.AudioChannel.CHANNEL_2,
  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
R
rahul 已提交
4627 4628 4629
}

var audioCapturerInfo = {
J
jiao_yanlin 已提交
4630
  source: audio.SourceType.SOURCE_TYPE_MIC,
J
jiao_yanlin 已提交
4631
  capturerFlags: 0
R
rahul 已提交
4632 4633 4634 4635
}

var audioCapturer;
audio.createAudioCapturer(audioCapturerOptions).then((data) => {
J
jiao_yanlin 已提交
4636
  audioCapturer = data;
4637
  console.info('AudioFrameworkRecLog: AudioCapturer Created: SUCCESS');
J
jiao_yanlin 已提交
4638
  }).catch((err) => {
4639
  console.info(`AudioFrameworkRecLog: AudioCapturer Created: ERROR: ${err.message}`);
J
jiao_yanlin 已提交
4640
  });
L
lwx1059628 已提交
4641
audioCapturer.start().then(() => {
4642 4643 4644 4645
  console.info('AudioFrameworkRecLog: ---------START---------');
  console.info('AudioFrameworkRecLog: Capturer started: SUCCESS');
  console.info(`AudioFrameworkRecLog: AudioCapturer: STATE: ${audioCapturer.state}`);
  console.info('AudioFrameworkRecLog: Capturer started: SUCCESS');
J
jiao_yanlin 已提交
4646
  if ((audioCapturer.state == audio.AudioState.STATE_RUNNING)) {
4647
    console.info('AudioFrameworkRecLog: AudioCapturer is in Running State');
J
jiao_yanlin 已提交
4648
  }
L
lwx1059628 已提交
4649
}).catch((err) => {
4650
  console.info(`AudioFrameworkRecLog: Capturer start :ERROR : ${err.message}`);
L
lwx1059628 已提交
4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669
});
```

### stop<sup>8+</sup>

stop(callback: AsyncCallback<void\>): void

停止采集。使用callback方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**参数:**

| 参数名   | 类型                 | 必填 | 说明                           |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | 是   | 使用callback方式异步返回结果。 |

**示例:**

J
jiao_yanlin 已提交
4670
```js
L
lwx1059628 已提交
4671
audioCapturer.stop((err) => {
J
jiao_yanlin 已提交
4672
  if (err) {
4673
    console.error('Capturer stop failed');
J
jiao_yanlin 已提交
4674
  } else {
4675
    console.info('Capturer stopped.');
J
jiao_yanlin 已提交
4676
  }
L
lwx1059628 已提交
4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696
});
```


### stop<sup>8+</sup>

stop(): Promise<void\>

停止采集。使用Promise方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**返回值:**

| 类型           | 说明                          |
| :------------- | :---------------------------- |
| Promise<void\> | 使用Promise方式异步返回结果。 |

**示例:**

J
jiao_yanlin 已提交
4697
```js
L
lwx1059628 已提交
4698
audioCapturer.stop().then(() => {
4699 4700
  console.info('AudioFrameworkRecLog: ---------STOP RECORD---------');
  console.info('AudioFrameworkRecLog: Capturer stopped: SUCCESS');
J
jiao_yanlin 已提交
4701
  if ((audioCapturer.state == audio.AudioState.STATE_STOPPED)){
4702
    console.info('AudioFrameworkRecLog: State is Stopped:');
J
jiao_yanlin 已提交
4703
  }
L
lwx1059628 已提交
4704
}).catch((err) => {
4705
  console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err.message}`);
L
lwx1059628 已提交
4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724
});
```

### release<sup>8+</sup>

release(callback: AsyncCallback<void\>): void

释放采集器。使用callback方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**参数:**

| 参数名   | 类型                 | 必填 | 说明                                |
| :------- | :------------------- | :--- | :---------------------------------- |
| callback | AsyncCallback<void\> | 是   | Callback used to return the result. |

**示例:**

J
jiao_yanlin 已提交
4725
```js
L
lwx1059628 已提交
4726
audioCapturer.release((err) => {
J
jiao_yanlin 已提交
4727
  if (err) {
4728
    console.error('capturer release failed');
J
jiao_yanlin 已提交
4729
  } else {
4730
    console.info('capturer released.');
J
jiao_yanlin 已提交
4731
  }
L
lwx1059628 已提交
4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751
});
```


### release<sup>8+</sup>

release(): Promise<void\>

释放采集器。使用Promise方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**返回值:**

| 类型           | 说明                          |
| :------------- | :---------------------------- |
| Promise<void\> | 使用Promise方式异步返回结果。 |

**示例:**

J
jiao_yanlin 已提交
4752
```js
J
jiao_yanlin 已提交
4753
var stateFlag;
L
lwx1059628 已提交
4754
audioCapturer.release().then(() => {
4755 4756 4757 4758
  console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
  console.info('AudioFrameworkRecLog: Capturer release : SUCCESS');
  console.info(`AudioFrameworkRecLog: AudioCapturer : STATE : ${audioCapturer.state}`);
  console.info(`AudioFrameworkRecLog: stateFlag : ${stateFlag}`);
L
lwx1059628 已提交
4759
}).catch((err) => {
4760
  console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err.message}`);
L
lwx1059628 已提交
4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772
});
```


### read<sup>8+</sup>

read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void

读入缓冲区。使用callback方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

4773
**参数:**
L
lwx1059628 已提交
4774 4775 4776 4777 4778 4779 4780 4781 4782

| 参数名         | 类型                        | 必填 | 说明                             |
| :------------- | :-------------------------- | :--- | :------------------------------- |
| size           | number                      | 是   | 读入的字节数。                   |
| isBlockingRead | boolean                     | 是   | 是否阻塞读操作。                 |
| callback       | AsyncCallback<ArrayBuffer\> | 是   | 使用callback方式异步返回缓冲区。 |

**示例:**

J
jiao_yanlin 已提交
4783
```js
R
rahul 已提交
4784 4785
var bufferSize;
audioCapturer.getBufferSize().then((data) => {
4786
  console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ${data}`);
J
jiao_yanlin 已提交
4787 4788
  bufferSize = data;
  }).catch((err) => {
4789
    console.error(`AudioFrameworkRecLog: getBufferSize: EROOR: ${err.message}`);
J
jiao_yanlin 已提交
4790
  });
L
lwx1059628 已提交
4791
audioCapturer.read(bufferSize, true, async(err, buffer) => {
J
jiao_yanlin 已提交
4792
  if (!err) {
4793
    console.info('Success in reading the buffer data');
J
jiao_yanlin 已提交
4794
  }
J
jiao_yanlin 已提交
4795
});
L
lwx1059628 已提交
4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821
```


### read<sup>8+</sup>

read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>

读入缓冲区。使用Promise方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**参数:**

| 参数名         | 类型    | 必填 | 说明             |
| :------------- | :------ | :--- | :--------------- |
| size           | number  | 是   | 读入的字节数。   |
| isBlockingRead | boolean | 是   | 是否阻塞读操作。 |

**返回值:**

| 类型                  | 说明                                                   |
| :-------------------- | :----------------------------------------------------- |
| Promise<ArrayBuffer\> | 如果操作成功,返回读取的缓冲区数据;否则返回错误代码。 |

**示例:**

J
jiao_yanlin 已提交
4822
```js
R
rahul 已提交
4823 4824
var bufferSize;
audioCapturer.getBufferSize().then((data) => {
4825
  console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ${data}`);
J
jiao_yanlin 已提交
4826 4827
  bufferSize = data;
  }).catch((err) => {
4828
  console.info(`AudioFrameworkRecLog: getBufferSize: ERROR ${err.message}`);
J
jiao_yanlin 已提交
4829
  });
4830
console.info(`Buffer size: ${bufferSize}`);
L
lwx1059628 已提交
4831
audioCapturer.read(bufferSize, true).then((buffer) => {
4832
  console.info('buffer read successfully');
L
lwx1059628 已提交
4833
}).catch((err) => {
4834
  console.info(`ERROR : ${err.message}`);
L
lwx1059628 已提交
4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854
});
```


### getAudioTime<sup>8+</sup>

getAudioTime(callback: AsyncCallback<number\>): void

获取时间戳(从1970年1月1日开始),单位为纳秒。使用callback方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**参数:**

| 参数名   | 类型                   | 必填 | 说明                           |
| :------- | :--------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<number\> | 是   | 使用callback方式异步返回结果。 |

**示例:**

J
jiao_yanlin 已提交
4855
```js
L
lwx1059628 已提交
4856
audioCapturer.getAudioTime((err, timestamp) => {
4857
  console.info(`Current timestamp: ${timestamp}`);
L
lwx1059628 已提交
4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877
});
```


### getAudioTime<sup>8+</sup>

getAudioTime(): Promise<number\>

获取时间戳(从1970年1月1日开始),单位为纳秒。使用Promise方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**返回值:**

| 类型             | 说明                          |
| :--------------- | :---------------------------- |
| Promise<number\> | 使用Promise方式异步返回结果。 |

**示例:**

J
jiao_yanlin 已提交
4878
```js
L
lwx1059628 已提交
4879
audioCapturer.getAudioTime().then((audioTime) => {
4880
  console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTime : Success ${audioTime}`);
L
lwx1059628 已提交
4881
}).catch((err) => {
4882
  console.info(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err.message}`);
L
lwx1059628 已提交
4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902
});
```


### getBufferSize<sup>8+</sup>

getBufferSize(callback: AsyncCallback<number\>): void

获取采集器合理的最小缓冲区大小。使用callback方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**参数:**

| 参数名   | 类型                   | 必填 | 说明                                 |
| :------- | :--------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<number\> | 是   | 使用callback方式异步返回缓冲区大小。 |

**示例:**

J
jiao_yanlin 已提交
4903
```js
L
lwx1059628 已提交
4904
audioCapturer.getBufferSize((err, bufferSize) => {
J
jiao_yanlin 已提交
4905
  if (!err) {
4906
    console.info(`BufferSize : ${bufferSize}`);
J
jiao_yanlin 已提交
4907
    audioCapturer.read(bufferSize, true).then((buffer) => {
4908
      console.info(`Buffer read is ${buffer}`);
J
jiao_yanlin 已提交
4909
    }).catch((err) => {
4910
      console.error(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err.message}`);
J
jiao_yanlin 已提交
4911 4912
    });
  }
L
lwx1059628 已提交
4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932
});
```


### getBufferSize<sup>8+</sup>

getBufferSize(): Promise<number\>

获取采集器合理的最小缓冲区大小。使用Promise方式异步返回结果。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**返回值:**

| 类型             | 说明                                |
| :--------------- | :---------------------------------- |
| Promise<number\> | 使用Promise方式异步返回缓冲区大小。 |

**示例:**

J
jiao_yanlin 已提交
4933
```js
R
rahul 已提交
4934 4935
var bufferSize;
audioCapturer.getBufferSize().then((data) => {
4936
  console.info(`AudioFrameworkRecLog: getBufferSize :SUCCESS ${data}`);
J
jiao_yanlin 已提交
4937
  bufferSize = data;
R
rahul 已提交
4938
}).catch((err) => {
4939
  console.info(`AudioFrameworkRecLog: getBufferSize :ERROR : ${err.message}`);
L
lwx1059628 已提交
4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953
});
```


### on('markReach')<sup>8+</sup>

on(type: 'markReach', frame: number, callback: (position: number) => {}): void

订阅标记到达的事件。 当采集的帧数达到 frame 参数的值时,回调被触发。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**参数:**

4954 4955 4956 4957 4958
| 参数名   | 类型                     | 必填 | 说明                                       |
| :------- | :----------------------  | :--- | :----------------------------------------- |
| type     | string                   | 是   | 事件回调类型,支持的事件为:'markReach'。  |
| frame    | number                   | 是   | 触发事件的帧数。 该值必须大于0。           |
| callback | (position: number) => {} | 是   | 使用callback方式异步返回被触发事件的回调。 |
L
lwx1059628 已提交
4959 4960 4961

**示例:**

J
jiao_yanlin 已提交
4962
```js
L
lwx1059628 已提交
4963
audioCapturer.on('markReach', 1000, (position) => {
J
jiao_yanlin 已提交
4964
  if (position == 1000) {
4965
    console.info('ON Triggered successfully');
J
jiao_yanlin 已提交
4966
  }
L
lwx1059628 已提交
4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985
});
```

### off('markReach')<sup>8+</sup>

off(type: 'markReach'): void

取消订阅标记到达的事件。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**参数:**

| 参数名 | 类型   | 必填 | 说明                                          |
| :----- | :----- | :--- | :-------------------------------------------- |
| type   | string | 是   | 取消事件回调类型,支持的事件为:'markReach'。 |

**示例:**

J
jiao_yanlin 已提交
4986
```js
L
lwx1059628 已提交
4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007
audioCapturer.off('markReach');
```

### on('periodReach')<sup>8+</sup>

on(type: "periodReach", frame: number, callback: (position: number) => {}): void

订阅到达标记的事件。 当采集的帧数达到 frame 参数的值时,回调被循环调用。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**参数:**

| 参数名   | 类型                     | 必填 | 说明                                        |
| :------- | :----------------------- | :--- | :------------------------------------------ |
| type     | string                   | 是   | 事件回调类型,支持的事件为:'periodReach'。 |
| frame    | number                   | 是   | 触发事件的帧数。 该值必须大于0。            |
| callback | (position: number) => {} | 是   | 使用callback方式异步返回被触发事件的回调    |

**示例:**

J
jiao_yanlin 已提交
5008
```js
L
lwx1059628 已提交
5009
audioCapturer.on('periodReach', 1000, (position) => {
J
jiao_yanlin 已提交
5010
  if (position == 1000) {
5011
    console.info('ON Triggered successfully');
J
jiao_yanlin 已提交
5012
  }
L
lwx1059628 已提交
5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031
});
```

### off('periodReach')<sup>8+</sup>

off(type: 'periodReach'): void

取消订阅标记到达的事件。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**参数:**

| 参数名 | 类型   | 必填 | 说明                                            |
| :----- | :----- | :--- | :---------------------------------------------- |
| type   | string | Yes  | 取消事件回调类型,支持的事件为:'periodReach'。 |

**示例:**

J
jiao_yanlin 已提交
5032
```js
L
lwx1059628 已提交
5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048
audioCapturer.off('periodReach')
```

### on('stateChange') <sup>8+</sup>

on(type: 'stateChange', callback: Callback<AudioState\>): void

订阅监听状态变化。

**系统能力:** SystemCapability.Multimedia.Audio.Capturer

**参数:**

| 参数名   | 类型                       | 必填 | 说明                                        |
| :------- | :------------------------- | :--- | :------------------------------------------ |
| type     | string                     | 是   | 事件回调类型,支持的事件为:'stateChange'。 |
Z
zengyawen 已提交
5049
| callback | [AudioState](#audiostate8) | 是   | 返回监听的状态。                            |
L
lwx1059628 已提交
5050 5051 5052

**示例:**

J
jiao_yanlin 已提交
5053
```js
L
lwx1059628 已提交
5054
audioCapturer.on('stateChange', (state) => {
J
jiao_yanlin 已提交
5055
  if (state == 1) {
5056
    console.info('audio capturer state is: STATE_PREPARED');
J
jiao_yanlin 已提交
5057 5058
  }
  if (state == 2) {
5059
    console.info('audio capturer state is: STATE_RUNNING');
J
jiao_yanlin 已提交
5060
  }
L
lwx1059628 已提交
5061
});
5062
```