Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 09-06-2011, 12:31 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default Audio Session - why this error?

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).
RLScott is offline   Reply With Quote
Old 09-06-2011, 02:26 PM   #2 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

I just got some additional information from my ad hoc tester that may shed some light on the sequence of events. Apparently the applicationDidBecomeActive that caused the error is not the call that happened after the SMS text reply was sent. From the timing it appears that applicationDidBecomeActive is being called some time before the SMS text reply was sent. Here is why I think that. After the SMS text reply is sent, the user is presented with a screen as shown in the attached image. My app is clearly in background at this time. From this screen he goes back to my app. What he sees when he goes back to my app is the app running normally, but with an AlertView showing the report of the failure of AudioSessionSetActive(true) overlaid on the normally running screen. When he dismisses the AlertView, everything is normal. That indicates that there was a successful starting of the audio queue in addition to the unsuccessful one. The successful one was the result of calling applicationDidBecomeActive after the app being in background during the SMS reply. (I also start the audio from applicationDidBecomeActive if the main view controller's view is supposedly still showing.) The logging then shows that the error occurred before the entry into background, even though the reporting of that error was not visible until much later. Here is the complete log from the user in Sweden:

applicationDidBecomeActive (audio opening deferred in this case)
viewDidAppear (audio is opened)
viewWillDisappear (audio is closed)
viewWillAppear (audio is opened)
applicationWillResignActive (audio is closed)
applicationDidBecomeActive (audio opening is attempted with error)
applicationWillResignActive
applicationDidEnterBackground (SMS text reply is being entered?)
applicationDidBecomeActive (audio opened successfully)

By the way, the log is a custom implementation, not NSLog.
Attached Images
File Type: jpg IMG_0185.jpg (15.0 KB, 6 views)
RLScott is offline   Reply With Quote
Old 09-08-2011, 04:30 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

Still looking for some explanation of why I get a kAudioSessionIncompatibleCategory error when making my Audio Session active.
RLScott is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 378
10 members and 368 guests
bignoggins, epaga, hussain1982, LunarMoon, momolgtm, Newbie123, omagod, Paul10, pinacate, skog
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,643
Threads: 94,110
Posts: 402,860
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Diligent
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:51 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0