Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically sense the iPhone mute switch?

I can't seem to find in the SDK how to programatically sense the mute button/switch on the iPhone. When my app plays background music, it responds properly to the volume button without me having any code to follow that but, when I use the mute switch, it just keeps playing away.

How do I test the position of mute?

(NOTE: My program has its own mute switch, but I'd like the physical switch to override that.)

like image 990
Olie Avatar asked Nov 13 '08 17:11

Olie


People also ask

How do you bypass mute switch on iPhone?

When you tap on edit, go to the individual's ringtone and tap there. Scroll to the top of that page and there is a setting for Emergency Bypass. With that switch on, you will receive sounds from that caller even if the phone is on Mute or Do Not Disturb is on. Sorry for the confusion.

Why does iPhone have a switch for silent mode?

The moon (Silent Mode) switch, is to block incoming notifications. Show activity on this post.

Does mute button work on iPhone?

1 | Operating the silent mode switch on an iPhoneAll iPhones and some iPads have a ring / silent switch on the left side of the device (above the volume buttons). Move the switch in way that the switch does not have an orange background color as the image below.


2 Answers

Thanks, JPM. Indeed, the link you provide leads to the correct answer (eventually. ;) For completeness (because S.O. should be a source of QUICK answers! )...

// "Ambient" makes it respect the mute switch // Must call this once to init session if (!gAudioSessionInited) {     AudioSessionInterruptionListener    inInterruptionListener = NULL;     OSStatus    error;     if ((error = AudioSessionInitialize (NULL, NULL, inInterruptionListener, NULL)))     {         NSLog(@"*** Error *** error in AudioSessionInitialize: %d.", error);     }     else     {         gAudioSessionInited = YES;     } }  SInt32  ambient = kAudioSessionCategory_AmbientSound; if (AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (ambient), &ambient)) {     NSLog(@"*** Error *** could not set Session property to ambient."); } 
like image 167
Olie Avatar answered Sep 29 '22 11:09

Olie


I answered a similar question here (link). The relevant code:

 -(BOOL)silenced {      #if TARGET_IPHONE_SIMULATOR          // return NO in simulator. Code causes crashes for some reason.          return NO;      #endif      CFStringRef state;     UInt32 propertySize = sizeof(CFStringRef);     AudioSessionInitialize(NULL, NULL, NULL, NULL);     AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);     if(CFStringGetLength(state) > 0)             return NO;     else             return YES;      } 
like image 20
Chris Ladd Avatar answered Sep 29 '22 11:09

Chris Ladd