don't play button sounds when audio is off
authorkoda
Sat, 19 Feb 2011 01:01:03 +0100
changeset 4947 cfac6aab84a0
parent 4946 076767e86f2b
child 4948 c3dc41ae68fa
don't play button sounds when audio is off
project_files/HedgewarsMobile/Classes/CommodityFunctions.m
project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m
--- a/project_files/HedgewarsMobile/Classes/CommodityFunctions.m	Fri Feb 18 00:31:01 2011 +0100
+++ b/project_files/HedgewarsMobile/Classes/CommodityFunctions.m	Sat Feb 19 01:01:03 2011 +0100
@@ -90,20 +90,21 @@
 }
 
 void playSound (NSString *snd) {
-    //Get the filename of the sound file:
-    NSString *path = [NSString stringWithFormat:@"%@/%@.wav",[[NSBundle mainBundle] resourcePath],snd];
-    
-    //declare a system sound id
-    SystemSoundID soundID;
+    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
+    NSNumber *audio = [prefs objectForKey:@"audio"];
+
+    if (audio == nil || [audio boolValue] == YES) {
+        // get the filename of the sound file:
+        NSString *path = [NSString stringWithFormat:@"%@/%@.wav",[[NSBundle mainBundle] resourcePath],snd];
 
-    //Get a URL for the sound file
-    NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
+        // declare a system sound id and get a URL for the sound file
+        SystemSoundID soundID;
+        NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
 
-    //Use audio sevices to create the sound
-    AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
-
-    //Use audio services to play the sound
-    AudioServicesPlaySystemSound(soundID);
+        // use audio sevices to create and play the sound
+        AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
+        AudioServicesPlaySystemSound(soundID);
+    }
 }
 
 NSArray inline *getAvailableColors (void) {
--- a/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m	Fri Feb 18 00:31:01 2011 +0100
+++ b/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m	Sat Feb 19 01:01:03 2011 +0100
@@ -49,6 +49,11 @@
 -(void) viewWillDisappear:(BOOL)animated {
     [super viewWillDisappear:animated];
     [self.settingsDictionary writeToFile:SETTINGS_FILE() atomically:YES];
+
+    // we save the sound settings to respect that flag everywhere
+    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
+    [prefs setObject:[NSNumber numberWithBool:[[self.settingsDictionary objectForKey:@"sound"] boolValue]] forKey:@"audio"];
+    [prefs synchronize];
 }
 
 #pragma mark -