iPhone Developer Tips Stats: 87,476 pageviews and 61,009 visitors in the past month! Thank you for your support to make iPhone Developer Tips your #1 resource for iPhone Tips and Tricks!
|
In a previous tip, Playing Short Sounds, I wrote an example to show how you can play a short sound, up to 30 seconds, by calling one of the C-based functions in the Audio Session Services library.
There is one aspect of this that can be troublesome – by default, playing an Audio Session sound will ~not~ respect the setting of the mute switch on the iPhone. In other words, if you make a call to play a sound and the silent (hardware) switch on the iPhone is set to silent, you’ll still hear the sound.
To respect the setting of the silent switch, add this code above any calls to play a sound:
// Choose a category identifier for audio sessions
UInt32 sessionCategory = kAudioSessionCategory_SoloAmbientSound;
// Set the session property
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory,
sizeof(sessionCategory), &sessionCategory);
There are a number of pre-defined session categories, many will have the same end result as the kAudioSessionCategory_SoloAmbientSound that I opted to use.
Comments
2 Responses to “Silent Mode Switch and Playing Sounds”
Leave Comment
Will this be approved by Apple? Is it allowed per SDK rules and Developer Agreement?
Yes, this call is provided in the public SDK.