Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
4b76f849
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
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看板
未验证
提交
4b76f849
编写于
5月 09, 2022
作者:
杨
杨帅
提交者:
Gitee
5月 09, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Signed-off-by: yangshuai<yangshuai67@huawei.com>
上级
15632dcc
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
112 addition
and
73 deletion
+112
-73
zh-cn/application-dev/media/opensles-playback.md
zh-cn/application-dev/media/opensles-playback.md
+112
-73
未找到文件。
zh-cn/application-dev/media/opensles-playback.md
浏览文件 @
4b76f849
OpenSL ES音频播放开发指导
#
OpenSL ES音频播放开发指导
场景介绍
##
场景介绍
开发者可以通过本文了解到在
OpenHarmony如何使用OpenSL ES进行音频播放相关操作;当前仅实现了部分OpenSL ES接口,未实现接口调用后会返回SL_RESULT_FEATURE_UNSUPPORTED
开发者可以通过本文了解到在
**OpenHarmony**
如何使用
**OpenSL ES**
进行音频播放相关操作;当前仅实现了部分
[
**OpenSL ES**接口
](
https://gitee.com/openharmony/third_party_opensles/blob/master/api/1.0.1/OpenSLES.h
)
,未实现接口调用后会返回
**SL_RESULT_FEATURE_UNSUPPORTED**
开发步骤
##
开发步骤
以下步骤描述了在
OpenHarmony如何使用OpenSL ES
开发音频播放功能:
以下步骤描述了在
**OpenHarmony**
如何使用
**OpenSL ES**
开发音频播放功能:
1.
添加头文件
1.
添加头文件
```
c++
#include <OpenSLES.h>
#include <OpenSLES.h>
#include <OpenSLES_OpenHarmony.h>
#include <OpenSLES_OpenHarmony.h>
#include <OpenSLES_Platform.h>
#include <OpenSLES_Platform.h>
```
2.
使用 slCreateEngine 接口和获取 engine 实例。
2.
使用
**slCreateEngine**
接口和获取
**engine**
实例。
```
c++
SLObjectItf
engineObject
=
nullptr
;
SLObjectItf
engineObject
=
nullptr
;
slCreateEngine
(
&
engineObject
,
0
,
nullptr
,
0
,
nullptr
,
nullptr
);
slCreateEngine
(
&
engineObject
,
0
,
nullptr
,
0
,
nullptr
,
nullptr
);
(
*
engineObject
)
->
Realize
(
engineObject
,
SL_BOOLEAN_FALSE
);
(
*
engineObject
)
->
Realize
(
engineObject
,
SL_BOOLEAN_FALSE
);
```
3.
获取接口 SL_IID_ENGINE 的 engineEngine 实例
3.
获取接口
**SL_IID_ENGINE**
的
**engineEngine**
实例
```
c++
SLEngineItf
engineEngine
=
nullptr
;
SLEngineItf
engineEngine
=
nullptr
;
(
*
engineObject
)
->
GetInterface
(
engineObject
,
SL_IID_ENGINE
,
&
engineEngine
);
(
*
engineObject
)
->
GetInterface
(
engineObject
,
SL_IID_ENGINE
,
&
engineEngine
);
```
4.
配置播放器信息,创建 AudioPlayer 。
4.
配置播放器信息,创建
**AudioPlayer**
。
```
c++
SLDataLocator_BufferQueue
slBufferQueue
=
{
SLDataLocator_BufferQueue
slBufferQueue
=
{
SL_DATALOCATOR_BUFFERQUEUE
,
SL_DATALOCATOR_BUFFERQUEUE
,
0
0
...
@@ -47,12 +64,22 @@ OpenSL ES音频播放开发指导
...
@@ -47,12 +64,22 @@ OpenSL ES音频播放开发指导
SLObjectItf
pcmPlayerObject
=
nullptr
;
SLObjectItf
pcmPlayerObject
=
nullptr
;
(
*
engineEngine
)
->
CreateAudioPlayer
(
engineEngine
,
&
pcmPlayerObject
,
&
slSource
,
null
,
0
,
nullptr
,
nullptr
);
(
*
engineEngine
)
->
CreateAudioPlayer
(
engineEngine
,
&
pcmPlayerObject
,
&
slSource
,
null
,
0
,
nullptr
,
nullptr
);
(
*
pcmPlayerObject
)
->
Realize
(
pcmPlayerObject
,
SL_BOOLEAN_FALSE
);
(
*
pcmPlayerObject
)
->
Realize
(
pcmPlayerObject
,
SL_BOOLEAN_FALSE
);
```
5.
获取接口 SL_IID_OH_BUFFERQUEUE 的 bufferQueueItf 实例
5.
获取接口
**SL_IID_OH_BUFFERQUEUE**
的
**bufferQueueItf**
实例
```
SLOHBufferQueueItf bufferQueueItf;
SLOHBufferQueueItf bufferQueueItf;
(*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_OH_BUFFERQUEUE, &bufferQueueItf);
(*pcmPlayerObject)->GetInterface(pcmPlayerObject, SL_IID_OH_BUFFERQUEUE, &bufferQueueItf);
```
6.
打开音频文件,注册 BuqqerQueueCallback 回调
6.
打开音频文件,注册
**BuqqerQueueCallback**
回调
```
c++
FILE
*
wavFile_
=
nullptr
;
FILE
*
wavFile_
=
nullptr
;
static
void
BuqqerQueueCallback
(
SLOHBufferQueueItf
bufferQueueItf
,
void
*
pContext
,
SLuint32
size
)
static
void
BuqqerQueueCallback
(
SLOHBufferQueueItf
bufferQueueItf
,
void
*
pContext
,
SLuint32
size
)
...
@@ -72,13 +99,25 @@ OpenSL ES音频播放开发指导
...
@@ -72,13 +99,25 @@ OpenSL ES音频播放开发指导
//wavFile_ 需要设置为用户想要播放的文件描述符
//wavFile_ 需要设置为用户想要播放的文件描述符
wavFile_
=
fopen
(
path
,
"rb"
);
wavFile_
=
fopen
(
path
,
"rb"
);
(
*
bufferQueueItf
)
->
RegisterCallback
(
bufferQueueItf
,
BuqqerQueueCallback
,
wavFile_
);
(
*
bufferQueueItf
)
->
RegisterCallback
(
bufferQueueItf
,
BuqqerQueueCallback
,
wavFile_
);
```
7.
获取接口 SL_PLAYSTATE_PLAYING 的 playItf 实例,开始播放
7.
获取接口
**SL_PLAYSTATE_PLAYING**
的
**playItf**
实例,开始播放
```
c++
SLPlayItf
playItf
=
nullptr
;
SLPlayItf
playItf
=
nullptr
;
(
*
pcmPlayerObject
)
->
GetInterface
(
pcmPlayerObject
,
SL_IID_PLAY
,
&
playItf
);
(
*
pcmPlayerObject
)
->
GetInterface
(
pcmPlayerObject
,
SL_IID_PLAY
,
&
playItf
);
(
*
playItf
)
->
SetPlayState
(
playItf
,
SL_PLAYSTATE_PLAYING
);
(
*
playItf
)
->
SetPlayState
(
playItf
,
SL_PLAYSTATE_PLAYING
);
```
8.
结束音频播放
8.
结束音频播放
```
c++
(
*
playItf
)
->
SetPlayState
(
playItf
,
SL_PLAYSTATE_STOPPED
);
(
*
playItf
)
->
SetPlayState
(
playItf
,
SL_PLAYSTATE_STOPPED
);
(
*
pcmPlayerObject
)
->
Destroy
(
pcmPlayerObject
);
(
*
pcmPlayerObject
)
->
Destroy
(
pcmPlayerObject
);
(
*
engineObject
)
->
Destroy
(
engineObject
);
(
*
engineObject
)
->
Destroy
(
engineObject
);
```
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录