0

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
kanstraktar
  • 5,357
  • 2
  • 21
  • 29

2 Answers2

2

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.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • so i took everything out of the appdelegate, but the project doesn't even get to my viewDidLoad in SoundCheckViewController. from what i think, the ViewController should initalize with that initWithAudioController in order to start the audio engine, but i don't know where to put this code. – kanstraktar Apr 26 '13 at 17:26
  • It works! I took out all the code from appDelegate and got it to work by calling [self initWithAudioController:self.audioController]; in viewDidLoad. Thank you! – kanstraktar Apr 27 '13 at 15:27
0

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;
}
Kal
  • 24,724
  • 7
  • 65
  • 65
  • Thanks, I added that. I have another app, and I'm running tests on both of them. On one I still have a black screen and a working app, however the other one crashes with this message: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'test'' ---- two part message --- – kanstraktar Apr 26 '13 at 16:19
  • --- second part ---- *** First throw call stack: (0x22a5012 0x14e1e7e 0x22a4deb 0x641ef9 0x5067e7 0x506dc8 0x506ff8 0x507232 0x4563d5 0x45676f 0x456905 0x45f917 0x2897 0x423157 0x423747 0x42494b 0x435cb5 0x436beb 0x428698 0x2de7df9 0x2de7ad0 0x221abf5 0x221a962 0x224bbb6 0x224af44 0x224ae1b 0x42417a 0x425ffc 0x2462 0x2395) libc++abi.dylib: terminate called throwing an exception – kanstraktar Apr 26 '13 at 16:22