SLES 获取歌曲时长的接口是哪个?
c4droid吧
全部回复
仅看楼主
level 12
简单aaaaaaa 楼主
2016年03月21日 15点03分 1
level 12
简单aaaaaaa 楼主
struct SLPlayItf_ {
SLresult (*SetPlayState) ( SLPlayItf self, SLuint32 state );
SLresult (*GetPlayState) ( SLPlayItf self, SLuint32 *pState );
SLresult (*GetDuration) ( SLPlayItf self, SLmillisecond *pMsec );
SLresult (*GetPosition) ( SLPlayItf self, SLmillisecond *pMsec );
SLresult (*RegisterCallback) ( SLPlayItf self, slPlayCallback callback, void *pContext );
SLresult (*SetCallbackEventsMask) (SLPlayItf self,SLuint32 eventFlags +);
SLresult (*GetCallbackEventsMask) (SLPlayItf self, SLuint32 *pEventFlags +);
SLresult (*SetMarkerPosition) ( SLPlayItf self, SLmillisecond mSec +); +SLresult (*ClearMarkerPosition) ( +SLPlayItf self +);
SLresult (*GetMarkerPosition) ( SLPlayItf self, +SLmillisecond *pMsec +);
SLresult (*SetPositionUpdatePeriod) (SLPlayItf self, SLmillisecond mSec );
SLresult (*GetPositionUpdatePeriod) ( SLPlayItf self, +SLmillisecond *pMsec +);
};
+ +struct SLBufferQueueItf_ {
SLresult (*Enqueue) ( SLBufferQueueItf self, const void *pBuffer, SLuint32 size );
SLresult (*Clear) ( +SLBufferQueueItf self +);
SLresult (*GetState) ( +SLBufferQueueItf self, +SLBufferQueueState *pState +);
SLresult (*RegisterCallback) ( +SLBufferQueueItf self, +slBufferQueueCallback callback, +void* pContext +); +};
+struct SLEffectSendItf_ { +SLresult (*EnableEffectSend) ( +SLEffectSendItf self, +const void *pAuxEffect, +SLboolean enable, +SLmillibel initialLevel +); +SLresult (*IsEnabled) ( +SLEffectSendItf self, +const void * pAuxEffect, +SLboolean *pEnable +); +SLresult (*SetDirectLevel) ( +SLEffectSendItf self, +SLmillibel directLevel +); +SLresult (*GetDirectLevel) ( +SLEffectSendItf self, +SLmillibel *pDirectLevel +); +SLresult (*SetSendLevel) ( +SLEffectSendItf self, +const void *pAuxEffect, +SLmillibel sendLevel +); +SLresult (*GetSendLevel)( +SLEffectSendItf self, +const void *pAuxEffect, +SLmillibel *pSendLevel +); +};
+struct SL
2016年03月21日 15点03分 2
level 10
SLSeekItf->GetPosition()? 不太记得了,多蒙几下就好了[滑稽][滑稽][滑稽]
2016年03月22日 08点03分 5
level 10
GetDuration
2016年03月22日 09点03分 6
好像不是
2016年03月23日 15点03分
@简单aaaaaaa 就是个o
2016年03月23日 16点03分
level 12
简单aaaaaaa 楼主
+struct SLSeekItf_; +typedef const struct SLSeekItf_ * const * SLSeekItf; + +struct SLSeekItf_ { +SLresult (*SetPosition)( +SLSeekItf self, +SLmillisecond pos, +SLuint32 seekMode +); +SLresult (*SetLoop)( +SLSeekItf self, +SLboolean loopEnable, +SLmillisecond startPos, +SLmillisecond endPos +); +SLresult (*GetLoop)( +SLSeekItf self, +SLboolean *pLoopEnabled, +SLmillisecond *pStartPos, +SLmillisecond *pEndPos +); +}; +
2016年03月23日 15点03分 7
level 10
看第三个
2016年03月23日 16点03分 8
[真棒][真棒][真棒]成功 那从指定时间开始播放怎么搞? 就是滑杆滑到哪就从哪播放。大神[乖]
2016年03月23日 23点03分
level 10
第一个[滑稽]
2016年03月24日 01点03分 9
看楼下,这样还是从头播放的[委屈]
2016年03月24日 05点03分
level 12
简单aaaaaaa 楼主
if (uriSeek != NULL)
{
(*uriSeek)->SetPosition(uriSeek,pos,SL_SEEKMODE_ACCURATE);
}
2016年03月24日 05点03分 10
贴完整代码
2016年03月24日 05点03分
@ohce🐶 楼下,大神帮试试。你在控制台帮测试一下吧
2016年03月24日 05点03分
level 12
简单aaaaaaa 楼主
#include <stdio.h>
#include <SDL2/SDL.h>
#include <SDL_UI.h>
#include <playMusic.c>
int main()
{
char abc[100]="";
init("",720,1280);
ttf_init(100);
initMusic();
unsigned long int pos=50000;
playMusic("/storage/sdcard0/C/mp3_3.mp3");
if (uriPlayerPlay != NULL)
{
(*uriPlayerPlay)->SetPlayState(uriPlayerPlay,SL_PLAYSTATE_PAUSED);
}
if (uriSeek != NULL)
{
(*uriSeek)->SetPosition(uriSeek,pos,SL_SEEKMODE_ACCURATE);
}
if (uriPlayerPlay != NULL)
{
(*uriPlayerPlay)->SetPlayState(uriPlayerPlay,SL_PLAYSTATE_PLAYING);
}
while(1)
{
/*
if (uriPlayerPlay != NULL)
{
//(*uriPlayerPlay)->GetDuration(uriPlayerPlay,&pos);
(*uriPlayerPlay)->GetPosition(uriPlayerPlay,&pos);
}
*/
eventstate();SDL_SetRenderDrawColor(ren,255,0,0,255);
sprintf(abc,"%ld",pos);
if(button(site(500,500,100,100),0xffff,"p",0,100,0))
{
if (uriPlayerPlay != NULL)
{
(*uriPlayerPlay)->SetPlayState(uriPlayerPlay,SL_PLAYSTATE_PAUSED);
}
}
displaytext(site(100,000,200,50),abc,0,0);
txtbox(site(0,0,200,50),FPS_str,0,20);
reflush(0xffffffff);
}
quit();
return 0;
}
2016年03月24日 05点03分 11
level 12
简单aaaaaaa 楼主
layOverEvent(SLPlayItf caller, void *pContext, SLuint32 playevent)
{
if (playevent ==SL_PLAYEVENT_HEADATEND)
{
/*播放结束自动下一曲*/
printf("播放完毕\n");
PLAYSTATE=NOPLAY;
//获取playstate
}
}
/*加载声音源*/
bool LoadMUS(char *uriPath)
{
SLresult result;
SLDataLocator_URI loc_uri = { SL_DATALOCATOR_URI, (SLchar *) uriPath};
/*数据格式*/
SLDataFormat_MIME format_mime=
{ SL_DATAFORMAT_MIME, NULL, SL_CONTAINERTYPE_UNSPECIFIED };
SLDataSource audioSrc = { &loc_uri, &format_mime };
/*混音器数据*/
SLDataLocator_OutputMix loc_outmix =
{ SL_DATALOCATOR_OUTPUTMIX, output_mix};
SLDataSink audioSnk = { &loc_outmix, NULL };
result =(*engine_e)->CreateAudioPlayer(engine_e, &uriPlayerObject,&audioSrc, &audioSnk, 0,NULL,NULL);
assert(SL_RESULT_SUCCESS == result);
/*实现播放对象*/
result = (*uriPlayerObject)->Realize(uriPlayerObject, SL_BOOLEAN_FALSE);
if (SL_RESULT_SUCCESS != result)
{
(*uriPlayerObject)->Destroy(uriPlayerObject);
uriPlayerObject = NULL;
return false;
}
//SLBufferQueueItf _aud_buf;//缓冲区
/*获取播放控制接口uriPlayerPlay*/
result =(*uriPlayerObject)->GetInterface(uriPlayerObject, SL_IID_PLAY,&uriPlayerPlay);
result =(*uriPlayerObject)->GetInterface(uriPlayerObject, SL_IID_PLAY,&uriSeek);
assert(SL_RESULT_SUCCESS == result);
/*设置播放接口监听*/
result =(*uriPlayerPlay)->RegisterCallback(uriPlayerPlay, playOverEvent, NULL);
result =(*uriPlayerPlay)->SetCallbackEventsMask(uriPlayerPlay,SL_PLAYEVENT_HEADATEND);
assert(SL_RESULT_SUCCESS == result);
return true;
}
/*设置播放状态*/
void setPlayingUriAudioPlayer(bool played)
{
SLresult result;
if (uriPlayerPlay != NULL)
{
result =(*uriPlayerPlay)->SetPlayState(uriPlayerPlay,played ? SL_PLAYSTATE_PLAYING : SL_PLAYSTATE_PAUSED);
assert(SL_RESULT_SUCCESS == result);
}
}
/*播放歌曲*/
void playMusic(char *MUSPath)
{
/*不同状态,执行不同*/
switch (PLAYSTATE)
{
case NOPLAY:
LoadMUS(MUSPath);
setPlayingUriAudioPlayer(true);
PLAYSTATE=PLAYING;
break;
case PLAYING:
setPlayingUriAudioPlayer(false);
s
2016年03月24日 05点03分 14
卧槽这么长,我在打英雄联盟……不过你获取seek接口的时候不应该是SL_IID_SEEK吗
2016年03月24日 06点03分
@ohce🐶 result =(*uriPlayerObject)->GetInterface(uriPlayerObject, SL_IID_SEEK,&uriSeek); 这样就闪退了。 找了半天了[不高兴]
2016年03月24日 07点03分
&
2016年03月24日 09点03分
level 12
简单aaaaaaa 楼主
topMusic();
createEngine();
LoadMUS(MUSPath);setPlayingUriAudioPlayer(true);
break;
case PAUSED:
stopMusic();
createEngine();
LoadMUS(MUSPath);
setPlayingUriAudioPlayer(true);
PLAYSTATE=PLAYING;
break;
}
}
/*暂停歌曲*/
void pauseMusic()
{
switch (PLAYSTATE)
{
case PLAYING:
setPlayingUriAudioPlayer(false);
PLAYSTATE=PAUSED;
break;
case PAUSED:
setPlayingUriAudioPlayer(true);
PLAYSTATE=PLAYING;
break;
}
}
/*停止,关闭声音*/
void stopMusic()
{
if (uriPlayerObject != NULL)
{
(*uriPlayerObject)->Destroy(uriPlayerObject);
uriPlayerObject = NULL;
uriPlayerPlay = NULL;
}
/*销毁混音器*/
if (output_mix!= NULL)
{
(*output_mix)->Destroy(output_mix);
output_mix= NULL;
outputMixEnvironmentalReverb = NULL;
}
/*销毁声音引擎声音对象接口*/
if (engine_m!= NULL)
{(*engine_m)->Destroy(engine_m);
engine_m= NULL;
}
}
/*启动音乐*/
bool initMusic()
{
/*创建声音引擎*/
createEngine();
return true;
}
2016年03月24日 05点03分 15
level 12
简单aaaaaaa 楼主
13楼被度娘吃了[怒]
2016年03月24日 05点03分 16
level 12
简单aaaaaaa 楼主
/*
源码:音乐播放
作者:傻傻_痴痴
来源:c4droid吧
日期:2014.3.30 若要转载源码,请注明作者出处,禁止修改为自己名义发布源码
*/
#include <stdio.h>
#include <SLES/OpenSLES.h>
#include <stdbool.h>
#include <assert.h>
/*播放状态:未播放、正在播放、暂停*/
#define NOPLAY 1
#define PLAYING 2
#define PAUSED 3
/*当前播放歌曲编号*/
int ListNum = 0;
/*播放状态,初始化为未播放*/
int PLAYSTATE=NOPLAY;
/* 声音对象接口*/
static SLObjectItf engine_m = NULL;
/*声音引擎接口*/
static SLEngineItf engine_e;
/* 混音器对象接口 */
static SLObjectItf output_mix = NULL;
/*混音器输出池接口*/
static SLEnvironmentalReverbItf outputMixEnvironmentalReverb = NULL;
/* 环境回响音效*/
static const SLEnvironmentalReverbSettings reverbSettings =SL_I3DL2_ENVIRONMENT_PRESET_STONECORRIDOR;
/* 播放声音源对象接口*/
static SLObjectItf uriPlayerObject = NULL;
static SLPlayItf uriPlayerPlay;//播放控制接口
static SLSeekItf uriSeek;
void stopMusic();
/*创建声音引擎函数*/
void createEngine()
{
SLresult result;
/*创建声音引擎*/
result = slCreateEngine(&engine_m, 0, NULL, 0, NULL, NULL);
/*返回结果,如果失败则出现提示*/
assert(SL_RESULT_SUCCESS == result);
/*实现声音引擎*/
result = (*engine_m)->Realize(engine_m, SL_BOOLEAN_FALSE);
assert(SL_RESULT_SUCCESS == result);
/*获取声音引擎接口*/
result =(*engine_m)->GetInterface(engine_m, SL_IID_ENGINE,&engine_e);
assert(SL_RESULT_SUCCESS == result);
/*设置播放器功能,环境回响效果,音量*/
const SLInterfaceID ids[] = { SL_IID_ENVIRONMENTALREVERB,
};
/*设置是否强制实现实现*/
const SLboolean req[] = {
SL_BOOLEAN_FALSE,
};
/*从声音引擎创建混音器*/
result =(*engine_e)->CreateOutputMix(engine_e, &output_mix,1, ids, req);
assert(SL_RESULT_SUCCESS == result);
/*实现混音器效果*/
result = (*output_mix)->Realize(output_mix, SL_BOOLEAN_FALSE);
assert(SL_RESULT_SUCCESS == result);
#if 0
/* 获取接口混音器接口并放到混音器输出池*/
result =(*output_mix)->GetInterface(output_mix, SL_IID_ENVIRONMENTALREVERB, &outputMixEnvironmentalReverb);
if (SL_RESULT_SUCCESS == result)
{
result =(*outputMixEnvironmentalReverb)->SetEnvironmentalReverbProperties
(outputMixEnvironmentalReverb, &reverbSettings);
}
#endif
}
/*监听是否播放结束*/
void p
2016年03月24日 05点03分 19
度娘别删,这是13楼
2016年03月24日 05点03分
level 12
简单aaaaaaa 楼主
result =(*uriPlayerObject)->GetInterface(uriPlayerObject, SL_IID_SEEK,&uriSeek);
2016年03月24日 07点03分 20
result =(*uriPlayerObject)->GetInterface(&uriPlayerObject, SL_IID_SEEK,&uriSeek);
2016年03月24日 10点03分
@ohce🐶 这样报错啊
2016年03月24日 10点03分
@简单aaaaaaa 我记错了,你写法是对的,原因我也看不出来…
2016年03月24日 10点03分
@ohce🐶 const SLInterfaceID ids[2] = { SL_IID_ENVIRONMENTALREVERB, SL_IID_SEEK, }; 加这也没用
2016年03月24日 10点03分
level 12
简单aaaaaaa 楼主
好激动,
改成这样就好了[泪]
const SLInterfaceID ids[] = { //SL_IID_ENVIRONMENTALREVERB,
SL_IID_SEEK,
SL_IID_MUTESOLO,
SL_IID_VOLUME,
SL_IID_PLAYBACKRATE
};
谢谢楼上大神帮助[泪]
2016年03月25日 03点03分 21
应该怎么改?我改了一些然后segmentation fault
2016年11月17日 22点11分
怎么初始化uriSeek?
2016年11月17日 22点11分
ids里加了,(*uriPlayerObject)->GetInterface(uriPlayerObject, SL_IID_SEEK,&uriSeek);这样还segmentation fault
2016年11月17日 22点11分
2016年11月18日 01点11分
1