我正在使用Audiotoolbox
.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‘文件。
我如何解决这个问题才能在我的手机上运行它?
发布于 2012-08-11 03:58:33
正如stackmonster所说的,确保它在Build Phases>Link Binary with Library中,你还需要将它包含在你试图使用它的类中(也许也可以尝试包含audioUnit,但不明白为什么你也会这样做)
你也可以尝试使用AVAudioPlayer,这对你来说可能更简单(我知道对我来说是这样)
AVAudioPlayer *theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:NULL];
theAudio.volume = 1.0;
theAudio.delegate = self;
[theAudio prepareToPlay];
[theAudio play];发布于 2012-08-11 00:11:40
将音频工具箱框架添加到构建Phases...linked库中的应用程序中
https://stackoverflow.com/questions/11905366
复制相似问题