Question

Can someone please tell me how to switch off sound in an iPhone Application. Thanks :)

Was it helpful?

Solution

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;

OTHER TIPS

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top