原創作品,轉載請標明:
Android:在android上CocosDenshion能支援的音頻格式是對應於android.media.MediaPlayer所支援的格式。iOS:在IOS上面Cocos2d-x的CocosDenshion所支援的格式和Cocos2d-iphone中所支援的是一樣,mp3,caf是推薦的格式。windows:.mid, .wav are supported. Note that mp3 is not supported.Marmalade:mp3
#include "SimpleAudioEngine.h" using namespace CocosDenshion;//很多人少了這一步導致找不到SimpleAudioEngine
CocosDenshion::SimpleAudioEngine
SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic("sound/game_music.mp3");
SimpleAudioEngine::sharedEngine()->playBackgroundMusic("sound/game_music.mp3",true);//開始播放背景音樂,true表示迴圈SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();//停止背景音樂,這是一個預設參數函數,傳參表示是否釋放音樂檔案SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();//暫停背景音樂SimpleAudioEngine::sharedEngine()->rewindBackgroundMusic();//重頭調用背景音樂SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying()//返回布爾型參數,表示是否在放著背景音樂SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.5);//設定音量0.0-1.0
SimpleAudioEngine::sharedEngine()->preloadEffect("sound/bullet.mp3");
SimpleAudioEngine::sharedEngine()->playEffect("sound/bullet.mp3",false);//開始播放背景音效,false表示不迴圈SimpleAudioEngine::sharedEngine()->stopEffect(m_nSoundId);//停止音效,可以選擇單獨停掉一個音效,這個值是由playEffect返回的SimpleAudioEngine::sharedEngine()->stopAllEffects();//停止全部音效SimpleAudioEngine::sharedEngine()->pauseEffect(m_nSoundId);//暫停單個音效SimpleAudioEngine::sharedEngine()->resumeEffect(m_nSoundId);//重新開始音效SimpleAudioEngine::sharedEngine()->pauseAllEffects();//暫停全部音效SimpleAudioEngine::sharedEngine()->resumeAllEffects();//重新開始全部音效SimpleAudioEngine::sharedEngine()->setEffectsVolume(0.5);//設定音效音量0.0-1.0SimpleAudioEngine::sharedEngine()->unloadEffect("sound/bullet.mp3");//卸載音效
static EffectList s_List;
void SimpleAudioEngine::end()
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath){}
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop){ if (! pszFilePath) { return; } sharedMusic().Open(_FullPath(pszFilePath), _Hash(pszFilePath)); sharedMusic().Play((bLoop) ? -1 : 1);}