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