Reading the Silent Switch?
Is it possible to read the state of the silent switch on the side of the phone? I can't seem to find anything in the docs or SDK.
its a bit tricky, you have to set your output to ambient level sound then it will respect the silent switch. There is no true way to "read" it though.
Also note that setting the session to ambient works fine with OpenAL, but not with Audio Queues. With Audio Queues, the system apparently tries to pipe audio through the same single hardware decoder as iTunes, if the user had played music, or turns on iTunes during your game (double-clicking the home button). This can freeze the device, requiring a reboot!
Sweet, that's exactly what I needed. And it solved another issue with the game audio stopping any iPod playback. Here's the code I used for anyone searching in the future. Just stick it before any OAL initialization.
https://developer.apple.com/iphone/libra...rence.html
https://developer.apple.com/iphone/libra...SpeakHere/
https://developer.apple.com/iphone/libra...rence.html
https://developer.apple.com/iphone/libra...SpeakHere/
Code:
// The audio session setup
UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
AudioSessionInitialize(NULL, NULL, interruptionListenerCallback, self);
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
AudioSessionSetActive(YES);
// The interruption callback
void interruptionListenerCallback(void *inUserData, UInt32 interruptionState)
{
MySoundController *controller = (MySoundController *)inUserData;
if (interruptionState == kAudioSessionBeginInterruption)
{
// stop sound/music here
[controller stopPlaying]; // or whatever
}
else if (interruptionState == kAudioSessionEndInterruption)
{
// resume any sound/music necessary here
[controller resumePlaying]; // etc
}
}
There is a rumor that 2.2 will fix the silent switch issue and give us an easy way to check for it.
This page is also required reading for any app that wants to play audio:
Audio Sessions: Cooperating with Core Audio
That link should be in big huge +10 font on the iPhone dev homepage.
Audio Sessions: Cooperating with Core Audio
That link should be in big huge +10 font on the iPhone dev homepage.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| How do I get iPod Player to respect silent switch? | CVogelbusch | 0 | 1,472 |
Nov 25, 2009 05:34 AM Last Post: CVogelbusch |
|
| Added openfient, switch to c++ duplicate symbol | kendric | 7 | 3,197 |
Aug 9, 2009 02:47 AM Last Post: backslash |
|

