0
我完全按照阅读我文件中的说明操作,但由于某种原因,在我的应用程序中,每当我点击与代码相对应的UIButton来播放声音时[[soundA play];该应用程序只是崩溃而没有任何详细的错误除了lldb之外,我使用的是Finch,因为它使用OpenAL播放音频,我需要使用OpenAL作为我制作的应用程序的类型,因为AVAudioPlayer或System Sounds不适用于我正在制作的内容。我使用的代码当我尝试使用Finch库for iPhone SDK播放声音时,为什么我的应用程序崩溃?
主文件:
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
soundFactory = [[FIFactory alloc] init];
engine = [soundFactory buildSoundEngine];
[engine activateAudioSessionWithCategory:AVAudioSessionCategoryPlayback];
[engine openAudioDevice];
soundA = [soundFactory loadSoundNamed:@"1.caf" maxPolyphony:16 error:NULL];
soundB = [soundFactory loadSoundNamed:@"2.caf" maxPolyphony:16 error:NULL];
soundC = [soundFactory loadSoundNamed:@"3.caf" maxPolyphony:16 error:NULL];
soundD = [soundFactory loadSoundNamed:@"4.caf" maxPolyphony:16 error:NULL];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
- (IBAction) PlaySoundA {[soundA play];}
- (IBAction) PlaySoundB {[soundB play];}
- (IBAction) PlaySoundC {[soundC play];}
- (IBAction) PlaySoundD {[soundD play];}
@end
头文件:
#import <UIKit/UIKit.h>
#import "FISoundEngine.h"
#import "FIFactory.h"
#import "FISound.h"
@interface ViewController : UIViewController {
FIFactory* soundFactory;
FISoundEngine* engine;
FISound* soundA;
FISound* soundB;
FISound* soundC;
FISound* soundD;
}
@end
任何帮助,将不胜感激!谢谢!
该文件已添加到项目中,已复制到项目资源文件夹中并添加到目标中。我也运行了一些代码来搜索这些文件,因为我认为这也是问题,但是应用程序可以找到这些文件并用其他音频框架播放它们,但我需要使用OpenAL和Finch来播放这些文件。 – 2012-08-15 01:01:18
您是否已通过界面构建器中的连接检查器将UIButton链接到XIB文件中的按钮? – FierceMonkey 2012-08-16 01:58:37
是的,如果它没有链接,那么它不会崩溃,因为它不会调用导致应用程序崩溃的方法 – 2012-08-16 23:05:18