1

Here is the code:

-(void)stop
{
    NSLog(@"Disposing Sounds");
    AudioServicesDisposeSystemSoundID (soundID);
    //AudioServicesRemoveSystemSoundCompletion (soundID);
}

static void completionCallback (SystemSoundID  mySSID, void* myself) {
    NSLog(@"completion Callback");
}
- (void) playall: (id) sender {

    [self stop];

    AudioServicesAddSystemSoundCompletion (soundID,NULL,NULL,
     completionCallback,
     (void*) self);


    OSStatus err = kAudioServicesNoError;
    NSString *aiffPath = [[NSBundle mainBundle] pathForResource:@"slide1" ofType:@"m4a"];
    NSURL *aiffURL = [NSURL fileURLWithPath:aiffPath];
    err = AudioServicesCreateSystemSoundID((CFURLRef) aiffURL, &soundID);
    AudioServicesPlaySystemSound (soundID);
    NSLog(@"Done Playing");
}

Output:

Disposing Sounds
Done Playing

In actual no sound gets play at all and completion call back isn't called as well. Any idea what could be wrong here? I want to stop any previous sound before playing current.

Shoaibi
  • 859
  • 2
  • 11
  • 23

3 Answers3

1

AFAIK, the only supported files are .caf, .aif, or .wav:

To play your own sounds, add the sound file to your application bundle; the sound file must adhere to the following requirements:

  • Must be .caf, .aif, or .wav files.
  • The audio data in the file must be in PCM or IMA/ADPCM (IMA4) format.
  • The file's audio duration must be less than 30 seconds.

Audio & Video Coding How-To's

Chris Gummer
  • 4,772
  • 1
  • 24
  • 17
0

You can use AudioToolBox framework for this:

CFBundleRef mainbundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef = CFBundleCopyResourceURL(mainbundle, CFSTR("tap"), CFSTR("aif"), NULL);
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundFileObject);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
AudioServicesPlaySystemSound(1100);
John Riselvato
  • 12,854
  • 5
  • 62
  • 89
Govind
  • 2,337
  • 33
  • 43
0

What does err contain? From that you should be able to infer the problem.

Dave Gamble
  • 4,146
  • 23
  • 28
  • I printed err using NSLog and apears to be (null) – Shoaibi Jul 19 '09 at 01:37
  • Do you mean (null) or zero? I think you need to be a little more cautious with your NSLog... (null) is not an integer... ;) – Dave Gamble Jul 19 '09 at 03:19
  • i did this: NSLog(@"Error: %@", err); so i guess i am printing string, and it tells me its "(null)" on console. – Shoaibi Jul 19 '09 at 03:33
  • NSLog(@"Error: %d", err); please. err is an OSStatus, which is of integer type. – Dave Gamble Jul 19 '09 at 03:49
  • Great. Now set err=AudioServicesPlaySystemSound(soundID); and see what err returns there. – Dave Gamble Jul 19 '09 at 04:30
  • gives: "error: void values not ignored as its ought to be" i am using Iphone SDK 3 beta 2 with simulator 3.1 – Shoaibi Jul 19 '09 at 08:16
  • Did you find a solution for this? I'm dealing with the same behavior - it happens whenever the ringer is muted. I can't find a way to override this (even with AudioSessionInitialize and kAudioSessionProperty_AudioCategory). – pix0r Dec 03 '09 at 21:17