1

I am trying to play a background music for a scene of a game I am developing using Cocos2d 2.0

but the execution stops at

in CDAudioManager.m:

-(void) load:(NSString*) filePath {
    ........
    .........
    [[audioSourcePlayer prepareToPlay]; //This is where the execution stops!!

and it gives NO details about the exception!, it just breaks!

and this is how I am playing the music:

NSString *soundFile = [[NSBundle mainBundle] pathForResource:@"background_music" ofType:@"mp3"];
NSLog(@"soundFile: %@", soundFile); //The path is correct
SimpleAudioEngine *sae = [SimpleAudioEngine sharedEngine];
if (sae != nil) {
    [sae preloadBackgroundMusic:soundFile];
    if (sae.willPlayBackgroundMusic) {
        sae.backgroundMusicVolume = 0.5f;
    }
}

I am using Cocos2d 2.0, Xcode 4.5.1, iOS SDK 6.0

mim
  • 199
  • 1
  • 3
  • 10

1 Answers1

0

Check if the file passes the exists test:

NSLog(@"soundFile: %@, exists: %u", 
      soundFile, [[NSFileManager defaultManager] fileExistsAtPath:soundFile]);

exists will be 1 if the file exists.

If it does exists, step into preloadBackgroundMusic and see if there's anything returning nil. I could imagine that the mp3 uses a format that's not supported by CD. If so, use Audacity or similar audio tool to open and re-save the mp3 file.

You should also add the add the global exception breakpoint in Xcode. That way Xcode doesn't just stop when an exception occurs but also jumps to the offending line.

Community
  • 1
  • 1
CodeSmile
  • 64,284
  • 20
  • 132
  • 217