This is how I played a beep sound effect in iOS 4:
SystemSoundId beepOnSoundId;
CFURLRef soundUrl = CFBundleCopyResourceURL(
CFBundleGet
I have almost the same code and it works for me in iOS5 with a video and an audio media sessions on. If you have all the code in a function to play the sound the problem may be that the SystemSoundID object gets deallocated before the sound can be played, or the problem may be with the URL. But I guess it is the first one.
See, the following code works:
The SystemSoundID declaration is in the header of the object and the object lives long enough to play the sound.
SystemSoundID soundID;
The AudioServicesCreateSystemSoundID is in the object initialization.
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource: @"sound" ofType:@"wav"]], &soundID);
Then you can use AudioServicesPlaySystemSound wherever you want inside the object.
AudioServicesPlaySystemSound(soundID);
Try putting this pieces codes in the appropriate places and you should hear the sound.