2012-08-02 13:02:59 +08:00
|
|
|
#include "SimpleAudioEngine.h"
|
|
|
|
#include "FmodAudioPlayer.h"
|
2013-01-27 19:20:49 +08:00
|
|
|
#include "cocos2d.h"
|
|
|
|
USING_NS_CC;
|
2012-08-02 13:02:59 +08:00
|
|
|
|
|
|
|
namespace CocosDenshion {
|
|
|
|
|
|
|
|
static AudioPlayer* oAudioPlayer;
|
|
|
|
|
|
|
|
SimpleAudioEngine::SimpleAudioEngine() {
|
|
|
|
oAudioPlayer = FmodAudioPlayer::sharedPlayer();
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleAudioEngine::~SimpleAudioEngine() {
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleAudioEngine* SimpleAudioEngine::sharedEngine() {
|
|
|
|
static SimpleAudioEngine s_SharedEngine;
|
|
|
|
return &s_SharedEngine;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::end() {
|
|
|
|
oAudioPlayer->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// BackgroundMusic
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath,
|
|
|
|
bool bLoop) {
|
2013-01-27 19:20:49 +08:00
|
|
|
// Changing file path to full path
|
2013-06-20 14:12:43 +08:00
|
|
|
std::string fullPath = FileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
|
2013-01-27 19:20:49 +08:00
|
|
|
oAudioPlayer->playBackgroundMusic(fullPath.c_str(), bLoop);
|
2012-08-02 13:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::stopBackgroundMusic(bool bReleaseData) {
|
|
|
|
oAudioPlayer->stopBackgroundMusic(bReleaseData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::pauseBackgroundMusic() {
|
|
|
|
oAudioPlayer->pauseBackgroundMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::resumeBackgroundMusic() {
|
|
|
|
oAudioPlayer->resumeBackgroundMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::rewindBackgroundMusic() {
|
|
|
|
oAudioPlayer->rewindBackgroundMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SimpleAudioEngine::willPlayBackgroundMusic() {
|
|
|
|
return oAudioPlayer->willPlayBackgroundMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SimpleAudioEngine::isBackgroundMusicPlaying() {
|
|
|
|
return oAudioPlayer->isBackgroundMusicPlaying();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath) {
|
2013-01-27 19:20:49 +08:00
|
|
|
// Changing file path to full path
|
2013-06-20 14:12:43 +08:00
|
|
|
std::string fullPath = FileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
|
2013-01-27 19:20:49 +08:00
|
|
|
return oAudioPlayer->preloadBackgroundMusic(fullPath.c_str());
|
2012-08-02 13:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// effect function
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath,
|
|
|
|
bool bLoop) {
|
2013-01-27 19:20:49 +08:00
|
|
|
// Changing file path to full path
|
2013-06-20 14:12:43 +08:00
|
|
|
std::string fullPath = FileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
|
2013-01-27 19:20:49 +08:00
|
|
|
return oAudioPlayer->playEffect(fullPath.c_str(), bLoop);
|
2012-08-02 13:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::stopEffect(unsigned int nSoundId) {
|
|
|
|
return oAudioPlayer->stopEffect(nSoundId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::preloadEffect(const char* pszFilePath) {
|
2013-01-27 19:20:49 +08:00
|
|
|
// Changing file path to full path
|
2013-06-20 14:12:43 +08:00
|
|
|
std::string fullPath = FileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
|
2013-01-27 19:20:49 +08:00
|
|
|
return oAudioPlayer->preloadEffect(fullPath.c_str());
|
2012-08-02 13:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::unloadEffect(const char* pszFilePath) {
|
2013-01-27 19:20:49 +08:00
|
|
|
// Changing file path to full path
|
2013-06-20 14:12:43 +08:00
|
|
|
std::string fullPath = FileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
|
2013-01-27 19:20:49 +08:00
|
|
|
return oAudioPlayer->unloadEffect(fullPath.c_str());
|
2012-08-02 13:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::pauseEffect(unsigned int uSoundId) {
|
|
|
|
oAudioPlayer->pauseEffect(uSoundId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::pauseAllEffects() {
|
|
|
|
oAudioPlayer->pauseAllEffects();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::resumeEffect(unsigned int uSoundId) {
|
|
|
|
oAudioPlayer->resumeEffect(uSoundId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::resumeAllEffects() {
|
|
|
|
oAudioPlayer->resumeAllEffects();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::stopAllEffects() {
|
|
|
|
oAudioPlayer->stopAllEffects();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// volume interface
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
float SimpleAudioEngine::getBackgroundMusicVolume() {
|
|
|
|
return oAudioPlayer->getBackgroundMusicVolume();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::setBackgroundMusicVolume(float volume) {
|
|
|
|
return oAudioPlayer->setBackgroundMusicVolume(volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
float SimpleAudioEngine::getEffectsVolume() {
|
2013-03-02 08:12:42 +08:00
|
|
|
return oAudioPlayer->getEffectsVolume();
|
2012-08-02 13:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleAudioEngine::setEffectsVolume(float volume) {
|
|
|
|
return oAudioPlayer->setEffectsVolume(volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // end of namespace CocosDenshion
|