1.1 --- a/Source/GGBUtils.m Wed May 28 12:47:10 2008 -0700
1.2 +++ b/Source/GGBUtils.m Thu May 29 15:04:06 2008 -0700
1.3 @@ -42,9 +42,47 @@
1.4 }
1.5
1.6
1.7 +#if TARGET_OS_IPHONE
1.8 +static SystemSoundID GetSound( NSString *name )
1.9 +{
1.10 + static NSMutableDictionary *sSoundIDs;
1.11 + NSNumber *soundIDObj = [sSoundIDs objectForKey: name];
1.12 + if( ! soundIDObj ) {
1.13 + NSLog(@"Loading sound '%@'",name);
1.14 + NSString *type = name.pathExtension;
1.15 + if( ! type.length )
1.16 + type = @"aiff";
1.17 + NSString *path = [[NSBundle mainBundle] pathForResource: name.stringByDeletingPathExtension
1.18 + ofType: type];
1.19 + NSURL *url;
1.20 + if( path )
1.21 + url = [NSURL fileURLWithPath: path];
1.22 + else {
1.23 + NSLog(@"Couldn't find sound %@",name);
1.24 + return 0;
1.25 + }
1.26 + //url = [NSURL fileURLWithPath: [@"/Library/Sounds/" stringByAppendingPathComponent: name]];
1.27 + SystemSoundID soundID;
1.28 + if( AudioServicesCreateSystemSoundID((CFURLRef)url,&soundID) != noErr ) {
1.29 + NSLog(@"Couldn't load sound %@",url);
1.30 + return 0;
1.31 + }
1.32 +
1.33 + soundIDObj = [NSNumber numberWithUnsignedInt: soundID];
1.34 + if( ! sSoundIDs )
1.35 + sSoundIDs = [[NSMutableDictionary alloc] init];
1.36 + [sSoundIDs setObject: soundIDObj forKey: name];
1.37 + }
1.38 + return [soundIDObj unsignedIntValue];
1.39 +}
1.40 +#endif
1.41 +
1.42 +
1.43 void PreloadSound( NSString* name )
1.44 {
1.45 -#if ! TARGET_OS_IPHONE
1.46 +#if TARGET_OS_IPHONE
1.47 + GetSound(name);
1.48 +#else
1.49 NSSound *sound = [[NSSound soundNamed: @"Pop"] copy];
1.50 sound.volume = 0;
1.51 [sound play];
1.52 @@ -56,13 +94,7 @@
1.53 void PlaySound( NSString* name )
1.54 {
1.55 #if TARGET_OS_IPHONE
1.56 - NSURL *url = [NSURL fileURLWithPath: [@"/Library/Sounds/" stringByAppendingPathComponent: name]];
1.57 - SystemSoundID soundID;
1.58 - if( AudioServicesCreateSystemSoundID((CFURLRef)url,&soundID) != noErr ) {
1.59 - NSLog(@"Couldn't load sound %@",url);
1.60 - return;
1.61 - }
1.62 - AudioServicesPlaySystemSound(soundID);
1.63 + AudioServicesPlaySystemSound( GetSound(name) );
1.64 #else
1.65 [[NSSound soundNamed: name] play];
1.66 #endif
1.67 @@ -71,7 +103,7 @@
1.68 void Beep()
1.69 {
1.70 #if TARGET_OS_IPHONE
1.71 - AudioServicesPlayAlertSound(0x00001000/*kSystemSoundID_UserPreferredAlert*/);
1.72 + AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
1.73 #else
1.74 NSBeep();
1.75 #endif