Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
db6ef3c3
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看板
提交
db6ef3c3
编写于
9月 26, 2022
作者:
J
jiao_yanlin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Sample code error modification
Signed-off-by:
N
jiao_yanlin
<
jiaoyanlin@huawei.com
>
上级
edd52ed2
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
16 addition
and
110 deletion
+16
-110
zh-cn/application-dev/reference/apis/js-apis-audio.md
zh-cn/application-dev/reference/apis/js-apis-audio.md
+16
-110
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-audio.md
浏览文件 @
db6ef3c3
...
...
@@ -752,7 +752,7 @@ getRoutingManager(callback: AsyncCallback<AudioRoutingManager>): void
**示例:**
```
js
a
wait
a
udioManager
.
getRoutingManager
((
err
,
callback
)
=>
{
audioManager
.
getRoutingManager
((
err
,
callback
)
=>
{
if
(
err
)
{
console
.
error
(
`Result ERROR:
${
err
}
`
);
}
...
...
@@ -3360,28 +3360,19 @@ AudioRenderChangeInfo数组,只读。
import
audio
from
'
@ohos.multimedia.audio
'
;
var
audioStreamManager
;
var
audioStreamManagerCB
;
var
resultFlag
=
false
;
async
function
getStreamManager
(){
await
audioManager
.
getStreamManager
().
then
(
async
function
(
data
)
{
audioStreamManager
=
data
;
console
.
info
(
'
Get AudioStream Manager : Success
'
);
}).
catch
((
err
)
=>
{
console
.
error
(
`Get AudioStream Manager : ERROR :
${
err
}
`
);
});
}
var
audioManager
=
audio
.
getAudioManager
();
audioManager
.
getStreamManager
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`Get AudioStream Manager : ERROR :
${
err
}
`
);
}
else
{
audioStreamManager
CB
=
data
;
audioStreamManager
=
data
;
console
.
info
(
'
Get AudioStream Manager : Success
'
);
}
});
audioStreamManager
CB
.
on
(
'
audioRendererChange
'
,
(
AudioRendererChangeInfoArray
)
=>
{
audioStreamManager
.
on
(
'
audioRendererChange
'
,
(
AudioRendererChangeInfoArray
)
=>
{
for
(
let
i
=
0
;
i
<
AudioRendererChangeInfoArray
.
length
;
i
++
)
{
console
.
info
(
`## RendererChange on is called for
${
i
}
##`
);
console
.
info
(
`StreamId for
${
i
}
is:
${
AudioRendererChangeInfoArray
[
i
].
streamId
}
`
);
...
...
@@ -3434,6 +3425,16 @@ AudioCapturerChangeInfo数组,只读。
import
audio
from
'
@ohos.multimedia.audio
'
;
const
audioManager
=
audio
.
getAudioManager
();
let
audioStreamManager
;
audioManager
.
getStreamManager
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`getStreamManager : Error:
${
err
}
`
);
}
else
{
console
.
info
(
'
getStreamManager : Success : SUCCESS
'
);
audioStreamManager
=
data
;
}
});
var
resultFlag
=
false
;
audioStreamManager
.
on
(
'
audioCapturerChange
'
,
(
AudioCapturerChangeInfoArray
)
=>
{
for
(
let
i
=
0
;
i
<
AudioCapturerChangeInfoArray
.
length
;
i
++
)
{
...
...
@@ -3926,34 +3927,6 @@ write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void
**示例:**
```
js
import
audio
from
'
@ohos.multimedia.audio
'
;
import
fileio
from
'
@ohos.fileio
'
;
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
audioStreamInfo
=
{
samplingRate
:
audio
.
AudioSamplingRate
.
SAMPLE_RATE_48000
,
channels
:
audio
.
AudioChannel
.
CHANNEL_2
,
sampleFormat
:
audio
.
AudioSampleFormat
.
SAMPLE_FORMAT_S32LE
,
encodingType
:
audio
.
AudioEncodingType
.
ENCODING_TYPE_RAW
}
var
audioRendererInfo
=
{
content
:
audio
.
ContentType
.
CONTENT_TYPE_SPEECH
,
usage
:
audio
.
StreamUsage
.
STREAM_USAGE_VOICE_COMMUNICATION
,
rendererFlags
:
0
}
var
audioRendererOptions
=
{
streamInfo
:
audioStreamInfo
,
rendererInfo
:
audioRendererInfo
}
var
audioRenderer
;
audio
.
createAudioRenderer
(
audioRendererOptions
).
then
((
data
)
=>
{
audioRenderer
=
data
;
console
.
info
(
'
AudioFrameworkRenderLog: AudioRenderer Created: SUCCESS
'
);
}).
catch
((
err
)
=>
{
console
.
error
(
`AudioFrameworkRenderLog: AudioRenderer Created: ERROR:
${
err
}
`
);
});
var
bufferSize
;
audioRenderer
.
getBufferSize
().
then
((
data
)
=>
{
console
.
info
(
`AudioFrameworkRenderLog: getBufferSize: SUCCESS
${
data
}
`
);
...
...
@@ -4034,10 +4007,11 @@ audioRenderer.getBufferSize().then((data) => {
});
console
.
info
(
`BufferSize:
${
bufferSize
}
`
);
var
context
=
featureAbility
.
getContext
();
var
path
;
async
function
getCacheDir
(){
path
=
await
context
.
getCacheDir
();
}
var
filePath
=
'
data
/StarWars10s-2C-48000-4SW.wav
'
;
var
filePath
=
path
+
'
/StarWars10s-2C-48000-4SW.wav
'
;
let
ss
=
fileio
.
createStreamSync
(
filePath
,
'
r
'
);
let
buf
=
new
ArrayBuffer
(
bufferSize
);
ss
.
readSync
(
buf
);
...
...
@@ -4300,26 +4274,6 @@ setInterruptMode(mode: InterruptMode): Promise<void>
**示例:**
```
js
var
audioStreamInfo
=
{
samplingRate
:
audio
.
AudioSamplingRate
.
SAMPLE_RATE_48000
,
channels
:
audio
.
AudioChannel
.
CHANNEL_1
,
sampleFormat
:
audio
.
AudioSampleFormat
.
SAMPLE_FORMAT_S16LE
,
encodingType
:
audio
.
AudioEncodingType
.
ENCODING_TYPE_RAW
}
var
audioRendererInfo
=
{
content
:
audio
.
ContentType
.
CONTENT_TYPE_MUSIC
,
usage
:
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
,
rendererFlags
:
0
}
var
audioRendererOptions
=
{
streamInfo
:
audioStreamInfo
,
rendererInfo
:
audioRendererInfo
}
let
audioRenderer
;
async
function
createAudioRenderer
(){
audioRenderer
=
await
audio
.
createAudioRenderer
(
audioRendererOptions
);
}
let
mode
=
0
;
audioRenderer
.
setInterruptMode
(
mode
).
then
(
data
=>
{
console
.
info
(
'
setInterruptMode Success!
'
);
...
...
@@ -4345,27 +4299,6 @@ setInterruptMode(mode: InterruptMode, callback: AsyncCallback\<void>): void
**示例:**
```
js
var
audioStreamInfo
=
{
samplingRate
:
audio
.
AudioSamplingRate
.
SAMPLE_RATE_48000
,
channels
:
audio
.
AudioChannel
.
CHANNEL_1
,
sampleFormat
:
audio
.
AudioSampleFormat
.
SAMPLE_FORMAT_S16LE
,
encodingType
:
audio
.
AudioEncodingType
.
ENCODING_TYPE_RAW
}
var
audioRendererInfo
=
{
content
:
audio
.
ContentType
.
CONTENT_TYPE_MUSIC
,
usage
:
audio
.
StreamUsage
.
STREAM_USAGE_MEDIA
,
rendererFlags
:
0
}
var
audioRendererOptions
=
{
streamInfo
:
audioStreamInfo
,
rendererInfo
:
audioRendererInfo
}
let
audioRenderer
;
async
function
createAudioRenderer
(){
audioRenderer
=
await
audio
.
createAudioRenderer
(
audioRendererOptions
);
}
let
mode
=
1
;
audioRenderer
.
setInterruptMode
(
mode
,
(
err
,
data
)
=>
{
if
(
err
){
...
...
@@ -4740,33 +4673,6 @@ start(): Promise<void\>
**示例:**
```
js
import
audio
from
'
@ohos.multimedia.audio
'
;
import
fileio
from
'
@ohos.fileio
'
;
var
audioStreamInfo
=
{
samplingRate
:
audio
.
AudioSamplingRate
.
SAMPLE_RATE_44100
,
channels
:
audio
.
AudioChannel
.
CHANNEL_2
,
sampleFormat
:
audio
.
AudioSampleFormat
.
SAMPLE_FORMAT_S16LE
,
encodingType
:
audio
.
AudioEncodingType
.
ENCODING_TYPE_RAW
}
var
audioCapturerInfo
=
{
source
:
audio
.
SourceType
.
SOURCE_TYPE_MIC
,
capturerFlags
:
0
}
var
audioCapturerOptions
=
{
streamInfo
:
audioStreamInfo
,
capturerInfo
:
audioCapturerInfo
}
var
audioCapturer
;
audio
.
createAudioCapturer
(
audioCapturerOptions
).
then
((
data
)
=>
{
audioCapturer
=
data
;
console
.
info
(
'
AudioFrameworkRecLog: AudioCapturer Created: SUCCESS
'
);
}).
catch
((
err
)
=>
{
console
.
info
(
`AudioFrameworkRecLog: AudioCapturer Created: ERROR:
${
err
}
`
);
});
audioCapturer
.
start
().
then
(()
=>
{
console
.
info
(
'
AudioFrameworkRecLog: ---------START---------
'
);
console
.
info
(
'
AudioFrameworkRecLog: Capturer started: SUCCESS
'
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录