您好,很高兴为您解答:
SimpleAudioEngine是cocos2d-x播放声音、音效的引擎。像对于背景音乐会提供一个判断当前背景音乐是否播放完毕的接口,但是查了半天,音效并没有提供类似的接口, 大体看了下SimpleAudioEngine.cpp的实现,感觉自己写一个是可以的,所以将代码贴出来,跟大家分享下。
SimpleAudioEngine.h文件中添加以下函数定义:
//判断当前音效是否已经播放完
bool getEffectIsPlaying(unsigned int nSoundId);
SimpleAudioEngine.cpp函数实现,比较简单:
//判断当前音效是否已经播放完
bool SimpleAudioEngine::getEffectIsPlaying(unsigned int
nSoundId)
{
EffectList::iterator p =
sharedList().find(nSoundId);
bool bRet = false;
if (p !=
sharedList().end())
{
bRet =
p->second->IsPlaying();
}
return bRet;
}复制代码
注:修改后将libCocosDenshion类库重新编译一下。只要通过我们的soundid参数,便可找到MciPlayer,这样就好处理了。