[CppTests:ExtensionsTest-->CocoStudioComponentsTest]Fixed crash on Android 5.0.x

This commit is contained in:
Wenhai Lin 2015-06-26 10:16:52 +08:00
parent 117a72fa07
commit 1875829ab4
3 changed files with 23 additions and 23 deletions

View File

@ -285,16 +285,7 @@ void AudioEngineImpl::update(float dt)
for (auto iter = _audioPlayers.begin(); iter != itend; )
{
player = &(iter->second);
if (player->_playOver)
{
if (player->_finishCallback)
player->_finishCallback(player->_audioID, *AudioEngine::_audioIDInfoMap[player->_audioID].filePath);
AudioEngine::remove(player->_audioID);
iter = _audioPlayers.erase(iter);
continue;
}
else if (player->_delayTimeToRemove > 0.f)
if (player->_delayTimeToRemove > 0.f)
{
player->_delayTimeToRemove -= dt;
if (player->_delayTimeToRemove < 0.f)
@ -303,6 +294,15 @@ void AudioEngineImpl::update(float dt)
continue;
}
}
else if (player->_playOver)
{
if (player->_finishCallback)
player->_finishCallback(player->_audioID, *AudioEngine::_audioIDInfoMap[player->_audioID].filePath);
AudioEngine::remove(player->_audioID);
iter = _audioPlayers.erase(iter);
continue;
}
++iter;
}

View File

@ -366,9 +366,9 @@ void AndroidJavaEngine::setEffectsVolume(float volume)
if (_effectVolume != volume)
{
_effectVolume = volume;
for (auto& it : _soundIDs)
for (auto it : _soundIDs)
{
AudioEngine::setVolume(it.first, volume);
AudioEngine::setVolume(it, volume);
}
}
}
@ -386,10 +386,10 @@ unsigned int AndroidJavaEngine::playEffect(const char* filePath, bool loop,
auto soundID = AudioEngine::play2d(filePath, loop, _effectVolume);
if (soundID != AudioEngine::INVALID_AUDIO_ID)
{
_soundIDs[soundID] = soundID;
_soundIDs.push_back(soundID);
AudioEngine::setFinishCallback(soundID, [this](int id, const std::string& filePath){
_soundIDs.erase(id);
_soundIDs.remove(id);
});
}
@ -430,7 +430,7 @@ void AndroidJavaEngine::stopEffect(unsigned int soundID)
if (_implementBaseOnAudioEngine)
{
AudioEngine::stop(soundID);
_soundIDs.erase(soundID);
_soundIDs.remove(soundID);
}
else
{
@ -442,9 +442,9 @@ void AndroidJavaEngine::pauseAllEffects()
{
if (_implementBaseOnAudioEngine)
{
for (auto& it : _soundIDs)
for (auto it : _soundIDs)
{
AudioEngine::pause(it.first);
AudioEngine::pause(it);
}
}
else
@ -457,9 +457,9 @@ void AndroidJavaEngine::resumeAllEffects()
{
if (_implementBaseOnAudioEngine)
{
for (auto& it : _soundIDs)
for (auto it : _soundIDs)
{
AudioEngine::resume(it.first);
AudioEngine::resume(it);
}
}
else
@ -472,9 +472,9 @@ void AndroidJavaEngine::stopAllEffects()
{
if (_implementBaseOnAudioEngine)
{
for (auto& it : _soundIDs)
for (auto it : _soundIDs)
{
AudioEngine::stop(it.first);
AudioEngine::stop(it);
}
_soundIDs.clear();
}

View File

@ -27,7 +27,7 @@ THE SOFTWARE.
#include "SimpleAudioEngine.h"
#include "platform/android/jni/JniHelper.h"
#include <unordered_map>
#include <list>
namespace CocosDenshion {
namespace android {
@ -62,7 +62,7 @@ namespace CocosDenshion {
private :
bool _implementBaseOnAudioEngine;
float _effectVolume;
std::unordered_map<int, int> _soundIDs;
std::list<int> _soundIDs;
};
}
}