I have found so many solutions here on stackoverflow, but for some reason all of them failed to produce any sound what so ever.
Here is my current code:
PRE: I've added AudioToolbox.framework and imported <AVFoundation/AVFoundation.h> in my .m file
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL* sndurl = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"aif"];
SystemSoundID snd;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)sndurl, &snd);
AudioServicesAddSystemSoundCompletion(snd, nil, nil, SoundFinished, nil);
AudioServicesPlaySystemSound(snd);
}
void SoundFinished (SystemSoundID snd, void* context) {
AudioServicesRemoveSystemSoundCompletion(snd);
AudioServicesDisposeSystemSoundID(snd);
}
This solution is straight out of book. But when I run the project, if fails to produce any sound. My file is test.aif, which is 5 seconds long.
Any suggestions why it's not working? If that's not the best solution, how do you produce a sound on iOS6?