Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
31728d13
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
31728d13
编写于
9月 05, 2023
作者:
Z
zhangkai269
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
arkts audio 整改
Signed-off-by:
N
zhangkai269
<
zhangkai269@huawei.com
>
上级
c055f716
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
825 addition
and
659 deletion
+825
-659
zh-cn/application-dev/media/audio-effect-management.md
zh-cn/application-dev/media/audio-effect-management.md
+27
-21
zh-cn/application-dev/reference/apis/js-apis-audio.md
zh-cn/application-dev/reference/apis/js-apis-audio.md
+798
-638
未找到文件。
zh-cn/application-dev/media/audio-effect-management.md
浏览文件 @
31728d13
...
...
@@ -6,52 +6,55 @@
主要包括查询和设置当前音频播放流的音效模式,音效模式包括EFFECT_NONE关闭音效模式和EFFECT_DEFAULT默认音效模式。默认音效模式会根据创建音频流的ContentType和StreamUsage自动加载对应场景的音效。
### 获取播放实例
(示例代码仅支持JS格式)
### 获取播放实例
管理播放实例音效的接口是getAudioEffectMode()查询当前音频播放流的音效模式和setAudioEffectMode(mode: AudioEffectMode)设置当前音频播放流的音效模式,在使用之前,需要使用createAudioRenderer(options: AudioRendererOptions)先创建音频播放流AudioRenderer实例。
1.
步骤一:导入音频接口。
```
j
s
```
t
s
import
audio
from
'
@ohos.multimedia.audio
'
;
```
2.
步骤二:配置音频渲染参数并创建AudioRenderer实例,音频渲染参数的详细信息可以查看
[
AudioRendererOptions
](
../reference/apis/js-apis-audio.md#audiorendereroptions8
)
,创建AudioRenderer实例时会默认挂载EFFECT_DEFAULT模式音效。
```
js
let
audioStreamInfo
=
{
```
ts
import
audio
from
'
@ohos.multimedia.audio
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
audioStreamInfo
:
audio
.
AudioStreamInfo
=
{
samplingRate
:
audio
.
AudioSamplingRate
.
SAMPLE_RATE_44100
,
channels
:
audio
.
AudioChannel
.
CHANNEL_1
,
sampleFormat
:
audio
.
AudioSampleFormat
.
SAMPLE_FORMAT_S16LE
,
encodingType
:
audio
.
AudioEncodingType
.
ENCODING_TYPE_RAW
};
let
audioRendererInfo
=
{
let
audioRendererInfo
:
audio
.
AudioRendererInfo
=
{
content
:
audio
.
ContentType
.
CONTENT_TYPE_SPEECH
,
usage
:
audio
.
StreamUsage
.
STREAM_USAGE_VOICE_COMMUNICATION
,
rendererFlags
:
0
};
let
audioRendererOptions
=
{
let
audioRendererOptions
:
audio
.
AudioRendererOptions
=
{
streamInfo
:
audioStreamInfo
,
rendererInfo
:
audioRendererInfo
};
audio
.
createAudioRenderer
(
audioRendererOptions
,
(
err
,
data
)
=>
{
audio
.
createAudioRenderer
(
audioRendererOptions
,
(
err
:
BusinessError
,
data
:
audio
.
AudioRenderer
)
=>
{
if
(
err
)
{
console
.
error
(
`Invoke createAudioRenderer failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
}
else
{
console
.
info
(
'
Invoke createAudioRenderer succeeded.
'
);
let
audioRenderer
=
data
;
let
audioRenderer
:
audio
.
AudioRenderer
=
data
;
}
});
```
### 查询当前播放实例的音效模式
(示例代码仅支持JS格式)
### 查询当前播放实例的音效模式
```
js
audioRenderer
.
getAudioEffectMode
((
err
,
effectmode
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getAudioEffectMode
((
err
:
BusinessError
,
effectmode
:
audio
.
AudioEffectMode
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to get params, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
...
...
@@ -61,12 +64,13 @@
});
```
### 设置当前播放实例的音效模式
(示例代码仅支持JS格式)
### 设置当前播放实例的音效模式
关闭系统音效:
```
js
audioRenderer
.
setAudioEffectMode
(
audio
.
AudioEffectMode
.
EFFECT_NONE
,
(
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
setAudioEffectMode
(
audio
.
AudioEffectMode
.
EFFECT_NONE
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to set params, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
...
...
@@ -78,8 +82,9 @@
开启系统音效默认模式:
```
js
audioRenderer
.
setAudioEffectMode
(
audio
.
AudioEffectMode
.
EFFECT_DEFAULT
,
(
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
setAudioEffectMode
(
audio
.
AudioEffectMode
.
EFFECT_DEFAULT
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to set params, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
...
...
@@ -94,20 +99,21 @@
主要包括全局音效查询相应StreamUsage对应场景的音效模式。
对于播放音频类的应用,开发者需要关注该应用的音频流使用什么音效模式并做出相应的操作,比如音乐App播放时,应选择音乐场景下的模式。在使用查询接口前,开发者需要使用getStreamManager()创建一个AudioStreamManager音频流管理实例。
### 获取音频流管理接口
(示例代码仅支持JS格式)
### 获取音频流管理接口
1.
创建AudioStreamManager实例。在使用AudioStreamManager的API前,需要使用getStreamManager()创建一个AudioStreamManager实例。
```
j
s
```
t
s
import
audio
from
'
@ohos.multimedia.audio
'
;
let
audioManager
=
audio
.
getAudioManager
();
let
audioStreamManager
=
audioManager
.
getStreamManager
();
```
### 查询对应场景的音效模式
(示例代码仅支持JS格式)
### 查询对应场景的音效模式
```
js
audioStreamManager
.
getAudioEffectInfoArray
(
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
,
async
(
err
,
audioEffectInfoArray
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioStreamManager
.
getAudioEffectInfoArray
(
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
,
async
(
err
:
BusinessError
,
audioEffectInfoArray
:
audio
.
AudioEffectInfoArray
)
=>
{
if
(
err
)
{
console
.
error
(
'
Failed to get effect info array
'
);
return
;
...
...
zh-cn/application-dev/reference/apis/js-apis-audio.md
浏览文件 @
31728d13
...
...
@@ -14,7 +14,7 @@
## 导入模块
```
j
s
```
t
s
import
audio
from
'
@ohos.multimedia.audio
'
;
```
...
...
@@ -28,7 +28,7 @@ import audio from '@ohos.multimedia.audio';
**示例:**
```
j
s
```
t
s
import
audio
from
'
@ohos.multimedia.audio
'
;
const
localNetworkId
=
audio
.
LOCAL_NETWORK_ID
;
...
...
@@ -51,8 +51,8 @@ getAudioManager(): AudioManager
|
[
AudioManager
](
#audiomanager
)
| 音频管理类。 |
**示例:**
```
j
s
let
audioManager
=
audio
.
getAudioManager
();
```
t
s
let
audioManager
:
audio
.
AudioManager
=
audio
.
getAudioManager
();
```
## audio.createAudioRenderer<sup>8+</sup>
...
...
@@ -72,24 +72,24 @@ createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\<Audi
**示例:**
```
j
s
```
t
s
import
fs
from
'
@ohos.file.fs
'
;
import
audio
from
'
@ohos.multimedia.audio
'
;
let
audioStreamInfo
=
{
let
audioStreamInfo
:
audio
.
AudioStreamInfo
=
{
samplingRate
:
audio
.
AudioSamplingRate
.
SAMPLE_RATE_44100
,
channels
:
audio
.
AudioChannel
.
CHANNEL_1
,
sampleFormat
:
audio
.
AudioSampleFormat
.
SAMPLE_FORMAT_S16LE
,
encodingType
:
audio
.
AudioEncodingType
.
ENCODING_TYPE_RAW
}
let
audioRendererInfo
=
{
let
audioRendererInfo
:
audio
.
AudioRendererInfo
=
{
content
:
audio
.
ContentType
.
CONTENT_TYPE_SPEECH
,
usage
:
audio
.
StreamUsage
.
STREAM_USAGE_VOICE_COMMUNICATION
,
rendererFlags
:
0
}
let
audioRendererOptions
=
{
let
audioRendererOptions
:
audio
.
AudioRendererOptions
=
{
streamInfo
:
audioStreamInfo
,
rendererInfo
:
audioRendererInfo
}
...
...
@@ -126,33 +126,34 @@ createAudioRenderer(options: AudioRendererOptions): Promise<AudioRenderer\>
**示例:**
```
j
s
```
t
s
import
fs
from
'
@ohos.file.fs
'
;
import
audio
from
'
@ohos.multimedia.audio
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
audioStreamInfo
=
{
let
audioStreamInfo
:
audio
.
AudioStreamInfo
=
{
samplingRate
:
audio
.
AudioSamplingRate
.
SAMPLE_RATE_44100
,
channels
:
audio
.
AudioChannel
.
CHANNEL_1
,
sampleFormat
:
audio
.
AudioSampleFormat
.
SAMPLE_FORMAT_S16LE
,
encodingType
:
audio
.
AudioEncodingType
.
ENCODING_TYPE_RAW
}
let
audioRendererInfo
=
{
let
audioRendererInfo
:
audio
.
AudioRendererInfo
=
{
content
:
audio
.
ContentType
.
CONTENT_TYPE_SPEECH
,
usage
:
audio
.
StreamUsage
.
STREAM_USAGE_VOICE_COMMUNICATION
,
rendererFlags
:
0
}
let
audioRendererOptions
=
{
let
audioRendererOptions
:
audio
.
AudioRendererOptions
=
{
streamInfo
:
audioStreamInfo
,
rendererInfo
:
audioRendererInfo
}
let
audioRenderer
;
let
audioRenderer
:
audio
.
AudioRenderer
;
audio
.
createAudioRenderer
(
audioRendererOptions
).
then
((
data
)
=>
{
audioRenderer
=
data
;
console
.
info
(
'
AudioFrameworkRenderLog: AudioRenderer Created : Success : Stream Type: SUCCESS
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`AudioFrameworkRenderLog: AudioRenderer Created : ERROR :
${
err
}
`
);
});
```
...
...
@@ -176,21 +177,21 @@ createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback<Audio
**示例:**
```
j
s
```
t
s
import
audio
from
'
@ohos.multimedia.audio
'
;
let
audioStreamInfo
=
{
let
audioStreamInfo
:
audio
.
AudioStreamInfo
=
{
samplingRate
:
audio
.
AudioSamplingRate
.
SAMPLE_RATE_44100
,
channels
:
audio
.
AudioChannel
.
CHANNEL_2
,
sampleFormat
:
audio
.
AudioSampleFormat
.
SAMPLE_FORMAT_S16LE
,
encodingType
:
audio
.
AudioEncodingType
.
ENCODING_TYPE_RAW
}
let
audioCapturerInfo
=
{
let
audioCapturerInfo
:
audio
.
AudioCapturerInfo
=
{
source
:
audio
.
SourceType
.
SOURCE_TYPE_MIC
,
capturerFlags
:
0
}
let
audioCapturerOptions
=
{
let
audioCapturerOptions
:
audio
.
AudioCapturerOptions
=
{
streamInfo
:
audioStreamInfo
,
capturerInfo
:
audioCapturerInfo
}
...
...
@@ -229,31 +230,32 @@ createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\>
**示例:**
```
j
s
```
t
s
import
audio
from
'
@ohos.multimedia.audio
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
audioStreamInfo
=
{
let
audioStreamInfo
:
audio
.
AudioStreamInfo
=
{
samplingRate
:
audio
.
AudioSamplingRate
.
SAMPLE_RATE_44100
,
channels
:
audio
.
AudioChannel
.
CHANNEL_2
,
sampleFormat
:
audio
.
AudioSampleFormat
.
SAMPLE_FORMAT_S16LE
,
encodingType
:
audio
.
AudioEncodingType
.
ENCODING_TYPE_RAW
}
let
audioCapturerInfo
=
{
let
audioCapturerInfo
:
audio
.
AudioCapturerInfo
=
{
source
:
audio
.
SourceType
.
SOURCE_TYPE_MIC
,
capturerFlags
:
0
}
let
audioCapturerOptions
=
{
let
audioCapturerOptions
:
audio
.
AudioCapturerOptions
=
{
streamInfo
:
audioStreamInfo
,
capturerInfo
:
audioCapturerInfo
}
let
audioCapturer
;
let
audioCapturer
:
audio
.
AudioCapturer
;
audio
.
createAudioCapturer
(
audioCapturerOptions
).
then
((
data
)
=>
{
audioCapturer
=
data
;
console
.
info
(
'
AudioCapturer Created : Success : Stream Type: SUCCESS
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`AudioCapturer Created : ERROR :
${
err
}
`
);
});
```
...
...
@@ -277,15 +279,15 @@ createTonePlayer(options: AudioRendererInfo, callback: AsyncCallback<TonePlay
**示例:**
```
j
s
```
t
s
import
audio
from
'
@ohos.multimedia.audio
'
;
let
audioRendererInfo
=
{
let
audioRendererInfo
:
audio
.
AudioRendererInfo
=
{
content
:
audio
.
ContentType
.
CONTENT_TYPE_SONIFICATION
,
usage
:
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
,
rendererFlags
:
0
}
let
tonePlayer
;
let
tonePlayer
:
audio
.
TonePlayer
;
audio
.
createTonePlayer
(
audioRendererInfo
,
(
err
,
data
)
=>
{
console
.
info
(
`callback call createTonePlayer: audioRendererInfo:
${
audioRendererInfo
}
`
);
...
...
@@ -322,11 +324,11 @@ createTonePlayer(options: AudioRendererInfo): Promise<TonePlayer>
**示例:**
```
j
s
```
t
s
import
audio
from
'
@ohos.multimedia.audio
'
;
let
tonePlayer
;
let
tonePlayer
:
audio
.
TonePlayer
;
async
function
createTonePlayerBefore
(){
let
audioRendererInfo
=
{
let
audioRendererInfo
:
audio
.
AudioRendererInfo
=
{
content
:
audio
.
ContentType
.
CONTENT_TYPE_SONIFICATION
,
usage
:
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
,
rendererFlags
:
0
...
...
@@ -910,8 +912,9 @@ setAudioParameter(key: string, value: string, callback: AsyncCallback<void>
**示例:**
```
js
audioManager
.
setAudioParameter
(
'
key_example
'
,
'
value_example
'
,
(
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
setAudioParameter
(
'
key_example
'
,
'
value_example
'
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to set the audio parameter.
${
err
}
`
);
return
;
...
...
@@ -947,7 +950,7 @@ setAudioParameter(key: string, value: string): Promise<void>
**示例:**
```
j
s
```
t
s
audioManager
.
setAudioParameter
(
'
key_example
'
,
'
value_example
'
).
then
(()
=>
{
console
.
info
(
'
Promise returned to indicate a successful setting of the audio parameter.
'
);
});
...
...
@@ -972,8 +975,9 @@ getAudioParameter(key: string, callback: AsyncCallback<string>): void
**示例:**
```
js
audioManager
.
getAudioParameter
(
'
key_example
'
,
(
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
getAudioParameter
(
'
key_example
'
,
(
err
:
BusinessError
,
value
:
string
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the value of the audio parameter.
${
err
}
`
);
return
;
...
...
@@ -1006,8 +1010,8 @@ getAudioParameter(key: string): Promise<string>
**示例:**
```
j
s
audioManager
.
getAudioParameter
(
'
key_example
'
).
then
((
value
)
=>
{
```
t
s
audioManager
.
getAudioParameter
(
'
key_example
'
).
then
((
value
:
string
)
=>
{
console
.
info
(
`Promise returned to indicate that the value of the audio parameter is obtained
${
value
}
.`
);
});
```
...
...
@@ -1031,8 +1035,9 @@ setAudioScene\(scene: AudioScene, callback: AsyncCallback<void\>\): void
**示例:**
```
js
audioManager
.
setAudioScene
(
audio
.
AudioScene
.
AUDIO_SCENE_PHONE_CALL
,
(
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
setAudioScene
(
audio
.
AudioScene
.
AUDIO_SCENE_PHONE_CALL
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to set the audio scene mode.
${
err
}
`
);
return
;
...
...
@@ -1065,10 +1070,11 @@ setAudioScene\(scene: AudioScene\): Promise<void\>
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
setAudioScene
(
audio
.
AudioScene
.
AUDIO_SCENE_PHONE_CALL
).
then
(()
=>
{
console
.
info
(
'
Promise returned to indicate a successful setting of the audio scene mode.
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Failed to set the audio scene mode
${
err
}
`
);
});
```
...
...
@@ -1089,8 +1095,9 @@ getAudioScene\(callback: AsyncCallback<AudioScene\>\): void
**示例:**
```
js
audioManager
.
getAudioScene
((
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
getAudioScene
((
err
:
BusinessError
,
value
:
audio
.
AudioScene
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the audio scene mode.
${
err
}
`
);
return
;
...
...
@@ -1115,10 +1122,11 @@ getAudioScene\(\): Promise<AudioScene\>
**示例:**
```
js
audioManager
.
getAudioScene
().
then
((
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
getAudioScene
().
then
((
value
:
audio
.
AudioScene
)
=>
{
console
.
info
(
`Promise returned to indicate that the audio scene mode is obtained
${
value
}
.`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Failed to obtain the audio scene mode
${
err
}
`
);
});
```
...
...
@@ -1133,8 +1141,8 @@ getVolumeManager(): AudioVolumeManager
**示例:**
```
j
s
let
audioVolumeManager
=
audioManager
.
getVolumeManager
();
```
t
s
let
audioVolumeManager
:
audio
.
AudioVolumeManager
=
audioManager
.
getVolumeManager
();
```
### getStreamManager<sup>9+</sup>
...
...
@@ -1147,8 +1155,8 @@ getStreamManager(): AudioStreamManager
**示例:**
```
j
s
let
audioStreamManager
=
audioManager
.
getStreamManager
();
```
t
s
let
audioStreamManager
:
audio
.
AudioStreamManager
=
audioManager
.
getStreamManager
();
```
### getRoutingManager<sup>9+</sup>
...
...
@@ -1161,8 +1169,8 @@ getRoutingManager(): AudioRoutingManager
**示例:**
```
j
s
let
audioRoutingManager
=
audioManager
.
getRoutingManager
();
```
t
s
let
audioRoutingManager
:
audio
.
AudioRoutingManager
=
audioManager
.
getRoutingManager
();
```
### setVolume<sup>(deprecated)</sup>
...
...
@@ -1190,8 +1198,9 @@ setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&l
**示例:**
```
js
audioManager
.
setVolume
(
audio
.
AudioVolumeType
.
MEDIA
,
10
,
(
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
setVolume
(
audio
.
AudioVolumeType
.
MEDIA
,
10
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to set the volume.
${
err
}
`
);
return
;
...
...
@@ -1230,7 +1239,7 @@ setVolume(volumeType: AudioVolumeType, volume: number): Promise<void>
**示例:**
```
j
s
```
t
s
audioManager
.
setVolume
(
audio
.
AudioVolumeType
.
MEDIA
,
10
).
then
(()
=>
{
console
.
info
(
'
Promise returned to indicate a successful volume setting.
'
);
});
...
...
@@ -1256,8 +1265,9 @@ getVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): v
**示例:**
```
js
audioManager
.
getVolume
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
getVolume
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
:
BusinessError
,
value
:
number
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the volume.
${
err
}
`
);
return
;
...
...
@@ -1291,8 +1301,8 @@ getVolume(volumeType: AudioVolumeType): Promise<number>
**示例:**
```
j
s
audioManager
.
getVolume
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
value
)
=>
{
```
t
s
audioManager
.
getVolume
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
value
:
number
)
=>
{
console
.
info
(
`Promise returned to indicate that the volume is obtained
${
value
}
.`
);
});
```
...
...
@@ -1317,8 +1327,9 @@ getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>)
**示例:**
```
js
audioManager
.
getMinVolume
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
getMinVolume
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
:
BusinessError
,
value
:
number
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the minimum volume.
${
err
}
`
);
return
;
...
...
@@ -1352,8 +1363,8 @@ getMinVolume(volumeType: AudioVolumeType): Promise<number>
**示例:**
```
j
s
audioManager
.
getMinVolume
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
value
)
=>
{
```
t
s
audioManager
.
getMinVolume
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
value
:
number
)
=>
{
console
.
info
(
`Promised returned to indicate that the minimum volume is obtained.
${
value
}
`
);
});
```
...
...
@@ -1378,8 +1389,9 @@ getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>)
**示例:**
```
js
audioManager
.
getMaxVolume
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
getMaxVolume
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
:
BusinessError
,
value
:
number
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the maximum volume.
${
err
}
`
);
return
;
...
...
@@ -1413,8 +1425,8 @@ getMaxVolume(volumeType: AudioVolumeType): Promise<number>
**示例:**
```
j
s
audioManager
.
getMaxVolume
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
data
)
=>
{
```
t
s
audioManager
.
getMaxVolume
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
data
:
number
)
=>
{
console
.
info
(
'
Promised returned to indicate that the maximum volume is obtained.
'
);
});
```
...
...
@@ -1440,8 +1452,9 @@ mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback<void
**示例:**
```
js
audioManager
.
mute
(
audio
.
AudioVolumeType
.
MEDIA
,
true
,
(
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
mute
(
audio
.
AudioVolumeType
.
MEDIA
,
true
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to mute the stream.
${
err
}
`
);
return
;
...
...
@@ -1477,7 +1490,7 @@ mute(volumeType: AudioVolumeType, mute: boolean): Promise<void>
**示例:**
```
j
s
```
t
s
audioManager
.
mute
(
audio
.
AudioVolumeType
.
MEDIA
,
true
).
then
(()
=>
{
console
.
info
(
'
Promise returned to indicate that the stream is muted.
'
);
});
...
...
@@ -1503,8 +1516,9 @@ isMute(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): voi
**示例:**
```
js
audioManager
.
isMute
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
isMute
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
:
BusinessError
,
value
:
boolean
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the mute status.
${
err
}
`
);
return
;
...
...
@@ -1538,8 +1552,8 @@ isMute(volumeType: AudioVolumeType): Promise<boolean>
**示例:**
```
j
s
audioManager
.
isMute
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
value
)
=>
{
```
t
s
audioManager
.
isMute
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
value
:
boolean
)
=>
{
console
.
info
(
`Promise returned to indicate that the mute status of the stream is obtained
${
value
}
.`
);
});
```
...
...
@@ -1564,8 +1578,9 @@ isActive(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): v
**示例:**
```
js
audioManager
.
isActive
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
isActive
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
:
BusinessError
,
value
:
boolean
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the active status of the stream.
${
err
}
`
);
return
;
...
...
@@ -1599,8 +1614,8 @@ isActive(volumeType: AudioVolumeType): Promise<boolean>
**示例:**
```
j
s
audioManager
.
isActive
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
value
)
=>
{
```
t
s
audioManager
.
isActive
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
value
:
boolean
)
=>
{
console
.
info
(
`Promise returned to indicate that the active status of the stream is obtained
${
value
}
.`
);
});
```
...
...
@@ -1629,8 +1644,9 @@ setRingerMode(mode: AudioRingMode, callback: AsyncCallback<void>): void
**示例:**
```
js
audioManager
.
setRingerMode
(
audio
.
AudioRingMode
.
RINGER_MODE_NORMAL
,
(
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
setRingerMode
(
audio
.
AudioRingMode
.
RINGER_MODE_NORMAL
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to set the ringer mode.
${
err
}
`
);
return
;
...
...
@@ -1669,7 +1685,7 @@ setRingerMode(mode: AudioRingMode): Promise<void>
**示例:**
```
j
s
```
t
s
audioManager
.
setRingerMode
(
audio
.
AudioRingMode
.
RINGER_MODE_NORMAL
).
then
(()
=>
{
console
.
info
(
'
Promise returned to indicate a successful setting of the ringer mode.
'
);
});
...
...
@@ -1694,8 +1710,9 @@ getRingerMode(callback: AsyncCallback<AudioRingMode>): void
**示例:**
```
js
audioManager
.
getRingerMode
((
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
getRingerMode
((
err
:
BusinessError
,
value
:
audio
.
AudioRingMode
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the ringer mode.
${
err
}
`
);
return
;
...
...
@@ -1723,8 +1740,8 @@ getRingerMode(): Promise<AudioRingMode>
**示例:**
```
j
s
audioManager
.
getRingerMode
().
then
((
value
)
=>
{
```
t
s
audioManager
.
getRingerMode
().
then
((
value
:
audio
.
AudioRingMode
)
=>
{
console
.
info
(
`Promise returned to indicate that the ringer mode is obtained
${
value
}
.`
);
});
```
...
...
@@ -1748,8 +1765,9 @@ getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback<AudioDeviceDescrip
| callback | AsyncCallback
<
[AudioDeviceDescriptors](#audiodevicedescriptors)
>
| 是 | 回调,返回设备列表。 |
**示例:**
```
js
audioManager
.
getDevices
(
audio
.
DeviceFlag
.
OUTPUT_DEVICES_FLAG
,
(
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
getDevices
(
audio
.
DeviceFlag
.
OUTPUT_DEVICES_FLAG
,
(
err
:
BusinessError
,
value
:
audio
.
AudioDeviceDescriptors
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the device list.
${
err
}
`
);
return
;
...
...
@@ -1783,8 +1801,8 @@ getDevices(deviceFlag: DeviceFlag): Promise<AudioDeviceDescriptors>
**示例:**
```
j
s
audioManager
.
getDevices
(
audio
.
DeviceFlag
.
OUTPUT_DEVICES_FLAG
).
then
((
data
)
=>
{
```
t
s
audioManager
.
getDevices
(
audio
.
DeviceFlag
.
OUTPUT_DEVICES_FLAG
).
then
((
data
:
audio
.
AudioDeviceDescriptors
)
=>
{
console
.
info
(
'
Promise returned to indicate that the device list is obtained.
'
);
});
```
...
...
@@ -1810,8 +1828,9 @@ setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCa
**示例:**
```
js
audioManager
.
setDeviceActive
(
audio
.
ActiveDeviceType
.
SPEAKER
,
true
,
(
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
setDeviceActive
(
audio
.
ActiveDeviceType
.
SPEAKER
,
true
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to set the active status of the device.
${
err
}
`
);
return
;
...
...
@@ -1847,7 +1866,7 @@ setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise<void&
**示例:**
```
j
s
```
t
s
audioManager
.
setDeviceActive
(
audio
.
ActiveDeviceType
.
SPEAKER
,
true
).
then
(()
=>
{
console
.
info
(
'
Promise returned to indicate that the device is set to the active status.
'
);
});
...
...
@@ -1873,8 +1892,9 @@ isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback<boolean&
**示例:**
```
js
audioManager
.
isDeviceActive
(
audio
.
ActiveDeviceType
.
SPEAKER
,
(
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
isDeviceActive
(
audio
.
ActiveDeviceType
.
SPEAKER
,
(
err
:
BusinessError
,
value
:
boolean
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the active status of the device.
${
err
}
`
);
return
;
...
...
@@ -1908,8 +1928,8 @@ isDeviceActive(deviceType: ActiveDeviceType): Promise<boolean>
**示例:**
```
j
s
audioManager
.
isDeviceActive
(
audio
.
ActiveDeviceType
.
SPEAKER
).
then
((
value
)
=>
{
```
t
s
audioManager
.
isDeviceActive
(
audio
.
ActiveDeviceType
.
SPEAKER
).
then
((
value
:
boolean
)
=>
{
console
.
info
(
`Promise returned to indicate that the active status of the device is obtained
${
value
}
.`
);
});
```
...
...
@@ -1936,8 +1956,9 @@ setMicrophoneMute(mute: boolean, callback: AsyncCallback<void>): void
**示例:**
```
js
audioManager
.
setMicrophoneMute
(
true
,
(
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
setMicrophoneMute
(
true
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to mute the microphone.
${
err
}
`
);
return
;
...
...
@@ -1973,7 +1994,7 @@ setMicrophoneMute(mute: boolean): Promise<void>
**示例:**
```
j
s
```
t
s
audioManager
.
setMicrophoneMute
(
true
).
then
(()
=>
{
console
.
info
(
'
Promise returned to indicate that the microphone is muted.
'
);
});
...
...
@@ -2000,8 +2021,9 @@ isMicrophoneMute(callback: AsyncCallback<boolean>): void
**示例:**
```
js
audioManager
.
isMicrophoneMute
((
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioManager
.
isMicrophoneMute
((
err
:
BusinessError
,
value
:
boolean
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the mute status of the microphone.
${
err
}
`
);
return
;
...
...
@@ -2031,8 +2053,8 @@ isMicrophoneMute(): Promise<boolean>
**示例:**
```
j
s
audioManager
.
isMicrophoneMute
().
then
((
value
)
=>
{
```
t
s
audioManager
.
isMicrophoneMute
().
then
((
value
:
boolean
)
=>
{
console
.
info
(
`Promise returned to indicate that the mute status of the microphone is obtained
${
value
}
.`
);
});
```
...
...
@@ -2061,8 +2083,8 @@ on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
**示例:**
```
j
s
audioManager
.
on
(
'
volumeChange
'
,
(
volumeEvent
)
=>
{
```
t
s
audioManager
.
on
(
'
volumeChange
'
,
(
volumeEvent
:
audio
.
VolumeEvent
)
=>
{
console
.
info
(
`VolumeType of stream:
${
volumeEvent
.
volumeType
}
`
);
console
.
info
(
`Volume level:
${
volumeEvent
.
volume
}
`
);
console
.
info
(
`Whether to updateUI:
${
volumeEvent
.
updateUi
}
`
);
...
...
@@ -2091,8 +2113,8 @@ on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void
**示例:**
```
j
s
audioManager
.
on
(
'
ringerModeChange
'
,
(
ringerMode
)
=>
{
```
t
s
audioManager
.
on
(
'
ringerModeChange
'
,
(
ringerMode
:
audio
.
AudioRingMode
)
=>
{
console
.
info
(
`Updated ringermode:
${
ringerMode
}
`
);
});
```
...
...
@@ -2117,8 +2139,8 @@ on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void
**示例:**
```
j
s
audioManager
.
on
(
'
deviceChange
'
,
(
deviceChanged
)
=>
{
```
t
s
audioManager
.
on
(
'
deviceChange
'
,
(
deviceChanged
:
audio
.
DeviceChangeAction
)
=>
{
console
.
info
(
`device change type :
${
deviceChanged
.
type
}
`
);
console
.
info
(
`device descriptor size :
${
deviceChanged
.
deviceDescriptors
.
length
}
`
);
console
.
info
(
`device change descriptor :
${
deviceChanged
.
deviceDescriptors
[
0
].
deviceRole
}
`
);
...
...
@@ -2146,7 +2168,7 @@ off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void
**示例:**
```
j
s
```
t
s
audioManager
.
off
(
'
deviceChange
'
);
```
...
...
@@ -2170,13 +2192,14 @@ on(type: 'interrupt', interrupt: AudioInterrupt, callback: Callback\<InterruptAc
**示例:**
```
js
let
interAudioInterrupt
=
{
```
ts
import
audio
from
'
@ohos.multimedia.audio
'
;
let
interAudioInterrupt
:
audio
.
AudioInterrupt
=
{
streamUsage
:
2
,
contentType
:
0
,
pauseWhenDucked
:
true
};
audioManager
.
on
(
'
interrupt
'
,
interAudioInterrupt
,
(
InterruptAction
)
=>
{
audioManager
.
on
(
'
interrupt
'
,
interAudioInterrupt
,
(
InterruptAction
:
audio
.
InterruptAction
)
=>
{
if
(
InterruptAction
.
actionType
===
0
)
{
console
.
info
(
'
An event to gain the audio focus starts.
'
);
console
.
info
(
`Focus gain event:
${
InterruptAction
}
`
);
...
...
@@ -2206,16 +2229,17 @@ off(type: 'interrupt', interrupt: AudioInterrupt, callback?: Callback\<Interrupt
**示例:**
```
js
let
interAudioInterrupt
=
{
```
ts
import
audio
from
'
@ohos.multimedia.audio
'
;
let
interAudioInterrupt
:
audio
.
AudioInterrupt
=
{
streamUsage
:
2
,
contentType
:
0
,
pauseWhenDucked
:
true
};
audioManager
.
off
(
'
interrupt
'
,
interAudioInterrupt
,
(
InterruptAction
)
=>
{
audioManager
.
off
(
'
interrupt
'
,
interAudioInterrupt
,
(
InterruptAction
:
audio
.
InterruptAction
)
=>
{
if
(
InterruptAction
.
actionType
===
0
)
{
console
.
info
(
'
An event to release the audio focus starts.
'
);
console
.
info
(
`Focus release event:
${
InterruptAction
}
`
);
console
.
info
(
'
An event to release the audio focus starts.
'
);
console
.
info
(
`Focus release event:
${
InterruptAction
}
`
);
}
});
```
...
...
@@ -2242,8 +2266,9 @@ getVolumeGroupInfos(networkId: string, callback: AsyncCallback<VolumeGroupInfos\
| callback | AsyncCallback
<
[VolumeGroupInfos](#volumegroupinfos9)
>
| 是 | 回调,返回音量组信息列表。 |
**示例:**
```
js
audioVolumeManager
.
getVolumeGroupInfos
(
audio
.
LOCAL_NETWORK_ID
,
(
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioVolumeManager
.
getVolumeGroupInfos
(
audio
.
LOCAL_NETWORK_ID
,
(
err
:
BusinessError
,
value
:
audio
.
VolumeGroupInfos
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the volume group infos list.
${
err
}
`
);
return
;
...
...
@@ -2276,9 +2301,9 @@ getVolumeGroupInfos(networkId: string\): Promise<VolumeGroupInfos\>
**示例:**
```
j
s
```
t
s
async
function
getVolumeGroupInfos
(){
let
volumegroupinfos
=
await
audio
.
getAudioManager
().
getVolumeManager
().
getVolumeGroupInfos
(
audio
.
LOCAL_NETWORK_ID
);
let
volumegroupinfos
:
audio
.
VolumeGroupInfos
=
await
audio
.
getAudioManager
().
getVolumeManager
().
getVolumeGroupInfos
(
audio
.
LOCAL_NETWORK_ID
);
console
.
info
(
'
Promise returned to indicate that the volumeGroup list is obtained.
'
+
JSON
.
stringify
(
volumegroupinfos
))
}
```
...
...
@@ -2300,9 +2325,10 @@ getVolumeGroupManager(groupId: number, callback: AsyncCallback<AudioVolumeGroupM
**示例:**
```
js
let
groupid
=
audio
.
DEFAULT_VOLUME_GROUP_ID
;
audioVolumeManager
.
getVolumeGroupManager
(
groupid
,
(
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
groupid
:
number
=
audio
.
DEFAULT_VOLUME_GROUP_ID
;
audioVolumeManager
.
getVolumeGroupManager
(
groupid
,
(
err
:
BusinessError
,
value
:
audio
.
AudioVolumeGroupManager
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the volume group infos list.
${
err
}
`
);
return
;
...
...
@@ -2334,9 +2360,9 @@ getVolumeGroupManager(groupId: number\): Promise<AudioVolumeGroupManager\>
**示例:**
```
j
s
let
groupid
=
audio
.
DEFAULT_VOLUME_GROUP_ID
;
let
audioVolumeGroupManager
;
```
t
s
let
groupid
:
number
=
audio
.
DEFAULT_VOLUME_GROUP_ID
;
let
audioVolumeGroupManager
:
audio
.
AudioVolumeGroupManager
;
getVolumeGroupManager
();
async
function
getVolumeGroupManager
(){
audioVolumeGroupManager
=
await
audioVolumeManager
.
getVolumeGroupManager
(
groupid
);
...
...
@@ -2370,8 +2396,8 @@ on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
**示例:**
```
j
s
audioVolumeManager
.
on
(
'
volumeChange
'
,
(
volumeEvent
)
=>
{
```
t
s
audioVolumeManager
.
on
(
'
volumeChange
'
,
(
volumeEvent
:
audio
.
VolumeEvent
)
=>
{
console
.
info
(
`VolumeType of stream:
${
volumeEvent
.
volumeType
}
`
);
console
.
info
(
`Volume level:
${
volumeEvent
.
volume
}
`
);
console
.
info
(
`Whether to updateUI:
${
volumeEvent
.
updateUi
}
`
);
...
...
@@ -2406,8 +2432,9 @@ setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&l
**示例:**
```
js
audioVolumeGroupManager
.
setVolume
(
audio
.
AudioVolumeType
.
MEDIA
,
10
,
(
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioVolumeGroupManager
.
setVolume
(
audio
.
AudioVolumeType
.
MEDIA
,
10
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to set the volume.
${
err
}
`
);
return
;
...
...
@@ -2445,7 +2472,7 @@ setVolume(volumeType: AudioVolumeType, volume: number): Promise<void>
**示例:**
```
j
s
```
t
s
audioVolumeGroupManager
.
setVolume
(
audio
.
AudioVolumeType
.
MEDIA
,
10
).
then
(()
=>
{
console
.
info
(
'
Promise returned to indicate a successful volume setting.
'
);
});
...
...
@@ -2468,8 +2495,9 @@ getVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): v
**示例:**
```
js
audioVolumeGroupManager
.
getVolume
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioVolumeGroupManager
.
getVolume
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
:
BusinessError
,
value
:
number
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the volume.
${
err
}
`
);
return
;
...
...
@@ -2500,8 +2528,8 @@ getVolume(volumeType: AudioVolumeType): Promise<number>
**示例:**
```
j
s
audioVolumeGroupManager
.
getVolume
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
value
)
=>
{
```
t
s
audioVolumeGroupManager
.
getVolume
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
value
:
number
)
=>
{
console
.
info
(
`Promise returned to indicate that the volume is obtained
${
value
}
.`
);
});
```
...
...
@@ -2523,8 +2551,9 @@ getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>)
**示例:**
```
js
audioVolumeGroupManager
.
getMinVolume
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioVolumeGroupManager
.
getMinVolume
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
:
BusinessError
,
value
:
number
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the minimum volume.
${
err
}
`
);
return
;
...
...
@@ -2555,8 +2584,8 @@ getMinVolume(volumeType: AudioVolumeType): Promise<number>
**示例:**
```
j
s
audioVolumeGroupManager
.
getMinVolume
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
value
)
=>
{
```
t
s
audioVolumeGroupManager
.
getMinVolume
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
value
:
number
)
=>
{
console
.
info
(
`Promised returned to indicate that the minimum volume is obtained
${
value
}
.`
);
});
```
...
...
@@ -2578,8 +2607,9 @@ getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>)
**示例:**
```
js
audioVolumeGroupManager
.
getMaxVolume
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioVolumeGroupManager
.
getMaxVolume
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
:
BusinessError
,
value
:
number
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the maximum volume.
${
err
}
`
);
return
;
...
...
@@ -2610,8 +2640,8 @@ getMaxVolume(volumeType: AudioVolumeType): Promise<number>
**示例:**
```
j
s
audioVolumeGroupManager
.
getMaxVolume
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
data
)
=>
{
```
t
s
audioVolumeGroupManager
.
getMaxVolume
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
data
:
number
)
=>
{
console
.
info
(
'
Promised returned to indicate that the maximum volume is obtained.
'
);
});
```
...
...
@@ -2640,8 +2670,9 @@ mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback<void
**示例:**
```
js
audioVolumeGroupManager
.
mute
(
audio
.
AudioVolumeType
.
MEDIA
,
true
,
(
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioVolumeGroupManager
.
mute
(
audio
.
AudioVolumeType
.
MEDIA
,
true
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to mute the stream.
${
err
}
`
);
return
;
...
...
@@ -2679,7 +2710,7 @@ mute(volumeType: AudioVolumeType, mute: boolean): Promise<void>
**示例:**
```
j
s
```
t
s
audioVolumeGroupManager
.
mute
(
audio
.
AudioVolumeType
.
MEDIA
,
true
).
then
(()
=>
{
console
.
info
(
'
Promise returned to indicate that the stream is muted.
'
);
});
...
...
@@ -2702,8 +2733,9 @@ isMute(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): voi
**示例:**
```
js
audioVolumeGroupManager
.
isMute
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioVolumeGroupManager
.
isMute
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
:
BusinessError
,
value
:
boolean
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the mute status.
${
err
}
`
);
return
;
...
...
@@ -2734,8 +2766,8 @@ isMute(volumeType: AudioVolumeType): Promise<boolean>
**示例:**
```
j
s
audioVolumeGroupManager
.
isMute
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
value
)
=>
{
```
t
s
audioVolumeGroupManager
.
isMute
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
value
:
boolean
)
=>
{
console
.
info
(
`Promise returned to indicate that the mute status of the stream is obtained
${
value
}
.`
);
});
```
...
...
@@ -2763,8 +2795,9 @@ setRingerMode(mode: AudioRingMode, callback: AsyncCallback<void>): void
**示例:**
```
js
audioVolumeGroupManager
.
setRingerMode
(
audio
.
AudioRingMode
.
RINGER_MODE_NORMAL
,
(
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioVolumeGroupManager
.
setRingerMode
(
audio
.
AudioRingMode
.
RINGER_MODE_NORMAL
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to set the ringer mode.
${
err
}
`
);
return
;
...
...
@@ -2801,7 +2834,7 @@ setRingerMode(mode: AudioRingMode): Promise<void>
**示例:**
```
j
s
```
t
s
audioVolumeGroupManager
.
setRingerMode
(
audio
.
AudioRingMode
.
RINGER_MODE_NORMAL
).
then
(()
=>
{
console
.
info
(
'
Promise returned to indicate a successful setting of the ringer mode.
'
);
});
...
...
@@ -2823,8 +2856,9 @@ getRingerMode(callback: AsyncCallback<AudioRingMode>): void
**示例:**
```
js
audioVolumeGroupManager
.
getRingerMode
((
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioVolumeGroupManager
.
getRingerMode
((
err
:
BusinessError
,
value
:
audio
.
AudioRingMode
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the ringer mode.
${
err
}
`
);
return
;
...
...
@@ -2849,8 +2883,8 @@ getRingerMode(): Promise<AudioRingMode>
**示例:**
```
j
s
audioVolumeGroupManager
.
getRingerMode
().
then
((
value
)
=>
{
```
t
s
audioVolumeGroupManager
.
getRingerMode
().
then
((
value
:
audio
.
AudioRingMode
)
=>
{
console
.
info
(
`Promise returned to indicate that the ringer mode is obtained
${
value
}
.`
);
});
```
...
...
@@ -2880,8 +2914,8 @@ on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void
**示例:**
```
j
s
audioVolumeGroupManager
.
on
(
'
ringerModeChange
'
,
(
ringerMode
)
=>
{
```
t
s
audioVolumeGroupManager
.
on
(
'
ringerModeChange
'
,
(
ringerMode
:
audio
.
AudioRingMode
)
=>
{
console
.
info
(
`Updated ringermode:
${
ringerMode
}
`
);
});
```
...
...
@@ -2904,8 +2938,9 @@ setMicrophoneMute(mute: boolean, callback: AsyncCallback<void>): void
**示例:**
```
js
audioVolumeGroupManager
.
setMicrophoneMute
(
true
,
(
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioVolumeGroupManager
.
setMicrophoneMute
(
true
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to mute the microphone.
${
err
}
`
);
return
;
...
...
@@ -2938,7 +2973,7 @@ setMicrophoneMute(mute: boolean): Promise<void>
**示例:**
```
j
s
```
t
s
audioVolumeGroupManager
.
setMicrophoneMute
(
true
).
then
(()
=>
{
console
.
info
(
'
Promise returned to indicate that the microphone is muted.
'
);
});
...
...
@@ -2960,8 +2995,9 @@ isMicrophoneMute(callback: AsyncCallback<boolean>): void
**示例:**
```
js
audioVolumeGroupManager
.
isMicrophoneMute
((
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioVolumeGroupManager
.
isMicrophoneMute
((
err
:
BusinessError
,
value
:
boolean
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the mute status of the microphone.
${
err
}
`
);
return
;
...
...
@@ -2986,8 +3022,8 @@ isMicrophoneMute(): Promise<boolean>
**示例:**
```
j
s
audioVolumeGroupManager
.
isMicrophoneMute
().
then
((
value
)
=>
{
```
t
s
audioVolumeGroupManager
.
isMicrophoneMute
().
then
((
value
:
boolean
)
=>
{
console
.
info
(
`Promise returned to indicate that the mute status of the microphone is obtained
${
value
}
.`
);
});
```
...
...
@@ -3019,8 +3055,8 @@ on(type: 'micStateChange', callback: Callback<MicStateChangeEvent>): void
**示例:**
```
j
s
audioVolumeGroupManager
.
on
(
'
micStateChange
'
,
(
micStateChange
)
=>
{
```
t
s
audioVolumeGroupManager
.
on
(
'
micStateChange
'
,
(
micStateChange
:
audio
.
MicStateChangeEvent
)
=>
{
console
.
info
(
`Current microphone status is:
${
micStateChange
.
mute
}
`
);
});
```
...
...
@@ -3041,8 +3077,8 @@ isVolumeUnadjustable(): boolean
**示例:**
```
j
s
let
volumeAdjustSwitch
=
audioVolumeGroupManager
.
isVolumeUnadjustable
();
```
t
s
let
volumeAdjustSwitch
:
boolean
=
audioVolumeGroupManager
.
isVolumeUnadjustable
();
console
.
info
(
`Whether it is volume unadjustable:
${
volumeAdjustSwitch
}
.`
);
```
...
...
@@ -3078,8 +3114,9 @@ adjustVolumeByStep(adjustType: VolumeAdjustType, callback: AsyncCallback<void
**示例:**
```
js
audioVolumeGroupManager
.
adjustVolumeByStep
(
audio
.
VolumeAdjustType
.
VOLUME_UP
,
(
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioVolumeGroupManager
.
adjustVolumeByStep
(
audio
.
VolumeAdjustType
.
VOLUME_UP
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to adjust the volume by step.
${
err
}
`
);
return
;
...
...
@@ -3125,10 +3162,11 @@ adjustVolumeByStep(adjustType: VolumeAdjustType): Promise<void>
**示例:**
```
js
audioVolumeGroupManager
.
adjustVolumeByStep
(
audio
.
VolumeAdjustType
.
VOLUME_UP
).
then
((
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioVolumeGroupManager
.
adjustVolumeByStep
(
audio
.
VolumeAdjustType
.
VOLUME_UP
).
then
(()
=>
{
console
.
info
(
'
Success to adjust the volume by step.
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
Fail to adjust the volume by step.
'
);
});
```
...
...
@@ -3166,8 +3204,9 @@ adjustSystemVolumeByStep(volumeType: AudioVolumeType, adjustType: VolumeAdjustTy
**示例:**
```
js
audioVolumeGroupManager
.
adjustSystemVolumeByStep
(
audio
.
AudioVolumeType
.
MEDIA
,
audio
.
VolumeAdjustType
.
VOLUME_UP
,
(
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioVolumeGroupManager
.
adjustSystemVolumeByStep
(
audio
.
AudioVolumeType
.
MEDIA
,
audio
.
VolumeAdjustType
.
VOLUME_UP
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to adjust the system volume by step
${
err
}
`
);
}
else
{
...
...
@@ -3213,10 +3252,11 @@ adjustSystemVolumeByStep(volumeType: AudioVolumeType, adjustType: VolumeAdjustTy
**示例:**
```
js
audioVolumeGroupManager
.
adjustSystemVolumeByStep
(
audio
.
AudioVolumeType
.
MEDIA
,
audio
.
VolumeAdjustType
.
VOLUME_UP
).
then
((
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioVolumeGroupManager
.
adjustSystemVolumeByStep
(
audio
.
AudioVolumeType
.
MEDIA
,
audio
.
VolumeAdjustType
.
VOLUME_UP
).
then
(()
=>
{
console
.
info
(
'
Success to adjust the system volume by step.
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
Fail to adjust the system volume by step.
'
);
});
```
...
...
@@ -3249,8 +3289,9 @@ getSystemVolumeInDb(volumeType: AudioVolumeType, volumeLevel: number, device: De
**示例:**
```
js
audioVolumeGroupManager
.
getSystemVolumeInDb
(
audio
.
AudioVolumeType
.
MEDIA
,
3
,
audio
.
DeviceType
.
SPEAKER
,
(
err
,
dB
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioVolumeGroupManager
.
getSystemVolumeInDb
(
audio
.
AudioVolumeType
.
MEDIA
,
3
,
audio
.
DeviceType
.
SPEAKER
,
(
err
:
BusinessError
,
dB
:
number
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to get the volume DB.
${
err
}
`
);
}
else
{
...
...
@@ -3291,10 +3332,11 @@ getSystemVolumeInDb(volumeType: AudioVolumeType, volumeLevel: number, device: De
**示例:**
```
js
audioVolumeGroupManager
.
getSystemVolumeInDb
(
audio
.
AudioVolumeType
.
MEDIA
,
3
,
audio
.
DeviceType
.
SPEAKER
).
then
((
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioVolumeGroupManager
.
getSystemVolumeInDb
(
audio
.
AudioVolumeType
.
MEDIA
,
3
,
audio
.
DeviceType
.
SPEAKER
).
then
((
value
:
number
)
=>
{
console
.
info
(
`Success to get the volume DB.
${
value
}
`
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
`Fail to adjust the system volume by step.
${
error
}
`
);
});
```
...
...
@@ -3319,21 +3361,22 @@ getCurrentAudioRendererInfoArray(callback: AsyncCallback<AudioRendererChangeI
**示例:**
```
js
audioStreamManager
.
getCurrentAudioRendererInfoArray
(
async
(
err
,
AudioRendererChangeInfoArray
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioStreamManager
.
getCurrentAudioRendererInfoArray
(
async
(
err
:
BusinessError
,
AudioRendererChangeInfoArray
:
audio
.
AudioRendererChangeInfoArray
)
=>
{
console
.
info
(
'
getCurrentAudioRendererInfoArray **** Get Callback Called ****
'
);
if
(
err
)
{
console
.
error
(
`getCurrentAudioRendererInfoArray :ERROR:
${
err
}
`
);
}
else
{
if
(
AudioRendererChangeInfoArray
!=
null
)
{
for
(
let
i
=
0
;
i
<
AudioRendererChangeInfoArray
.
length
;
i
++
)
{
let
AudioRendererChangeInfo
=
AudioRendererChangeInfoArray
[
i
];
let
AudioRendererChangeInfo
:
audio
.
AudioRendererChangeInfo
=
AudioRendererChangeInfoArray
[
i
];
console
.
info
(
`StreamId for
${
i
}
is:
${
AudioRendererChangeInfo
.
streamId
}
`
);
console
.
info
(
`ClientUid for
${
i
}
is:
${
AudioRendererChangeInfo
.
clientUid
}
`
);
console
.
info
(
`Content
${
i
}
is:
${
AudioRendererChangeInfo
.
rendererInfo
.
content
}
`
);
console
.
info
(
`Stream
${
i
}
is:
${
AudioRendererChangeInfo
.
rendererInfo
.
usage
}
`
);
console
.
info
(
`Flag
${
i
}
is:
${
AudioRendererChangeInfo
.
rendererInfo
.
rendererFlags
}
`
);
console
.
info
(
`State for
${
i
}
is:
${
AudioRendererChangeInfo
.
rendererState
}
`
);
console
.
info
(
`Flag
${
i
}
is:
${
AudioRendererChangeInfo
.
rendererInfo
.
rendererFlags
}
`
);
console
.
info
(
`State for
${
i
}
is:
${
AudioRendererChangeInfo
.
rendererState
}
`
);
for
(
let
j
=
0
;
j
<
AudioRendererChangeInfo
.
deviceDescriptors
.
length
;
j
++
)
{
console
.
info
(
`Id:
${
i
}
:
${
AudioRendererChangeInfo
.
deviceDescriptors
[
j
].
id
}
`
);
console
.
info
(
`Type:
${
i
}
:
${
AudioRendererChangeInfo
.
deviceDescriptors
[
j
].
deviceType
}
`
);
...
...
@@ -3366,19 +3409,20 @@ getCurrentAudioRendererInfoArray(): Promise<AudioRendererChangeInfoArray>
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
getCurrentAudioRendererInfoArray
(){
await
audioStreamManager
.
getCurrentAudioRendererInfoArray
().
then
(
function
(
AudioRendererChangeInfoArray
)
{
await
audioStreamManager
.
getCurrentAudioRendererInfoArray
().
then
(
(
AudioRendererChangeInfoArray
:
audio
.
AudioRendererChangeInfoArray
)
=>
{
console
.
info
(
`getCurrentAudioRendererInfoArray ######### Get Promise is called ##########`
);
if
(
AudioRendererChangeInfoArray
!=
null
)
{
for
(
let
i
=
0
;
i
<
AudioRendererChangeInfoArray
.
length
;
i
++
)
{
let
AudioRendererChangeInfo
=
AudioRendererChangeInfoArray
[
i
];
let
AudioRendererChangeInfo
:
audio
.
AudioRendererChangeInfo
=
AudioRendererChangeInfoArray
[
i
];
console
.
info
(
`StreamId for
${
i
}
is:
${
AudioRendererChangeInfo
.
streamId
}
`
);
console
.
info
(
`ClientUid for
${
i
}
is:
${
AudioRendererChangeInfo
.
clientUid
}
`
);
console
.
info
(
`Content
${
i
}
is:
${
AudioRendererChangeInfo
.
rendererInfo
.
content
}
`
);
console
.
info
(
`Stream
${
i
}
is:
${
AudioRendererChangeInfo
.
rendererInfo
.
usage
}
`
);
console
.
info
(
`Flag
${
i
}
is:
${
AudioRendererChangeInfo
.
rendererInfo
.
rendererFlags
}
`
);
console
.
info
(
`State for
${
i
}
is:
${
AudioRendererChangeInfo
.
rendererState
}
`
);
console
.
info
(
`Flag
${
i
}
is:
${
AudioRendererChangeInfo
.
rendererInfo
.
rendererFlags
}
`
);
console
.
info
(
`State for
${
i
}
is:
${
AudioRendererChangeInfo
.
rendererState
}
`
);
for
(
let
j
=
0
;
j
<
AudioRendererChangeInfo
.
deviceDescriptors
.
length
;
j
++
)
{
console
.
info
(
`Id:
${
i
}
:
${
AudioRendererChangeInfo
.
deviceDescriptors
[
j
].
id
}
`
);
console
.
info
(
`Type:
${
i
}
:
${
AudioRendererChangeInfo
.
deviceDescriptors
[
j
].
deviceType
}
`
);
...
...
@@ -3391,7 +3435,7 @@ async function getCurrentAudioRendererInfoArray(){
}
}
}
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`getCurrentAudioRendererInfoArray :ERROR:
${
err
}
`
);
});
}
...
...
@@ -3413,8 +3457,9 @@ getCurrentAudioCapturerInfoArray(callback: AsyncCallback<AudioCapturerChangeI
**示例:**
```
js
audioStreamManager
.
getCurrentAudioCapturerInfoArray
(
async
(
err
,
AudioCapturerChangeInfoArray
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioStreamManager
.
getCurrentAudioCapturerInfoArray
(
async
(
err
:
BusinessError
,
AudioCapturerChangeInfoArray
:
audio
.
AudioCapturerChangeInfoArray
)
=>
{
console
.
info
(
'
getCurrentAudioCapturerInfoArray **** Get Callback Called ****
'
);
if
(
err
)
{
console
.
error
(
`getCurrentAudioCapturerInfoArray :ERROR:
${
err
}
`
);
...
...
@@ -3425,7 +3470,7 @@ audioStreamManager.getCurrentAudioCapturerInfoArray(async (err, AudioCapturerCha
console
.
info
(
`ClientUid for
${
i
}
is:
${
AudioCapturerChangeInfoArray
[
i
].
clientUid
}
`
);
console
.
info
(
`Source for
${
i
}
is:
${
AudioCapturerChangeInfoArray
[
i
].
capturerInfo
.
source
}
`
);
console
.
info
(
`Flag
${
i
}
is:
${
AudioCapturerChangeInfoArray
[
i
].
capturerInfo
.
capturerFlags
}
`
);
console
.
info
(
`State for
${
i
}
is:
${
AudioCapturerChangeInfoArray
[
i
].
capturerState
}
`
);
console
.
info
(
`State for
${
i
}
is:
${
AudioCapturerChangeInfoArray
[
i
].
capturerState
}
`
);
for
(
let
j
=
0
;
j
<
AudioCapturerChangeInfoArray
[
i
].
deviceDescriptors
.
length
;
j
++
)
{
console
.
info
(
`Id:
${
i
}
:
${
AudioCapturerChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
id
}
`
);
console
.
info
(
`Type:
${
i
}
:
${
AudioCapturerChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
deviceType
}
`
);
...
...
@@ -3458,9 +3503,10 @@ getCurrentAudioCapturerInfoArray(): Promise<AudioCapturerChangeInfoArray>
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
getCurrentAudioCapturerInfoArray
(){
await
audioStreamManager
.
getCurrentAudioCapturerInfoArray
().
then
(
function
(
AudioCapturerChangeInfoArray
)
{
await
audioStreamManager
.
getCurrentAudioCapturerInfoArray
().
then
(
(
AudioCapturerChangeInfoArray
:
audio
.
AudioCapturerChangeInfoArray
)
=>
{
console
.
info
(
'
getCurrentAudioCapturerInfoArray **** Get Promise Called ****
'
);
if
(
AudioCapturerChangeInfoArray
!=
null
)
{
for
(
let
i
=
0
;
i
<
AudioCapturerChangeInfoArray
.
length
;
i
++
)
{
...
...
@@ -3468,7 +3514,7 @@ async function getCurrentAudioCapturerInfoArray(){
console
.
info
(
`ClientUid for
${
i
}
is:
${
AudioCapturerChangeInfoArray
[
i
].
clientUid
}
`
);
console
.
info
(
`Source for
${
i
}
is:
${
AudioCapturerChangeInfoArray
[
i
].
capturerInfo
.
source
}
`
);
console
.
info
(
`Flag
${
i
}
is:
${
AudioCapturerChangeInfoArray
[
i
].
capturerInfo
.
capturerFlags
}
`
);
console
.
info
(
`State for
${
i
}
is:
${
AudioCapturerChangeInfoArray
[
i
].
capturerState
}
`
);
console
.
info
(
`State for
${
i
}
is:
${
AudioCapturerChangeInfoArray
[
i
].
capturerState
}
`
);
for
(
let
j
=
0
;
j
<
AudioCapturerChangeInfoArray
[
i
].
deviceDescriptors
.
length
;
j
++
)
{
console
.
info
(
`Id:
${
i
}
:
${
AudioCapturerChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
id
}
`
);
console
.
info
(
`Type:
${
i
}
:
${
AudioCapturerChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
deviceType
}
`
);
...
...
@@ -3481,7 +3527,7 @@ async function getCurrentAudioCapturerInfoArray(){
}
}
}
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`getCurrentAudioCapturerInfoArray :ERROR:
${
err
}
`
);
});
}
...
...
@@ -3512,17 +3558,17 @@ on(type: 'audioRendererChange', callback: Callback<AudioRendererChangeInfoArr
**示例:**
```
j
s
audioStreamManager
.
on
(
'
audioRendererChange
'
,
(
AudioRendererChangeInfoArray
)
=>
{
```
t
s
audioStreamManager
.
on
(
'
audioRendererChange
'
,
(
AudioRendererChangeInfoArray
:
audio
.
AudioRendererChangeInfoArray
)
=>
{
for
(
let
i
=
0
;
i
<
AudioRendererChangeInfoArray
.
length
;
i
++
)
{
let
AudioRendererChangeInfo
=
AudioRendererChangeInfoArray
[
i
];
let
AudioRendererChangeInfo
:
audio
.
AudioRendererChangeInfo
=
AudioRendererChangeInfoArray
[
i
];
console
.
info
(
`## RendererChange on is called for
${
i
}
##`
);
console
.
info
(
`StreamId for
${
i
}
is:
${
AudioRendererChangeInfo
.
streamId
}
`
);
console
.
info
(
`ClientUid for
${
i
}
is:
${
AudioRendererChangeInfo
.
clientUid
}
`
);
console
.
info
(
`Content
${
i
}
is:
${
AudioRendererChangeInfo
.
rendererInfo
.
content
}
`
);
console
.
info
(
`Stream
${
i
}
is:
${
AudioRendererChangeInfo
.
rendererInfo
.
usage
}
`
);
console
.
info
(
`Flag
${
i
}
is:
${
AudioRendererChangeInfo
.
rendererInfo
.
rendererFlags
}
`
);
console
.
info
(
`State for
${
i
}
is:
${
AudioRendererChangeInfo
.
rendererState
}
`
);
console
.
info
(
`Flag
${
i
}
is:
${
AudioRendererChangeInfo
.
rendererInfo
.
rendererFlags
}
`
);
console
.
info
(
`State for
${
i
}
is:
${
AudioRendererChangeInfo
.
rendererState
}
`
);
for
(
let
j
=
0
;
j
<
AudioRendererChangeInfo
.
deviceDescriptors
.
length
;
j
++
)
{
console
.
info
(
`Id:
${
i
}
:
${
AudioRendererChangeInfo
.
deviceDescriptors
[
j
].
id
}
`
);
console
.
info
(
`Type:
${
i
}
:
${
AudioRendererChangeInfo
.
deviceDescriptors
[
j
].
deviceType
}
`
);
...
...
@@ -3561,7 +3607,7 @@ off(type: 'audioRendererChange'): void
**示例:**
```
j
s
```
t
s
audioStreamManager
.
off
(
'
audioRendererChange
'
);
console
.
info
(
'
######### RendererChange Off is called #########
'
);
```
...
...
@@ -3591,16 +3637,16 @@ on(type: 'audioCapturerChange', callback: Callback<AudioCapturerChangeInfoArr
**示例:**
```
j
s
audioStreamManager
.
on
(
'
audioCapturerChange
'
,
(
AudioCapturerChangeInfoArray
)
=>
{
```
t
s
audioStreamManager
.
on
(
'
audioCapturerChange
'
,
(
AudioCapturerChangeInfoArray
:
audio
.
AudioCapturerChangeInfoArray
)
=>
{
for
(
let
i
=
0
;
i
<
AudioCapturerChangeInfoArray
.
length
;
i
++
)
{
console
.
info
(
`## CapChange on is called for element
${
i
}
##`
);
console
.
info
(
`StreamId for
${
i
}
is:
${
AudioCapturerChangeInfoArray
[
i
].
streamId
}
`
);
console
.
info
(
`ClientUid for
${
i
}
is:
${
AudioCapturerChangeInfoArray
[
i
].
clientUid
}
`
);
console
.
info
(
`Source for
${
i
}
is:
${
AudioCapturerChangeInfoArray
[
i
].
capturerInfo
.
source
}
`
);
console
.
info
(
`Flag
${
i
}
is:
${
AudioCapturerChangeInfoArray
[
i
].
capturerInfo
.
capturerFlags
}
`
);
console
.
info
(
`State for
${
i
}
is:
${
AudioCapturerChangeInfoArray
[
i
].
capturerState
}
`
);
let
devDescriptor
=
AudioCapturerChangeInfoArray
[
i
].
deviceDescriptors
;
console
.
info
(
`State for
${
i
}
is:
${
AudioCapturerChangeInfoArray
[
i
].
capturerState
}
`
);
let
devDescriptor
:
audio
.
AudioCapturerChangeInfo
=
AudioCapturerChangeInfoArray
[
i
].
deviceDescriptors
;
for
(
let
j
=
0
;
j
<
AudioCapturerChangeInfoArray
[
i
].
deviceDescriptors
.
length
;
j
++
)
{
console
.
info
(
`Id:
${
i
}
:
${
AudioCapturerChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
id
}
`
);
console
.
info
(
`Type:
${
i
}
:
${
AudioCapturerChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
deviceType
}
`
);
...
...
@@ -3639,7 +3685,7 @@ off(type: 'audioCapturerChange'): void;
**示例:**
```
j
s
```
t
s
audioStreamManager
.
off
(
'
audioCapturerChange
'
);
console
.
info
(
'
######### CapturerChange Off is called #########
'
);
...
...
@@ -3662,12 +3708,13 @@ isActive(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): v
**示例:**
```
js
audioStreamManager
.
isActive
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
,
value
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the active status of the stream.
${
err
}
`
);
return
;
}
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioStreamManager
.
isActive
(
audio
.
AudioVolumeType
.
MEDIA
,
(
err
:
BusinessError
,
value
:
boolean
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the active status of the stream.
${
err
}
`
);
return
;
}
console
.
info
(
`Callback invoked to indicate that the active status of the stream is obtained
${
value
}
.`
);
});
```
...
...
@@ -3694,8 +3741,8 @@ isActive(volumeType: AudioVolumeType): Promise<boolean>
**示例:**
```
j
s
audioStreamManager
.
isActive
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
value
)
=>
{
```
t
s
audioStreamManager
.
isActive
(
audio
.
AudioVolumeType
.
MEDIA
).
then
((
value
:
boolean
)
=>
{
console
.
info
(
`Promise returned to indicate that the active status of the stream is obtained
${
value
}
.`
);
});
```
...
...
@@ -3725,8 +3772,9 @@ getAudioEffectInfoArray(usage: StreamUsage, callback: AsyncCallback<AudioEffe
**示例:**
```
js
audioStreamManager
.
getAudioEffectInfoArray
(
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
,
async
(
err
,
audioEffectInfoArray
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioStreamManager
.
getAudioEffectInfoArray
(
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
,
async
(
err
:
BusinessError
,
audioEffectInfoArray
:
audio
.
AudioEffectInfoArray
)
=>
{
console
.
info
(
'
getAudioEffectInfoArray **** Get Callback Called ****
'
);
if
(
err
)
{
console
.
error
(
`getAudioEffectInfoArray :ERROR:
${
err
}
`
);
...
...
@@ -3767,11 +3815,12 @@ getAudioEffectInfoArray(usage: StreamUsage): Promise<AudioEffectInfoArray>
**示例:**
```
js
audioStreamManager
.
getAudioEffectInfoArray
(
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
).
then
((
audioEffectInfoArray
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioStreamManager
.
getAudioEffectInfoArray
(
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
).
then
((
audioEffectInfoArray
:
audio
.
AudioEffectInfoArray
)
=>
{
console
.
info
(
'
getAudioEffectInfoArray ######### Get Promise is called ##########
'
);
console
.
info
(
`The effect modes are:
${
audioEffectInfoArray
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`getAudioEffectInfoArray :ERROR:
${
err
}
`
);
});
```
...
...
@@ -3797,8 +3846,9 @@ getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback<AudioDeviceDescrip
**示例:**
```
js
audioRoutingManager
.
getDevices
(
audio
.
DeviceFlag
.
OUTPUT_DEVICES_FLAG
,
(
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRoutingManager
.
getDevices
(
audio
.
DeviceFlag
.
OUTPUT_DEVICES_FLAG
,
(
err
:
BusinessError
,
value
:
audio
.
AudioDeviceDescriptors
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the device list.
${
err
}
`
);
return
;
...
...
@@ -3829,8 +3879,8 @@ getDevices(deviceFlag: DeviceFlag): Promise<AudioDeviceDescriptors>
**示例:**
```
j
s
audioRoutingManager
.
getDevices
(
audio
.
DeviceFlag
.
OUTPUT_DEVICES_FLAG
).
then
((
data
)
=>
{
```
t
s
audioRoutingManager
.
getDevices
(
audio
.
DeviceFlag
.
OUTPUT_DEVICES_FLAG
).
then
((
data
:
audio
.
AudioDeviceDescriptors
)
=>
{
console
.
info
(
'
Promise returned to indicate that the device list is obtained.
'
);
});
```
...
...
@@ -3861,8 +3911,8 @@ on(type: 'deviceChange', deviceFlag: DeviceFlag, callback: Callback<DeviceChange
**示例:**
```
j
s
audioRoutingManager
.
on
(
'
deviceChange
'
,
audio
.
DeviceFlag
.
OUTPUT_DEVICES_FLAG
,
(
deviceChanged
)
=>
{
```
t
s
audioRoutingManager
.
on
(
'
deviceChange
'
,
audio
.
DeviceFlag
.
OUTPUT_DEVICES_FLAG
,
(
deviceChanged
:
audio
.
DeviceChangeAction
)
=>
{
console
.
info
(
'
device change type :
'
+
deviceChanged
.
type
);
console
.
info
(
'
device descriptor size :
'
+
deviceChanged
.
deviceDescriptors
.
length
);
console
.
info
(
'
device change descriptor :
'
+
deviceChanged
.
deviceDescriptors
[
0
].
deviceRole
);
...
...
@@ -3895,7 +3945,7 @@ off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void
**示例:**
```
j
s
```
t
s
audioRoutingManager
.
off
(
'
deviceChange
'
);
```
...
...
@@ -3917,28 +3967,31 @@ selectInputDevice(inputAudioDevices: AudioDeviceDescriptors, callback: AsyncCall
| callback | AsyncCallback
<
void
>
| 是 | 回调,返回选择输入设备结果。 |
**示例:**
```
js
let
inputAudioDeviceDescriptor
=
[{
deviceRole
:
audio
.
DeviceRole
.
INPUT_DEVICE
,
deviceType
:
audio
.
DeviceType
.
EARPIECE
,
id
:
1
,
name
:
""
,
address
:
""
,
sampleRates
:
[
44100
],
channelCounts
:
[
2
],
channelMasks
:
[
0
],
networkId
:
audio
.
LOCAL_NETWORK_ID
,
interruptGroupId
:
1
,
volumeGroupId
:
1
,
displayName
:
""
,
```
ts
import
audio
from
'
@ohos.multimedia.audio
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
inputAudioDeviceDescriptor
:
audio
.
AudioDeviceDescriptors
=
[{
deviceRole
:
audio
.
DeviceRole
.
INPUT_DEVICE
,
deviceType
:
audio
.
DeviceType
.
EARPIECE
,
id
:
1
,
name
:
""
,
address
:
""
,
sampleRates
:
[
44100
],
channelCounts
:
[
2
],
channelMasks
:
[
0
],
networkId
:
audio
.
LOCAL_NETWORK_ID
,
interruptGroupId
:
1
,
volumeGroupId
:
1
,
displayName
:
""
,
}];
async
function
selectInputDevice
(){
audioRoutingManager
.
selectInputDevice
(
inputAudioDeviceDescriptor
,
(
err
)
=>
{
audioRoutingManager
.
selectInputDevice
(
inputAudioDeviceDescriptor
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Result ERROR:
${
err
}
`
);
}
else
{
console
.
info
(
'
Select input devices result callback: SUCCESS
'
);
}
console
.
info
(
'
Select input devices result callback: SUCCESS
'
);
}
});
}
```
...
...
@@ -3967,28 +4020,30 @@ selectInputDevice(inputAudioDevices: AudioDeviceDescriptors): Promise<void>
**示例:**
```
js
let
inputAudioDeviceDescriptor
=
[{
deviceRole
:
audio
.
DeviceRole
.
INPUT_DEVICE
,
deviceType
:
audio
.
DeviceType
.
EARPIECE
,
id
:
1
,
name
:
""
,
address
:
""
,
sampleRates
:
[
44100
],
channelCounts
:
[
2
],
channelMasks
:
[
0
],
networkId
:
audio
.
LOCAL_NETWORK_ID
,
interruptGroupId
:
1
,
volumeGroupId
:
1
,
displayName
:
""
,
```
ts
import
audio
from
'
@ohos.multimedia.audio
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
inputAudioDeviceDescriptor
:
audio
.
AudioDeviceDescriptors
=
[{
deviceRole
:
audio
.
DeviceRole
.
INPUT_DEVICE
,
deviceType
:
audio
.
DeviceType
.
EARPIECE
,
id
:
1
,
name
:
""
,
address
:
""
,
sampleRates
:
[
44100
],
channelCounts
:
[
2
],
channelMasks
:
[
0
],
networkId
:
audio
.
LOCAL_NETWORK_ID
,
interruptGroupId
:
1
,
volumeGroupId
:
1
,
displayName
:
""
,
}];
async
function
getRoutingManager
(){
audioRoutingManager
.
selectInputDevice
(
inputAudioDeviceDescriptor
).
then
(()
=>
{
console
.
info
(
'
Select input devices result promise: SUCCESS
'
);
}).
catch
((
er
r
)
=>
{
console
.
error
(
`Result ERROR:
${
err
}
`
);
});
audioRoutingManager
.
selectInputDevice
(
inputAudioDeviceDescriptor
).
then
(()
=>
{
console
.
info
(
'
Select input devices result promise: SUCCESS
'
);
}).
catch
((
err
:
BusinessErro
r
)
=>
{
console
.
error
(
`Result ERROR:
${
err
}
`
);
});
}
```
...
...
@@ -4010,8 +4065,9 @@ setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean, cal
**示例:**
```
js
audioRoutingManager
.
setCommunicationDevice
(
audio
.
CommunicationDeviceType
.
SPEAKER
,
true
,
(
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRoutingManager
.
setCommunicationDevice
(
audio
.
CommunicationDeviceType
.
SPEAKER
,
true
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to set the active status of the device.
${
err
}
`
);
return
;
...
...
@@ -4043,7 +4099,7 @@ setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean): Pr
**示例:**
```
j
s
```
t
s
audioRoutingManager
.
setCommunicationDevice
(
audio
.
CommunicationDeviceType
.
SPEAKER
,
true
).
then
(()
=>
{
console
.
info
(
'
Promise returned to indicate that the device is set to the active status.
'
);
});
...
...
@@ -4066,8 +4122,9 @@ isCommunicationDeviceActive(deviceType: CommunicationDeviceType, callback: Async
**示例:**
```
js
audioRoutingManager
.
isCommunicationDeviceActive
(
audio
.
CommunicationDeviceType
.
SPEAKER
,
(
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRoutingManager
.
isCommunicationDeviceActive
(
audio
.
CommunicationDeviceType
.
SPEAKER
,
(
err
:
BusinessError
,
value
:
boolean
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to obtain the active status of the device.
${
err
}
`
);
return
;
...
...
@@ -4098,8 +4155,8 @@ isCommunicationDeviceActive(deviceType: CommunicationDeviceType): Promise<boo
**示例:**
```
j
s
audioRoutingManager
.
isCommunicationDeviceActive
(
audio
.
CommunicationDeviceType
.
SPEAKER
).
then
((
value
)
=>
{
```
t
s
audioRoutingManager
.
isCommunicationDeviceActive
(
audio
.
CommunicationDeviceType
.
SPEAKER
).
then
((
value
:
boolean
)
=>
{
console
.
info
(
`Promise returned to indicate that the active status of the device is obtained
${
value
}
.`
);
});
```
...
...
@@ -4122,24 +4179,26 @@ selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCa
| callback | AsyncCallback
<
void
>
| 是 | 回调,返回获取输出设备结果。 |
**示例:**
```
js
let
outputAudioDeviceDescriptor
=
[{
deviceRole
:
audio
.
DeviceRole
.
OUTPUT_DEVICE
,
deviceType
:
audio
.
DeviceType
.
SPEAKER
,
id
:
1
,
name
:
""
,
address
:
""
,
sampleRates
:
[
44100
],
channelCounts
:
[
2
],
channelMasks
:
[
0
],
networkId
:
audio
.
LOCAL_NETWORK_ID
,
interruptGroupId
:
1
,
volumeGroupId
:
1
,
displayName
:
""
,
```
ts
import
audio
from
'
@ohos.multimedia.audio
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
outputAudioDeviceDescriptor
:
audio
.
AudioDeviceDescriptors
=
[{
deviceRole
:
audio
.
DeviceRole
.
OUTPUT_DEVICE
,
deviceType
:
audio
.
DeviceType
.
SPEAKER
,
id
:
1
,
name
:
""
,
address
:
""
,
sampleRates
:
[
44100
],
channelCounts
:
[
2
],
channelMasks
:
[
0
],
networkId
:
audio
.
LOCAL_NETWORK_ID
,
interruptGroupId
:
1
,
volumeGroupId
:
1
,
displayName
:
""
,
}];
async
function
selectOutputDevice
(){
audioRoutingManager
.
selectOutputDevice
(
outputAudioDeviceDescriptor
,
(
err
)
=>
{
audioRoutingManager
.
selectOutputDevice
(
outputAudioDeviceDescriptor
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Result ERROR:
${
err
}
`
);
}
else
{
...
...
@@ -4172,26 +4231,28 @@ selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors): Promise<void&
**示例:**
```
js
let
outputAudioDeviceDescriptor
=
[{
deviceRole
:
audio
.
DeviceRole
.
OUTPUT_DEVICE
,
deviceType
:
audio
.
DeviceType
.
SPEAKER
,
id
:
1
,
name
:
""
,
address
:
""
,
sampleRates
:
[
44100
],
channelCounts
:
[
2
],
channelMasks
:
[
0
],
networkId
:
audio
.
LOCAL_NETWORK_ID
,
interruptGroupId
:
1
,
volumeGroupId
:
1
,
displayName
:
""
,
```
ts
import
audio
from
'
@ohos.multimedia.audio
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
outputAudioDeviceDescriptor
:
audio
.
AudioDeviceDescriptors
=
[{
deviceRole
:
audio
.
DeviceRole
.
OUTPUT_DEVICE
,
deviceType
:
audio
.
DeviceType
.
SPEAKER
,
id
:
1
,
name
:
""
,
address
:
""
,
sampleRates
:
[
44100
],
channelCounts
:
[
2
],
channelMasks
:
[
0
],
networkId
:
audio
.
LOCAL_NETWORK_ID
,
interruptGroupId
:
1
,
volumeGroupId
:
1
,
displayName
:
""
,
}];
async
function
selectOutputDevice
(){
audioRoutingManager
.
selectOutputDevice
(
outputAudioDeviceDescriptor
).
then
(()
=>
{
console
.
info
(
'
Select output devices result promise: SUCCESS
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Result ERROR:
${
err
}
`
);
});
}
...
...
@@ -4216,32 +4277,36 @@ selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: Audi
| callback | AsyncCallback
<
void
>
| 是 | 回调,返回获取输出设备结果。 |
**示例:**
```
js
let
outputAudioRendererFilter
=
{
```
ts
import
audio
from
'
@ohos.multimedia.audio
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
outputAudioRendererFilter
:
audio
.
AudioRendererFilter
=
{
uid
:
20010041
,
rendererInfo
:
{
content
:
audio
.
ContentType
.
CONTENT_TYPE_MUSIC
,
usage
:
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
,
rendererFlags
:
0
},
rendererId
:
0
};
let
outputAudioDeviceDescriptor
=
[{
deviceRole
:
audio
.
DeviceRole
.
OUTPUT_DEVICE
,
deviceType
:
audio
.
DeviceType
.
SPEAKER
,
id
:
1
,
name
:
""
,
address
:
""
,
sampleRates
:
[
44100
],
channelCounts
:
[
2
],
channelMasks
:
[
0
],
networkId
:
audio
.
LOCAL_NETWORK_ID
,
interruptGroupId
:
1
,
volumeGroupId
:
1
,
displayName
:
""
,
rendererFlags
:
0
},
rendererId
:
0
};
let
outputAudioDeviceDescriptor
:
audio
.
AudioDeviceDescriptors
=
[{
deviceRole
:
audio
.
DeviceRole
.
OUTPUT_DEVICE
,
deviceType
:
audio
.
DeviceType
.
SPEAKER
,
id
:
1
,
name
:
""
,
address
:
""
,
sampleRates
:
[
44100
],
channelCounts
:
[
2
],
channelMasks
:
[
0
],
networkId
:
audio
.
LOCAL_NETWORK_ID
,
interruptGroupId
:
1
,
volumeGroupId
:
1
,
displayName
:
""
,
}];
async
function
selectOutputDeviceByFilter
(){
audioRoutingManager
.
selectOutputDeviceByFilter
(
outputAudioRendererFilter
,
outputAudioDeviceDescriptor
,
(
err
)
=>
{
audioRoutingManager
.
selectOutputDeviceByFilter
(
outputAudioRendererFilter
,
outputAudioDeviceDescriptor
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Result ERROR:
${
err
}
`
);
}
else
{
...
...
@@ -4275,34 +4340,38 @@ selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: Audi
**示例:**
```
js
let
outputAudioRendererFilter
=
{
```
ts
import
audio
from
'
@ohos.multimedia.audio
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
outputAudioRendererFilter
:
audio
.
AudioRendererFilter
=
{
uid
:
20010041
,
rendererInfo
:
{
content
:
audio
.
ContentType
.
CONTENT_TYPE_MUSIC
,
usage
:
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
,
rendererFlags
:
0
},
rendererId
:
0
};
let
outputAudioDeviceDescriptor
=
[{
deviceRole
:
audio
.
DeviceRole
.
OUTPUT_DEVICE
,
deviceType
:
audio
.
DeviceType
.
SPEAKER
,
id
:
1
,
name
:
""
,
address
:
""
,
sampleRates
:
[
44100
],
channelCounts
:
[
2
],
channelMasks
:
[
0
],
networkId
:
audio
.
LOCAL_NETWORK_ID
,
interruptGroupId
:
1
,
volumeGroupId
:
1
,
displayName
:
""
,
rendererFlags
:
0
},
rendererId
:
0
};
let
outputAudioDeviceDescriptor
:
audio
.
AudioDeviceDescriptors
=
[{
deviceRole
:
audio
.
DeviceRole
.
OUTPUT_DEVICE
,
deviceType
:
audio
.
DeviceType
.
SPEAKER
,
id
:
1
,
name
:
""
,
address
:
""
,
sampleRates
:
[
44100
],
channelCounts
:
[
2
],
channelMasks
:
[
0
],
networkId
:
audio
.
LOCAL_NETWORK_ID
,
interruptGroupId
:
1
,
volumeGroupId
:
1
,
displayName
:
""
,
}];
async
function
selectOutputDeviceByFilter
(){
audioRoutingManager
.
selectOutputDeviceByFilter
(
outputAudioRendererFilter
,
outputAudioDeviceDescriptor
).
then
(()
=>
{
console
.
info
(
'
Select output devices by filter result promise: SUCCESS
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Result ERROR:
${
err
}
`
);
})
}
...
...
@@ -4333,14 +4402,17 @@ getPreferredOutputDeviceForRendererInfo(rendererInfo: AudioRendererInfo, callbac
| 6800301 | System error. Return by callback. |
**示例:**
```
js
let
rendererInfo
=
{
content
:
audio
.
ContentType
.
CONTENT_TYPE_MUSIC
,
usage
:
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
,
rendererFlags
:
0
}
```
ts
import
audio
from
'
@ohos.multimedia.audio
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
rendererInfo
:
audio
.
AudioRendererInfo
=
{
content
:
audio
.
ContentType
.
CONTENT_TYPE_MUSIC
,
usage
:
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
,
rendererFlags
:
0
}
async
function
getPreferredOutputDevice
()
{
audioRoutingManager
.
getPreferredOutputDeviceForRendererInfo
(
rendererInfo
,
(
err
,
desc
)
=>
{
audioRoutingManager
.
getPreferredOutputDeviceForRendererInfo
(
rendererInfo
,
(
err
:
BusinessError
,
desc
:
audio
.
AudioDeviceDescriptors
)
=>
{
if
(
err
)
{
console
.
error
(
`Result ERROR:
${
err
}
`
);
}
else
{
...
...
@@ -4380,16 +4452,19 @@ getPreferredOutputDeviceForRendererInfo(rendererInfo: AudioRendererInfo): Promis
**示例:**
```
js
let
rendererInfo
=
{
content
:
audio
.
ContentType
.
CONTENT_TYPE_MUSIC
,
usage
:
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
,
rendererFlags
:
0
}
```
ts
import
audio
from
'
@ohos.multimedia.audio
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
rendererInfo
:
audio
.
AudioRendererInfo
=
{
content
:
audio
.
ContentType
.
CONTENT_TYPE_MUSIC
,
usage
:
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
,
rendererFlags
:
0
}
async
function
getPreferredOutputDevice
()
{
audioRoutingManager
.
getPreferredOutputDeviceForRendererInfo
(
rendererInfo
).
then
((
desc
)
=>
{
audioRoutingManager
.
getPreferredOutputDeviceForRendererInfo
(
rendererInfo
).
then
((
desc
:
audio
.
AudioDeviceDescriptors
)
=>
{
console
.
info
(
`device descriptor:
${
desc
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Result ERROR:
${
err
}
`
);
})
}
...
...
@@ -4421,13 +4496,15 @@ on(type: 'preferredOutputDeviceChangeForRendererInfo', rendererInfo: AudioRender
**示例:**
```
js
let
rendererInfo
=
{
content
:
audio
.
ContentType
.
CONTENT_TYPE_MUSIC
,
usage
:
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
,
rendererFlags
:
0
}
```
ts
import
audio
from
'
@ohos.multimedia.audio
'
;
let
rendererInfo
:
audio
.
AudioRendererInfo
=
{
content
:
audio
.
ContentType
.
CONTENT_TYPE_MUSIC
,
usage
:
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
,
rendererFlags
:
0
}
audioRoutingManager
.
on
(
'
preferredOutputDeviceChangeForRendererInfo
'
,
rendererInfo
,
(
desc
)
=>
{
audioRoutingManager
.
on
(
'
preferredOutputDeviceChangeForRendererInfo
'
,
rendererInfo
,
(
desc
:
audio
.
AudioDeviceDescriptors
)
=>
{
console
.
info
(
`device descriptor:
${
desc
}
`
);
});
```
...
...
@@ -4457,7 +4534,7 @@ off(type: 'preferredOutputDeviceChangeForRendererInfo', callback?: Callback<Audi
**示例:**
```
j
s
```
t
s
audioRoutingManager
.
off
(
'
preferredOutputDeviceChangeForRendererInfo
'
);
```
...
...
@@ -4486,13 +4563,15 @@ getPreferredInputDeviceForCapturerInfo(capturerInfo: AudioCapturerInfo, callback
| 6800301 | System error. Return by callback. |
**示例:**
```
js
let
capturerInfo
=
{
```
ts
import
audio
from
'
@ohos.multimedia.audio
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
capturerInfo
:
audio
.
AudioCapturerInfo
=
{
source
:
audio
.
SourceType
.
SOURCE_TYPE_MIC
,
capturerFlags
:
0
}
audioRoutingManager
.
getPreferredInputDeviceForCapturerInfo
(
capturerInfo
,
(
err
,
desc
)
=>
{
audioRoutingManager
.
getPreferredInputDeviceForCapturerInfo
(
capturerInfo
,
(
err
:
BusinessError
,
desc
:
audio
.
AudioDeviceDescriptors
)
=>
{
if
(
err
)
{
console
.
error
(
`Result ERROR:
${
err
}
`
);
}
else
{
...
...
@@ -4532,17 +4611,19 @@ getPreferredInputDeviceForCapturerInfo(capturerInfo: AudioCapturerInfo): Promise
**示例:**
```
js
let
capturerInfo
=
{
```
ts
import
audio
from
'
@ohos.multimedia.audio
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
capturerInfo
:
audio
.
AudioCapturerInfo
=
{
source
:
audio
.
SourceType
.
SOURCE_TYPE_MIC
,
capturerFlags
:
0
}
audioRoutingManager
.
getPreferredInputDeviceForCapturerInfo
(
capturerInfo
).
then
((
desc
)
=>
{
audioRoutingManager
.
getPreferredInputDeviceForCapturerInfo
(
capturerInfo
).
then
((
desc
:
audio
.
AudioDeviceDescriptors
)
=>
{
console
.
info
(
`device descriptor:
${
desc
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Result ERROR:
${
err
}
`
);
})
})
;
```
### on('preferredInputDeviceChangeForCapturerInfo')<sup>10+</sup>
...
...
@@ -4571,13 +4652,14 @@ on(type: 'preferredInputDeviceChangeForCapturerInfo', capturerInfo: AudioCapture
**示例:**
```
js
let
capturerInfo
=
{
```
ts
import
audio
from
'
@ohos.multimedia.audio
'
;
let
capturerInfo
:
audio
.
AudioCapturerInfo
=
{
source
:
audio
.
SourceType
.
SOURCE_TYPE_MIC
,
capturerFlags
:
0
}
audioRoutingManager
.
on
(
'
preferredInputDeviceChangeForCapturerInfo
'
,
capturerInfo
,
(
desc
)
=>
{
audioRoutingManager
.
on
(
'
preferredInputDeviceChangeForCapturerInfo
'
,
capturerInfo
,
(
desc
:
audio
.
AudioDeviceDescriptors
)
=>
{
console
.
info
(
`device descriptor:
${
desc
}
`
);
});
```
...
...
@@ -4607,7 +4689,7 @@ off(type: 'preferredInputDeviceChangeForCapturerInfo', callback?: Callback<Audio
**示例:**
```
j
s
```
t
s
audioRoutingManager
.
off
(
'
preferredInputDeviceChangeForCapturerInfo
'
);
```
...
...
@@ -4633,8 +4715,7 @@ audioRoutingManager.off('preferredInputDeviceChangeForCapturerInfo');
**示例:**
```
js
```
ts
import
audio
from
'
@ohos.multimedia.audio
'
;
const
audioManager
=
audio
.
getAudioManager
();
...
...
@@ -4650,17 +4731,17 @@ audioStreamManager.on('audioRendererChange', (AudioRendererChangeInfoArray) =>
console
.
info
(
`Stream for
${
i
}
is:
${
AudioRendererChangeInfoArray
[
i
].
rendererInfo
.
usage
}
`
);
console
.
info
(
`Flag
${
i
}
is:
${
AudioRendererChangeInfoArray
[
i
].
rendererInfo
.
rendererFlags
}
`
);
console
.
info
(
`State for
${
i
}
is:
${
AudioRendererChangeInfoArray
[
i
].
rendererState
}
`
);
let
devDescriptor
=
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
;
for
(
let
j
=
0
;
j
<
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
.
length
;
j
++
)
{
console
.
info
(
`Id:
${
i
}
:
${
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
id
}
`
);
console
.
info
(
`Type:
${
i
}
:
${
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
deviceType
}
`
);
console
.
info
(
`Role:
${
i
}
:
${
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
deviceRole
}
`
);
console
.
info
(
`Name:
${
i
}
:
${
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
name
}
`
);
console
.
info
(
`Addr:
${
i
}
:
${
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
address
}
`
);
console
.
info
(
`SR:
${
i
}
:
${
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
sampleRates
[
0
]}
`
);
console
.
info
(
`C
${
i
}
:
${
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
channelCounts
[
0
]}
`
);
console
.
info
(
`CM:
${
i
}
:
${
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
channelMasks
}
`
);
}
let
devDescriptor
=
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
;
for
(
let
j
=
0
;
j
<
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
.
length
;
j
++
)
{
console
.
info
(
`Id:
${
i
}
:
${
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
id
}
`
);
console
.
info
(
`Type:
${
i
}
:
${
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
deviceType
}
`
);
console
.
info
(
`Role:
${
i
}
:
${
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
deviceRole
}
`
);
console
.
info
(
`Name:
${
i
}
:
${
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
name
}
`
);
console
.
info
(
`Addr:
${
i
}
:
${
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
address
}
`
);
console
.
info
(
`SR:
${
i
}
:
${
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
sampleRates
[
0
]}
`
);
console
.
info
(
`C
${
i
}
:
${
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
channelCounts
[
0
]}
`
);
console
.
info
(
`CM:
${
i
}
:
${
AudioRendererChangeInfoArray
[
i
].
deviceDescriptors
[
j
].
channelMasks
}
`
);
}
if
(
AudioRendererChangeInfoArray
[
i
].
rendererState
==
1
&&
devDescriptor
!=
null
)
{
resultFlag
=
true
;
console
.
info
(
`ResultFlag for
${
i
}
is:
${
resultFlag
}
`
);
...
...
@@ -4692,7 +4773,7 @@ audioStreamManager.on('audioRendererChange', (AudioRendererChangeInfoArray) =>
**示例:**
```
j
s
```
t
s
import
audio
from
'
@ohos.multimedia.audio
'
;
const
audioManager
=
audio
.
getAudioManager
();
...
...
@@ -4757,18 +4838,16 @@ audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) =>
**示例:**
```
js
import
audio
from
'
@ohos.multimedia.audio
'
;
function
displayDeviceProp
(
value
)
{
```
ts
function
displayDeviceProp
(
value
:
audio
.
AudioDeviceDescriptor
)
{
deviceRoleValue
=
value
.
deviceRole
;
deviceTypeValue
=
value
.
deviceType
;
}
let
deviceRoleValue
=
null
;
let
deviceTypeValue
=
null
;
let
deviceRoleValue
:
audio
.
DeviceRole
=
null
;
let
deviceTypeValue
:
audio
.
DeviceType
=
null
;
const
promise
=
audio
.
getAudioManager
().
getDevices
(
1
);
promise
.
then
(
function
(
value
)
{
promise
.
then
(
(
value
)
=>
{
console
.
info
(
'
AudioFrameworkTest: Promise: getDevices OUTPUT_DEVICES_FLAG
'
);
value
.
forEach
(
displayDeviceProp
);
if
(
deviceTypeValue
!=
null
&&
deviceRoleValue
!=
null
){
...
...
@@ -4793,14 +4872,17 @@ promise.then(function (value) {
**示例:**
```
js
let
outputAudioRendererFilter
=
{
"
uid
"
:
20010041
,
"
rendererInfo
"
:
{
"
contentType
"
:
audio
.
ContentType
.
CONTENT_TYPE_MUSIC
,
"
streamUsage
"
:
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
,
"
rendererFlags
"
:
0
},
"
rendererId
"
:
0
};
```
ts
import
audio
from
'
@ohos.multimedia.audio
'
;
let
outputAudioRendererFilter
:
audio
.
AudioRendererFilter
=
{
uid
:
20010041
,
rendererInfo
:
{
content
:
audio
.
ContentType
.
CONTENT_TYPE_MUSIC
,
usage
:
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
,
rendererFlags
:
0
},
rendererId
:
0
};
```
## AudioRenderer<sup>8+</sup>
...
...
@@ -4817,8 +4899,8 @@ let outputAudioRendererFilter = {
**示例:**
```
j
s
let
state
=
audioRenderer
.
state
;
```
t
s
let
state
:
audio
.
AudioState
=
audioRenderer
.
state
;
```
### getRendererInfo<sup>8+</sup>
...
...
@@ -4837,8 +4919,9 @@ getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void
**示例:**
```
js
audioRenderer
.
getRendererInfo
((
err
,
rendererInfo
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getRendererInfo
((
err
:
BusinessError
,
rendererInfo
:
audio
.
AudioRendererInfo
)
=>
{
console
.
info
(
'
Renderer GetRendererInfo:
'
);
console
.
info
(
`Renderer content:
${
rendererInfo
.
content
}
`
);
console
.
info
(
`Renderer usage:
${
rendererInfo
.
usage
}
`
);
...
...
@@ -4862,13 +4945,14 @@ getRendererInfo(): Promise<AudioRendererInfo\>
**示例:**
```
js
audioRenderer
.
getRendererInfo
().
then
((
rendererInfo
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getRendererInfo
().
then
((
rendererInfo
:
audio
.
AudioRendererInfo
)
=>
{
console
.
info
(
'
Renderer GetRendererInfo:
'
);
console
.
info
(
`Renderer content:
${
rendererInfo
.
content
}
`
);
console
.
info
(
`Renderer usage:
${
rendererInfo
.
usage
}
`
);
console
.
info
(
`Renderer flags:
${
rendererInfo
.
rendererFlags
}
`
)
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`AudioFrameworkRenderLog: RendererInfo :ERROR:
${
err
}
`
);
});
```
...
...
@@ -4889,8 +4973,9 @@ getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
**示例:**
```
js
audioRenderer
.
getStreamInfo
((
err
,
streamInfo
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getStreamInfo
((
err
:
BusinessError
,
streamInfo
:
audio
.
AudioStreamInfo
)
=>
{
console
.
info
(
'
Renderer GetStreamInfo:
'
);
console
.
info
(
`Renderer sampling rate:
${
streamInfo
.
samplingRate
}
`
);
console
.
info
(
`Renderer channel:
${
streamInfo
.
channels
}
`
);
...
...
@@ -4915,14 +5000,15 @@ getStreamInfo(): Promise<AudioStreamInfo\>
**示例:**
```
js
audioRenderer
.
getStreamInfo
().
then
((
streamInfo
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getStreamInfo
().
then
((
streamInfo
:
audio
.
AudioStreamInfo
)
=>
{
console
.
info
(
'
Renderer GetStreamInfo:
'
);
console
.
info
(
`Renderer sampling rate:
${
streamInfo
.
samplingRate
}
`
);
console
.
info
(
`Renderer channel:
${
streamInfo
.
channels
}
`
);
console
.
info
(
`Renderer format:
${
streamInfo
.
sampleFormat
}
`
);
console
.
info
(
`Renderer encoding type:
${
streamInfo
.
encodingType
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`ERROR:
${
err
}
`
);
});
```
...
...
@@ -4943,8 +5029,9 @@ getAudioStreamId(callback: AsyncCallback<number\>): void
**示例:**
```
js
audioRenderer
.
getAudioStreamId
((
err
,
streamid
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getAudioStreamId
((
err
:
BusinessError
,
streamid
:
number
)
=>
{
console
.
info
(
`Renderer GetStreamId:
${
streamid
}
`
);
});
```
...
...
@@ -4965,10 +5052,11 @@ getAudioStreamId(): Promise<number\>
**示例:**
```
js
audioRenderer
.
getAudioStreamId
().
then
((
streamid
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getAudioStreamId
().
then
((
streamid
:
number
)
=>
{
console
.
info
(
`Renderer getAudioStreamId:
${
streamid
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`ERROR:
${
err
}
`
);
});
```
...
...
@@ -4998,8 +5086,9 @@ setAudioEffectMode(mode: AudioEffectMode, callback: AsyncCallback\<void>): void
**示例:**
```
js
audioRenderer
.
setAudioEffectMode
(
audio
.
AudioEffectMode
.
EFFECT_DEFAULT
,
(
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
setAudioEffectMode
(
audio
.
AudioEffectMode
.
EFFECT_DEFAULT
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
'
Failed to set params
'
);
}
else
{
...
...
@@ -5038,10 +5127,11 @@ setAudioEffectMode(mode: AudioEffectMode): Promise\<void>
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
setAudioEffectMode
(
audio
.
AudioEffectMode
.
EFFECT_DEFAULT
).
then
(()
=>
{
console
.
info
(
'
setAudioEffectMode SUCCESS
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`ERROR:
${
err
}
`
);
});
```
...
...
@@ -5062,8 +5152,9 @@ getAudioEffectMode(callback: AsyncCallback\<AudioEffectMode>): void
**示例:**
```
js
audioRenderer
.
getAudioEffectMode
((
err
,
effectmode
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getAudioEffectMode
((
err
:
BusinessError
,
effectmode
:
audio
.
AudioEffectMode
)
=>
{
if
(
err
)
{
console
.
error
(
'
Failed to get params
'
);
}
else
{
...
...
@@ -5088,10 +5179,11 @@ getAudioEffectMode(): Promise\<AudioEffectMode>
**示例:**
```
js
audioRenderer
.
getAudioEffectMode
().
then
((
effectmode
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getAudioEffectMode
().
then
((
effectmode
:
audio
.
AudioEffectMode
)
=>
{
console
.
info
(
`getAudioEffectMode:
${
effectmode
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`ERROR:
${
err
}
`
);
});
```
...
...
@@ -5112,8 +5204,9 @@ start(callback: AsyncCallback<void\>): void
**示例:**
```
js
audioRenderer
.
start
((
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
start
((
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
'
Renderer start failed.
'
);
}
else
{
...
...
@@ -5138,10 +5231,11 @@ start(): Promise<void\>
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
start
().
then
(()
=>
{
console
.
info
(
'
Renderer started
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`ERROR:
${
err
}
`
);
});
```
...
...
@@ -5162,8 +5256,9 @@ pause(callback: AsyncCallback\<void>): void
**示例:**
```
js
audioRenderer
.
pause
((
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
pause
((
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
'
Renderer pause failed
'
);
}
else
{
...
...
@@ -5188,10 +5283,11 @@ pause(): Promise\<void>
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
pause
().
then
(()
=>
{
console
.
info
(
'
Renderer paused
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`ERROR:
${
err
}
`
);
});
```
...
...
@@ -5212,8 +5308,9 @@ drain(callback: AsyncCallback\<void>): void
**示例:**
```
js
audioRenderer
.
drain
((
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
drain
((
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
'
Renderer drain failed
'
);
}
else
{
...
...
@@ -5238,10 +5335,11 @@ drain(): Promise\<void>
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
drain
().
then
(()
=>
{
console
.
info
(
'
Renderer drained successfully
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`ERROR:
${
err
}
`
);
});
```
...
...
@@ -5262,8 +5360,9 @@ stop(callback: AsyncCallback\<void>): void
**示例:**
```
js
audioRenderer
.
stop
((
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
stop
((
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
'
Renderer stop failed
'
);
}
else
{
...
...
@@ -5288,10 +5387,11 @@ stop(): Promise\<void>
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
stop
().
then
(()
=>
{
console
.
info
(
'
Renderer stopped successfully
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`ERROR:
${
err
}
`
);
});
```
...
...
@@ -5312,8 +5412,9 @@ release(callback: AsyncCallback\<void>): void
**示例:**
```
js
audioRenderer
.
release
((
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
release
((
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
'
Renderer release failed
'
);
}
else
{
...
...
@@ -5338,10 +5439,11 @@ release(): Promise\<void>
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
release
().
then
(()
=>
{
console
.
info
(
'
Renderer released successfully
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`ERROR:
${
err
}
`
);
});
```
...
...
@@ -5363,26 +5465,31 @@ write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void
**示例:**
```
js
let
bufferSize
;
audioRenderer
.
getBufferSize
().
then
((
data
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
bufferSize
:
number
;
class
Options
{
offset
?:
number
;
length
?:
number
;
}
audioRenderer
.
getBufferSize
().
then
((
data
:
number
)
=>
{
console
.
info
(
`AudioFrameworkRenderLog: getBufferSize: SUCCESS
${
data
}
`
);
bufferSize
=
data
;
console
.
info
(
`Buffer size:
${
bufferSize
}
`
);
let
path
=
getContext
().
cacheDir
;
let
filePath
=
path
+
'
/StarWars10s-2C-48000-4SW.wav
'
;
let
file
=
fs
.
openSync
(
filePath
,
fs
.
OpenMode
.
READ_ONLY
);
fs
.
stat
(
filePath
).
then
(
async
(
stat
)
=>
{
let
file
:
fs
.
File
=
fs
.
openSync
(
filePath
,
fs
.
OpenMode
.
READ_ONLY
);
fs
.
stat
(
filePath
).
then
(
async
(
stat
:
fs
.
Stat
)
=>
{
let
buf
=
new
ArrayBuffer
(
bufferSize
);
let
len
=
stat
.
size
%
bufferSize
==
0
?
Math
.
floor
(
stat
.
size
/
bufferSize
)
:
Math
.
floor
(
stat
.
size
/
bufferSize
+
1
);
for
(
let
i
=
0
;
i
<
len
;
i
++
)
{
let
options
=
{
let
options
:
Options
=
{
offset
:
i
*
bufferSize
,
length
:
bufferSize
}
let
readsize
=
await
fs
.
read
(
file
.
fd
,
buf
,
options
)
let
writeSize
=
await
new
Promise
((
resolve
,
reject
)
=>
{
audioRenderer
.
write
(
buf
,(
err
,
writeSize
)
=>
{
let
readsize
:
number
=
await
fs
.
read
(
file
.
fd
,
buf
,
options
)
let
writeSize
:
number
=
await
new
Promise
((
resolve
,
reject
)
=>
{
audioRenderer
.
write
(
buf
,(
err
:
BusinessError
,
writeSize
:
number
)
=>
{
if
(
err
){
reject
(
err
)
}
else
{
...
...
@@ -5392,8 +5499,8 @@ audioRenderer.getBufferSize().then((data)=> {
})
}
});
}).
catch
((
er
r
)
=>
{
console
.
error
(
`AudioFrameworkRenderLog: getBufferSize: ERROR:
${
err
}
`
);
}).
catch
((
err
:
BusinessErro
r
)
=>
{
console
.
error
(
`AudioFrameworkRenderLog: getBufferSize: ERROR:
${
err
}
`
);
});
...
...
@@ -5415,33 +5522,39 @@ write(buffer: ArrayBuffer): Promise\<number>
**示例:**
```
js
let
bufferSize
;
audioRenderer
.
getBufferSize
().
then
((
data
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
bufferSize
:
number
;
class
Options
{
offset
?:
number
;
length
?:
number
;
}
audioRenderer
.
getBufferSize
().
then
((
data
:
number
)
=>
{
console
.
info
(
`AudioFrameworkRenderLog: getBufferSize: SUCCESS
${
data
}
`
);
bufferSize
=
data
;
console
.
info
(
`BufferSize:
${
bufferSize
}
`
);
let
path
=
getContext
().
cacheDir
;
let
filePath
=
path
+
'
/StarWars10s-2C-48000-4SW.wav
'
;
let
file
=
fs
.
openSync
(
filePath
,
fs
.
OpenMode
.
READ_ONLY
);
fs
.
stat
(
filePath
).
then
(
async
(
stat
)
=>
{
let
file
:
fs
.
File
=
fs
.
openSync
(
filePath
,
fs
.
OpenMode
.
READ_ONLY
);
fs
.
stat
(
filePath
).
then
(
async
(
stat
:
fs
.
Stat
)
=>
{
let
buf
=
new
ArrayBuffer
(
bufferSize
);
let
len
=
stat
.
size
%
bufferSize
==
0
?
Math
.
floor
(
stat
.
size
/
bufferSize
)
:
Math
.
floor
(
stat
.
size
/
bufferSize
+
1
);
for
(
let
i
=
0
;
i
<
len
;
i
++
)
{
let
options
=
{
offset
:
i
*
bufferSize
,
length
:
bufferSize
}
let
readsize
=
await
fs
.
read
(
file
.
fd
,
buf
,
options
)
try
{
let
writeSize
=
await
audioRenderer
.
write
(
buf
);
}
catch
(
err
)
{
console
.
error
(
`audioRenderer.write err:
${
err
}
`
);
}
let
options
:
Options
=
{
offset
:
i
*
bufferSize
,
length
:
bufferSize
}
let
readsize
:
number
=
await
fs
.
read
(
file
.
fd
,
buf
,
options
)
try
{
let
writeSize
:
number
=
await
audioRenderer
.
write
(
buf
);
}
catch
(
err
)
{
let
error
:
BusinessError
=
err
;
console
.
error
(
`audioRenderer.write err:
${
error
}
`
);
}
}
});
}).
catch
((
er
r
)
=>
{
console
.
info
(
`AudioFrameworkRenderLog: getBufferSize: ERROR:
${
err
}
`
);
}).
catch
((
err
:
BusinessErro
r
)
=>
{
console
.
info
(
`AudioFrameworkRenderLog: getBufferSize: ERROR:
${
err
}
`
);
});
```
...
...
@@ -5461,8 +5574,9 @@ getAudioTime(callback: AsyncCallback\<number>): void
**示例:**
```
js
audioRenderer
.
getAudioTime
((
err
,
timestamp
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getAudioTime
((
err
:
BusinessError
,
timestamp
:
number
)
=>
{
console
.
info
(
`Current timestamp:
${
timestamp
}
`
);
});
```
...
...
@@ -5483,10 +5597,11 @@ getAudioTime(): Promise\<number>
**示例:**
```
js
audioRenderer
.
getAudioTime
().
then
((
timestamp
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getAudioTime
().
then
((
timestamp
:
number
)
=>
{
console
.
info
(
`Current timestamp:
${
timestamp
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`ERROR:
${
err
}
`
);
});
```
...
...
@@ -5507,10 +5622,15 @@ getBufferSize(callback: AsyncCallback\<number>): void
**示例:**
```
js
let
bufferSize
=
audioRenderer
.
getBufferSize
(
async
(
err
,
bufferSize
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
bufferSize
:
number
;
audioRenderer
.
getBufferSize
((
err
:
BusinessError
,
data
:
number
)
=>
{
if
(
err
)
{
console
.
error
(
'
getBufferSize error
'
);
}
else
{
console
.
info
(
`AudioFrameworkRenderLog: getBufferSize: SUCCESS
${
data
}
`
);
bufferSize
=
data
;
}
});
```
...
...
@@ -5531,12 +5651,13 @@ getBufferSize(): Promise\<number>
**示例:**
```
js
let
bufferSize
;
audioRenderer
.
getBufferSize
().
then
((
data
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
bufferSize
:
number
;
audioRenderer
.
getBufferSize
().
then
((
data
:
number
)
=>
{
console
.
info
(
`AudioFrameworkRenderLog: getBufferSize: SUCCESS
${
data
}
`
);
bufferSize
=
data
;
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`AudioFrameworkRenderLog: getBufferSize: ERROR:
${
err
}
`
);
});
```
...
...
@@ -5558,8 +5679,9 @@ setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\<void>): void
**示例:**
```
js
audioRenderer
.
setRenderRate
(
audio
.
AudioRendererRate
.
RENDER_RATE_NORMAL
,
(
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
setRenderRate
(
audio
.
AudioRendererRate
.
RENDER_RATE_NORMAL
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
'
Failed to set params
'
);
}
else
{
...
...
@@ -5590,10 +5712,11 @@ setRenderRate(rate: AudioRendererRate): Promise\<void>
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
setRenderRate
(
audio
.
AudioRendererRate
.
RENDER_RATE_NORMAL
).
then
(()
=>
{
console
.
info
(
'
setRenderRate SUCCESS
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`ERROR:
${
err
}
`
);
});
```
...
...
@@ -5614,8 +5737,9 @@ getRenderRate(callback: AsyncCallback\<AudioRendererRate>): void
**示例:**
```
js
audioRenderer
.
getRenderRate
((
err
,
renderrate
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getRenderRate
((
err
:
BusinessError
,
renderrate
:
audio
.
AudioRendererRate
)
=>
{
console
.
info
(
`getRenderRate:
${
renderrate
}
`
);
});
```
...
...
@@ -5636,10 +5760,11 @@ getRenderRate(): Promise\<AudioRendererRate>
**示例:**
```
js
audioRenderer
.
getRenderRate
().
then
((
renderRate
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getRenderRate
().
then
((
renderRate
:
audio
.
AudioRendererRate
)
=>
{
console
.
info
(
`getRenderRate:
${
renderRate
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`ERROR:
${
err
}
`
);
});
```
...
...
@@ -5665,11 +5790,12 @@ setInterruptMode(mode: InterruptMode): Promise<void>
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
mode
=
0
;
audioRenderer
.
setInterruptMode
(
mode
).
then
(
data
=>
{
audioRenderer
.
setInterruptMode
(
mode
).
then
(
()
=>
{
console
.
info
(
'
setInterruptMode Success!
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`setInterruptMode Fail:
${
err
}
`
);
});
```
...
...
@@ -5690,9 +5816,10 @@ setInterruptMode(mode: InterruptMode, callback: AsyncCallback\<void>): void
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
mode
=
1
;
audioRenderer
.
setInterruptMode
(
mode
,
(
err
,
data
)
=>
{
audioRenderer
.
setInterruptMode
(
mode
,
(
err
:
BusinessError
)
=>
{
if
(
err
){
console
.
error
(
`setInterruptMode Fail:
${
err
}
`
);
}
...
...
@@ -5722,10 +5849,11 @@ setVolume(volume: number): Promise<void>
**示例:**
```
js
audioRenderer
.
setVolume
(
0.5
).
then
(
data
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
setVolume
(
0.5
).
then
(()
=>
{
console
.
info
(
'
setVolume Success!
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`setVolume Fail:
${
err
}
`
);
});
```
...
...
@@ -5746,8 +5874,9 @@ setVolume(volume: number, callback: AsyncCallback\<void>): void
**示例:**
```
js
audioRenderer
.
setVolume
(
0.5
,
(
err
,
data
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
setVolume
(
0.5
,
(
err
:
BusinessError
)
=>
{
if
(
err
){
console
.
error
(
`setVolume Fail:
${
err
}
`
);
}
...
...
@@ -5771,8 +5900,9 @@ getMinStreamVolume(callback: AsyncCallback<number>): void
**示例:**
```
js
audioRenderer
.
getMinStreamVolume
((
err
,
minVolume
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getMinStreamVolume
((
err
:
BusinessError
,
minVolume
:
number
)
=>
{
if
(
err
)
{
console
.
error
(
`getMinStreamVolume error:
${
err
}
`
);
}
else
{
...
...
@@ -5796,10 +5926,11 @@ getMinStreamVolume(): Promise<number>
**示例:**
```
js
audioRenderer
.
getMinStreamVolume
().
then
((
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getMinStreamVolume
().
then
((
value
:
number
)
=>
{
console
.
info
(
`Get min stream volume Success!
${
value
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Get min stream volume Fail:
${
err
}
`
);
});
```
...
...
@@ -5820,8 +5951,9 @@ getMaxStreamVolume(callback: AsyncCallback<number>): void
**示例:**
```
js
audioRenderer
.
getMaxStreamVolume
((
err
,
maxVolume
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getMaxStreamVolume
((
err
:
BusinessError
,
maxVolume
:
number
)
=>
{
if
(
err
)
{
console
.
error
(
`getMaxStreamVolume Fail:
${
err
}
`
);
}
else
{
...
...
@@ -5845,10 +5977,11 @@ getMaxStreamVolume(): Promise<number>
**示例:**
```
js
audioRenderer
.
getMaxStreamVolume
().
then
((
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getMaxStreamVolume
().
then
((
value
:
number
)
=>
{
console
.
info
(
`Get max stream volume Success!
${
value
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Get max stream volume Fail:
${
err
}
`
);
});
```
...
...
@@ -5869,8 +6002,9 @@ getUnderflowCount(callback: AsyncCallback<number>): void
**示例:**
```
js
audioRenderer
.
getUnderflowCount
((
err
,
underflowCount
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getUnderflowCount
((
err
:
BusinessError
,
underflowCount
:
number
)
=>
{
if
(
err
)
{
console
.
error
(
`getUnderflowCount Fail:
${
err
}
`
);
}
else
{
...
...
@@ -5894,10 +6028,11 @@ getUnderflowCount(): Promise<number>
**示例:**
```
js
audioRenderer
.
getUnderflowCount
().
then
((
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getUnderflowCount
().
then
((
value
:
number
)
=>
{
console
.
info
(
`Get underflow count Success!
${
value
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Get underflow count Fail:
${
err
}
`
);
});
```
...
...
@@ -5918,8 +6053,9 @@ getCurrentOutputDevices(callback: AsyncCallback<AudioDeviceDescriptors>):
**示例:**
```
js
audioRenderer
.
getCurrentOutputDevices
((
err
,
deviceInfo
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getCurrentOutputDevices
((
err
:
BusinessError
,
deviceInfo
:
audio
.
AudioDeviceDescriptors
)
=>
{
if
(
err
)
{
console
.
error
(
`getCurrentOutputDevices Fail:
${
err
}
`
);
}
else
{
...
...
@@ -5950,8 +6086,9 @@ getCurrentOutputDevices(): Promise<AudioDeviceDescriptors>
**示例:**
```
js
audioRenderer
.
getCurrentOutputDevices
().
then
((
deviceInfo
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioRenderer
.
getCurrentOutputDevices
().
then
((
deviceInfo
:
audio
.
AudioDeviceDescriptors
)
=>
{
console
.
info
(
`DeviceInfo id:
${
deviceInfo
[
0
].
id
}
`
);
console
.
info
(
`DeviceInfo type:
${
deviceInfo
[
0
].
deviceType
}
`
);
console
.
info
(
`DeviceInfo role:
${
deviceInfo
[
0
].
deviceRole
}
`
);
...
...
@@ -5960,7 +6097,7 @@ audioRenderer.getCurrentOutputDevices().then((deviceInfo) => {
console
.
info
(
`DeviceInfo samplerates:
${
deviceInfo
[
0
].
sampleRates
[
0
]}
`
);
console
.
info
(
`DeviceInfo channelcounts:
${
deviceInfo
[
0
].
channelCounts
[
0
]}
`
);
console
.
info
(
`DeviceInfo channelmask:
${
deviceInfo
[
0
].
channelMasks
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Get current output devices Fail:
${
err
}
`
);
});
```
...
...
@@ -5992,13 +6129,15 @@ on(type: 'audioInterrupt', callback: Callback\<InterruptEvent>): void
**示例:**
```
js
let
isPlaying
;
// 标识符,表示是否正在渲染
let
isDucked
;
// 标识符,表示是否被降低音量
```
ts
import
audio
from
'
@ohos.multimedia.audio
'
;
let
isPlaying
:
boolean
;
// 标识符,表示是否正在渲染
let
isDucked
:
boolean
;
// 标识符,表示是否被降低音量
onAudioInterrupt
();
async
function
onAudioInterrupt
(){
audioRenderer
.
on
(
'
audioInterrupt
'
,
async
(
i
nterruptEvent
)
=>
{
audioRenderer
.
on
(
'
audioInterrupt
'
,
(
interruptEvent
:
audio
.
I
nterruptEvent
)
=>
{
if
(
interruptEvent
.
forceType
==
audio
.
InterruptForceType
.
INTERRUPT_FORCE
)
{
// 由系统进行操作,强制打断音频渲染,应用需更新自身状态及显示内容等
switch
(
interruptEvent
.
hintType
)
{
...
...
@@ -6057,7 +6196,7 @@ async function onAudioInterrupt(){
default
:
break
;
}
}
}
});
}
```
...
...
@@ -6080,8 +6219,8 @@ on(type: 'markReach', frame: number, callback: Callback<number>): void
**示例:**
```
j
s
audioRenderer
.
on
(
'
markReach
'
,
1000
,
(
position
)
=>
{
```
t
s
audioRenderer
.
on
(
'
markReach
'
,
1000
,
(
position
:
number
)
=>
{
if
(
position
==
1000
)
{
console
.
info
(
'
ON Triggered successfully
'
);
}
...
...
@@ -6105,7 +6244,7 @@ off(type: 'markReach'): void
**示例:**
```
j
s
```
t
s
audioRenderer
.
off
(
'
markReach
'
);
```
...
...
@@ -6127,8 +6266,8 @@ on(type: 'periodReach', frame: number, callback: Callback<number>): void
**示例:**
```
j
s
audioRenderer
.
on
(
'
periodReach
'
,
1000
,
(
position
)
=>
{
```
t
s
audioRenderer
.
on
(
'
periodReach
'
,
1000
,
(
position
:
number
)
=>
{
if
(
position
==
1000
)
{
console
.
info
(
'
ON Triggered successfully
'
);
}
...
...
@@ -6151,7 +6290,7 @@ off(type: 'periodReach'): void
**示例:**
```
j
s
```
t
s
audioRenderer
.
off
(
'
periodReach
'
)
```
...
...
@@ -6172,8 +6311,8 @@ on(type: 'stateChange', callback: Callback<AudioState\>): void
**示例:**
```
j
s
audioRenderer
.
on
(
'
stateChange
'
,
(
state
)
=>
{
```
t
s
audioRenderer
.
on
(
'
stateChange
'
,
(
state
:
audio
.
AudioState
)
=>
{
if
(
state
==
1
)
{
console
.
info
(
'
audio renderer state is: STATE_PREPARED
'
);
}
...
...
@@ -6206,11 +6345,11 @@ on(type: 'outputDeviceChange', callback: Callback\<AudioDeviceDescriptors>): voi
**示例:**
```
j
s
audioRenderer
.
on
(
'
outputDeviceChange
'
,
(
deviceInfo
)
=>
{
console
.
info
(
`DeviceInfo id:
${
deviceInfo
[
0
].
id
}
`
);
console
.
info
(
`DeviceInfo name:
${
deviceInfo
[
0
].
name
}
`
);
console
.
info
(
`DeviceInfo address:
${
deviceInfo
[
0
].
address
}
`
);
```
t
s
audioRenderer
.
on
(
'
outputDeviceChange
'
,
(
deviceInfo
:
audio
.
AudioDeviceDescriptors
)
=>
{
console
.
info
(
`DeviceInfo id:
${
deviceInfo
[
0
].
id
}
`
);
console
.
info
(
`DeviceInfo name:
${
deviceInfo
[
0
].
name
}
`
);
console
.
info
(
`DeviceInfo address:
${
deviceInfo
[
0
].
address
}
`
);
});
```
### off('outputDeviceChange') <sup>10+</sup>
...
...
@@ -6236,11 +6375,11 @@ off(type: 'outputDeviceChange', callback?: Callback\<AudioDeviceDescriptors>): v
**示例:**
```
j
s
audioRenderer
.
off
(
'
outputDeviceChange
'
,
(
deviceInfo
)
=>
{
console
.
info
(
`DeviceInfo id:
${
deviceInfo
[
0
].
id
}
`
);
console
.
info
(
`DeviceInfo name:
${
deviceInfo
[
0
].
name
}
`
);
console
.
info
(
`DeviceInfo address:
${
deviceInfo
[
0
].
address
}
`
);
```
t
s
audioRenderer
.
off
(
'
outputDeviceChange
'
,
(
deviceInfo
:
audio
.
AudioDeviceDescriptors
)
=>
{
console
.
info
(
`DeviceInfo id:
${
deviceInfo
[
0
].
id
}
`
);
console
.
info
(
`DeviceInfo name:
${
deviceInfo
[
0
].
name
}
`
);
console
.
info
(
`DeviceInfo address:
${
deviceInfo
[
0
].
address
}
`
);
});
```
...
...
@@ -6258,8 +6397,8 @@ audioRenderer.off('outputDeviceChange', (deviceInfo) => {
**示例:**
```
j
s
let
state
=
audioCapturer
.
state
;
```
t
s
let
state
:
audio
.
AudioState
=
audioCapturer
.
state
;
```
### getCapturerInfo<sup>8+</sup>
...
...
@@ -6278,8 +6417,9 @@ getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void
**示例:**
```
js
audioCapturer
.
getCapturerInfo
((
err
,
capturerInfo
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioCapturer
.
getCapturerInfo
((
err
:
BusinessError
,
capturerInfo
:
audio
.
AudioCapturerInfo
)
=>
{
if
(
err
)
{
console
.
error
(
'
Failed to get capture info
'
);
}
else
{
...
...
@@ -6307,8 +6447,9 @@ getCapturerInfo(): Promise<AudioCapturerInfo\>
**示例:**
```
js
audioCapturer
.
getCapturerInfo
().
then
((
audioParamsGet
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioCapturer
.
getCapturerInfo
().
then
((
audioParamsGet
:
audio
.
AudioCapturerInfo
)
=>
{
if
(
audioParamsGet
!=
undefined
)
{
console
.
info
(
'
AudioFrameworkRecLog: Capturer CapturerInfo:
'
);
console
.
info
(
`AudioFrameworkRecLog: Capturer SourceType:
${
audioParamsGet
.
source
}
`
);
...
...
@@ -6317,9 +6458,9 @@ audioCapturer.getCapturerInfo().then((audioParamsGet) => {
console
.
info
(
`AudioFrameworkRecLog: audioParamsGet is :
${
audioParamsGet
}
`
);
console
.
info
(
'
AudioFrameworkRecLog: audioParams getCapturerInfo are incorrect
'
);
}
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`AudioFrameworkRecLog: CapturerInfo :ERROR:
${
err
}
`
);
})
;
})
```
### getStreamInfo<sup>8+</sup>
...
...
@@ -6338,8 +6479,9 @@ getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
**示例:**
```
js
audioCapturer
.
getStreamInfo
((
err
,
streamInfo
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioCapturer
.
getStreamInfo
((
err
:
BusinessError
,
streamInfo
:
audio
.
AudioStreamInfo
)
=>
{
if
(
err
)
{
console
.
error
(
'
Failed to get stream info
'
);
}
else
{
...
...
@@ -6368,14 +6510,15 @@ getStreamInfo(): Promise<AudioStreamInfo\>
**示例:**
```
js
audioCapturer
.
getStreamInfo
().
then
((
audioParamsGet
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioCapturer
.
getStreamInfo
().
then
((
audioParamsGet
:
audio
.
AudioStreamInfo
)
=>
{
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
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`getStreamInfo :ERROR:
${
err
}
`
);
});
```
...
...
@@ -6396,8 +6539,9 @@ getAudioStreamId(callback: AsyncCallback<number\>): void
**示例:**
```
js
audioCapturer
.
getAudioStreamId
((
err
,
streamid
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioCapturer
.
getAudioStreamId
((
err
:
BusinessError
,
streamid
:
number
)
=>
{
console
.
info
(
`audioCapturer GetStreamId:
${
streamid
}
`
);
});
```
...
...
@@ -6418,10 +6562,11 @@ getAudioStreamId(): Promise<number\>
**示例:**
```
js
audioCapturer
.
getAudioStreamId
().
then
((
streamid
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioCapturer
.
getAudioStreamId
().
then
((
streamid
:
number
)
=>
{
console
.
info
(
`audioCapturer getAudioStreamId:
${
streamid
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`ERROR:
${
err
}
`
);
});
```
...
...
@@ -6442,8 +6587,9 @@ start(callback: AsyncCallback<void\>): void
**示例:**
```
js
audioCapturer
.
start
((
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioCapturer
.
start
((
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
'
Capturer start failed.
'
);
}
else
{
...
...
@@ -6469,7 +6615,8 @@ start(): Promise<void\>
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioCapturer
.
start
().
then
(()
=>
{
console
.
info
(
'
AudioFrameworkRecLog: ---------START---------
'
);
console
.
info
(
'
AudioFrameworkRecLog: Capturer started: SUCCESS
'
);
...
...
@@ -6478,7 +6625,7 @@ audioCapturer.start().then(() => {
if
((
audioCapturer
.
state
==
audio
.
AudioState
.
STATE_RUNNING
))
{
console
.
info
(
'
AudioFrameworkRecLog: AudioCapturer is in Running State
'
);
}
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
info
(
`AudioFrameworkRecLog: Capturer start :ERROR :
${
err
}
`
);
});
```
...
...
@@ -6499,8 +6646,9 @@ stop(callback: AsyncCallback<void\>): void
**示例:**
```
js
audioCapturer
.
stop
((
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioCapturer
.
stop
((
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
'
Capturer stop failed
'
);
}
else
{
...
...
@@ -6526,14 +6674,15 @@ stop(): Promise<void\>
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioCapturer
.
stop
().
then
(()
=>
{
console
.
info
(
'
AudioFrameworkRecLog: ---------STOP RECORD---------
'
);
console
.
info
(
'
AudioFrameworkRecLog: Capturer stopped: SUCCESS
'
);
if
((
audioCapturer
.
state
==
audio
.
AudioState
.
STATE_STOPPED
)){
console
.
info
(
'
AudioFrameworkRecLog: State is Stopped:
'
);
}
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
info
(
`AudioFrameworkRecLog: Capturer stop: ERROR:
${
err
}
`
);
});
```
...
...
@@ -6554,8 +6703,9 @@ release(callback: AsyncCallback<void\>): void
**示例:**
```
js
audioCapturer
.
release
((
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioCapturer
.
release
((
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
'
capturer release failed
'
);
}
else
{
...
...
@@ -6581,14 +6731,13 @@ release(): Promise<void\>
**示例:**
```
j
s
let
stateFlag
;
```
t
s
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioCapturer
.
release
().
then
(()
=>
{
console
.
info
(
'
AudioFrameworkRecLog: ---------RELEASE RECORD---------
'
);
console
.
info
(
'
AudioFrameworkRecLog: Capturer release : SUCCESS
'
);
console
.
info
(
`AudioFrameworkRecLog: AudioCapturer : STATE :
${
audioCapturer
.
state
}
`
);
console
.
info
(
`AudioFrameworkRecLog: stateFlag :
${
stateFlag
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
info
(
`AudioFrameworkRecLog: Capturer stop: ERROR:
${
err
}
`
);
});
```
...
...
@@ -6611,15 +6760,16 @@ read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\
**示例:**
```
js
let
bufferSize
;
audioCapturer
.
getBufferSize
().
then
((
data
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
bufferSize
:
number
;
audioCapturer
.
getBufferSize
().
then
((
data
:
number
)
=>
{
console
.
info
(
`AudioFrameworkRecLog: getBufferSize: SUCCESS
${
data
}
`
);
bufferSize
=
data
;
}).
catch
((
er
r
)
=>
{
console
.
error
(
`AudioFrameworkRecLog: getBufferSize: ERROR:
${
err
}
`
);
});
audioCapturer
.
read
(
bufferSize
,
true
,
async
(
err
,
buff
er
)
=>
{
}).
catch
((
err
:
BusinessErro
r
)
=>
{
console
.
error
(
`AudioFrameworkRecLog: getBufferSize: ERROR:
${
err
}
`
);
});
audioCapturer
.
read
(
bufferSize
,
true
,
(
err
:
BusinessError
,
buffer
:
numb
er
)
=>
{
if
(
!
err
)
{
console
.
info
(
'
Success in reading the buffer data
'
);
}
...
...
@@ -6649,18 +6799,19 @@ read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
**示例:**
```
js
let
bufferSize
;
audioCapturer
.
getBufferSize
().
then
((
data
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
bufferSize
:
number
;
audioCapturer
.
getBufferSize
().
then
((
data
:
number
)
=>
{
console
.
info
(
`AudioFrameworkRecLog: getBufferSize: SUCCESS
${
data
}
`
);
bufferSize
=
data
;
}).
catch
((
er
r
)
=>
{
}).
catch
((
err
:
BusinessErro
r
)
=>
{
console
.
info
(
`AudioFrameworkRecLog: getBufferSize: ERROR
${
err
}
`
);
});
});
console
.
info
(
`Buffer size:
${
bufferSize
}
`
);
audioCapturer
.
read
(
bufferSize
,
true
).
then
((
buffer
)
=>
{
audioCapturer
.
read
(
bufferSize
,
true
).
then
((
buffer
:
number
)
=>
{
console
.
info
(
'
buffer read successfully
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
info
(
`ERROR :
${
err
}
`
);
});
```
...
...
@@ -6681,8 +6832,9 @@ getAudioTime(callback: AsyncCallback<number\>): void
**示例:**
```
js
audioCapturer
.
getAudioTime
((
err
,
timestamp
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioCapturer
.
getAudioTime
((
err
:
BusinessError
,
timestamp
:
number
)
=>
{
console
.
info
(
`Current timestamp:
${
timestamp
}
`
);
});
```
...
...
@@ -6703,10 +6855,11 @@ getAudioTime(): Promise<number\>
**示例:**
```
js
audioCapturer
.
getAudioTime
().
then
((
audioTime
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioCapturer
.
getAudioTime
().
then
((
audioTime
:
number
)
=>
{
console
.
info
(
`AudioFrameworkRecLog: AudioCapturer getAudioTime : Success
${
audioTime
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
info
(
`AudioFrameworkRecLog: AudioCapturer Created : ERROR :
${
err
}
`
);
});
```
...
...
@@ -6727,13 +6880,14 @@ getBufferSize(callback: AsyncCallback<number\>): void
**示例:**
```
js
audioCapturer
.
getBufferSize
((
err
,
bufferSize
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
audioCapturer
.
getBufferSize
((
err
:
BusinessError
,
bufferSize
:
number
)
=>
{
if
(
!
err
)
{
console
.
info
(
`BufferSize :
${
bufferSize
}
`
);
audioCapturer
.
read
(
bufferSize
,
true
).
then
((
buffer
)
=>
{
audioCapturer
.
read
(
bufferSize
,
true
).
then
((
buffer
:
number
)
=>
{
console
.
info
(
`Buffer read is
${
buffer
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`AudioFrameworkRecLog: AudioCapturer Created : ERROR :
${
err
}
`
);
});
}
...
...
@@ -6756,12 +6910,13 @@ getBufferSize(): Promise<number\>
**示例:**
```
js
let
bufferSize
;
audioCapturer
.
getBufferSize
().
then
((
data
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
bufferSize
:
number
;
audioCapturer
.
getBufferSize
().
then
((
data
:
number
)
=>
{
console
.
info
(
`AudioFrameworkRecLog: getBufferSize :SUCCESS
${
data
}
`
);
bufferSize
=
data
;
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
info
(
`AudioFrameworkRecLog: getBufferSize :ERROR :
${
err
}
`
);
});
```
...
...
@@ -6793,12 +6948,13 @@ on(type: 'audioInterrupt', callback: Callback\<InterruptEvent>): void
**示例:**
```
js
let
isCapturing
;
// 标识符,表示是否正在采集
```
ts
import
audio
from
'
@ohos.multimedia.audio
'
;
let
isCapturing
:
boolean
;
// 标识符,表示是否正在采集
onAudioInterrupt
();
async
function
onAudioInterrupt
(){
audioCapturer
.
on
(
'
audioInterrupt
'
,
async
(
i
nterruptEvent
)
=>
{
audioCapturer
.
on
(
'
audioInterrupt
'
,
(
interruptEvent
:
audio
.
I
nterruptEvent
)
=>
{
if
(
interruptEvent
.
forceType
==
audio
.
InterruptForceType
.
INTERRUPT_FORCE
)
{
// 由系统进行操作,强制打断音频采集,应用需更新自身状态及显示内容等
switch
(
interruptEvent
.
hintType
)
{
...
...
@@ -6837,7 +6993,7 @@ async function onAudioInterrupt(){
default
:
break
;
}
}
}
});
}
```
...
...
@@ -6866,7 +7022,7 @@ off(type: 'audioInterrupt'): void
**示例:**
```
j
s
```
t
s
audioCapturer
.
off
(
'
audioInterrupt
'
);
```
...
...
@@ -6889,8 +7045,8 @@ on(type: 'markReach', frame: number, callback: Callback<number>): void
**示例:**
```
j
s
audioCapturer
.
on
(
'
markReach
'
,
1000
,
(
position
)
=>
{
```
t
s
audioCapturer
.
on
(
'
markReach
'
,
1000
,
(
position
:
number
)
=>
{
if
(
position
==
1000
)
{
console
.
info
(
'
ON Triggered successfully
'
);
}
...
...
@@ -6913,7 +7069,7 @@ off(type: 'markReach'): void
**示例:**
```
j
s
```
t
s
audioCapturer
.
off
(
'
markReach
'
);
```
...
...
@@ -6935,8 +7091,8 @@ on(type: 'periodReach', frame: number, callback: Callback<number>): void
**示例:**
```
j
s
audioCapturer
.
on
(
'
periodReach
'
,
1000
,
(
position
)
=>
{
```
t
s
audioCapturer
.
on
(
'
periodReach
'
,
1000
,
(
position
:
number
)
=>
{
if
(
position
==
1000
)
{
console
.
info
(
'
ON Triggered successfully
'
);
}
...
...
@@ -6959,7 +7115,7 @@ off(type: 'periodReach'): void
**示例:**
```
j
s
```
t
s
audioCapturer
.
off
(
'
periodReach
'
)
```
...
...
@@ -6980,8 +7136,8 @@ on(type: 'stateChange', callback: Callback<AudioState\>): void
**示例:**
```
j
s
audioCapturer
.
on
(
'
stateChange
'
,
(
state
)
=>
{
```
t
s
audioCapturer
.
on
(
'
stateChange
'
,
(
state
:
audio
.
AudioState
)
=>
{
if
(
state
==
1
)
{
console
.
info
(
'
audio capturer state is: STATE_PREPARED
'
);
}
...
...
@@ -7054,8 +7210,9 @@ load(type: ToneType, callback: AsyncCallback<void>): void
**示例:**
```
js
tonePlayer
.
load
(
audio
.
ToneType
.
TONE_TYPE_DIAL_5
,
(
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
tonePlayer
.
load
(
audio
.
ToneType
.
TONE_TYPE_DIAL_5
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`callback call load failed error:
${
err
.
message
}
`
);
return
;
...
...
@@ -7089,7 +7246,7 @@ load(type: ToneType): Promise<void>
**示例:**
```
j
s
```
t
s
tonePlayer
.
load
(
audio
.
ToneType
.
TONE_TYPE_DIAL_1
).
then
(()
=>
{
console
.
info
(
'
promise call load
'
);
}).
catch
(()
=>
{
...
...
@@ -7115,8 +7272,9 @@ start(callback: AsyncCallback<void>): void
**示例:**
```
js
tonePlayer
.
start
((
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
tonePlayer
.
start
((
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`callback call start failed error:
${
err
.
message
}
`
);
return
;
...
...
@@ -7144,7 +7302,7 @@ start(): Promise<void>
**示例:**
```
j
s
```
t
s
tonePlayer
.
start
().
then
(()
=>
{
console
.
info
(
'
promise call start
'
);
}).
catch
(()
=>
{
...
...
@@ -7170,8 +7328,9 @@ stop(callback: AsyncCallback<void>): void
**示例:**
```
js
tonePlayer
.
stop
((
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
tonePlayer
.
stop
((
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`callback call stop error:
${
err
.
message
}
`
);
return
;
...
...
@@ -7199,7 +7358,7 @@ stop(): Promise<void>
**示例:**
```
j
s
```
t
s
tonePlayer
.
stop
().
then
(()
=>
{
console
.
info
(
'
promise call stop finish
'
);
}).
catch
(()
=>
{
...
...
@@ -7225,8 +7384,9 @@ release(callback: AsyncCallback<void>): void
**示例:**
```
js
tonePlayer
.
release
((
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
tonePlayer
.
release
((
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`callback call release failed error:
${
err
.
message
}
`
);
return
;
...
...
@@ -7254,7 +7414,7 @@ release(): Promise<void>
**示例:**
```
j
s
```
t
s
tonePlayer
.
release
().
then
(()
=>
{
console
.
info
(
'
promise call release
'
);
}).
catch
(()
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录