CocosDenshion - CDAudioManager的加载方法失败

时间:2012-11-01 11:11:11

标签: iphone ios cocos2d-iphone avaudioplayer

我正在尝试使用Cocos2d 2.0为我正在开发的游戏场景播放背景音乐

但执行在

处停止

在CDAudioManager.m中:

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

并且它没有提供关于异常的详细信息!它只是打破了!

这就是我演奏音乐的方式:

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;
    }
}

我使用的是Cocos2d 2.0,Xcode 4.5.1,iOS SDK 6.0

2 个答案:

答案 0 :(得分:1)

好消息,这已在这里得到解答,甚至更好的消息,你没有代码更改,只是调试器设置!

Xcode stops on prepareToPlay

答案 1 :(得分:0)

检查文件是否通过了存在测试:

NSLog(@"soundFile: %@, exists: %u", 
      soundFile, [[NSFileManager defaultManager] fileExistsAtPath:soundFile]);
如果文件存在,

将为1。

如果确实存在,请进入preloadBackgroundMusic并查看是否有返回nil的内容。我可以想象mp3使用的是CD不支持的格式。如果是这样,请使用Audacity或类似的音频工具打开并重新保存mp3文件。

您还应该添加add the global exception breakpoint in Xcode。这样,Xcode不仅会在发生异常时停止,还会跳转到违规行。

相关问题