I am writing an iPhone app that when a certain thing occurs, a sound is played. I have trying using different WAV, MP3, M4A files and have intermittent problems. The below code works fine in the simulator but the MP3 does not play on the iPhone. (3GS if it matters). Any ideas? I have changed the mp3 file to a wav and it will work for the one supplied below (knock_knock), but not another. Possibly the way it is encoded?
Any help is appreciated. Thanks
Here is the code:
SystemSoundID soundID;
NSString *soundFile;
if (something == somethingelse) {
soundFile = [[NSBundle mainBundle] pathForResource:@"knock_knock" ofType:@"wav"];
}
else {
soundFile = [[NSBundle mainBundle] pathForResource:@"strike" ofType:@"mp3"];
}
AudioServicesCreateSystemSoundID((CFURLRef)
[NSURL fileURLWithPath:soundFile]
, &soundID);
AudioServicesPlaySystemSound(soundID);