I wrote a simple Objective-C wrapper around AudioServicesPlaySystemSound
and friends:
#import <AudioToolbox/AudioToolbox.h>
/*
Trivial wrapper around system sound as provided
by Audio Services. Don’t forget to add the Audio
Toolbox framework.
*/
@interface Sound : NSObject
{
SystemSoundID handle;
}
// Path is relative to the resources dir.
- (id) initWithPath: (NSString*) path;
- (void) play;
@end
@implementation Sound
- (id) initWithPath: (NSString*) path
{
[super init];
NSString *resourceDir = [[NSBundle mainBundle] resourcePath];
NSString *fullPath = [resourceDir stringByAppendingPathComponent:path];
NSURL *url = [NSURL fileURLWithPath:fullPath];
OSStatus errcode = AudioServicesCreateSystemSoundID((CFURLRef) url, &handle);
NSAssert1(errcode == 0, @"Failed to load sound: %@", path);
return self;
}
- (void) dealloc
{
AudioServicesDisposeSystemSoundID(handle);
[super dealloc];
}
- (void) play
{
AudioServicesPlaySystemSound(handle);
}
@end
Lives here. For other sound options see this question.