I was having this issue with cocos2d-x 2.1.4, but I also just updated to 2.1.5 and still have the issue. Basically, while I can hear sound effects played through playEffect, I hear nothing playing when using playBackgroundMusic. I checked to make sure that the volume was set properly, but even when set to 1.0, I still get no audio. I get background music under Android just fine, but iOS I am getting nothing for background music.
[[Audio formats supported by CocosDenshion on different platforms]]
Which audio format are you using on iOS?
Here is my simple solution, I don’t know if it might help you or someone else.
in the header file
#include "cocos2d.h"
#include "SimpleAudioEngine.h"
#define STE_SFX_HIT 1
#define STE_SFX_PICKUP 2
#define STE_SFX_MOVE 3
#if(CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
#define SFX_PICKUP_FILE "pickup.caf"
#define SFX_HIT_FILE "hit.caf"
#define SFX_MOVE_FILE "move.caf"
#define SFX_MUSIC_GAME "TileMap.caf"
#define SFX_MUSIC_MENU "TileMap.caf"
#endif
#if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#define SFX_PICKUP_FILE "pickup.mp3"
#define SFX_HIT_FILE "hit.mp3"
#define SFX_MOVE_FILE "move.mp3"
#define SFX_MUSIC_GAME "TileMap.ogg"
#define SFX_MUSIC_MENU "TileMap.ogg"
#endif
#if(CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#define SFX_PICKUP_FILE "pickup.wav"
#define SFX_HIT_FILE "hit.wav"
#define SFX_MOVE_FILE "move.wav"
#define SFX_MUSIC_GAME "TileMap.mid"
#define SFX_MUSIC_MENU "TileMap.mid"
#endif
and in the C++
void STEMusicManager::playGameMusic(int musicType)
{
SimpleAudioEngine::sharedEngine()->playBackgroundMusic(SFX_MUSIC_GAME);
}
Zhe Wang wrote:
[[Audio formats supported by CocosDenshion on different platforms]]
Which audio format are you using on iOS?
I’m using MP3s. The music played for us just fine back in cocos2d-x 2.0.4, but since updating to 2.1.4 and 2.1.5, I have been getting no music.