2012-08-10 66 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