Hi, Can someone please tell me how to switch off sound in an iPhone Application. Thanks :)
A:
Are you talking about stopping any currently playing music when your application is launched? You can have the music fade out when your app is launched by setting the audio category for media playback. Add the code below to your applicationDidFinishLaunching method in the app delegate.
AudioSessionInitialize(NULL, NULL, NULL, self);
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
Greg Martin
2009-10-24 21:32:56
Hey...Thanks for the reply...Actually, I am looking for a way to mute the sounds in my application :). Can you please help me with it
Felix
2009-10-25 03:28:51
The sound your application plays or sounds the system might play?
Greg Martin
2009-10-25 15:05:02
Thanks Greg. It is just the sound my application plays :)
Felix
2009-10-25 19:02:24
+2
A:
In the view controller that plays your sounds, add an ivar with a @property
BOOL muteSoundFlag // as ivar of view controller
@property (nonatomic, retain) BOOL muteSound; // in header
@synthesize muteSound; // in implementation
Wrap all your sound playing code in an if...block
if (!self.muteSoundFlag) {
// your sound player code
}
When you want sound muted, set the flag to true
self.muteSoundFlag = YES;
willc2
2009-10-25 15:36:54