views:

662

answers:

1

I have an application which has two kinds of sounds: 1. Background sounds, looping forever till next view. 2. Sounds clips that could be played separately or all in one go.

Previously i tried using AVAudioPlayer but there was always a very little silence interval between two clips (to which i didn't find any solution, if you have one, please post in reply), so shifted to Finch e.g. http://github.com/zoul/Finch/tree/master

Now here is the deal: I am using AVAudioPlayer to play looping forever sounds while Finch to play those back-to-back clips. I am doing this:

- (void)viewDidLoad {
    [super viewDidLoad];

    soundEngine = [[Finch alloc] init];
/***
CLIPPED
***/
}
-(void) playclip:(id) sender {
    NSString *fullPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"sitar.wav"];
    NSLog(@"Song is %@", fullPath);
    clip = [[Sound alloc] initWithFile:fullPath];
    NSLog(@"Clip Length: %@", clip.length);
    NSLog(@"Clip Playing ? : %d", clip.playing);
    [clip play];
    NSLog(@"Played Clip");
}

This is almost same code as the demo project provided as in the git repository. But for some reason i get this on console:

Song is /Users/shoaibi/Library/Application Support/iPhone Simulator/User/Applications/17FBA26F-6047-4D56-9E45-ADAFE07B7234/Test.app/sitar.wav
Failed to create OpenAL source, error code a004.
Clip Length: (null)
Clip Playing ? : 0
Played Clip

An ls on the directory printed on console reveals that there is sitar.wav there with the correct permissions. What could be the issue? may be the background sound AVAudioPlayer which i stop using:

- (void)viewWillAppear:(BOOL)animated {

    //Stop the background music before my ears bleed :P
    d = [[UIApplication sharedApplication] delegate];
    if (d.bg.playing)
    {
     [d.bg stop];
     NSLog(@"Background music stoped");
    }

}

is not freeing up sound resource?

+1  A: 

Latest Finch now checks whether OpenAL is initialized when you initialize a new Sound. If current OpenAL context is not set because you forgot or failed to initialize Finch, you get a better error message. Give it a try, it might be the case that your initialization code is buggy.

zoul