project_files/HedgewarsMobile/Classes/AudioManagerController.m
changeset 6871 5aadbfe02613
parent 6869 a187c280dd3d
child 6908 896ed2afcfb8
equal deleted inserted replaced
6870:f72cac290325 6871:5aadbfe02613
   125 #pragma mark sound effects control
   125 #pragma mark sound effects control
   126 -(SystemSoundID) loadSound:(NSString *)snd {
   126 -(SystemSoundID) loadSound:(NSString *)snd {
   127     SystemSoundID soundID;
   127     SystemSoundID soundID;
   128 
   128 
   129     // get the filename of the sound file in a NSURL format
   129     // get the filename of the sound file in a NSURL format
   130     NSString *path = [[NSString alloc] initWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath],snd];
   130     NSString *path = [[NSBundle mainBundle] pathForResource:snd ofType:@"caf"];
   131     NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
   131     NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
   132     [path release];
       
   133 
   132 
   134     // use audio sevices to create and play the sound
   133     // use audio sevices to create and play the sound
   135     AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
   134     AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
   136     return soundID;
   135     return soundID;
   137 }
   136 }
   145 -(void) playClickSound {
   144 -(void) playClickSound {
   146     if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO)
   145     if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO)
   147         return;
   146         return;
   148     
   147     
   149     if (self.clickSound == -1)
   148     if (self.clickSound == -1)
   150         self.clickSound = [self loadSound:@"clickSound.wav"];
   149         self.clickSound = [self loadSound:@"clickSound"];
   151     
   150     
   152     AudioServicesPlaySystemSound(self.clickSound);
   151     AudioServicesPlaySystemSound(self.clickSound);
   153 }
   152 }
   154 
   153 
   155 -(void) playBackSound {
   154 -(void) playBackSound {
   156     if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO)
   155     if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO)
   157         return;
   156         return;
   158     
   157     
   159     if (self.backSound == -1)
   158     if (self.backSound == -1)
   160         self.backSound = [self loadSound:@"backSound.wav"];
   159         self.backSound = [self loadSound:@"backSound"];
   161     
   160     
   162     AudioServicesPlaySystemSound(self.backSound);
   161     AudioServicesPlaySystemSound(self.backSound);
   163 }
   162 }
   164 
   163 
   165 -(void) playSelectSound {
   164 -(void) playSelectSound {
   166     if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO)
   165     if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO)
   167         return;
   166         return;
   168     
   167     
   169     if (self.selSound == -1)
   168     if (self.selSound == -1)
   170         self.selSound = [self loadSound:@"selSound.wav"];
   169         self.selSound = [self loadSound:@"selSound"];
   171     
   170     
   172     AudioServicesPlaySystemSound(self.selSound);
   171     AudioServicesPlaySystemSound(self.selSound);
   173 }
   172 }
   174 
   173 
   175 @end
   174 @end