How to play sounds in iPhone app

audio, iphone, objective-c

Solution

You can use System Sound Services to play short sounds:

CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef = CFBundleCopyResourceURL(mainBundle, CFSTR("filename"), CFSTR("aiff"), NULL);
SystemSoundID soundId;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundId);
AudioServicesPlaySystemSound(soundId);
CFRelease(soundFileURLRef)

.caf, .aiff and .wav formats are supported.

Problem

I am a beginner in this very confusing Objective-C game. I would like to play a very short sound effect every time a certain button is pushed. How can I do this? Can I use an mp3 file? Or will I have to convert to wav?

Original source