采用github上最新的android 声音引擎,
for (int32 i = 0; i < 20; ++i) {
cocos2d::experimental::AudioEngine::play2d(“test.caf” ,0 ,100);
}
在play2d的引擎中
int AudioEngine::play2d(const std::string& filePath, bool loop, float volume, const AudioProfile *profile)
{
int ret = AudioEngine::INVALID_AUDIO_ID;
do {
if ( !lazyInit() ){
break;
}
if ( !CCFileUtils::sharedFileUtils()->isFileExist(filePath)){
break;
}
auto profileHelper = _defaultProfileHelper;
if (profile && profile != &profileHelper->profile){
CC_ASSERT(!profile->name.empty());
profileHelper = &_audioPathProfileHelperMap;
profileHelper->profile = *profile;
}
CCLOG("~~~~~~ current _audioIdInfoMap size is %d\n " ,_audioIDInfoMap.size() );
if (_audioIDInfoMap.size() >= _maxInstances) {
CCLOG("Fail to play %s cause by limited max instance of AudioEngine",filePath.c_str());
break;
}
if (profileHelper)
{
if(profileHelper->profile.maxInstances != 0 && profileHelper->audioIDs.size() >= profileHelper->profile.maxInstances){
CCLOG("Fail to play %s cause by limited max instance of AudioProfile",filePath.c_str());
break;
}
if (profileHelper->profile.minDelay > TIME_DELAY_PRECISION) {
auto currTime = utils::gettime();
if (profileHelper->lastPlayTime > TIME_DELAY_PRECISION && currTime - profileHelper->lastPlayTime <= profileHelper->profile.minDelay) {
CCLOG("Fail to play %s cause by limited minimum delay",filePath.c_str());
break;
}
}
}
if (volume < 0.0f) {
volume = 0.0f;
}
else if (volume > 1.0f){
volume = 1.0f;
}
ret = _audioEngineImpl->play2d(filePath, loop, volume);
if (ret != INVALID_AUDIO_ID)
{
_audioPathIDMap.push_back(ret);
auto it = _audioPathIDMap.find(filePath);
auto& audioRef = _audioIDInfoMap;
audioRef.volume = volume;
audioRef.loop = loop;
audioRef.is3dAudio = false;
audioRef.filePath = &it->first;
if (profileHelper) {
profileHelper->lastPlayTime = utils::gettime();
profileHelper->audioIDs.push_back(ret);
}
audioRef.profileHelper = profileHelper;
}
} while (0);
return ret;
}
打印log ,_audioIdInfoMap 数量有可能是一直存在的,也就是没有被释放掉
而在AudioEngineImpl::update(float dt) 中 , _audioPlayers 存有跟这个map数量相同的player, 并且状态是1 ,也就是playing的状态,然后一直没有被释放
这个在nexus6 上必然出现, 系统是android6.0,
而我有的其他设备 ,是4.x 或者 5.x的非nexus机器,并没有这个问题