[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; ) for (auto iter = _audioPlayers.begin(); iter != itend; )
{ {
player = &(iter->second); player = &(iter->second);
if (player->_playOver) if (player->_delayTimeToRemove > 0.f)
{
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)
{ {
player->_delayTimeToRemove -= dt; player->_delayTimeToRemove -= dt;
if (player->_delayTimeToRemove < 0.f) if (player->_delayTimeToRemove < 0.f)
@ -303,6 +294,15 @@ void AudioEngineImpl::update(float dt)
continue; 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; ++iter;
} }

View File

@ -366,9 +366,9 @@ void AndroidJavaEngine::setEffectsVolume(float volume)
if (_effectVolume != volume) if (_effectVolume != volume)
{ {
_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); auto soundID = AudioEngine::play2d(filePath, loop, _effectVolume);
if (soundID != AudioEngine::INVALID_AUDIO_ID) if (soundID != AudioEngine::INVALID_AUDIO_ID)
{ {
_soundIDs[soundID] = soundID; _soundIDs.push_back(soundID);
AudioEngine::setFinishCallback(soundID, [this](int id, const std::string& filePath){ 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) if (_implementBaseOnAudioEngine)
{ {
AudioEngine::stop(soundID); AudioEngine::stop(soundID);
_soundIDs.erase(soundID); _soundIDs.remove(soundID);
} }
else else
{ {
@ -442,9 +442,9 @@ void AndroidJavaEngine::pauseAllEffects()
{ {
if (_implementBaseOnAudioEngine) if (_implementBaseOnAudioEngine)
{ {
for (auto& it : _soundIDs) for (auto it : _soundIDs)
{ {
AudioEngine::pause(it.first); AudioEngine::pause(it);
} }
} }
else else
@ -457,9 +457,9 @@ void AndroidJavaEngine::resumeAllEffects()
{ {
if (_implementBaseOnAudioEngine) if (_implementBaseOnAudioEngine)
{ {
for (auto& it : _soundIDs) for (auto it : _soundIDs)
{ {
AudioEngine::resume(it.first); AudioEngine::resume(it);
} }
} }
else else
@ -472,9 +472,9 @@ void AndroidJavaEngine::stopAllEffects()
{ {
if (_implementBaseOnAudioEngine) if (_implementBaseOnAudioEngine)
{ {
for (auto& it : _soundIDs) for (auto it : _soundIDs)
{ {
AudioEngine::stop(it.first); AudioEngine::stop(it);
} }
_soundIDs.clear(); _soundIDs.clear();
} }

View File

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