tags:

views:

21

answers:

1

Hello, I have set up part of my app to play a sound. Simple - but only is working in Simulator.

Initing audio session this way:

  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }

 AudioSessionInitialize(NULL,NULL,NULL,NULL);
 AudioSessionSetActive(YES);
 return self;
}

Playing sound, setting completion calback, and checking for file this way:

NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"mp3"];

 AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
 AudioServicesAddSystemSoundCompletion (soundID,NULL,NULL,
             completionCallback,
             (void*) self);


 if([[NSFileManager defaultManager] fileExistsAtPath:path])
 {
  NSLog(@"Playing Sound" );
  AudioServicesPlaySystemSound(soundID);
 }
 else {
  NSLog(@"NO SOUND");
 }

In Simulator, the file is found, sound plays, and completion happens. In device, file is found, sound does not play, and completion is never called.

Any ideas? Thank you very much, both my forehead and my desk appreciate any replies...:)

A: 

OK, So there were a few things I changed to get this working. DOn't have the code in front of me, will try to add later.

  1. I stopped using the system sound and started using AVAudioPlayer instead.
  2. I didn't have my UIView set up as the audio delegate
  3. Was not starting the audio session. Now am starting the audio session in the initNib function(I saw tutrorials that said to use awakeFromNib, but the awakeFromNib never fired...)
Jon