Search This Blog

Tuesday, February 2, 2010

Play sound


#import


@interface CSSound : NSObject {

}
+(void)playSound:(NSString *)soundName;
@end


#import "CSSound.h"
#import

@implementation CSSound
+(void)playSound:(NSString *)soundName{
SystemSoundID mySSID;
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:soundName];

OSStatus error = AudioServicesCreateSystemSoundID( (CFURLRef)[NSURL fileURLWithPath:path], &mySSID);

if(error == kAudioServicesNoError){
//DLog(@"successfully contructed sound %@", soundName);
AudioServicesPlaySystemSound(mySSID);
}else{
DLog(@"error playing sound %@", soundName);
}
}

No comments:

Post a Comment