views:

194

answers:

2

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
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
The sound your application plays or sounds the system might play?
Greg Martin
Thanks Greg. It is just the sound my application plays :)
Felix
+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
Thank you very much. It works flawlessly :)
Felix