这是我在这里的第一个问题。我正在尝试制作一个适用于 Core Audio 的应用程序。我找到了我正在尝试使用的这个框架http://theamazingaudioengine.com/,到目前为止,我设法完成了文档中的第一件事,即播放文件。但是,通过在应用程序的委托中自定义初始化 UIViewController,我丢失了它的所有内容,并且视图控制器变黑,没有其他元素。
我的 UIViewController 只有一个按钮,我想用它来开始播放文件,但由于我无权访问它,目前,文件在项目构建时开始播放。
知道我在做什么错吗?
这是我的 appDelegate:
@implementation SoundCheckAppDelegate
@synthesize window = _window;
@synthesize audioController = _audioController;
@synthesize viewController = _viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Create an instance of the audio controller, set it up and start it running
self.audioController = [[[AEAudioController alloc] initWithAudioDescription:[AEAudioController nonInterleaved16BitStereoAudioDescription] inputEnabled:YES] autorelease];
_audioController.preferredBufferDuration = 0.005;
[_audioController start:NULL];
// Create and display view controller
self.viewController = [[SoundCheckViewController alloc] initWithAudioController:_audioController];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
@end
还有我的 UIViewController:
@interface SoundCheckViewController ()
@property (nonatomic, strong) AEAudioController *audioController;
@property (nonatomic, strong) AEAudioFilePlayer *loop;
@end
@implementation SoundCheckViewController
- (id)initWithAudioController:(AEAudioController*)audioController {
self.audioController = audioController;
NSError *error;
NSURL *file = [[NSBundle mainBundle] URLForResource:@"Southern Rock Drums" withExtension:@"m4a"];
self.loop = [AEAudioFilePlayer audioFilePlayerWithURL:file
audioController:_audioController
error:&error];
if(error)
NSLog(@"couldn't start loop");
_loop.removeUponFinish = YES;
_loop.loop = YES;
_loop.completionBlock = ^{
self.loop = nil;
};
[_audioController addChannels:[NSArray arrayWithObject:_loop]];
return self;
}
@end