Playing sounds in iPhone SDK can be realized in many ways. This solution shows how to play short sounds using SystemSoundID class and can be taken into consideration when playing sounds f.e in menu of your application.
Before we start writing code we should add AudioToolbox framework to our project.
Now the code part. First of all we have to import AudioServices.h to our project.
Than we can create a container for our sounds. It can be either an array of SystemSoundIDs, NSMutableArray or a single SystemSoundId object.
Now we have to initialize our sound. To do so in init or viewDidLoad etc. :
//Path for our sound: NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"my-sound" ofType:@"wav"]; CFURLRef soundURL = (__bridge CFURLRef)[NSURL fileURLWithPath:soundPath]; AudioServicesCreateSystemSoundID(soundURL, &sounds);
To play it: