原文转自:http://www.58player.com/blog-2537-88088.html
cocos2dx/cocos2d-x-2.1.5/CocosDenshion/android/opensl/SimpleAudioEngineOpenSL.cpp
unsigned int SimpleAudioEngineOpenSL::playEffect(const char* pszFilePath, bool bLoop)
{
unsigned int soundID = s_pOpenSL->preloadEffect(pszFilePath);
if (soundID != FILE_NOT_FOUND)
{
if (s_pOpenSL->getEffectState(soundID) == PLAYSTATE_PLAYING)
{
s_pOpenSL->setEffectState(soundID, PLAYSTATE_STOPPED);
s_pOpenSL->setEffectState(soundID, PLAYSTATE_PLAYING);
s_pOpenSL->setEffectLooping(soundID, bLoop);
}
else
{
s_pOpenSL->setEffectState(soundID, PLAYSTATE_STOPPED);
s_pOpenSL->setEffectState(soundID, PLAYSTATE_PLAYING);
s_pOpenSL->setEffectLooping(soundID, bLoop);
}
}
return soundID;
}
就是在播放音效时不创建新的音效,而是停止之前的音效再重新播放,播出来会比较怪,但不闪退了