Detect Mute Switch State on iPhone

You’re a developer! You’re the coolest person on your block! You want to know how to detect if the mute switch on the iPhone is flipped (ya know, for reminding dumb user why their phone isn’t playing any sound.) Well, I stumbled upon a solution – and I thought I’d share. Our goofy app, Wookiee Translator was about to be updated with this new detection before we pulled it from the store.

Here’s how it goes: If you’re calling a sound to play with AVAudioPlayer, and the mute switch is ON, the iPhone software doesn’t play anything, or waste time reading the audio file. (This might be true of OpenAL as well) If you create a “check” to see if anything is playing or not, you’ll get an indication of whether the switch is flipped or not!

In the Wookiee Translator, I set up a timer to calculate how long it was from when the sound file is called to play, to when it finishes playing. If that timer check returns a value less than the shortest sound files, then I know the mute switch is flipped, and can alert the user.

If your app isn’t as audio focussed, you could add a small silent audio file of a certain length, and call it to “play” and check go see if it does or not, and bingo – there’s your hardware switch state – do with it what you will.

And please, leave a comment if this is helpful!


2 Responses

  1. Great tip. Thanks for the post, I was frustrated with no API call to check for mute, and this workaround works great!

  2. Hi,

    I tried our tip with 4.0.2 but it didn’t work reliably! Maybe they changed something…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: