Pergunta

This is my first question here. I'm trying to make an app that will work with Core Audio. I found this framework http://theamazingaudioengine.com/ that I'm trying to use and so far I managed to do the first thing in the documentation, which is to play a file. However, by custom initializing the UIViewController in app's delegate, I lose all its content and the view controller comes black with no other elements.

My UIViewController only has one button, which I wanted to use to start the playback of the file, but since I have no access to it, at the moment, the file starts playing when the project builds.

Any idea what am I doing wrong?

This is my 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

And my 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
Foi útil?

Solução

Since you're using a storyboard, you should take all that code out of the app delegate. The storyboard automatically instantiates your initial controller and puts it on screen. By alloc init'ing one, you're just creating another one that doesn't have any custom view.

To add your audio controller, you should add code in the viewDidLoad method of SoundCheckViewController that does that, rather than in an init method. This would be the usual way to do this, but I'm not sure what is possible with the framework you're using.

Outras dicas

I think you should initialize your view controller first.

- (id)initWithAudioController:(AEAudioController*)audioController {
    // THIS LINE IS MISSING IN YOUR CODE
    self = [super initWithNibName:@"SoundCheckViewController" bundle:nil];
    if ( self ) {
       self.audioController = audioController;
       ...
    }

    return self;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top