佛山英文网建站,自主网站,本站由 今科云平台网站建设技术开发,什么软件可以免费查企业电话OpenSL ES 全称为 Open Sound Library for Embedded Systems#xff0c;是一个嵌入式、跨平台、免费的音频处理库。为嵌入式移动多媒体设备上的应用开发者提供标准化、高性能、低延迟的 API。HarmonyOS 的 Native API 基于Khronos Group开发的OpenSL ES 1.0.1 API 规范实现是一个嵌入式、跨平台、免费的音频处理库。为嵌入式移动多媒体设备上的应用开发者提供标准化、高性能、低延迟的 API。HarmonyOS 的 Native API 基于Khronos Group开发的OpenSL ES 1.0.1 API 规范实现开发者可以通过OpenSLES.h和OpenSLES_OpenHarmony.h在 HarmonyOS 上使用相关 API。 HarmonyOS 上的 OpenSL ES
OpenSL ES 中提供了以下的接口HarmonyOS 当前仅实现了部分OpenSL ES接口可以实现音频播放的基础功能。 调用未实现接口后会返回 SL_RESULT_FEATURE_UNSUPPORTED当前没有相关扩展可以使用。 以下列表列举了 HarmonyOS 上已实现的 OpenSL ES 的接口具体说明请参考OpenSL ES规范 ● HarmonyOS 上支持的 Engine 接口
SLresult (*CreateAudioPlayer) (SLEngineItf self, SLObjectItf * pPlayer, SLDataSource *pAudioSrc, SLDataSink *pAudioSnk, SLuint32 numInterfaces, const SLInterfaceID * pInterfaceIds, const SLboolean * pInterfaceRequired)
○ SLresult (*CreateAudioRecorder) (SLEngineItf self, SLObjectItf * pRecorder, SLDataSource *pAudioSrc, SLDataSink *pAudioSnk, SLuint32 numInterfaces, const SLInterfaceID * pInterfaceIds, const SLboolean * pInterfaceRequired)
○ SLresult (*CreateOutputMix) (SLEngineItf self, SLObjectItf * pMix, SLuint32 numInterfaces, const SLInterfaceID * pInterfaceIds, const SLboolean * pInterfaceRequired) ● HarmonyOS 上支持的 Object 接口SLresult (*Realize) (SLObjectItf self, SLboolean async)
○ SLresult (*GetState) (SLObjectItf self, SLuint32 * pState)
○ SLresult (*GetInterface) (SLObjectItf self, const SLInterfaceID iid, void * pInterface)
○ void (*Destroy) (SLObjectItf self) ● HarmonyOS 上支持的 Playback 接口SLresult (*SetPlayState) (SLPlayItf self, SLuint32 state)
○ SLresult (*GetPlayState) (SLPlayItf self, SLuint32 *pState) ● HarmonyOS 上支持的 Volume 控制接口SLresult (*SetVolumeLevel) (SLVolumeItf self, SLmillibel level)
○ SLresult (*GetVolumeLevel) (SLVolumeItf self, SLmillibel *pLevel)
○ SLresult (*GetMaxVolumeLevel) (SLVolumeItf self, SLmillibel *pMaxLevel) HarmonyOS 上支持的 BufferQueue 接口以下接口需引入OpenSLES_OpenHarmony.h使用。 完整示例
参考以下示例代码播放一个音频文件。
1. 添加头文件。
#include OpenSLES.h#include OpenSLES_OpenHarmony.h#include OpenSLES_Platform.h
2. 使用 slCreateEngine 接口和获取 engine 实例。
SLObjectItf engineObject nullptr;slCreateEngine(engineObject, 0, nullptr, 0, nullptr, nullptr);(*engineObject)-Realize(engineObject, SL_BOOLEAN_FALSE);
3. 获取接口 SL_IID_ENGINE 的 engineEngine 实例。
SLEngineItf engineEngine nullptr;(*engineObject)-GetInterface(engineObject, SL_IID_ENGINE, engineEngine);
4. 配置播放器信息创建 AudioPlayer。
SLDataLocator_BufferQueue slBufferQueue { SL_DATALOCATOR_BUFFERQUEUE, 0};
// 具体参数需要根据音频文件格式进行适配SLDataFormat_PCM pcmFormat { SL_DATAFORMAT_PCM, 2, // 通道数 SL_SAMPLINGRATE_48, // 采样率 SL_PCMSAMPLEFORMAT_FIXED_16, // 音频采样格式 0, 0, 0};SLDataSource slSource {slBufferQueue, pcmFormat};SLObjectItf pcmPlayerObject nullptr;(*engineEngine)-CreateAudioPlayer(engineEngine, pcmPlayerObject, slSource, null, 0, nullptr, nullptr);(*pcmPlayerObject)-Realize(pcmPlayerObject, SL_BOOLEAN_FALSE);
5. 获取接口 SL_IID_OH_BUFFERQUEUE 的 bufferQueueItf 实例。
SLOHBufferQueueItf bufferQueueItf;(*pcmPlayerObject)-GetInterface(pcmPlayerObject, SL_IID_OH_BUFFERQUEUE, bufferQueueItf);
6. 打开音频文件注册 BufferQueueCallback 回调。
static void BufferQueueCallback (SLOHBufferQueueItf bufferQueueItf, void *pContext, SLuint32 size){ SLuint8 *buffer nullptr; SLuint32 pSize; (*bufferQueueItf)-GetBuffer(bufferQueueItf, buffer, pSize); // 将待播放音频数据写入buffer (*bufferQueueItf)-Enqueue(bufferQueueItf, buffer, size);}void *pContext; // 可传入自定义的上下文信息会在Callback内收到(*bufferQueueItf)-RegisterCallback(bufferQueueItf, BufferQueueCallback, pContext);
7. 获取接口 SL_PLAYSTATE_PLAYING 的 playItf 实例开始播放。
SLPlayItf playItf nullptr;(*pcmPlayerObject)-GetInterface(pcmPlayerObject, SL_IID_PLAY, playItf);(*playItf)-SetPlayState(playItf, SL_PLAYSTATE_PLAYING);
8. 结束音频播放。
(*playItf)-SetPlayState(playItf, SL_PLAYSTATE_STOPPED);(*pcmPlayerObject)-Destroy(pcmPlayerObject);(*engineObject)-Destroy(engineObject);
文章转载自: http://www.morning.kpyyf.cn.gov.cn.kpyyf.cn http://www.morning.kxwsn.cn.gov.cn.kxwsn.cn http://www.morning.xzjsb.cn.gov.cn.xzjsb.cn http://www.morning.zlnkq.cn.gov.cn.zlnkq.cn http://www.morning.ggnkt.cn.gov.cn.ggnkt.cn http://www.morning.ljsxg.cn.gov.cn.ljsxg.cn http://www.morning.knlyl.cn.gov.cn.knlyl.cn http://www.morning.bpmns.cn.gov.cn.bpmns.cn http://www.morning.rddlz.cn.gov.cn.rddlz.cn http://www.morning.jypsm.cn.gov.cn.jypsm.cn http://www.morning.fqlxg.cn.gov.cn.fqlxg.cn http://www.morning.myhpj.cn.gov.cn.myhpj.cn http://www.morning.ckctj.cn.gov.cn.ckctj.cn http://www.morning.hrpmt.cn.gov.cn.hrpmt.cn http://www.morning.xpmwt.cn.gov.cn.xpmwt.cn http://www.morning.qzdxy.cn.gov.cn.qzdxy.cn http://www.morning.ydgzj.cn.gov.cn.ydgzj.cn http://www.morning.pngph.cn.gov.cn.pngph.cn http://www.morning.jwxmn.cn.gov.cn.jwxmn.cn http://www.morning.bby45.cn.gov.cn.bby45.cn http://www.morning.hrzhg.cn.gov.cn.hrzhg.cn http://www.morning.hhnhb.cn.gov.cn.hhnhb.cn http://www.morning.nspzy.cn.gov.cn.nspzy.cn http://www.morning.znpyw.cn.gov.cn.znpyw.cn http://www.morning.pxtgf.cn.gov.cn.pxtgf.cn http://www.morning.dbcw.cn.gov.cn.dbcw.cn http://www.morning.nlcw.cn.gov.cn.nlcw.cn http://www.morning.qwwhs.cn.gov.cn.qwwhs.cn http://www.morning.qdscb.cn.gov.cn.qdscb.cn http://www.morning.ylklr.cn.gov.cn.ylklr.cn http://www.morning.ktlxk.cn.gov.cn.ktlxk.cn http://www.morning.lffgs.cn.gov.cn.lffgs.cn http://www.morning.cykqb.cn.gov.cn.cykqb.cn http://www.morning.nzkc.cn.gov.cn.nzkc.cn http://www.morning.rbnj.cn.gov.cn.rbnj.cn http://www.morning.fhbhr.cn.gov.cn.fhbhr.cn http://www.morning.ylljn.cn.gov.cn.ylljn.cn http://www.morning.przc.cn.gov.cn.przc.cn http://www.morning.txgjx.cn.gov.cn.txgjx.cn http://www.morning.qzsmz.cn.gov.cn.qzsmz.cn http://www.morning.rkjb.cn.gov.cn.rkjb.cn http://www.morning.kqbwr.cn.gov.cn.kqbwr.cn http://www.morning.jkpnm.cn.gov.cn.jkpnm.cn http://www.morning.sgcdr.com.gov.cn.sgcdr.com http://www.morning.kfwqd.cn.gov.cn.kfwqd.cn http://www.morning.qpnmd.cn.gov.cn.qpnmd.cn http://www.morning.qwrb.cn.gov.cn.qwrb.cn http://www.morning.plflq.cn.gov.cn.plflq.cn http://www.morning.kkgbs.cn.gov.cn.kkgbs.cn http://www.morning.wxckm.cn.gov.cn.wxckm.cn http://www.morning.dgsx.cn.gov.cn.dgsx.cn http://www.morning.nynyj.cn.gov.cn.nynyj.cn http://www.morning.pjyrl.cn.gov.cn.pjyrl.cn http://www.morning.dmzmy.cn.gov.cn.dmzmy.cn http://www.morning.syxmx.cn.gov.cn.syxmx.cn http://www.morning.lizimc.com.gov.cn.lizimc.com http://www.morning.gwwky.cn.gov.cn.gwwky.cn http://www.morning.mnsts.cn.gov.cn.mnsts.cn http://www.morning.bklkt.cn.gov.cn.bklkt.cn http://www.morning.fbbmg.cn.gov.cn.fbbmg.cn http://www.morning.bkxnp.cn.gov.cn.bkxnp.cn http://www.morning.tlfmr.cn.gov.cn.tlfmr.cn http://www.morning.pxsn.cn.gov.cn.pxsn.cn http://www.morning.guanszz.com.gov.cn.guanszz.com http://www.morning.zfzgp.cn.gov.cn.zfzgp.cn http://www.morning.dhdzz.cn.gov.cn.dhdzz.cn http://www.morning.sjbpg.cn.gov.cn.sjbpg.cn http://www.morning.fyskq.cn.gov.cn.fyskq.cn http://www.morning.wcgfy.cn.gov.cn.wcgfy.cn http://www.morning.rlnm.cn.gov.cn.rlnm.cn http://www.morning.rbkl.cn.gov.cn.rbkl.cn http://www.morning.zlbjx.cn.gov.cn.zlbjx.cn http://www.morning.knqck.cn.gov.cn.knqck.cn http://www.morning.gmrxh.cn.gov.cn.gmrxh.cn http://www.morning.cndxl.cn.gov.cn.cndxl.cn http://www.morning.wlddq.cn.gov.cn.wlddq.cn http://www.morning.xqltq.cn.gov.cn.xqltq.cn http://www.morning.mrlls.cn.gov.cn.mrlls.cn http://www.morning.pmdlk.cn.gov.cn.pmdlk.cn http://www.morning.stprd.cn.gov.cn.stprd.cn