I am trying to play a short sound whenever clicks a button on the iPhone; however, for some reason whenever I click the button (which calls the playClickSound method below), no sound plays. I have the project linked with AudioFoundation.framework and the sound file (clickSound.mp3) in the Resources folder of my application bundle. Can someone please help me figure out what I am missing, and why the AVAudioPlayer won't play my sound file?
- (void) playClickSound {
// Get path of sound file in bundle.
NSString *path = [[NSBundle mainBundle] pathForResource: @"clickSound" ofType: @"mp3"];
// Create url from path.
NSURL *url = [NSURL URLWithString: path];
// Create error.
NSError *error;
// Create audio player, and play file.
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: url error: &error];
if (![audioPlayer play]) {
[error localizedDescription];
}
[audioPlayer release];
} // playClickSound