From 52cdcbcbe42ca65ed9ca1dc97774209e4062056b Mon Sep 17 00:00:00 2001 From: liswei Date: Thu, 28 Jul 2011 09:58:10 +0800 Subject: [PATCH] fixed #633 add playeffect looply,in win32 --- CocosDenshion/win32/MciPlayer.cpp | 2 +- CocosDenshion/win32/SimpleAudioEngine.cpp | 33 ++++++++++++++++------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/CocosDenshion/win32/MciPlayer.cpp b/CocosDenshion/win32/MciPlayer.cpp index 1d1681fbd8..ce917fe9ed 100644 --- a/CocosDenshion/win32/MciPlayer.cpp +++ b/CocosDenshion/win32/MciPlayer.cpp @@ -102,7 +102,7 @@ void MciPlayer::Play(UINT uTimes /* = 1 */) } MCI_PLAY_PARMS mciPlay = {0}; mciPlay.dwCallback = (DWORD_PTR)m_hWnd; - s_mciError = mciSendCommand(m_hDev,MCI_PLAY, MCI_NOTIFY,(DWORD)&mciPlay); + s_mciError = mciSendCommand(m_hDev,MCI_PLAY, MCI_FROM|MCI_NOTIFY,(DWORD)&mciPlay); if (! s_mciError) { m_bPlaying = true; diff --git a/CocosDenshion/win32/SimpleAudioEngine.cpp b/CocosDenshion/win32/SimpleAudioEngine.cpp index 68dc9ef85a..fe3266077d 100644 --- a/CocosDenshion/win32/SimpleAudioEngine.cpp +++ b/CocosDenshion/win32/SimpleAudioEngine.cpp @@ -9,8 +9,8 @@ using namespace std; namespace CocosDenshion { -typedef map EffectList; -typedef pair Effect; +typedef map EffectList; +typedef pair Effect; static char s_szRootPath[MAX_PATH]; static DWORD s_dwRootLen; @@ -50,6 +50,14 @@ SimpleAudioEngine* SimpleAudioEngine::sharedEngine() void SimpleAudioEngine::end() { sharedMusic().Close(); + + EffectList::iterator p = sharedList().begin(); + while (p != sharedList().end()) + { + delete p->second; + p->second = NULL; + p++; + } sharedList().clear(); return; } @@ -123,7 +131,7 @@ unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop) EffectList::iterator p = sharedList().find(nRet); if (p != sharedList().end()) { - p->second.Rewind(); + p->second->Play((bLoop) ? -1 : 1); } return nRet; @@ -134,7 +142,7 @@ void SimpleAudioEngine::stopEffect(unsigned int nSoundId) EffectList::iterator p = sharedList().find(nSoundId); if (p != sharedList().end()) { - p->second.Stop(); + p->second->Stop(); } } @@ -149,11 +157,11 @@ void SimpleAudioEngine::preloadEffect(const char* pszFilePath) BREAK_IF(sharedList().end() != sharedList().find(nRet)); - sharedList().insert(Effect(nRet, MciPlayer())); - MciPlayer& player = sharedList()[nRet]; - player.Open(_FullPath(pszFilePath), nRet); + sharedList().insert(Effect(nRet, new MciPlayer())); + MciPlayer * pPlayer = sharedList()[nRet]; + pPlayer->Open(_FullPath(pszFilePath), nRet); - BREAK_IF(nRet == player.GetSoundID()); + BREAK_IF(nRet == pPlayer->GetSoundID()); sharedList().erase(nRet); nRet = 0; @@ -168,7 +176,14 @@ void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath) void SimpleAudioEngine::unloadEffect(const char* pszFilePath) { unsigned int nID = _Hash(pszFilePath); - sharedList().erase(nID); + + EffectList::iterator p = sharedList().find(nID); + if (p != sharedList().end()) + { + delete p->second; + p->second = NULL; + sharedList().erase(nID); + } } //////////////////////////////////////////////////////////////////////////