js-apis-audio.md 112.4 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 16 17 18 19

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

Z
zengyawen 已提交
20

Z
zengyawen 已提交
21
## audio.getAudioManager
Z
zengyawen 已提交
22 23

getAudioManager(): AudioManager
M
mamingshuai 已提交
24 25 26

获取音频管理器。

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

M
mamingshuai 已提交
29
**返回值:**
Z
zengyawen 已提交
30 31
| 类型                          | 说明         |
| ----------------------------- | ------------ |
Z
zengyawen 已提交
32
| [AudioManager](#audiomanager) | 音频管理类。 |
M
mamingshuai 已提交
33 34 35 36 37 38

**示例:**
```
var audioManager = audio.getAudioManager();
```

Z
zengyawen 已提交
39 40
## audio.createAudioRenderer<sup>8+</sup>

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

43
获取音频渲染器。使用callback方式异步返回结果。
Z
zengyawen 已提交
44 45 46 47 48

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

**参数**

H
update  
HelloCrease 已提交
49 50 51
| 参数名   | 类型                                            | 必填 | 说明             |
| -------- | ----------------------------------------------- | ---- | ---------------- |
| options  | [AudioRendererOptions](#audiorendereroptions8)  | 是   | 配置渲染器。     |
M
magekkkk 已提交
52
| callback | AsyncCallback<[AudioRenderer](#audiorenderer8)> | 是   | 音频渲染器对象。 |
L
lwx1059628 已提交
53 54 55 56

**示例:**

```
L
lwx1059628 已提交
57
import audio from '@ohos.multimedia.audio';
L
lwx1059628 已提交
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
var audioStreamInfo = {
    samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
    channels: audio.AudioChannel.CHANNEL_1,
    sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
    encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}

var audioRendererInfo = {
    content: audio.ContentType.CONTENT_TYPE_SPEECH,
    usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
    rendererFlags: 1
}

var audioRendererOptions = {
    streamInfo: audioStreamInfo,
    rendererInfo: audioRendererInfo
}

audio.createAudioRenderer(audioRendererOptions,(err, data) => {
    if (err) {
L
lwx1059628 已提交
78
        console.error(`AudioRenderer Created : Error: ${err.message}`);
L
lwx1059628 已提交
79 80
    }
    else {
L
lwx1059628 已提交
81 82
        console.info('AudioRenderer Created : Success : SUCCESS');
        let audioRenderer = data;
L
lwx1059628 已提交
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
    }
});
```

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

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

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

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

**参数:**

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

**返回值:**

| 类型                                      | 说明             |
| ----------------------------------------- | ---------------- |
105
| Promise<[AudioRenderer](#audiorenderer8)> | 音频渲染器对象。 |
Z
zengyawen 已提交
106 107 108 109

**示例:**

```
L
lwx1059628 已提交
110 111
import audio from '@ohos.multimedia.audio';

Z
zengyawen 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
var audioStreamInfo = {
    samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
    channels: audio.AudioChannel.CHANNEL_1,
    sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
    encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}

var audioRendererInfo = {
    content: audio.ContentType.CONTENT_TYPE_SPEECH,
    usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
    rendererFlags: 1
}

var audioRendererOptions = {
    streamInfo: audioStreamInfo,
    rendererInfo: audioRendererInfo
}

L
lwx1059628 已提交
130 131 132 133 134 135 136
var audioRenderer;
audio.createAudioRenderer(audioRendererOptions).then((data) => {
    audioRenderer = data;
    console.info('AudioFrameworkRenderLog: AudioRenderer Created : Success : Stream Type: SUCCESS');
}).catch((err) => {
    console.info('AudioFrameworkRenderLog: AudioRenderer Created : ERROR : '+err.message);
});
Z
zengyawen 已提交
137
```
Z
zengyawen 已提交
138

L
lwx1059628 已提交
139 140 141 142 143 144 145 146 147 148
## audio.createAudioCapturer<sup>8+</sup>

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

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

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

**参数:**

H
update  
HelloCrease 已提交
149 150
| 参数名   | 类型                                            | 必填 | 说明             |
| :------- | :---------------------------------------------- | :--- | :--------------- |
Z
zengyawen 已提交
151
| options  | [AudioCapturerOptions](#audiocaptureroptions8)  | 是   | 配置音频采集器。 |
M
magekkkk 已提交
152
| callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | 是   | 音频采集器对象。 |
L
lwx1059628 已提交
153 154 155 156

**示例:**

```
L
lwx1059628 已提交
157
import audio from '@ohos.multimedia.audio';
L
lwx1059628 已提交
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
var audioStreamInfo = {
    samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
    channels: audio.AudioChannel.CHANNEL_2,
    sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
    encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}

var audioCapturerInfo = {
    source: audio.SourceType.SOURCE_TYPE_MIC,
    capturerFlags: 1
}

var audioCapturerOptions = {
    streamInfo: audioStreamInfo,
    capturerInfo: audioCapturerInfo
}

audio.createAudioCapturer(audioCapturerOptions,(err, data) => {
    if (err) {
        console.error(`AudioCapturer Created : Error: ${err.message}`);
    }
    else {
        console.info('AudioCapturer Created : Success : SUCCESS');
L
lwx1059628 已提交
181
        let audioCapturer = data;
L
lwx1059628 已提交
182 183 184 185 186 187 188 189 190 191 192 193 194 195
    }
});
```

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

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

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

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

**参数:**

Z
zengyawen 已提交
196 197 198
| 参数名  | 类型                                           | 必填 | 说明             |
| :------ | :--------------------------------------------- | :--- | :--------------- |
| options | [AudioCapturerOptions](#audiocaptureroptions8) | 是   | 配置音频采集器。 |
L
lwx1059628 已提交
199 200 201 202 203

**返回值:**

| 类型                                      | 说明           |
| ----------------------------------------- | -------------- |
M
magekkkk 已提交
204
| Promise<[AudioCapturer](#audiocapturer8)> | 音频采集器对象 |
L
lwx1059628 已提交
205 206 207 208

**示例:**

```
L
lwx1059628 已提交
209 210
import audio from '@ohos.multimedia.audio';

L
lwx1059628 已提交
211 212 213 214 215 216 217 218 219 220 221 222 223
var audioStreamInfo = {
    samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
    channels: audio.AudioChannel.CHANNEL_2,
    sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
    encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}

var audioCapturerInfo = {
    source: audio.SourceType.SOURCE_TYPE_MIC,
    capturerFlags: 1
}

var audioCapturerOptions = {
L
lwx1059628 已提交
224 225
    streamInfo: audioStreamInfo,
    capturerInfo: audioCapturerInfo
L
lwx1059628 已提交
226 227
}

L
lwx1059628 已提交
228
var audioCapturer;
R
rahul 已提交
229
audio.createAudioCapturer(audioCapturerOptions).then((data) => {
L
lwx1059628 已提交
230 231 232 233 234
    audioCapturer = data;
    console.info('AudioCapturer Created : Success : Stream Type: SUCCESS');
}).catch((err) => {
    console.info('AudioCapturer Created : ERROR : '+err.message);
});
L
lwx1059628 已提交
235 236
```

Z
zengyawen 已提交
237
## AudioVolumeType
M
mamingshuai 已提交
238

239
枚举,音频流类型。
M
mamingshuai 已提交
240

Z
zengyawen 已提交
241 242 243 244 245 246 247 248
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Volume

| 名称                         | 默认值 | 描述       |
| ---------------------------- | ------ | ---------- |
| VOICE_CALL<sup>8+</sup>      | 0      | 语音电话。 |
| RINGTONE                     | 2      | 铃声。     |
| MEDIA                        | 3      | 媒体。     |
| VOICE_ASSISTANT<sup>8+</sup> | 9      | 语音助手。 |
Z
zengyawen 已提交
249 250


251
## InterruptMode<sup>9+</sup>
252

253
枚举,焦点模型。
254

255
**系统能力:** SystemCapability.Multimedia.Audio.InterruptMode
256 257 258

| 名称                         | 默认值 | 描述       |
| ---------------------------- | ------ | ---------- |
259 260
| SHARE_MODE      | 0      | 共享焦点模式。 |
| INDEPENDENT_MODE| 1      | 独立焦点模式。     |
261

Z
zengyawen 已提交
262
## DeviceFlag
M
mamingshuai 已提交
263

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

Z
zengyawen 已提交
266 267 268 269 270 271 272
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Device

| 名称                | 默认值 | 描述       |
| ------------------- | ------ | ---------- |
| OUTPUT_DEVICES_FLAG | 1      | 输出设备。 |
| INPUT_DEVICES_FLAG  | 2      | 输入设备。 |
| ALL_DEVICES_FLAG    | 3      | 所有设备。 |
Z
zengyawen 已提交
273 274 275


## DeviceRole
M
mamingshuai 已提交
276

277
枚举,设备角色。
M
mamingshuai 已提交
278

Z
zengyawen 已提交
279 280 281 282 283 284
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Device

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


Z
zengyawen 已提交
287 288 289
## DeviceType

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

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

H
update  
HelloCrease 已提交
293 294 295 296 297 298 299 300 301 302 303
| 名称             | 默认值 | 描述                                                      |
| ---------------- | ------ | --------------------------------------------------------- |
| 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耳机,带麦克风。                                       |
M
magekkkk 已提交
304

Z
zengyawen 已提交
305
## ActiveDeviceType
M
magekkkk 已提交
306

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

Z
zengyawen 已提交
309 310 311 312 313 314
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Device

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

Z
zengyawen 已提交
316
## AudioRingMode
317 318 319

枚举,铃声模式。

Z
zengyawen 已提交
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Communication

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

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

枚举,音频采样格式。

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

| 名称                  | 默认值 | 描述                       |
| --------------------- | ------ | -------------------------- |
| SAMPLE_FORMAT_INVALID | -1     | 无效格式。                 |
| SAMPLE_FORMAT_U8      | 0      | 无符号8位整数。            |
| SAMPLE_FORMAT_S16LE   | 1      | 带符号的16位整数,小尾数。 |
| SAMPLE_FORMAT_S24LE   | 2      | 带符号的24位整数,小尾数。 |
| SAMPLE_FORMAT_S32LE   | 3      | 带符号的32位整数,小尾数。 |

## 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 已提交
384
## ContentType
Z
zengyawen 已提交
385 386 387 388 389

枚举,音频内容类型。

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

L
lwx1059628 已提交
390 391 392 393 394 395 396 397
| 名称                               | 默认值 | 描述       |
| ---------------------------------- | ------ | ---------- |
| 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 已提交
398

L
lwx1059628 已提交
399
## StreamUsage
Z
zengyawen 已提交
400 401 402 403 404 405 406 407 408 409

枚举,音频流使用类型。

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

| 名称                               | 默认值 | 描述       |
| ---------------------------------- | ------ | ---------- |
| STREAM_USAGE_UNKNOWN               | 0      | 未知类型。 |
| STREAM_USAGE_MEDIA                 | 1      | 音频。     |
| STREAM_USAGE_VOICE_COMMUNICATION   | 2      | 语音通信。 |
L
lwx1059628 已提交
410
| STREAM_USAGE_NOTIFICATION_RINGTONE | 6      | 通知铃声。 |
Z
zengyawen 已提交
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429

## 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 已提交
430
枚举,音频渲染速度。
Z
zengyawen 已提交
431 432 433 434 435 436 437 438 439

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

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

L
lwx1059628 已提交
440
## InterruptType
Z
zengyawen 已提交
441 442 443 444

枚举,中断类型。

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

Z
zengyawen 已提交
446 447 448 449 450
| 名称                 | 默认值 | 描述                   |
| -------------------- | ------ | ---------------------- |
| INTERRUPT_TYPE_BEGIN | 1      | 音频播放中断事件开始。 |
| INTERRUPT_TYPE_END   | 2      | 音频播放中断事件结束。 |

L
lwx1059628 已提交
451
## InterruptForceType<sup>9+</sup>
Z
zengyawen 已提交
452 453 454 455 456 457 458 459 460 461

枚举,强制打断类型。

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

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

L
lwx1059628 已提交
462
## InterruptHint
Z
zengyawen 已提交
463 464 465 466 467

枚举,中断提示。

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

L
lwx1059628 已提交
468 469 470 471 472 473 474 475
| 名称                               | 默认值 | 描述                                         |
| ---------------------------------- | ------ | -------------------------------------------- |
| 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 已提交
476

477 478 479 480 481 482
## InterruptActionType

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

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

H
update  
HelloCrease 已提交
483 484 485 486
| 名称           | 默认值 | 描述               |
| -------------- | ------ | ------------------ |
| TYPE_ACTIVATED | 0      | 表示触发焦点事件。 |
| TYPE_INTERRUPT | 1      | 表示音频打断事件。 |
487

Z
zengyawen 已提交
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
## 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 已提交
503
音频渲染器信息。
Z
zengyawen 已提交
504 505 506

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

L
lwx1059628 已提交
507 508
| 名称          | 类型                        | 必填 | 说明             |
| ------------- | --------------------------- | ---- | ---------------- |
Z
zengyawen 已提交
509
| content       | [ContentType](#contenttype) | 是   | 媒体类型。       |
L
lwx1059628 已提交
510 511
| usage         | [StreamUsage](#streamusage) | 是   | 音频流使用类型。 |
| rendererFlags | number                      | 是   | 音频渲染器标志。 |
Z
zengyawen 已提交
512 513 514

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

L
lwx1059628 已提交
515
音频渲染器选项信息。
Z
zengyawen 已提交
516 517 518 519 520 521

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

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

L
lwx1059628 已提交
524
## InterruptEvent<sup>9+</sup>
Z
zengyawen 已提交
525 526 527 528 529 530 531

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

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

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

536 537 538 539 540 541
## AudioInterrupt

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

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

H
update  
HelloCrease 已提交
542 543 544 545 546
| 名称            | 类型                        | 必填 | 说明                                                         |
| --------------- | --------------------------- | ---- | ------------------------------------------------------------ |
| streamUsage     | [StreamUsage](#streamusage) | 是   | 音频流使用类型。                                             |
| contentType     | [ContentType](#contenttype) | 是   | 音频打断媒体类型。                                           |
| pauseWhenDucked | boolean                     | 是   | 音频打断时是否可以暂停音频播放(true表示音频播放可以在音频打断期间暂停,false表示相反)。 |
547 548 549 550 551 552 553

## InterruptAction

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

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

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

Z
zengyawen 已提交
561 562 563 564
## VolumeEvent<sup>8+</sup>

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

565
此接口为系统接口,三方应用不支持调用。
L
lwx1059628 已提交
566

Z
zengyawen 已提交
567 568 569 570 571 572 573
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Volume

| 名称       | 类型                                | 必填 | 说明                                                     |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
| volume     | number                              | 是   | 音量等级,可设置范围通过getMinVolume和getMaxVolume获取。 |
| updateUi   | boolean                             | 是   | 在UI中显示音量变化。                                     |
Z
zengyawen 已提交
574

L
lwx1059628 已提交
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
## DeviceChangeAction

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

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

| 名称              | 类型                                              | 必填 | 说明               |
| :---------------- | :------------------------------------------------ | :--- | :----------------- |
| type              | [DeviceChangeType](#DeviceChangeType)             | 是   | 设备连接状态变化。 |
| deviceDescriptors | [AudioDeviceDescriptors](#AudioDeviceDescriptors) | 是   | 设备信息。         |

## DeviceChangeType

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

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

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

Z
zengyawen 已提交
597 598 599 600 601 602 603 604 605
## AudioCapturerOptions<sup>8+</sup>

音频采集器选项信息。

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

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

L
lwx1059628 已提交
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
## 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 已提交
625 626 627 628 629
| 名称                            | 默认值 | 描述                   |
| :------------------------------ | :----- | :--------------------- |
| SOURCE_TYPE_INVALID             | -1     | 无效的音频源。         |
| SOURCE_TYPE_MIC                 | 0      | Mic音频源。            |
| SOURCE_TYPE_VOICE_COMMUNICATION | 7      | 语音通话场景的音频源。 |
L
lwx1059628 已提交
630 631 632 633 634 635 636

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

枚举,音频场景。

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

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

Z
zengyawen 已提交
644
## AudioManager
M
mamingshuai 已提交
645

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

Z
zengyawen 已提交
648 649 650
### setVolume

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

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

654 655
**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY

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

M
mamingshuai 已提交
658 659
**参数:**

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

M
mamingshuai 已提交
666 667 668
**示例:**

```
L
lwx1059628 已提交
669 670 671 672 673 674 675
audioManager.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.');
});
M
mamingshuai 已提交
676 677
```

Z
zengyawen 已提交
678 679 680
### setVolume

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

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

684 685
**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY

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

M
mamingshuai 已提交
688 689
**参数:**

Z
zengyawen 已提交
690 691 692 693
| 参数名     | 类型                                | 必填 | 说明                                                     |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
| volume     | number                              | 是   | 音量等级,可设置范围通过getMinVolume和getMaxVolume获取。 |
M
mamingshuai 已提交
694 695 696

**返回值:**

Z
zengyawen 已提交
697 698
| 类型                | 说明                          |
| ------------------- | ----------------------------- |
Z
zengyawen 已提交
699
| Promise&lt;void&gt; | Promise回调表示成功还是失败。 |
M
mamingshuai 已提交
700 701 702 703

**示例:**

```
A
AOL 已提交
704
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
705
    console.log('Promise returned to indicate a successful volume setting.');
L
lwx1059628 已提交
706
});
M
mamingshuai 已提交
707 708
```

Z
zengyawen 已提交
709 710 711
### getVolume

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

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

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

M
mamingshuai 已提交
717 718
**参数:**

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

M
mamingshuai 已提交
724 725 726
**示例:**

```
727
audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
M
mamingshuai 已提交
728
   if (err) {
L
lwx1059628 已提交
729 730
       console.error('Failed to obtain the volume. ${err.message}');
       return;
M
mamingshuai 已提交
731
   }
732
   console.log('Callback invoked to indicate that the volume is obtained.');
L
lwx1059628 已提交
733
});
M
mamingshuai 已提交
734 735
```

Z
zengyawen 已提交
736 737 738
### getVolume

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

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

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

M
mamingshuai 已提交
744 745
**参数:**

Z
zengyawen 已提交
746 747 748
| 参数名     | 类型                                | 必填 | 说明         |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
M
mamingshuai 已提交
749 750 751

**返回值:**

Z
zengyawen 已提交
752 753
| 类型                  | 说明                      |
| --------------------- | ------------------------- |
Z
zengyawen 已提交
754
| Promise&lt;number&gt; | Promise回调返回音量大小。 |
M
mamingshuai 已提交
755 756 757 758

**示例:**

```
A
AOL 已提交
759
audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
760
    console.log('Promise returned to indicate that the volume is obtained.' + value);
L
lwx1059628 已提交
761
});
M
mamingshuai 已提交
762 763
```

Z
zengyawen 已提交
764 765 766
### getMinVolume

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

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

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

M
mamingshuai 已提交
772 773
**参数:**

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

M
mamingshuai 已提交
779 780 781
**示例:**

```
Z
zengyawen 已提交
782
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
783 784
    if (err) {
        console.error('Failed to obtain the minimum volume. ${err.message}');
L
lwx1059628 已提交
785
        return;
786 787
    }
    console.log('Callback invoked to indicate that the minimum volume is obtained.' + value);
L
lwx1059628 已提交
788
});
M
mamingshuai 已提交
789 790
```

Z
zengyawen 已提交
791 792 793
### getMinVolume

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

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

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

M
mamingshuai 已提交
799 800
**参数:**

Z
zengyawen 已提交
801 802 803
| 参数名     | 类型                                | 必填 | 说明         |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
M
mamingshuai 已提交
804 805 806

**返回值:**

Z
zengyawen 已提交
807 808
| 类型                  | 说明                      |
| --------------------- | ------------------------- |
Z
zengyawen 已提交
809
| Promise&lt;number&gt; | Promise回调返回最小音量。 |
M
mamingshuai 已提交
810 811 812 813

**示例:**

```
A
AOL 已提交
814
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
L
lwx1059628 已提交
815 816
    console.log('Promised returned to indicate that the minimum volume is obtained.' + value);
});
M
mamingshuai 已提交
817 818
```

Z
zengyawen 已提交
819 820 821
### getMaxVolume

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

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

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

M
mamingshuai 已提交
827 828
**参数:**

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

M
mamingshuai 已提交
834 835 836
**示例:**

```
837 838 839 840 841 842
audioManager.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);
L
lwx1059628 已提交
843
});
M
mamingshuai 已提交
844 845
```

Z
zengyawen 已提交
846 847 848
### getMaxVolume

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

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

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

M
mamingshuai 已提交
854 855
**参数:**

Z
zengyawen 已提交
856 857 858
| 参数名     | 类型                                | 必填 | 说明         |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
M
mamingshuai 已提交
859 860 861

**返回值:**

Z
zengyawen 已提交
862 863
| 类型                  | 说明                          |
| --------------------- | ----------------------------- |
Z
zengyawen 已提交
864
| Promise&lt;number&gt; | Promise回调返回最大音量大小。 |
M
mamingshuai 已提交
865 866 867 868

**示例:**

```
A
AOL 已提交
869
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
870
    console.log('Promised returned to indicate that the maximum volume is obtained.');
L
lwx1059628 已提交
871
});
Z
zengyawen 已提交
872 873
```

Z
zengyawen 已提交
874
### mute
Z
zengyawen 已提交
875 876

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

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

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

Z
zengyawen 已提交
882 883
**参数:**

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

Z
zengyawen 已提交
890 891 892
**示例:**

```
893 894 895
audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
    if (err) {
        console.error('Failed to mute the stream. ${err.message}');
L
lwx1059628 已提交
896
        return;
897 898
    }
    console.log('Callback invoked to indicate that the stream is muted.');
L
lwx1059628 已提交
899
});
900 901
```

Z
zengyawen 已提交
902
### mute
Z
zengyawen 已提交
903 904

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

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

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

910 911
**参数:**

Z
zengyawen 已提交
912 913 914 915
| 参数名     | 类型                                | 必填 | 说明                                  |
| ---------- | ----------------------------------- | ---- | ------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                          |
| mute       | boolean                             | 是   | 静音状态,true为静音,false为非静音。 |
916 917 918

**返回值:**

Z
zengyawen 已提交
919 920
| 类型                | 说明                          |
| ------------------- | ----------------------------- |
Z
zengyawen 已提交
921
| Promise&lt;void&gt; | Promise回调表示成功还是失败。 |
922 923 924

**示例:**

Z
zengyawen 已提交
925

926
```
A
AOL 已提交
927
audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
928
    console.log('Promise returned to indicate that the stream is muted.');
L
lwx1059628 已提交
929
});
930 931 932
```


Z
zengyawen 已提交
933
### isMute
934

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

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

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

Z
zengyawen 已提交
941
**参数:**
942

Z
zengyawen 已提交
943 944 945 946
| 参数名     | 类型                                | 必填 | 说明                                            |
| ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                    |
| callback   | AsyncCallback&lt;boolean&gt;        | 是   | 回调返回流静音状态,true为静音,false为非静音。 |
947 948 949 950 951

**示例:**

```
audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
M
mamingshuai 已提交
952
   if (err) {
L
lwx1059628 已提交
953 954
       console.error('Failed to obtain the mute status. ${err.message}');
       return;
M
mamingshuai 已提交
955
   }
956
   console.log('Callback invoked to indicate that the mute status of the stream is obtained.' + value);
L
lwx1059628 已提交
957
});
Z
zengyawen 已提交
958 959
```

Z
zengyawen 已提交
960

Z
zengyawen 已提交
961
### isMute
Z
zengyawen 已提交
962 963

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

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

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

Z
zengyawen 已提交
969 970
**参数:**

Z
zengyawen 已提交
971 972 973
| 参数名     | 类型                                | 必填 | 说明         |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
Z
zengyawen 已提交
974 975 976

**返回值:**

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

Z
zengyawen 已提交
981 982 983
**示例:**

```
A
AOL 已提交
984
audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
985
    console.log('Promise returned to indicate that the mute status of the stream is obtained.' + value);
L
lwx1059628 已提交
986
});
Z
zengyawen 已提交
987 988
```

Z
zengyawen 已提交
989
### isActive
Z
zengyawen 已提交
990 991

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

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

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

997 998
**参数:**

Z
zengyawen 已提交
999 1000 1001 1002
| 参数名     | 类型                                | 必填 | 说明                                              |
| ---------- | ----------------------------------- | ---- | ------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                      |
| callback   | AsyncCallback&lt;boolean&gt;        | 是   | 回调返回流的活跃状态,true为活跃,false为不活跃。 |
1003 1004 1005 1006 1007 1008 1009

**示例:**

```
audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
    if (err) {
        console.error('Failed to obtain the active status of the stream. ${err.message}');
L
lwx1059628 已提交
1010
        return;
1011 1012
    }
    console.log('Callback invoked to indicate that the active status of the stream is obtained.' + value);
L
lwx1059628 已提交
1013
});
1014 1015
```

Z
zengyawen 已提交
1016
### isActive
Z
zengyawen 已提交
1017 1018

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

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

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

1024 1025
**参数:**

Z
zengyawen 已提交
1026 1027 1028
| 参数名     | 类型                                | 必填 | 说明         |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。 |
1029 1030 1031

**返回值:**

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

1036 1037 1038
**示例:**

```
A
AOL 已提交
1039
audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
1040
    console.log('Promise returned to indicate that the active status of the stream is obtained.' + value);
L
lwx1059628 已提交
1041
});
1042 1043
```

Z
zengyawen 已提交
1044
### setRingerMode
Z
zengyawen 已提交
1045 1046

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

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

1050 1051
**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY

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

1054 1055
**参数:**

Z
zengyawen 已提交
1056 1057 1058 1059
| 参数名   | 类型                            | 必填 | 说明                     |
| -------- | ------------------------------- | ---- | ------------------------ |
| mode     | [AudioRingMode](#audioringmode) | 是   | 音频铃声模式。           |
| callback | AsyncCallback&lt;void&gt;       | 是   | 回调返回设置成功或失败。 |
1060 1061 1062 1063 1064 1065

**示例:**

```
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
   if (err) {
L
lwx1059628 已提交
1066
       console.error('Failed to set the ringer mode.​ ${err.message}');
1067 1068 1069
       return;
    }
    console.log('Callback invoked to indicate a successful setting of the ringer mode.');
L
lwx1059628 已提交
1070
});
1071 1072
```

Z
zengyawen 已提交
1073
### setRingerMode
Z
zengyawen 已提交
1074 1075

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

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

1079 1080
**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY

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

1083 1084
**参数:**

Z
zengyawen 已提交
1085 1086 1087
| 参数名 | 类型                            | 必填 | 说明           |
| ------ | ------------------------------- | ---- | -------------- |
| mode   | [AudioRingMode](#audioringmode) | 是   | 音频铃声模式。 |
1088 1089 1090

**返回值:**

Z
zengyawen 已提交
1091 1092
| 类型                | 说明                            |
| ------------------- | ------------------------------- |
Z
zengyawen 已提交
1093
| Promise&lt;void&gt; | Promise回调返回设置成功或失败。 |
1094 1095 1096 1097

**示例:**

```
A
AOL 已提交
1098
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
1099
    console.log('Promise returned to indicate a successful setting of the ringer mode.');
L
lwx1059628 已提交
1100
});
1101 1102 1103
```


Z
zengyawen 已提交
1104
### getRingerMode
1105

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

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

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

Z
zengyawen 已提交
1112
**参数:**
1113

Z
zengyawen 已提交
1114 1115 1116
| 参数名   | 类型                                                 | 必填 | 说明                     |
| -------- | ---------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback&lt;[AudioRingMode](#audioringmode)&gt; | 是   | 回调返回系统的铃声模式。 |
1117 1118 1119 1120 1121 1122

**示例:**

```
audioManager.getRingerMode((err, value) => {
   if (err) {
L
lwx1059628 已提交
1123 1124
       console.error('Failed to obtain the ringer mode.​ ${err.message}');
       return;
1125 1126
   }
   console.log('Callback invoked to indicate that the ringer mode is obtained.' + value);
L
lwx1059628 已提交
1127
});
1128 1129 1130
```


Z
zengyawen 已提交
1131
### getRingerMode
1132

Z
zengyawen 已提交
1133
getRingerMode(): Promise&lt;AudioRingMode&gt;
1134

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

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

1139 1140
**返回值:**

Z
zengyawen 已提交
1141 1142
| 类型                                           | 说明                            |
| ---------------------------------------------- | ------------------------------- |
1143
| Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise回调返回系统的铃声模式。 |
1144 1145 1146 1147

**示例:**

```
A
AOL 已提交
1148
audioManager.getRingerMode().then((value) => {
1149
    console.log('Promise returned to indicate that the ringer mode is obtained.' + value);
L
lwx1059628 已提交
1150
});
1151 1152
```

Z
zengyawen 已提交
1153
### setAudioParameter
Z
zengyawen 已提交
1154 1155

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

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

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

1161 1162
**需要权限:** ohos.permission.MODIFY_AUDIO_SETTINGS

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

1165 1166
**参数:**

Z
zengyawen 已提交
1167 1168 1169 1170 1171
| 参数名   | 类型                      | 必填 | 说明                     |
| -------- | ------------------------- | ---- | ------------------------ |
| key      | string                    | 是   | 被设置的音频参数的键。   |
| value    | string                    | 是   | 被设置的音频参数的值。   |
| callback | AsyncCallback&lt;void&gt; | 是   | 回调返回设置成功或失败。 |
1172 1173 1174 1175

**示例:**

```
1176
audioManager.setAudioParameter('key_example', 'value_example', (err) => {
1177 1178
    if (err) {
        console.error('Failed to set the audio parameter. ${err.message}');
L
lwx1059628 已提交
1179
        return;
1180 1181
    }
    console.log('Callback invoked to indicate a successful setting of the audio parameter.');
L
lwx1059628 已提交
1182
});
1183 1184
```

Z
zengyawen 已提交
1185
### setAudioParameter
Z
zengyawen 已提交
1186 1187

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

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

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

1193 1194
**需要权限:** ohos.permission.MODIFY_AUDIO_SETTINGS

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

1197 1198
**参数:**

Z
zengyawen 已提交
1199 1200 1201 1202
| 参数名 | 类型   | 必填 | 说明                   |
| ------ | ------ | ---- | ---------------------- |
| key    | string | 是   | 被设置的音频参数的键。 |
| value  | string | 是   | 被设置的音频参数的值。 |
1203 1204 1205

**返回值:**

Z
zengyawen 已提交
1206 1207
| 类型                | 说明                            |
| ------------------- | ------------------------------- |
Z
zengyawen 已提交
1208
| Promise&lt;void&gt; | Promise回调返回设置成功或失败。 |
1209 1210 1211 1212

**示例:**

```
1213
audioManager.setAudioParameter('key_example', 'value_example').then(() => {
1214
    console.log('Promise returned to indicate a successful setting of the audio parameter.');
L
lwx1059628 已提交
1215
});
1216 1217
```

Z
zengyawen 已提交
1218
### getAudioParameter
Z
zengyawen 已提交
1219 1220

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

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

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

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

1228 1229
**参数:**

Z
zengyawen 已提交
1230 1231 1232 1233
| 参数名   | 类型                        | 必填 | 说明                         |
| -------- | --------------------------- | ---- | ---------------------------- |
| key      | string                      | 是   | 待获取的音频参数的键。       |
| callback | AsyncCallback&lt;string&gt; | 是   | 回调返回获取的音频参数的值。 |
1234 1235 1236 1237

**示例:**

```
1238
audioManager.getAudioParameter('key_example', (err, value) => {
1239 1240
    if (err) {
        console.error('Failed to obtain the value of the audio parameter. ${err.message}');
L
lwx1059628 已提交
1241
        return;
1242 1243
    }
    console.log('Callback invoked to indicate that the value of the audio parameter is obtained.' + value);
L
lwx1059628 已提交
1244
});
1245 1246
```

Z
zengyawen 已提交
1247
### getAudioParameter
Z
zengyawen 已提交
1248 1249

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

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

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

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

1257 1258
**参数:**

Z
zengyawen 已提交
1259 1260 1261
| 参数名 | 类型   | 必填 | 说明                   |
| ------ | ------ | ---- | ---------------------- |
| key    | string | 是   | 待获取的音频参数的键。 |
1262 1263 1264

**返回值:**

Z
zengyawen 已提交
1265 1266
| 类型                  | 说明                                |
| --------------------- | ----------------------------------- |
Z
zengyawen 已提交
1267
| Promise&lt;string&gt; | Promise回调返回获取的音频参数的值。 |
1268 1269 1270 1271

**示例:**

```
1272
audioManager.getAudioParameter('key_example').then((value) => {
1273
    console.log('Promise returned to indicate that the value of the audio parameter is obtained.' + value);
L
lwx1059628 已提交
1274
});
1275 1276
```

Z
zengyawen 已提交
1277 1278 1279
### getDevices

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

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

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

1285 1286
**参数:**

Z
zengyawen 已提交
1287 1288 1289 1290
| 参数名     | 类型                                                         | 必填 | 说明                 |
| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
| deviceFlag | [DeviceFlag](#deviceflag)                                    | 是   | 设备类型的flag。     |
| callback   | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | 是   | 回调,返回设备列表。 |
1291 1292 1293

**示例:**
```
A
AOL 已提交
1294
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
1295
   if (err) {
L
lwx1059628 已提交
1296 1297
       console.error('Failed to obtain the device list. ${err.message}');
       return;
1298 1299
   }
   console.log('Callback invoked to indicate that the device list is obtained.');
L
lwx1059628 已提交
1300
});
1301 1302
```

Z
zengyawen 已提交
1303 1304
### getDevices

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

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

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

1311 1312
**参数:**

Z
zengyawen 已提交
1313 1314 1315
| 参数名     | 类型                      | 必填 | 说明             |
| ---------- | ------------------------- | ---- | ---------------- |
| deviceFlag | [DeviceFlag](#deviceflag) | 是   | 设备类型的flag。 |
1316 1317 1318

**返回值:**

Z
zengyawen 已提交
1319 1320
| 类型                                                         | 说明                      |
| ------------------------------------------------------------ | ------------------------- |
Z
zengyawen 已提交
1321
| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise回调返回设备列表。 |
1322 1323 1324 1325

**示例:**

```
A
AOL 已提交
1326
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
1327
    console.log('Promise returned to indicate that the device list is obtained.');
L
lwx1059628 已提交
1328
});
1329 1330
```

Z
zengyawen 已提交
1331
### setDeviceActive
Z
zengyawen 已提交
1332

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

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

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

1339 1340
**参数:**

H
update  
HelloCrease 已提交
1341 1342 1343 1344 1345
| 参数名     | 类型                                  | 必填 | 说明                     |
| ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | 是   | 活跃音频设备类型。       |
| active     | boolean                               | 是   | 设备激活状态。           |
| callback   | AsyncCallback&lt;void&gt;             | 是   | 回调返回设置成功或失败。 |
1346 1347 1348 1349

**示例:**

```
R
rahul 已提交
1350
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err) => {
1351 1352
    if (err) {
        console.error('Failed to set the active status of the device. ${err.message}');
L
lwx1059628 已提交
1353
        return;
1354 1355
    }
    console.log('Callback invoked to indicate that the device is set to the active status.');
L
lwx1059628 已提交
1356
});
1357 1358
```

Z
zengyawen 已提交
1359
### setDeviceActive
Z
zengyawen 已提交
1360

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

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

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

1367 1368
**参数:**

H
update  
HelloCrease 已提交
1369 1370
| 参数名     | 类型                                  | 必填 | 说明               |
| ---------- | ------------------------------------- | ---- | ------------------ |
A
AOL 已提交
1371
| deviceType | [ActiveDeviceType](#activedevicetype) | 是   | 活跃音频设备类型。 |
H
update  
HelloCrease 已提交
1372
| active     | boolean                               | 是   | 设备激活状态。     |
1373 1374 1375

**返回值:**

Z
zengyawen 已提交
1376 1377
| 类型                | 说明                            |
| ------------------- | ------------------------------- |
Z
zengyawen 已提交
1378
| Promise&lt;void&gt; | Promise回调返回设置成功或失败。 |
1379 1380 1381

**示例:**

Z
zengyawen 已提交
1382

1383
```
R
rahul 已提交
1384
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => {
1385
    console.log('Promise returned to indicate that the device is set to the active status.');
L
lwx1059628 已提交
1386
});
1387 1388
```

Z
zengyawen 已提交
1389
### isDeviceActive
Z
zengyawen 已提交
1390

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

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

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

1397 1398
**参数:**

H
update  
HelloCrease 已提交
1399 1400 1401 1402
| 参数名     | 类型                                  | 必填 | 说明                     |
| ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | 是   | 活跃音频设备类型。       |
| callback   | AsyncCallback&lt;boolean&gt;          | 是   | 回调返回设备的激活状态。 |
1403 1404 1405 1406

**示例:**

```
R
rahul 已提交
1407
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err, value) => {
1408 1409
    if (err) {
        console.error('Failed to obtain the active status of the device. ${err.message}');
L
lwx1059628 已提交
1410
        return;
1411 1412
    }
    console.log('Callback invoked to indicate that the active status of the device is obtained.');
L
lwx1059628 已提交
1413
});
1414 1415
```

Z
zengyawen 已提交
1416

Z
zengyawen 已提交
1417
### isDeviceActive
Z
zengyawen 已提交
1418

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

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

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

1425 1426
**参数:**

H
update  
HelloCrease 已提交
1427 1428
| 参数名     | 类型                                  | 必填 | 说明               |
| ---------- | ------------------------------------- | ---- | ------------------ |
A
AOL 已提交
1429
| deviceType | [ActiveDeviceType](#activedevicetype) | 是   | 活跃音频设备类型。 |
1430 1431 1432

**返回值:**

Z
zengyawen 已提交
1433 1434
| Type                   | Description                     |
| ---------------------- | ------------------------------- |
Z
zengyawen 已提交
1435
| Promise&lt;boolean&gt; | Promise回调返回设备的激活状态。 |
1436 1437 1438 1439

**示例:**

```
R
rahul 已提交
1440
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value) => {
1441
    console.log('Promise returned to indicate that the active status of the device is obtained.' + value);
L
lwx1059628 已提交
1442
});
1443 1444
```

Z
zengyawen 已提交
1445
### setMicrophoneMute
Z
zengyawen 已提交
1446 1447

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

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

1451 1452
**需要权限:** ohos.permission.MICROPHONE

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

1455 1456
**参数:**

Z
zengyawen 已提交
1457 1458 1459 1460
| 参数名   | 类型                      | 必填 | 说明                                          |
| -------- | ------------------------- | ---- | --------------------------------------------- |
| mute     | boolean                   | 是   | 待设置的静音状态,true为静音,false为非静音。 |
| callback | AsyncCallback&lt;void&gt; | 是   | 回调返回设置成功或失败。                      |
1461 1462 1463 1464 1465 1466 1467 1468 1469 1470

**示例:**

```
audioManager.setMicrophoneMute(true, (err) => {
    if (err) {
        console.error('Failed to mute the microphone. ${err.message}');
        return;
    }
    console.log('Callback invoked to indicate that the microphone is muted.');
L
lwx1059628 已提交
1471
});
1472 1473
```

Z
zengyawen 已提交
1474
### setMicrophoneMute
Z
zengyawen 已提交
1475 1476

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

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

1480 1481
**需要权限:** ohos.permission.MICROPHONE

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

1484 1485
**参数:**

Z
zengyawen 已提交
1486 1487 1488
| 参数名 | 类型    | 必填 | 说明                                          |
| ------ | ------- | ---- | --------------------------------------------- |
| mute   | boolean | 是   | 待设置的静音状态,true为静音,false为非静音。 |
1489 1490 1491

**返回值:**

Z
zengyawen 已提交
1492 1493
| 类型                | 说明                            |
| ------------------- | ------------------------------- |
Z
zengyawen 已提交
1494
| Promise&lt;void&gt; | Promise回调返回设置成功或失败。 |
1495 1496 1497 1498

**示例:**

```
A
AOL 已提交
1499
audioManager.setMicrophoneMute(true).then(() => {
1500
    console.log('Promise returned to indicate that the microphone is muted.');
L
lwx1059628 已提交
1501
});
1502 1503
```

Z
zengyawen 已提交
1504
### isMicrophoneMute
Z
zengyawen 已提交
1505 1506

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

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

1510 1511
**需要权限:** ohos.permission.MICROPHONE

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

1514 1515
**参数:**

Z
zengyawen 已提交
1516 1517 1518
| 参数名   | 类型                         | 必填 | 说明                                                    |
| -------- | ---------------------------- | ---- | ------------------------------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调返回系统麦克风静音状态,true为静音,false为非静音。 |
1519 1520 1521 1522 1523 1524 1525 1526 1527 1528

**示例:**

```
audioManager.isMicrophoneMute((err, value) => {
    if (err) {
        console.error('Failed to obtain the mute status of the microphone. ${err.message}');
        return;
    }
    console.log('Callback invoked to indicate that the mute status of the microphone is obtained.' + value);
L
lwx1059628 已提交
1529
});
1530 1531
```

Z
zengyawen 已提交
1532
### isMicrophoneMute
1533

Z
zengyawen 已提交
1534
isMicrophoneMute(): Promise&lt;boolean&gt;
1535

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

1538 1539
**需要权限:** ohos.permission.MICROPHONE

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

1542 1543
**返回值:**

Z
zengyawen 已提交
1544 1545
| 类型                   | 说明                                                         |
| ---------------------- | ------------------------------------------------------------ |
Z
zengyawen 已提交
1546
| Promise&lt;boolean&gt; | Promise回调返回系统麦克风静音状态,true为静音,false为非静音。 |
1547 1548 1549

**示例:**

Z
zengyawen 已提交
1550

1551
```
A
AOL 已提交
1552
audioManager.isMicrophoneMute().then((value) => {
1553
    console.log('Promise returned to indicate that the mute status of the microphone is obtained.', + value);
L
lwx1059628 已提交
1554
});
1555 1556
```

L
lwx1059628 已提交
1557
### on('volumeChange')<sup>8+</sup>
Z
zengyawen 已提交
1558 1559 1560 1561 1562

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

监听系统音量变化事件。

1563
此接口为系统接口,三方应用不支持调用。
L
lwx1059628 已提交
1564

Z
zengyawen 已提交
1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580
**系统能力:** SystemCapability.Multimedia.Audio.Volume

**参数:**

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

**示例:**

```
audioManager.on('volumeChange', (volumeEvent) => {
    console.log('VolumeType of stream: ' + volumeEvent.volumeType);
    console.log('Volume level: ' + volumeEvent.volume);
    console.log('Whether to updateUI: ' + volumeEvent.updateUi);
L
lwx1059628 已提交
1581
});
Z
zengyawen 已提交
1582 1583
```

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

A
AOL 已提交
1586
on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void
Z
zengyawen 已提交
1587 1588 1589

监听铃声模式变化事件。

1590
此接口为系统接口,三方应用不支持调用。
L
lwx1059628 已提交
1591

Z
zengyawen 已提交
1592 1593 1594 1595 1596 1597 1598 1599
**系统能力:** SystemCapability.Multimedia.Audio.Communication

**参数:**

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

L
lwx1059628 已提交
1601 1602 1603 1604 1605 1606 1607 1608
**示例:**

```
audioManager.on('ringerModeChange', (ringerMode) => {
    console.log('Updated ringermode: ' + ringerMode);
});
```

L
lwx1059628 已提交
1609 1610 1611 1612 1613 1614
### on('deviceChange')

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

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

1615 1616
此接口为系统接口,三方应用不支持调用。

L
lwx1059628 已提交
1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659
**系统能力:** SystemCapability.Multimedia.Audio.Device

**参数:**

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

**示例:**

```
audioManager.on('deviceChange', (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('deviceChange')

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

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

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

**参数:**

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

**示例:**

```
audioManager.off('deviceChange', (deviceChanged) => {
    console.log("Should be no callback.");
});
```

1660 1661 1662 1663 1664 1665
### on('interrupt')

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

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

1666 1667
此接口为系统接口,三方应用不支持调用。

1668 1669 1670 1671
**系统能力:** SystemCapability.Multimedia.Audio.Renderer

**参数:**

H
update  
HelloCrease 已提交
1672 1673 1674 1675 1676
| 参数名    | 类型                                          | 必填 | 说明                                                         |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type      | string                                        | 是   | 音频打断事件回调类型,支持的事件为:'interrupt'(多应用之间第二个应用会打断第一个应用,触发该事件)。 |
| interrupt | AudioInterrupt                                | 是   | 音频打断事件类型的参数。                                     |
| callback  | Callback<[InterruptAction](#interruptaction)> | 是   | 音频打断事件回调方法。                                       |
1677 1678 1679 1680 1681 1682 1683 1684 1685

**示例:**

```
var interAudioInterrupt = {
    streamUsage:2,
    contentType:0,
    pauseWhenDucked:true
};
R
rahul 已提交
1686
audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707
    if (InterruptAction.actionType === 0) {
        console.log("An event to gain the audio focus starts.");
        console.log("Focus gain event:" + JSON.stringify(InterruptAction));
    }
    if (InterruptAction.actionType === 1) {
        console.log("An audio interruption event starts.");
        console.log("Audio interruption event:" + JSON.stringify(InterruptAction));
    }
});
```

### off('interrupt')

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

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

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

**参数:**

H
update  
HelloCrease 已提交
1708 1709 1710 1711 1712
| 参数名    | 类型                                          | 必填 | 说明                                                         |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type      | string                                        | 是   | 音频打断事件回调类型,支持的事件为:'interrupt'(多应用之间第二个应用会打断第一个应用,触发该事件)。 |
| interrupt | AudioInterrupt                                | 是   | 音频打断事件类型的参数。                                     |
| callback  | Callback<[InterruptAction](#interruptaction)> | 否   | 音频打断事件回调方法。                                       |
1713 1714 1715 1716 1717 1718 1719 1720 1721

**示例:**

```
var interAudioInterrupt = {
    streamUsage:2,
    contentType:0,
    pauseWhenDucked:true
};
R
rahul 已提交
1722
audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
1723 1724 1725 1726 1727 1728 1729
    if (InterruptAction.actionType === 0) {
        console.log("An event to release the audio focus starts.");
        console.log("Focus release event:" + JSON.stringify(InterruptAction));
    }
});
```

L
lwx1059628 已提交
1730 1731 1732 1733 1734 1735
### setAudioScene<sup>8+</sup>

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

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

1736
此接口为系统接口,三方应用不支持调用。
L
lwx1059628 已提交
1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751

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

**参数:**

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

**示例:**

```
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => {
   if (err) {
L
lwx1059628 已提交
1752
       console.error('Failed to set the audio scene mode.​ ${err.message}');
L
lwx1059628 已提交
1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764
       return;
    }
    console.log('Callback invoked to indicate a successful setting of the audio scene mode.');
});
```

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

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

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

1765
此接口为系统接口,三方应用不支持调用。
L
lwx1059628 已提交
1766

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

Z
zengyawen 已提交
1769
**参数:**
L
lwx1059628 已提交
1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783

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

**返回值:**

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

**示例:**

```
R
rahul 已提交
1784
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => {
L
lwx1059628 已提交
1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796
    console.log('Promise returned to indicate a successful setting of the audio scene mode.');
}).catch ((err) => {
    console.log('Failed to set the audio scene mode');
});
```

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

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

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

Z
zengyawen 已提交
1797
**系统能力:** SystemCapability.Multimedia.Audio.Communication
L
lwx1059628 已提交
1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809

**参数:**

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

**示例:**

```
audioManager.getAudioScene((err, value) => {
   if (err) {
L
lwx1059628 已提交
1810
       console.error('Failed to obtain the audio scene mode.​ ${err.message}');
L
lwx1059628 已提交
1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841
       return;
   }
   console.log('Callback invoked to indicate that the audio scene mode is obtained.' + value);
});
```


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

getAudioScene\(\): Promise<AudioScene\>

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

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

**返回值:**

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

**示例:**

```
audioManager.getAudioScene().then((value) => {
    console.log('Promise returned to indicate that the audio scene mode is obtained.' + value);
}).catch ((err) => {
    console.log('Failed to obtain the audio scene mode');
});
```

Z
zengyawen 已提交
1842
## AudioDeviceDescriptor
1843 1844 1845

描述音频设备。

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

1848
| 名称       | 类型                    | 可读 | 可写 | 说明       |
Z
zengyawen 已提交
1849 1850 1851
| ---------- | ------------------------- | ---- | ---- | ---------- |
| deviceRole | [DeviceRole](#devicerole) | 是   | 否   | 设备角色。 |
| deviceType | [DeviceType](#devicetype) | 是   | 否   | 设备类型。 |
Z
zengyawen 已提交
1852 1853

## AudioDeviceDescriptors
M
mamingshuai 已提交
1854

H
update  
HelloCrease 已提交
1855
设备属性数组类型,为[AudioDeviceDescriptor](#audiodevicedescriptor)的数组,只读。
Z
zengyawen 已提交
1856 1857 1858 1859

**示例:**

```
L
lwx1059628 已提交
1860 1861 1862 1863 1864 1865
import audio from '@ohos.multimedia.audio';

function displayDeviceProp(value) {
    deviceRoleValue = value.deviceRole;
    deviceTypeValue = value.deviceType;

Z
zengyawen 已提交
1866 1867
}

L
lwx1059628 已提交
1868 1869 1870 1871 1872 1873
var deviceRoleValue = null;
var deviceTypeValue = null;
const promise = audio.getAudioManager().getDevices(1);
promise.then(function (value) {
    console.info('AudioFrameworkTest: Promise: getDevices OUTPUT_DEVICES_FLAG');
    value.forEach(displayDeviceProp);
Z
zengyawen 已提交
1874
    if (deviceTypeValue != null && deviceRoleValue != null){
L
lwx1059628 已提交
1875
        console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  PASS');
Z
zengyawen 已提交
1876 1877
    }
    else{
L
lwx1059628 已提交
1878 1879 1880
        console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  FAIL');
    }
});
Z
zengyawen 已提交
1881 1882 1883 1884
```

## AudioRenderer<sup>8+</sup>

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

1887
### 属性
Z
zengyawen 已提交
1888

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

1891
| 名称  | 类型                     | 可读 | 可写 | 说明               |
Z
zengyawen 已提交
1892
| ----- | -------------------------- | ---- | ---- | ------------------ |
1893
| state<sup>8+</sup> | [AudioState](#audiostate8) | 是   | 否   | 音频渲染器的状态。 |
Z
zengyawen 已提交
1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904

**示例:**

```
var state = audioRenderer.state;
```

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

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

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

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

**参数:**

L
lwx1059628 已提交
1911 1912 1913
| 参数名   | 类型                                                     | 必填 | 说明                   |
| :------- | :------------------------------------------------------- | :--- | :--------------------- |
| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | 是   | 返回音频渲染器的信息。 |
Z
zengyawen 已提交
1914 1915 1916 1917

**示例:**

```
L
lwx1059628 已提交
1918
audioRenderer.getRendererInfo((err, rendererInfo) => {
Z
zengyawen 已提交
1919 1920 1921 1922
    console.log('Renderer GetRendererInfo:');
    console.log('Renderer content:' + rendererInfo.content);
    console.log('Renderer usage:' + rendererInfo.usage);
    console.log('Renderer flags:' + rendererInfo.rendererFlags);
L
lwx1059628 已提交
1923
});
Z
zengyawen 已提交
1924 1925 1926 1927 1928 1929
```

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

getRendererInfo(): Promise<AudioRendererInfo\>

L
lwx1059628 已提交
1930
获取当前被创建的音频渲染器的信息,使用Promise方式异步返回结果。
Z
zengyawen 已提交
1931 1932 1933 1934 1935 1936 1937

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

**返回值:**

| 类型                                               | 说明                            |
| -------------------------------------------------- | ------------------------------- |
L
lwx1059628 已提交
1938
| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise用于返回音频渲染器信息。 |
Z
zengyawen 已提交
1939 1940 1941 1942

**示例:**

```
R
rahul 已提交
1943
var resultFlag = true;
L
lwx1059628 已提交
1944 1945 1946 1947 1948 1949 1950 1951 1952
audioRenderer.getRendererInfo().then((rendererInfo) => {
    console.log('Renderer GetRendererInfo:');
    console.log('Renderer content:' + rendererInfo.content);
    console.log('Renderer usage:' + rendererInfo.usage);
    console.log('Renderer flags:' + rendererInfo.rendererFlags);
}).catch((err) => {
    console.log('AudioFrameworkRenderLog: RendererInfo :ERROR: '+err.message);
    resultFlag = false;
});
Z
zengyawen 已提交
1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971
```

### getStreamInfo<sup>8+</sup>

getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void

获取音频流信息,使用callback方式异步返回结果。

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

**参数:**

| 参数名   | 类型                                                 | 必填 | 说明                 |
| :------- | :--------------------------------------------------- | :--- | :------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | 是   | 回调返回音频流信息。 |

**示例:**

```
L
lwx1059628 已提交
1972
audioRenderer.getStreamInfo((err, streamInfo) => {
Z
zengyawen 已提交
1973 1974
    console.log('Renderer GetStreamInfo:');
    console.log('Renderer sampling rate:' + streamInfo.samplingRate);
L
lwx1059628 已提交
1975 1976 1977
    console.log('Renderer channel:' + streamInfo.channels);
    console.log('Renderer format:' + streamInfo.sampleFormat);
    console.log('Renderer encoding type:' + streamInfo.encodingType);
L
lwx1059628 已提交
1978
});
Z
zengyawen 已提交
1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997
```

### getStreamInfo<sup>8+</sup>

getStreamInfo(): Promise<AudioStreamInfo\>

获取音频流信息,使用Promise方式异步返回结果。

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

**返回值:**

| 类型                                           | 说明                   |
| :--------------------------------------------- | :--------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise返回音频流信息. |

**示例:**

```
L
lwx1059628 已提交
1998 1999 2000 2001 2002 2003 2004 2005 2006
audioRenderer.getStreamInfo().then((streamInfo) => {
    console.log('Renderer GetStreamInfo:');
    console.log('Renderer sampling rate:' + streamInfo.samplingRate);
    console.log('Renderer channel:' + streamInfo.channels);
    console.log('Renderer format:' + streamInfo.sampleFormat);
    console.log('Renderer encoding type:' + streamInfo.encodingType);
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
Z
zengyawen 已提交
2007 2008 2009 2010 2011 2012
```

### start<sup>8+</sup>

start(callback: AsyncCallback<void\>): void

L
lwx1059628 已提交
2013
启动音频渲染器。使用callback方式异步返回结果。
Z
zengyawen 已提交
2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025

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

**参数:**

| 参数名   | 类型                 | 必填 | 说明       |
| -------- | -------------------- | ---- | ---------- |
| callback | AsyncCallback\<void> | 是   | 回调函数。 |

**示例:**

```
L
lwx1059628 已提交
2026
audioRenderer.start((err) => {
Z
zengyawen 已提交
2027 2028 2029 2030 2031
    if (err) {
        console.error('Renderer start failed.');
    } else {
        console.info('Renderer start success.');
    }
L
lwx1059628 已提交
2032
});
Z
zengyawen 已提交
2033 2034 2035 2036 2037 2038
```

### start<sup>8+</sup>

start(): Promise<void\>

L
lwx1059628 已提交
2039
启动音频渲染器。使用Promise方式异步返回结果。
Z
zengyawen 已提交
2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051

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

**返回值:**

| 类型           | 说明                      |
| -------------- | ------------------------- |
| Promise\<void> | Promise方式异步返回结果。 |

**示例:**

```
L
lwx1059628 已提交
2052 2053 2054 2055 2056
audioRenderer.start().then(() => {
    console.log('Renderer started');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
Z
zengyawen 已提交
2057 2058 2059 2060 2061 2062
```

### pause<sup>8+</sup>

pause(callback: AsyncCallback\<void>): void

L
lwx1059628 已提交
2063
暂停渲染。使用callback方式异步返回结果。
Z
zengyawen 已提交
2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075

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

**参数:**

| 参数名   | 类型                 | 必填 | 说明             |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | 是   | 返回回调的结果。 |

**示例:**

```
L
lwx1059628 已提交
2076
audioRenderer.pause((err) => {
Z
zengyawen 已提交
2077 2078 2079 2080 2081
    if (err) {
        console.error('Renderer pause failed');
    } else {
        console.log('Renderer paused.');
    }
L
lwx1059628 已提交
2082
});
Z
zengyawen 已提交
2083 2084 2085 2086 2087 2088
```

### pause<sup>8+</sup>

pause(): Promise\<void>

L
lwx1059628 已提交
2089
暂停渲染。使用Promise方式异步返回结果。
Z
zengyawen 已提交
2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101

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

**返回值:**

| 类型           | 说明                      |
| -------------- | ------------------------- |
| Promise\<void> | Promise方式异步返回结果。 |

**示例:**

```
L
lwx1059628 已提交
2102 2103 2104 2105 2106
audioRenderer.pause().then(() => {
    console.log('Renderer paused');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
Z
zengyawen 已提交
2107 2108 2109 2110 2111 2112
```

### drain<sup>8+</sup>

drain(callback: AsyncCallback\<void>): void

L
lwx1059628 已提交
2113
检查缓冲区是否已被耗尽。使用callback方式异步返回结果。
Z
zengyawen 已提交
2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125

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

**参数:**

| 参数名   | 类型                 | 必填 | 说明             |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | 是   | 返回回调的结果。 |

**示例:**

```
L
lwx1059628 已提交
2126
audioRenderer.drain((err) => {
Z
zengyawen 已提交
2127 2128 2129 2130 2131
    if (err) {
        console.error('Renderer drain failed');
    } else {
        console.log('Renderer drained.');
    }
L
lwx1059628 已提交
2132
});
Z
zengyawen 已提交
2133 2134 2135 2136 2137 2138
```

### drain<sup>8+</sup>

drain(): Promise\<void>

L
lwx1059628 已提交
2139
检查缓冲区是否已被耗尽。使用Promise方式异步返回结果。
Z
zengyawen 已提交
2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151

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

**返回值:**

| 类型           | 说明                      |
| -------------- | ------------------------- |
| Promise\<void> | Promise方式异步返回结果。 |

**示例:**

```
L
lwx1059628 已提交
2152 2153 2154 2155 2156
audioRenderer.drain().then(() => {
    console.log('Renderer drained successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
Z
zengyawen 已提交
2157 2158 2159 2160 2161 2162
```

### stop<sup>8+</sup>

stop(callback: AsyncCallback\<void>): void

L
lwx1059628 已提交
2163
停止渲染。使用callback方式异步返回结果。
Z
zengyawen 已提交
2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175

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

**参数:**

| 参数名   | 类型                 | 必填 | 说明             |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | 是   | 返回回调的结果。 |

**示例:**

```
L
lwx1059628 已提交
2176
audioRenderer.stop((err) => {
Z
zengyawen 已提交
2177 2178 2179 2180 2181
    if (err) {
        console.error('Renderer stop failed');
    } else {
        console.log('Renderer stopped.');
    }
L
lwx1059628 已提交
2182
});
Z
zengyawen 已提交
2183 2184 2185 2186 2187 2188
```

### stop<sup>8+</sup>

stop(): Promise\<void>

L
lwx1059628 已提交
2189
停止渲染。使用Promise方式异步返回结果。
Z
zengyawen 已提交
2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201

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

**返回值:**

| 类型           | 说明                      |
| -------------- | ------------------------- |
| Promise\<void> | Promise方式异步返回结果。 |

**示例:**

```
L
lwx1059628 已提交
2202 2203 2204 2205 2206
audioRenderer.stop().then(() => {
    console.log('Renderer stopped successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
Z
zengyawen 已提交
2207 2208 2209 2210 2211 2212
```

### release<sup>8+</sup>

release(callback: AsyncCallback\<void>): void

L
lwx1059628 已提交
2213
释放音频渲染器。使用callback方式异步返回结果。
Z
zengyawen 已提交
2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225

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

**参数:**

| 参数名   | 类型                 | 必填 | 说明             |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | 是   | 返回回调的结果。 |

**示例:**

```
L
lwx1059628 已提交
2226
audioRenderer.release((err) => {
Z
zengyawen 已提交
2227 2228 2229 2230 2231
    if (err) {
        console.error('Renderer release failed');
    } else {
        console.log('Renderer released.');
    }
L
lwx1059628 已提交
2232
});
Z
zengyawen 已提交
2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251
```

### release<sup>8+</sup>

release(): Promise\<void>

释放渲染器。使用Promise方式异步返回结果。

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

**返回值:**

| 类型           | 说明                      |
| -------------- | ------------------------- |
| Promise\<void> | Promise方式异步返回结果。 |

**示例:**

```
L
lwx1059628 已提交
2252 2253 2254 2255 2256
audioRenderer.release().then(() => {
    console.log('Renderer released successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
Z
zengyawen 已提交
2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276
```

### write<sup>8+</sup>

write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void

写入缓冲区。使用callback方式异步返回结果。

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

**参数:**

| 参数名   | 类型                   | 必填 | 说明                                                |
| -------- | ---------------------- | ---- | --------------------------------------------------- |
| buffer   | ArrayBuffer            | 是   | 要写入缓冲区的数据。                                |
| callback | AsyncCallback\<number> | 是   | 回调如果成功,返回写入的字节数,否则返回errorcode。 |

**示例:**

```
L
lwx1059628 已提交
2277 2278 2279
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';

Z
zengyawen 已提交
2280 2281 2282
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
L
lwx1059628 已提交
2283
audioRenderer.write(buf, (err, writtenbytes) => {
Z
zengyawen 已提交
2284
    if (writtenbytes < 0) {
L
lwx1059628 已提交
2285
        console.error('write failed.');
Z
zengyawen 已提交
2286 2287 2288
    } else {
       console.log('Actual written bytes: ' + writtenbytes);
    }
L
lwx1059628 已提交
2289
});
Z
zengyawen 已提交
2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308
```

### write<sup>8+</sup>

write(buffer: ArrayBuffer): Promise\<number>

写入缓冲区。使用Promise方式异步返回结果。

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

**返回值:**

| 类型             | 说明                                                         |
| ---------------- | ------------------------------------------------------------ |
| Promise\<number> | Promise返回结果,如果成功,返回写入的字节数,否则返回errorcode。 |

**示例:**

```
L
lwx1059628 已提交
2309 2310 2311 2312
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';

var filePath = 'data/StarWars10s-2C-48000-4SW.wav';
Z
zengyawen 已提交
2313 2314 2315
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
L
lwx1059628 已提交
2316 2317 2318 2319 2320 2321 2322 2323 2324
audioRenderer.write(buf).then((writtenbytes) => {
    if (writtenbytes < 0) {
        console.error('write failed.');
    } else {
        console.log('Actual written bytes: ' + writtenbytes);
    }
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
Z
zengyawen 已提交
2325 2326 2327 2328 2329 2330
```

### getAudioTime<sup>8+</sup>

getAudioTime(callback: AsyncCallback\<number>): void

L
lwx1059628 已提交
2331
获取时间戳(从 1970 年 1 月 1 日开始)。使用callback方式异步返回结果。
Z
zengyawen 已提交
2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343

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

**参数:**

| 参数名   | 类型                   | 必填 | 说明             |
| -------- | ---------------------- | ---- | ---------------- |
| callback | AsyncCallback\<number> | 是   | 回调返回时间戳。 |

**示例:**

```
L
lwx1059628 已提交
2344
audioRenderer.getAudioTime((err, timestamp) => {
Z
zengyawen 已提交
2345
    console.log('Current timestamp: ' + timestamp);
L
lwx1059628 已提交
2346
});
Z
zengyawen 已提交
2347 2348 2349 2350 2351 2352
```

### getAudioTime<sup>8+</sup>

getAudioTime(): Promise\<number>

L
lwx1059628 已提交
2353
获取时间戳(从 1970 年 1 月 1 日开始)。使用Promise方式异步返回结果。
Z
zengyawen 已提交
2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365

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

**返回值:**

| 类型             | 描述                    |
| ---------------- | ----------------------- |
| Promise\<number> | Promise回调返回时间戳。 |

**示例:**

```
L
lwx1059628 已提交
2366 2367 2368 2369 2370
audioRenderer.getAudioTime().then((timestamp) => {
    console.log('Current timestamp: ' + timestamp);
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
Z
zengyawen 已提交
2371 2372 2373 2374 2375 2376
```

### getBufferSize<sup>8+</sup>

getBufferSize(callback: AsyncCallback\<number>): void

L
lwx1059628 已提交
2377
获取音频渲染器的最小缓冲区大小。使用callback方式异步返回结果。
Z
zengyawen 已提交
2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389

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

**参数:**

| 参数名   | 类型                   | 必填 | 说明                 |
| -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback\<number> | 是   | 回调返回缓冲区大小。 |

**示例:**

```
R
rahul 已提交
2390
var bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
Z
zengyawen 已提交
2391 2392 2393
    if (err) {
        console.error('getBufferSize error');
    }
L
lwx1059628 已提交
2394
});
Z
zengyawen 已提交
2395 2396 2397 2398 2399 2400
```

### getBufferSize<sup>8+</sup>

getBufferSize(): Promise\<number>

L
lwx1059628 已提交
2401
获取音频渲染器的最小缓冲区大小。使用Promise方式异步返回结果。
Z
zengyawen 已提交
2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413

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

**返回值:**

| 类型             | 说明                        |
| ---------------- | --------------------------- |
| Promise\<number> | promise回调返回缓冲区大小。 |

**示例:**

```
R
rahul 已提交
2414 2415 2416 2417
var bufferSize;
await audioRenderer.getBufferSize().then(async function (data) => {
    console.info('AudioFrameworkRenderLog: getBufferSize :SUCCESS '+data);
    bufferSize=data;
L
lwx1059628 已提交
2418
}).catch((err) => {
R
rahul 已提交
2419
    console.info('AudioFrameworkRenderLog: getBufferSize :ERROR : '+err.message);
L
lwx1059628 已提交
2420
});
Z
zengyawen 已提交
2421 2422 2423 2424 2425 2426
```

### setRenderRate<sup>8+</sup>

setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\<void>): void

L
lwx1059628 已提交
2427
设置音频渲染速率。使用callback方式异步返回结果。
Z
zengyawen 已提交
2428 2429 2430 2431 2432 2433 2434

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

**参数:**

| 参数名   | 类型                                     | 必填 | 说明                     |
| -------- | ---------------------------------------- | ---- | ------------------------ |
L
lwx1059628 已提交
2435
| rate     | [AudioRendererRate](#audiorendererrate8) | 是   | 渲染的速率。             |
Z
zengyawen 已提交
2436 2437 2438 2439 2440
| callback | AsyncCallback\<void>                     | 是   | 用于返回执行结果的回调。 |

**示例:**

```
L
lwx1059628 已提交
2441
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => {
Z
zengyawen 已提交
2442
    if (err) {
L
lwx1059628 已提交
2443
        console.error('Failed to set params');
Z
zengyawen 已提交
2444 2445 2446
    } else {
        console.log('Callback invoked to indicate a successful render rate setting.');
    }
L
lwx1059628 已提交
2447
});
Z
zengyawen 已提交
2448 2449 2450 2451 2452 2453
```

### setRenderRate<sup>8+</sup>

setRenderRate(rate: AudioRendererRate): Promise\<void>

L
lwx1059628 已提交
2454
设置音频渲染速率。使用Promise方式异步返回结果。
Z
zengyawen 已提交
2455 2456 2457 2458 2459 2460 2461

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

**参数:**

| 参数名 | 类型                                     | 必填 | 说明         |
| ------ | ---------------------------------------- | ---- | ------------ |
L
lwx1059628 已提交
2462
| rate   | [AudioRendererRate](#audiorendererrate8) | 是   | 渲染的速率。 |
Z
zengyawen 已提交
2463 2464 2465 2466 2467 2468 2469 2470 2471 2472

**返回值:**

| 类型           | 说明                      |
| -------------- | ------------------------- |
| Promise\<void> | Promise用于返回执行结果。 |

**示例:**

```
L
lwx1059628 已提交
2473 2474 2475 2476 2477
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
    console.log('setRenderRate SUCCESS');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
Z
zengyawen 已提交
2478 2479 2480 2481 2482 2483
```

### getRenderRate<sup>8+</sup>

getRenderRate(callback: AsyncCallback\<AudioRendererRate>): void

L
lwx1059628 已提交
2484
获取当前渲染速率。使用callback方式异步返回结果。
Z
zengyawen 已提交
2485 2486 2487 2488 2489 2490 2491

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明               |
| -------- | ------------------------------------------------------- | ---- | ------------------ |
L
lwx1059628 已提交
2492
| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | 是   | 回调返回渲染速率。 |
Z
zengyawen 已提交
2493 2494 2495 2496

**示例:**

```
L
lwx1059628 已提交
2497
audioRenderer.getRenderRate((err, renderrate) => {
Z
zengyawen 已提交
2498
    console.log('getRenderRate: ' + renderrate);
L
lwx1059628 已提交
2499
});
Z
zengyawen 已提交
2500 2501 2502 2503 2504 2505
```

### getRenderRate<sup>8+</sup>

getRenderRate(): Promise\<AudioRendererRate>

L
lwx1059628 已提交
2506
获取当前渲染速率。使用Promise方式异步返回结果。
Z
zengyawen 已提交
2507 2508 2509 2510 2511 2512 2513

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

**返回值:**

| 类型                                              | 说明                      |
| ------------------------------------------------- | ------------------------- |
L
lwx1059628 已提交
2514
| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise回调返回渲染速率。 |
Z
zengyawen 已提交
2515 2516 2517 2518

**示例:**

```
L
lwx1059628 已提交
2519 2520 2521 2522 2523
audioRenderer.getRenderRate().then((renderRate) => {
    console.log('getRenderRate: ' + renderRate);
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
Z
zengyawen 已提交
2524
```
2525 2526
### setInterruptMode<sup>9+</sup>

2527
setInterruptMode(interruptMode: InterruptMode): Promise&lt;void&gt;
2528

2529
设置应用的焦点模型。使用Promise异步回调。
2530 2531 2532 2533 2534 2535 2536

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

**参数:**

| 参数名     | 类型                                | 必填 | 说明                                                     |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
2537
| interruptMode | [InterruptMode](#InterruptMode) | 是   | 焦点模型。                                             |
2538 2539 2540 2541 2542

**返回值:**

| 类型                | 说明                          |
| ------------------- | ----------------------------- |
2543
| Promise&lt;void&gt; | 以Promise对象返回结果,设置成功时返回undefined,否则返回error。 |
2544 2545

**示例:**
Z
zengyawen 已提交
2546

2547 2548 2549 2550
```
audioManager.setInterruptMode(audio.InterruptType.SHARE_MODE).then(() => {
    console.log('Promise returned to indicate a successful volume setting.');
});
Z
zhujie81 已提交
2551 2552 2553
```
### setInterruptMode<sup>9+</sup>

2554
setInterruptMode(interruptMode: InterruptMode, callback: Callback\<void>): void
Z
zhujie81 已提交
2555

Z
zhujie81 已提交
2556
设置应用的焦点模型。使用Callback回调返回执行结果。
Z
zhujie81 已提交
2557 2558 2559 2560

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

**参数:**
2561

2562
| 参数名 | 类型 | 必填 | 说明                                                     |
Z
zhujie81 已提交
2563
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
2564
|interruptMode | [InterruptMode](#InterruptMode) | 是   | 焦点模型。|
2565
|callback | Callback\<void>  | 是  |回调返回执行结果。|
Z
zengyawen 已提交
2566

Z
zhujie81 已提交
2567 2568 2569
**示例:**

```
2570
audioManager.setInterruptMode(audio.InterruptType.SHARE_MODE,()=>{
2571
    console.log('Callback returned to indicate a successful volume setting.');
2572
});
2573
```
L
lwx1059628 已提交
2574
### on('interrupt')<sup>9+</sup>
Z
zengyawen 已提交
2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586

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

监听音频中断事件。使用callback获取中断事件。

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

**参数:**

| 参数名   | 类型                                         | 必填 | 说明                                                         |
| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                                       | 是   | 事件回调类型,支持的事件为:'interrupt'(中断事件被触发,音频播放被中断。) |
L
lwx1059628 已提交
2587
| callback | Callback<[InterruptEvent](#interruptevent9)> | 是   | 被监听的中断事件的回调。                                     |
Z
zengyawen 已提交
2588 2589 2590 2591

**示例:**

```
R
rahul 已提交
2592 2593 2594
var isPlay;
var started;
audioRenderer.on('interrupt', async(interruptEvent) => {
Z
zengyawen 已提交
2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606
    if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
        switch (interruptEvent.hintType) {
            case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
                console.log('Force paused. Stop writing');
                isPlay = false;
                break;
            case audio.InterruptHint.INTERRUPT_HINT_STOP:
                console.log('Force stopped. Stop writing');
                isPlay = false;
                break;
        }
    } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
R
rahul 已提交
2607
        switch (interruptEvent.hintType) {
Z
zengyawen 已提交
2608 2609
            case audio.InterruptHint.INTERRUPT_HINT_RESUME:
                console.log('Resume force paused renderer or ignore');
R
rahul 已提交
2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622
                await audioRenderer.start().then(async function () {
                    console.info('AudioInterruptMusic: renderInstant started :SUCCESS ');
                    started = true;
                }).catch((err) => {
                    console.info('AudioInterruptMusic: renderInstant start :ERROR : '+err.message);
                    started = false;
                });
                if (started) {
                    isPlay = true;
                    console.info('AudioInterruptMusic Renderer started : isPlay : '+isPlay);
                } else {
                    console.error('AudioInterruptMusic Renderer start failed');
                }
Z
zengyawen 已提交
2623 2624 2625
                break;
            case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
                console.log('Choose to pause or ignore');
R
rahul 已提交
2626 2627 2628 2629 2630 2631 2632 2633
                if (isPlay == true) {
                    isPlay == false;
                    console.info('AudioInterruptMusic: Media PAUSE : TRUE');
                }
                else {
                    isPlay = true;
                    console.info('AudioInterruptMusic: Media PLAY : TRUE');
                }
Z
zengyawen 已提交
2634 2635 2636
                break;
        }
    }
L
lwx1059628 已提交
2637
});
Z
zengyawen 已提交
2638 2639
```

L
lwx1059628 已提交
2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687
### 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) => {} | 是   | 触发事件时调用的回调。                    |

**示例:**

```
audioRenderer.on('markReach', 1000, (position) => {
    if (position == "1000") {
        console.log('ON Triggered successfully');
    }
});
```


### off('markReach') <sup>8+</sup>

off(type: 'markReach'): void

取消订阅标记事件。

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

**参数:**

| 参数名 | 类型   | 必填 | 说明                                              |
| :----- | :----- | :--- | :------------------------------------------------ |
| type   | string | 是   | 要取消订阅事件的类型。支持的事件为:'markReach'。 |

**示例:**

```
audioRenderer.off('markReach');
```

### on('periodReach') <sup>8+</sup>
Z
zengyawen 已提交
2688

L
lwx1059628 已提交
2689
on(type: "periodReach", frame: number, callback: (position: number) => {}): void
Z
zengyawen 已提交
2690

L
lwx1059628 已提交
2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745
订阅到达标记的事件。 当渲染的帧数达到 frame 参数的值时,回调被循环调用。

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

**参数:**

| 参数名   | 类型                     | 必填 | 说明                                        |
| :------- | :----------------------- | :--- | :------------------------------------------ |
| type     | string                   | 是   | 事件回调类型,支持的事件为:'periodReach'。 |
| frame    | number                   | 是   | 触发事件的帧数。 该值必须大于 0。           |
| callback | (position: number) => {} | 是   | 触发事件时调用的回调。                      |

**示例:**

```
audioRenderer.on('periodReach', 1000, (position) => {
    if (position == "1000") {
        console.log('ON Triggered successfully');
    }
});
```

### off('periodReach') <sup>8+</sup>

off(type: 'periodReach'): void

取消订阅标记事件。

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

**参数:**

| 参数名 | 类型   | 必填 | 说明                                                |
| :----- | :----- | :--- | :-------------------------------------------------- |
| type   | string | 是   | 要取消订阅事件的类型。支持的事件为:'periodReach'。 |

**示例:**

```
audioRenderer.off('periodReach')
```

### on('stateChange') <sup>8+</sup>

on(type: 'stateChange', callback: Callback<AudioState\>): void

订阅监听状态变化。

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

**参数:**

| 参数名   | 类型                       | 必填 | 说明                                        |
| :------- | :------------------------- | :--- | :------------------------------------------ |
| type     | string                     | 是   | 事件回调类型,支持的事件为:'stateChange'。 |
Z
zengyawen 已提交
2746
| callback | [AudioState](#audiostate8) | 是   | 返回监听的状态。                            |
L
lwx1059628 已提交
2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764

**示例:**

```
audioRenderer.on('stateChange', (state) => {
    if (state == 1) {
        console.log("audio renderer state is: STATE_PREPARED");
    }
    if (state == 2) {
        console.log("audio renderer state is: STATE_RUNNING");
    }
});
```

## AudioCapturer<sup>8+</sup>

提供音频采集的相关接口。在调用AudioCapturer的接口前,需要先通过[createAudioCapturer](#audiocreateaudiocapturer8)创建实例。

2765
### 属性
L
lwx1059628 已提交
2766 2767 2768

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

2769
| 名称  | 类型                     | 可读 | 可写 | 说明             |
L
lwx1059628 已提交
2770
| :---- | :------------------------- | :--- | :--- | :--------------- |
2771
| state<sup>8+</sup>  | [AudioState](#audiostate8) | 是 | 否   | 音频采集器状态。 |
L
lwx1059628 已提交
2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795

**示例:**

```
var state = audioCapturer.state;
```

### getCapturerInfo<sup>8+</sup>

getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void

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

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

**参数:**

| 参数名   | 类型                              | 必填 | 说明                                 |
| :------- | :-------------------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<AudioCapturerInfo\> | 是   | 使用callback方式异步返回采集器信息。 |

**示例:**

```
L
lwx1059628 已提交
2796
audioCapturer.getCapturerInfo((err, capturerInfo) => {
L
lwx1059628 已提交
2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824
    if (err) {
        console.error('Failed to get capture info');
    } else {
        console.log('Capturer getCapturerInfo:');
        console.log('Capturer source:' + capturerInfo.source);
        console.log('Capturer flags:' + capturerInfo.capturerFlags);
    }
});
```


### getCapturerInfo<sup>8+</sup>

getCapturerInfo(): Promise<AudioCapturerInfo\>

获取采集器信息。使用Promise方式异步返回结果。

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

**返回值:**

| 类型                                              | 说明                                |
| :------------------------------------------------ | :---------------------------------- |
| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | 使用Promise方式异步返回采集器信息。 |

**示例:**

```
L
lwx1059628 已提交
2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835
audioCapturer.getCapturerInfo().then((audioParamsGet) => {
    if (audioParamsGet != undefined) {
        console.info('AudioFrameworkRecLog: Capturer CapturerInfo:');
        console.info('AudioFrameworkRecLog: Capturer SourceType:' + audioParamsGet.source);
        console.info('AudioFrameworkRecLog: Capturer capturerFlags:' + audioParamsGet.capturerFlags);
    }else {
        console.info('AudioFrameworkRecLog: audioParamsGet is : '+audioParamsGet);
        console.info('AudioFrameworkRecLog: audioParams getCapturerInfo are incorrect: ');
    }
}).catch((err) => {
    console.log('AudioFrameworkRecLog: CapturerInfo :ERROR: '+err.message);
L
lwx1059628 已提交
2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848
});
```

### getStreamInfo<sup>8+</sup>

getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void

获取采集器流信息。使用callback方式异步返回结果。

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

**参数:**

Z
zengyawen 已提交
2849 2850 2851
| 参数名   | 类型                                                 | 必填 | 说明                             |
| :------- | :--------------------------------------------------- | :--- | :------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | 是   | 使用callback方式异步返回流信息。 |
L
lwx1059628 已提交
2852 2853 2854 2855

**示例:**

```
L
lwx1059628 已提交
2856
audioCapturer.getStreamInfo((err, streamInfo) => {
L
lwx1059628 已提交
2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878
    if (err) {
        console.error('Failed to get stream info');
    } else {
        console.log('Capturer GetStreamInfo:');
        console.log('Capturer sampling rate:' + streamInfo.samplingRate);
        console.log('Capturer channel:' + streamInfo.channels);
        console.log('Capturer format:' + streamInfo.sampleFormat);
        console.log('Capturer encoding type:' + streamInfo.encodingType);
    }
});
```

### getStreamInfo<sup>8+</sup>

getStreamInfo(): Promise<AudioStreamInfo\>

获取采集器流信息。使用Promise方式异步返回结果。

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

**返回值:**

Z
zengyawen 已提交
2879 2880 2881
| 类型                                           | 说明                            |
| :--------------------------------------------- | :------------------------------ |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | 使用Promise方式异步返回流信息。 |
L
lwx1059628 已提交
2882 2883 2884 2885

**示例:**

```
L
lwx1059628 已提交
2886 2887 2888 2889 2890 2891 2892 2893
audioCapturer.getStreamInfo().then((audioParamsGet) => {
    console.info('getStreamInfo:');
    console.info('sampleFormat:' + audioParamsGet.sampleFormat);
    console.info('samplingRate:' + audioParamsGet.samplingRate);
    console.info('channels:' + audioParamsGet.channels);
    console.info('encodingType:' + audioParamsGet.encodingType);
}).catch((err) => {
    console.log('getStreamInfo :ERROR: ' + err.message);
L
lwx1059628 已提交
2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913
});
```

### start<sup>8+</sup>

start(callback: AsyncCallback<void\>): void

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

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

**参数**

| 参数名   | 类型                 | 必填 | 说明                           |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | 是   | 使用callback方式异步返回结果。 |

**示例:**

```
L
lwx1059628 已提交
2914
audioCapturer.start((err) => {
L
lwx1059628 已提交
2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941
    if (err) {
        console.error('Capturer start failed.');
    } else {
        console.info('Capturer start success.');
    }
});
```


### start<sup>8+</sup>

start(): Promise<void\>

启动音频采集器。使用Promise方式异步返回结果。

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

**返回值:**

| 类型           | 说明                          |
| :------------- | :---------------------------- |
| Promise<void\> | 使用Promise方式异步返回结果。 |

**示例:**

```
audioCapturer.start().then(() => {
L
lwx1059628 已提交
2942 2943 2944 2945 2946 2947 2948 2949 2950 2951
    console.info('AudioFrameworkRecLog: ---------START---------');
    console.info('AudioFrameworkRecLog: Capturer started :SUCCESS ');
    console.info('AudioFrameworkRecLog: AudioCapturer : STATE : '+audioCapturer.state);
    console.info('AudioFrameworkRecLog: Capturer started :SUCCESS ');
    if ((audioCapturer.state == audio.AudioState.STATE_RUNNING)) {
        stateFlag = true;
    }
}).catch((err) => {
    console.info('AudioFrameworkRecLog: Capturer start :ERROR : '+err.message);
    stateFlag=false;
L
lwx1059628 已提交
2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971
});
```

### stop<sup>8+</sup>

stop(callback: AsyncCallback<void\>): void

停止采集。使用callback方式异步返回结果。

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

**参数:**

| 参数名   | 类型                 | 必填 | 说明                           |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | 是   | 使用callback方式异步返回结果。 |

**示例:**

```
L
lwx1059628 已提交
2972
audioCapturer.stop((err) => {
L
lwx1059628 已提交
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
    if (err) {
        console.error('Capturer stop failed');
    } else {
        console.log('Capturer stopped.');
    }
});
```


### stop<sup>8+</sup>

stop(): Promise<void\>

停止采集。使用Promise方式异步返回结果。

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

**返回值:**

| 类型           | 说明                          |
| :------------- | :---------------------------- |
| Promise<void\> | 使用Promise方式异步返回结果。 |

**示例:**

```
audioCapturer.stop().then(() => {
L
lwx1059628 已提交
3000 3001
    console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
    console.info('AudioFrameworkRecLog: Capturer stopped : SUCCESS');
R
rahul 已提交
3002
    if ((audioCapturer.state == audio.AudioState.STATE_STOPPED)){
L
lwx1059628 已提交
3003 3004 3005 3006 3007 3008
        stateFlag=true;
        console.info('AudioFrameworkRecLog: resultFlag : '+stateFlag);
    }
}).catch((err) => {
    console.info('AudioFrameworkRecLog: Capturer stop:ERROR : '+err.message);
    stateFlag=false;
L
lwx1059628 已提交
3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028
});
```

### release<sup>8+</sup>

release(callback: AsyncCallback<void\>): void

释放采集器。使用callback方式异步返回结果。

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

**参数:**

| 参数名   | 类型                 | 必填 | 说明                                |
| :------- | :------------------- | :--- | :---------------------------------- |
| callback | AsyncCallback<void\> | 是   | Callback used to return the result. |

**示例:**

```
L
lwx1059628 已提交
3029
audioCapturer.release((err) => {
L
lwx1059628 已提交
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
    if (err) {
        console.error('capturer release failed');
    } else {
        console.log('capturer released.');
    }
});
```


### release<sup>8+</sup>

release(): Promise<void\>

释放采集器。使用Promise方式异步返回结果。

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

**返回值:**

| 类型           | 说明                          |
| :------------- | :---------------------------- |
| Promise<void\> | 使用Promise方式异步返回结果。 |

**示例:**

```
audioCapturer.release().then(() => {
L
lwx1059628 已提交
3057 3058 3059 3060 3061 3062 3063 3064
    console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
    console.info('AudioFrameworkRecLog: Capturer release : SUCCESS');
    console.info('AudioFrameworkRecLog: AudioCapturer : STATE : '+audioCapturer.state);
    stateFlag=true;
    console.info('AudioFrameworkRecLog: stateFlag : '+stateFlag);
}).catch((err) => {
    console.info('AudioFrameworkRecLog: Capturer stop:ERROR : '+err.message);
    stateFlag=false
L
lwx1059628 已提交
3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119
});
```


### read<sup>8+</sup>

read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void

读入缓冲区。使用callback方式异步返回结果。

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

**参数**

| 参数名         | 类型                        | 必填 | 说明                             |
| :------------- | :-------------------------- | :--- | :------------------------------- |
| size           | number                      | 是   | 读入的字节数。                   |
| isBlockingRead | boolean                     | 是   | 是否阻塞读操作。                 |
| callback       | AsyncCallback<ArrayBuffer\> | 是   | 使用callback方式异步返回缓冲区。 |

**示例:**

```
audioCapturer.read(bufferSize, true, async(err, buffer) => {
    if (!err) {
        console.log("Success in reading the buffer data");
    }
};
```


### read<sup>8+</sup>

read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>

读入缓冲区。使用Promise方式异步返回结果。

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

**参数:**

| 参数名         | 类型    | 必填 | 说明             |
| :------------- | :------ | :--- | :--------------- |
| size           | number  | 是   | 读入的字节数。   |
| isBlockingRead | boolean | 是   | 是否阻塞读操作。 |

**返回值:**

| 类型                  | 说明                                                   |
| :-------------------- | :----------------------------------------------------- |
| Promise<ArrayBuffer\> | 如果操作成功,返回读取的缓冲区数据;否则返回错误代码。 |

**示例:**

```
L
lwx1059628 已提交
3120 3121 3122 3123
audioCapturer.read(bufferSize, true).then((buffer) => {
    console.info('buffer read successfully');
}).catch((err) => {
    console.info('ERROR : '+err.message);
L
lwx1059628 已提交
3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144
});
```


### getAudioTime<sup>8+</sup>

getAudioTime(callback: AsyncCallback<number\>): void

获取时间戳(从1970年1月1日开始),单位为纳秒。使用callback方式异步返回结果。

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

**参数:**

| 参数名   | 类型                   | 必填 | 说明                           |
| :------- | :--------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<number\> | 是   | 使用callback方式异步返回结果。 |

**示例:**

```
L
lwx1059628 已提交
3145
audioCapturer.getAudioTime((err, timestamp) => {
L
lwx1059628 已提交
3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168
    console.log('Current timestamp: ' + timestamp);
});
```


### getAudioTime<sup>8+</sup>

getAudioTime(): Promise<number\>

获取时间戳(从1970年1月1日开始),单位为纳秒。使用Promise方式异步返回结果。

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

**返回值:**

| 类型             | 说明                          |
| :--------------- | :---------------------------- |
| Promise<number\> | 使用Promise方式异步返回结果。 |

**示例:**

```
audioCapturer.getAudioTime().then((audioTime) => {
L
lwx1059628 已提交
3169 3170 3171
    console.info('AudioFrameworkRecLog: AudioCapturer getAudioTime : Success' + audioTime );
}).catch((err) => {
    console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
L
lwx1059628 已提交
3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192
});
```


### getBufferSize<sup>8+</sup>

getBufferSize(callback: AsyncCallback<number\>): void

获取采集器合理的最小缓冲区大小。使用callback方式异步返回结果。

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

**参数:**

| 参数名   | 类型                   | 必填 | 说明                                 |
| :------- | :--------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<number\> | 是   | 使用callback方式异步返回缓冲区大小。 |

**示例:**

```
L
lwx1059628 已提交
3193
audioCapturer.getBufferSize((err, bufferSize) => {
L
lwx1059628 已提交
3194 3195
    if (!err) {
        console.log('BufferSize : ' + bufferSize);
L
lwx1059628 已提交
3196 3197 3198 3199 3200
        audioCapturer.read(bufferSize, true).then((buffer) => {
            console.info('Buffer read is ' + buffer );
        }).catch((err) => {
            console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
        });
L
lwx1059628 已提交
3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222
    }
});
```


### getBufferSize<sup>8+</sup>

getBufferSize(): Promise<number\>

获取采集器合理的最小缓冲区大小。使用Promise方式异步返回结果。

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

**返回值:**

| 类型             | 说明                                |
| :--------------- | :---------------------------------- |
| Promise<number\> | 使用Promise方式异步返回缓冲区大小。 |

**示例:**

```
R
rahul 已提交
3223 3224 3225 3226 3227 3228
await audioCapturer.getBufferSize().then(async function (bufferSize) {
    console.info('AudioFrameworkRecordLog: getBufferSize :SUCCESS '+ bufferSize);
    var buffer = await audioCapturer.read(bufferSize, true);
    console.info('Buffer read is ' + buffer );
    }).catch((err) => {
    console.info('AudioFrameworkRecordLog: getBufferSize :ERROR : '+err.message);
L
lwx1059628 已提交
3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337
});
```


### on('markReach')<sup>8+</sup>

on(type: 'markReach', frame: number, callback: (position: number) => {}): void

订阅标记到达的事件。 当采集的帧数达到 frame 参数的值时,回调被触发。

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

**参数:**

| 参数名   | 类型                    | 必填 | 说明                                       |
| :------- | :---------------------- | :--- | :----------------------------------------- |
| type     | string                  | 是   | 事件回调类型,支持的事件为:'markReach'。  |
| frame    | number                  | 是   | 触发事件的帧数。 该值必须大于0。           |
| callback | position: number) => {} | 是   | 使用callback方式异步返回被触发事件的回调。 |

**示例:**

```
audioCapturer.on('markReach', 1000, (position) => {
    if (position == "1000") {
        console.log('ON Triggered successfully');
    }
});
```

### off('markReach')<sup>8+</sup>

off(type: 'markReach'): void

取消订阅标记到达的事件。

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

**参数:**

| 参数名 | 类型   | 必填 | 说明                                          |
| :----- | :----- | :--- | :-------------------------------------------- |
| type   | string | 是   | 取消事件回调类型,支持的事件为:'markReach'。 |

**示例:**

```
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方式异步返回被触发事件的回调    |

**示例:**

```
audioCapturer.on('periodReach', 1000, (position) => {
    if (position == "1000") {
        console.log('ON Triggered successfully');
    }
});
```

### off('periodReach')<sup>8+</sup>

off(type: 'periodReach'): void

取消订阅标记到达的事件。

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

**参数:**

| 参数名 | 类型   | 必填 | 说明                                            |
| :----- | :----- | :--- | :---------------------------------------------- |
| type   | string | Yes  | 取消事件回调类型,支持的事件为:'periodReach'。 |

**示例:**

```
audioCapturer.off('periodReach')
```

### on('stateChange') <sup>8+</sup>

on(type: 'stateChange', callback: Callback<AudioState\>): void

订阅监听状态变化。

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

**参数:**

| 参数名   | 类型                       | 必填 | 说明                                        |
| :------- | :------------------------- | :--- | :------------------------------------------ |
| type     | string                     | 是   | 事件回调类型,支持的事件为:'stateChange'。 |
Z
zengyawen 已提交
3338
| callback | [AudioState](#audiostate8) | 是   | 返回监听的状态。                            |
L
lwx1059628 已提交
3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350

**示例:**

```
audioCapturer.on('stateChange', (state) => {
    if (state == 1) {
        console.log("audio capturer state is: STATE_PREPARED");
    }
    if (state == 2) {
        console.log("audio capturer state is: STATE_RUNNING");
    }
});
H
update  
HelloCrease 已提交
3351
```