felix
felix

Reputation: 11542

Switching Off Sound in an iPhone Application

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

Upvotes: 0

Views: 533

Answers (2)

willc2
willc2

Reputation: 39671

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;

Upvotes: 2

Greg Martin
Greg Martin

Reputation: 5064

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);

Upvotes: 0

Related Questions