diff --git a/CocosDenshion/include/SimpleAudioEngine.h b/CocosDenshion/include/SimpleAudioEngine.h index 92f669124a..0d5fee4376 100644 --- a/CocosDenshion/include/SimpleAudioEngine.h +++ b/CocosDenshion/include/SimpleAudioEngine.h @@ -76,8 +76,9 @@ public: /** @brief Stop playing background music + @param bReleaseData If release the background music data or not.As default value is false */ - void stopBackgroundMusic(); + void stopBackgroundMusic(bool bReleaseData = false); /** @brief Pause playing background music diff --git a/CocosDenshion/uphone/SimpleAudioEngine.cpp b/CocosDenshion/uphone/SimpleAudioEngine.cpp index eba3ca2fec..e1325061b7 100644 --- a/CocosDenshion/uphone/SimpleAudioEngine.cpp +++ b/CocosDenshion/uphone/SimpleAudioEngine.cpp @@ -10,7 +10,7 @@ static SoundDataManager *s_pDataManager = NULL; static SoundPlayer *s_pBackPlayer = NULL; static TSoundPlayer *s_pEffectPlayer = NULL; - +static int s_nBackMusicID = 0; static int s_nBackgroundMusicVolume = 100; static int s_nEffectsVolume = 100; static bool s_bWillPlayBackgroundMusic = false; @@ -85,8 +85,8 @@ void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop) nTimes = -1; } - int nSoundID = s_pDataManager->loadSoundData(pszFilePath); - tEffectElement* pElement = s_pDataManager->getSoundData(nSoundID); + s_nBackMusicID = s_pDataManager->loadSoundData(pszFilePath); + tEffectElement* pElement = s_pDataManager->getSoundData(s_nBackMusicID); if (pElement) { @@ -94,12 +94,18 @@ void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop) } } -void SimpleAudioEngine::stopBackgroundMusic() +void SimpleAudioEngine::stopBackgroundMusic(bool bReleaseData) { if (s_pBackPlayer) { s_pBackPlayer->Stop(); } + + if (bReleaseData && s_nBackMusicID) + { + s_pDataManager->unloadEffect(s_nBackMusicID); + s_nBackMusicID = 0; + } } void SimpleAudioEngine::pauseBackgroundMusic() diff --git a/CocosDenshion/uphone/SoundDataManager.cpp b/CocosDenshion/uphone/SoundDataManager.cpp index ce348a8232..a9cb13b786 100644 --- a/CocosDenshion/uphone/SoundDataManager.cpp +++ b/CocosDenshion/uphone/SoundDataManager.cpp @@ -70,8 +70,10 @@ void SoundDataManager::setSoundResInfo(const T_SoundResInfo ResInfo[], int nCoun int SoundDataManager::loadSoundData(const char* pszFilePath) { int nSoundID = 0; + SoundInfoMap::iterator iter; + iter = m_pSoundMap->find(pszFilePath); - if (! FileUtils::isFileExisted(pszFilePath)) + if (iter != m_pSoundMap->end()) { // if the file is not existed, find in the ResourceInfo nSoundID = loadFromResourceInfo(pszFilePath); @@ -166,6 +168,7 @@ int SoundDataManager::loadFromFile(const char* pFilePath) do { + BREAK_IF(! FileUtils::isFileExisted(pFilePath)); int nID = BKDRHash(pFilePath); // if we have loaded the file before,break diff --git a/CocosDenshion/win32/SimpleAudioEngine.cpp b/CocosDenshion/win32/SimpleAudioEngine.cpp index 7bcfaffa35..6663a40fb1 100644 --- a/CocosDenshion/win32/SimpleAudioEngine.cpp +++ b/CocosDenshion/win32/SimpleAudioEngine.cpp @@ -55,7 +55,7 @@ void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop) s_Music.Play((bLoop) ? -1 : 1); } -void SimpleAudioEngine::stopBackgroundMusic() +void SimpleAudioEngine::stopBackgroundMusic(bool bReleaseData) { s_Music.Stop(); }