views:

631

answers:

3

Hi, I would like to stop my application playing a sound if the user has switched the iPhone to silent mode. Where can I read that the phone is in silent mode? Is there some flag I can query? I noticed that some applications ignore the silent mode and some not, while I would have expected all apps to respect that silent is silent !!

Any hints or input would be greatly appreciated. Thanks Al

A: 

If the iPhone is silent, why stop playing a sound?

Or, does silent mode just not play certain sounds? I don't have an iPhone (iPod Touch) so I'm not sure.

chpwn
I think he wants to detect if the phone's ringer is switched off. On my iPhone at least, the switch that silences the ringer does not suppress all sound coming from the phone (the iPod app still plays music). Presumably, that's why the OP wants his app to be able to detect the state of the phone's ringer.
Stephen Van Dahm
Thanks for all the feedback. What I am looking to do is switch the aplication's sounds off. So if you were in the theater as mentioned in the first reply then you could still use the app without upsetting the rest of the theater-audience.I think Chris has pointed me in the right direction. Cheers all.
Alan Aherne
+1  A: 

You need to set the appropriate Audio Session Category.

You tell iPhone OS your application’s audio intentions by designating a category for your audio session.

For more detail see - Configuring the Audio Session

Chris Gummer
+1  A: 

The Human Interface Guidelines published by Apple describes what is the ideal behavior for Apps to follow for Ring/Silent switch. So you may not need to disable audio if the user explicitly played that audio clip despite on silent mode.

The Ring/Silent Switch—What Users Expect

Users use the Ring/Silent switch to silence their devices when they want to:

  • Avoid being interrupted by unexpected sounds, such as Phone ringtones and incoming message sounds.
  • Avoid hearing sounds that are the byproducts of user actions, such as keyboard or other feedback sounds, incidental sounds, or application startup sounds.
  • Avoid hearing game sounds, including incidental sounds and soundtracks, that are not essential to using the game.

For example, in a theater users switch their devices to silent to avoid bothering other people in the theater. In this situation, users still want to be able to use applications on their devices, but they don’t want to be surprised by sounds they don’t expect or explicitly request, such as ringtones or new message sounds.

However, the Ring/Silent switch does not silence sounds that result from user actions that are solely and explicitly intended to produce sound. For example:

  • Media playback in a media-only application is not silenced by the Ring/Silent switch because the media playback was explicitly requested by the user.
  • A Clock alarm is not silenced by the Ring/Silent switch because the alarm was explicitly set by the user.
  • A sound clip in a language-learning application is not silenced by the Ring/Silent switch because the user took explicit action to hear it.
  • Conversation in an audio chat application is not silenced by the Ring/Silent switch because the user started such an application for the sole purpose of having an audio chat.

This behavior follows the principle of user control because it is up to the user, not the device, to decide whether it's appropriate to hear sounds the user explicitly requests.

Anurag