EXC_BAD_ACCESS与Cocos2d中的声音

时间:2013-03-01 20:39:50

标签: ios objective-c cocos2d-iphone

(在继续之前,我想说我是在VMWare下在Mac OSX上开发的,所以如果有人知道它是否可能是VM问题,请回答相关问题)

我正在按照一个简单的cocos2d教程来到声音

这是我用于音频的代码

进口:

// Import the interfaces
#import "HelloWorldLayer.h"
#import "SimpleAudioEngine.h"

// Needed to obtain the Navigation Controller
#import "AppDelegate.h"

Init方法:

-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super's" return value
if( (self=[super init]) )
{
    [[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"Field1.mp3" loop:YES];

    CCMenuItemImage *uno = [CCMenuItemImage itemWithNormalImage:@"vblue.png" selectedImage:@"vblue.png" target:self selector:@selector(uno)];
    uno.position = ccp(-150,0);
    CCMenuItemImage *due = [CCMenuItemImage itemWithNormalImage:@"vgreen.png" selectedImage:@"vgreen.png" target:self selector:@selector(uno)];
   due.position = ccp(-50,0);

    CCMenuItemImage *start = [CCMenuItemImage itemWithNormalImage:@"play.png" selectedImage:@"play.png" target:self selector:@selector(uno)];
    start.position = ccp(150,0);
    CCMenuItemImage *stop = [CCMenuItemImage itemWithNormalImage:@"pausa.png" selectedImage:@"pausa.png" target:self selector:@selector(uno)];
    stop.position = ccp(50,0);

    CCMenu *menu = [CCMenu menuWithItems:uno,due,start,stop, nil];
    [self addChild:menu];

}
return self;
}

有问题的一行是

[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"Field1.mp3" loop:YES];

由于Xcode报告了音频错误而没有该行,游戏可以正常工作。

编译器输出:

<AudioControl> Error '!obj' trying to fetch default input device's sample rate
2013-03-01 12:29:09.101 Tutorial10[374:4803]  

<AudioControl> Error getting audio     input device sample rate: '!obj'2013-03-01 12:29:09.102   Tutorial10[374:4803]  

<AudioControl> AQMEIOManager::FindIOUnit: error 'NoHW'
2013-03-01 12:29:09.104 Tutorial10[374:1b03] 
<0xb0115000> AQMEIOManager::FindIOUnit: error 'NoHW'
(lldb) 

我怎样才能让它发挥作用?

1 个答案:

答案 0 :(得分:0)

经过一番挖掘后,我看到其他人也有同样的问题。他们的问题是他们没有在他们的系统上安装音频驱动程序,因此根本没有播放声音,并且他们收到的错误与你一样。

http://www.cocos2d-iphone.org/forum/topic/13970

如果这也发生在实际设备上,那会很奇怪。你在PC上测试的设备是什么?