Here is the sequence of events:
applicationDidFinishLaunching (AppDelegate): I call AudioSessionInitialize once and only once for the lifetime of the app.
viewDidAppear (MainViewController): In this method I start up an audio stream as follows -
Code:
UInt32 sessionCategory = kAudioSessionCategory_RecordAudio;
OSStatus status = AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,
sizeof (sessionCategory),
&sessionCategory);
if(status != 0)
{
//..report this error (never happens)
}
Float64 hSamRate = 22050.0;
status = AudioSessionSetProperty(kAudioSessionProperty_PreferredHardwareSampleRate, sizeof (hSamRate),&hSamRate);
if(status != 0)
{
//..report this error (never happens)
}
status = AudioSessionSetActive (true);
if(status)
{
//..report this error (sometimes happens - see text)
}
listener = [[Listener alloc] init]; //..my Class that processes audio buffers
status =[listener startListening]; //..creates and starts an Audio Queue
And my response to applicationWillResignActive, applicationDidEnterBackground, or viewWillDisappear is to close down the audio queue as follows:
Code:
AudioQueueFlush( queue );
AudioQueueStop( queue, TRUE);
AudioQueueDispose( queue, TRUE);
AudioSessionSetActive(false);
Now here's the problem (on only one customer's phone, not mine). When receiving an SMS text message the following events occur (confirmed by some logging that I added to the code):
applicationDidBecomeActive (AppDelegate)
viewDidAppear (MainViewController) (audio queue started OK)
applicationWillResignActive (SMS text message arrives, I close my audio)
applicationDidBecomeActive (SMS popup message dismissed)
At this point I once again try to start up the audio queue. But this time AudioSessionSetActive (true) returns 560161140, which is kAudioSessionIncompatibleCategory, which means according to Apple docs:
Quote:
The specified audio session category cannot be used for the attempted audio operation. For example, you attempted to play or record audio with the audio session category set to kAudioSessionCategory_AudioProcessing.
Available in iOS 3.1 and later.
|
I should mention that this one customer is using an iPhone 4, and these tests have been conducted with ad hoc builds. He is in Sweden and I am in the US so testing is a little slow.
But this application has been in the app store for nearly two years and I haven't heard this report before. (The app store version does have rudimentary reporting for such an error, so if there was such an error, I would hear about it.) I should also mention that my AudioSessionInitialize also defines an interruption listener callback to detect kAudioSessionBeginInterruption and kAudioSessionEndInterruption, but my logging indicates that these conditions are not being triggered in this particular case (but they are being correctly triggered when a phone call comes in).
Can anyone see why this particular interruption causes this error when the audio is restarted? Phone call interruptions restart just fine. SMS text message interruptions do not - on this one phone).