project_files/HedgewarsMobile/Classes/AudioManagerController.m
changeset 8441 a00b0fa0dbd7
parent 6908 896ed2afcfb8
child 10108 c68cf030eded
equal deleted inserted replaced
8440:ea4d6a7a2937 8441:a00b0fa0dbd7
    77         NSString *musicString = [[NSBundle mainBundle] pathForResource:@"hwclassic" ofType:@"mp3"];
    77         NSString *musicString = [[NSBundle mainBundle] pathForResource:@"hwclassic" ofType:@"mp3"];
    78         self.backgroundMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:musicString] error:nil];
    78         self.backgroundMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:musicString] error:nil];
    79         self.backgroundMusic.delegate = nil;
    79         self.backgroundMusic.delegate = nil;
    80         self.backgroundMusic.numberOfLoops = -1;
    80         self.backgroundMusic.numberOfLoops = -1;
    81     }
    81     }
    82     
    82 
    83     self.backgroundMusic.volume = DEFAULT_VOLUME;
    83     self.backgroundMusic.volume = DEFAULT_VOLUME;
    84     [self.backgroundMusic play];
    84     [self.backgroundMusic play];
    85 }
    85 }
    86 
    86 
    87 -(void) pauseBackgroundMusic {
    87 -(void) pauseBackgroundMusic {
    96     if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"music"] boolValue] == NO)
    96     if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"music"] boolValue] == NO)
    97         return;
    97         return;
    98 
    98 
    99     if (self.audioFaderQueue == nil)
    99     if (self.audioFaderQueue == nil)
   100         self.audioFaderQueue = [[NSOperationQueue alloc] init];
   100         self.audioFaderQueue = [[NSOperationQueue alloc] init];
   101     
   101 
   102     MXAudioPlayerFadeOperation *fadeOut = [[MXAudioPlayerFadeOperation alloc] initFadeWithAudioPlayer:self.backgroundMusic
   102     MXAudioPlayerFadeOperation *fadeOut = [[MXAudioPlayerFadeOperation alloc] initFadeWithAudioPlayer:self.backgroundMusic
   103                                                                                              toVolume:0.0
   103                                                                                              toVolume:0.0
   104                                                                                          overDuration:FADEOUT_DURATION];
   104                                                                                          overDuration:FADEOUT_DURATION];
   105     [self.audioFaderQueue addOperation:fadeOut];
   105     [self.audioFaderQueue addOperation:fadeOut];
   106     [fadeOut release];
   106     [fadeOut release];
   142 }
   142 }
   143 
   143 
   144 -(void) playClickSound {
   144 -(void) playClickSound {
   145     if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO)
   145     if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO)
   146         return;
   146         return;
   147     
   147 
   148     if (self.clickSound == -1)
   148     if (self.clickSound == -1)
   149         self.clickSound = [self loadSound:@"clickSound"];
   149         self.clickSound = [self loadSound:@"clickSound"];
   150     
   150 
   151     AudioServicesPlaySystemSound(self.clickSound);
   151     AudioServicesPlaySystemSound(self.clickSound);
   152 }
   152 }
   153 
   153 
   154 -(void) playBackSound {
   154 -(void) playBackSound {
   155     if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO)
   155     if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO)
   156         return;
   156         return;
   157     
   157 
   158     if (self.backSound == -1)
   158     if (self.backSound == -1)
   159         self.backSound = [self loadSound:@"backSound"];
   159         self.backSound = [self loadSound:@"backSound"];
   160     
   160 
   161     AudioServicesPlaySystemSound(self.backSound);
   161     AudioServicesPlaySystemSound(self.backSound);
   162 }
   162 }
   163 
   163 
   164 -(void) playSelectSound {
   164 -(void) playSelectSound {
   165     if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO)
   165     if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO)
   166         return;
   166         return;
   167     
   167 
   168     if (self.selSound == -1)
   168     if (self.selSound == -1)
   169         self.selSound = [self loadSound:@"selSound"];
   169         self.selSound = [self loadSound:@"selSound"];
   170     
   170 
   171     AudioServicesPlaySystemSound(self.selSound);
   171     AudioServicesPlaySystemSound(self.selSound);
   172 }
   172 }
   173 
   173 
   174 @end
   174 @end