views:

797

answers:

2

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.

A: 

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

Dave Gamble
I printed err using NSLog and apears to be (null)
Shoaibi
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
i did this:NSLog(@"Error: %@", err);so i guess i am printing string, and it tells me its "(null)" on console.
Shoaibi
NSLog(@"Error: %d", err); please. err is an OSStatus, which is of integer type.
Dave Gamble
In that case error outputs as "0".
Shoaibi
Great. Now set err=AudioServicesPlaySystemSound(soundID); and see what err returns there.
Dave Gamble
gives: "error: void values not ignored as its ought to be" i am using Iphone SDK 3 beta 2 with simulator 3.1
Shoaibi
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
A: 

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