2012-08-10 73 views
2

我使用Audiotoolbox'AudioUnit/AudioUnit.h' 找不到文件

.h文件中

#import <UIKit/UIKit.h> 
#import <AudioToolbox/AudioToolbox.h> 

@interface ViewController : UIViewController { 

} 

-(IBAction)buttonPressedWithSound:(id)sender; 

@end 

,并在.m文件

-(IBAction)buttonPressedWithSound:(id)sender { 

int randomSoundNumber = arc4random() % 4; //random number from 0 to 3 

NSLog(@"random NR = %i", randomSoundNumber); 

NSString *effectTitle; 

switch (randomSoundNumber) { 
    case 0: 
     effectTitle = @"Come at me BRO!"; 
     break; 

    default: 
     break; 
} 

SystemSoundID soundID; 

NSString *soundPath = [[NSBundle mainBundle] pathForResource:effectTitle ofType:@"mp3"]; 
NSSound *sound = [[[NSSound alloc] initWithContentsOfFile: soundPath byReference: NO]  autorelease]; 

[sound play]; 

AudioServicesCreateSystemSoundID ((CFURLRef)CFBridgingRetain(soundUrl), &soundID); 
AudioServicesPlaySystemSound(soundID); 
} 

但是当我去跑在我的iPhone上它出现在AUGraph.h日志中,在它的右侧没有找到#include AudioUnit/AudioUnit.h和'AudioUnit/AudioUnit.h'文件。

我该如何解决这个问题在我的手机上运行?

回答

-1

添加audiotoolbox框架,您的应用程序在构建阶段...链接库

+0

你是什么意思 – 2012-08-10 16:16:24

+0

我认为它已经存在,但我仍然收到错误 – 2012-08-10 16:28:35

1

正如stackmonster说,确保其在构建阶段>链接二进制与图书馆 你还需要#包括它的类,你试图使用它(也许尝试包括audioUnit以及但不明白你为什么也会)

你也可以尝试使用AVAudioPlayer,这可能会更容易为你(我知道它是为我)

AVAudioPlayer *theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:NULL]; 

theAudio.volume = 1.0; 

theAudio.delegate = self; 

[theAudio prepareToPlay]; 

[theAudio play]; 
+0

,所以我把它放在.m文件中,.h文件怎么样? – 2012-08-10 20:01:47

+0

是什么修复? AVAudioPlayer还是其中一个导入?很高兴它帮助,不管它是哪里虽然 – 2012-08-10 20:28:18

+0

以及它是修复,但现在当我把你的代码放在.m文件错误像未知类型名称一样强化,是在.h文件中的东西? – 2012-08-10 20:34:09