SimpleAudioEngine - no sound (cocos2d-x-3.15.1, iOS)

Hi there,
I’ve been trying to get audio working in my game for days, without success, both effects and background music.

Initial setup in AppDelegate:
#define USE_SIMPLE_AUDIO_ENGINE 1

auto audio = SimpleAudioEngine::getInstance();
audio->preloadEffect("/sound/hit.wav");
audio->preloadBackgroundMusic("/sound/music.mp3");

In game:
SimpleAudioEngine::getInstance()->playEffect("/sound/hit.wav");
SimpleAudioEngine::getInstance()->playBackgroundMusic("/sound/music.mp3");


With playEffect, it fails in SimpleAudioEngine_objc.m:
-(ALuint) playEffect:(NSString*) filePath loop:(BOOL) loop pitch:(Float32) pitch pan:(Float32) pan gain:(Float32) gain
{
int soundId = [bufferManager bufferForFile:filePath create:YES];
if (soundId != kCDNoBuffer) {
return [soundEngine playSound:soundId sourceGroupId:0 pitch:pitch pan:pan gain:gain loop:loop];
} else {
return CD_MUTE;
}
}
because soundId == -1, or kCDNoBuffer. Something wrong with the file, I thought, so I tried other different files, different formats like caf. Nothing works.

With playBackgroundMusic, it fails in CDAudioManager.m:
-(void) play {
if (enabled_) {
systemPaused = NO;
paused = NO;
stopped = NO;
[audioSourcePlayer play];
} else {
CDLOGINFO(@“Denshion::CDLongAudioSource long audio source didn’t play because it is disabled”);
}
}
because audioSourcePlayer == nil


Very confused as to what might be the problem. The location of the sound folder (Resources/sound) seems to be correct- if I change it, I get console errors saying file can’t be found. No other errors related to sound in the console. Tried different devices, same problem. Is there some initial setup that needs to be done that I’m missing, beyond defining USE_SIMPLE_AUDIO_ENGINE? Any sample projects I can look at?

I still think the “/” in your path is causing the problem. NONE of my code has a “/” in it. “/” means start looking at the root of something…". You want to start not in root, but in “the current path”. Try without the “/”.

If you get errors, paste in the console log and take a screenshot of your XCode where I can see your resources folder, etc.

Maybe it is a path problem, I thought the directory it looked in was Resources. I tried putting the file hit.wav directly in Resources and use that, and got the error:
cocos2d: fullPathForFilename: No file found at hit.wav. Possible missing file.
I never got this error previously.

Attaching a screenshot of what the directory structure looks like.
Thanks!

07 AM

then sound/.... is what you use. Make sure they are part of your copy resources build phase too.

Ahhh it wasn’t getting copied over in the build phases! I was extra confused, because I wasn’t getting console errors with /sound, but I did get errors if I changed the path, not sure why that is. Thanks for all your help you are awesome :slight_smile: