I\'m making an app for Mac OS X using Xcode, and I want it to play a alert sound when something happens.
What is the simplest code for playing a sound in Objective-C/Coc
For example, add the AudioToolbox framework, the add the sound file to your resources / project, then add the below to your .h:
#import
And then: (after @interface { blah } in your .h)
- (IBAction) playSound;
Add the following to your .m: (change 'Ping' and 'wav' to the respective file name and type)
- (IBAction) playSound
{
SystemSoundID soundID;
NSString *soundFile = [[NSBundle mainBundle] pathForResource:@"Ping" ofType:@"wav"];
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundFile], &soundID);
AudioServicesPlaySystemSound(soundID);
[soundFile release];
}