Sometime in games if your just using the SimpleAudioEngine it would be nice to just mute SFX or BGM and not everything, And When you mute the BGM, it would be nice to use the End users iPod music. If you want this to be the case and you are using SimpleAudioEngine then this might really help you out ;)
// // SimpleAudioEngineExt.h // Detonation // // Created by Craig Vella on 6/17/10. // Copyright 2010 craigvella. All rights reserved. // // Adds Muted Support for SFX & BGMusic w/Ability to play iPod Music when Muted #import <Foundation/Foundation.h> #import "SimpleAudioEngine.h" @interface SimpleAudioEngineExt : SimpleAudioEngine { BOOL muteSFX_; BOOL muteBGMusic_; } + (SimpleAudioEngineExt*) sharedEngine; @property (readwrite) BOOL muteSFX; @property (readwrite) BOOL muteBGMusic; @end
// // SimpleAudioEngineExt.m // Detonation // // Created by Craig Vella on 6/17/10. // Copyright 2010 craigvella. All rights reserved. // #import "SimpleAudioEngineExt.h" @implementation SimpleAudioEngineExt static SimpleAudioEngineExt *sharedEngine = nil; + (SimpleAudioEngineExt *) sharedEngine { @synchronized(self) { if (!sharedEngine) sharedEngine = [[SimpleAudioEngineExt alloc] init]; } return sharedEngine; } -(id) init { if ((self = [super init])) { muteSFX_ = NO; muteBGMusic_ = NO; } return self; } -(void) playBackgroundMusic:(NSString*) filePath loop:(BOOL) loop { if (!muteBGMusic_) [super playBackgroundMusic:filePath loop:loop]; else return; } -(ALuint) playEffect:(NSString*) filePath { if (muteSFX_) return 0; return [super playEffect:filePath]; } -(BOOL) muteSFX { return muteSFX_; } -(void) setMuteSFX:(BOOL)muteSFX { muteSFX_ = muteSFX; } -(BOOL) muteBGMusic { return muteBGMusic_; } -(void) setMuteBGMusic:(BOOL)muteBGMusic { muteBGMusic_ = muteBGMusic; if (muteBGMusic) { if ([self isBackgroundMusicPlaying]) [self stopBackgroundMusic]; [[CDAudioManager sharedManager] setMode:kAMM_FxOnly]; // Allow playing of iPod Music } else { [[CDAudioManager sharedManager] setMode:kAMM_FxPlusMusicIfNoOtherAudio]; } } @end