AVAudioSession Speaker Fix

Below is a code snipped that quickly solved what could have been a huge problem. In the development of the Affirmation Labs iOS App, I set a session up so my affirmation audio can loop and continue in the background regardless of home-button push and device lock. After this behemoth task and trickery was completed, I realized that during my AVAudioSession with Category set to AVAudioSessionCategoryPlayAndRecord, I had a huge issue with volume decreasing when the session was enabled. Once I created the fix for directing audio forcefully to the iOS speaker to retain my max volume level, I ran into another bug that certainly stumped me. When I would plug in headphones and unplug them during the audio session, the audio would revert off of the speaker and I would hear a huge decrease in iPhone audio. Much love to Jonas on StackOverflow for figuring this out and sharing it with the community. I’ve re-posted the code as a kickoff to my “Code” category on my blog as it certainly saved me a tone of time and investigation and is quite simple and elegant.

NSError *setCategoryErr = nil;

NSError *activationErr  = nil;

//Set the general audio session category

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&setCategoryErr];

//Make the default sound route for the session be to use the speaker

//Jonas' Code Begins ---------------

UInt32 doChangeDefaultRoute = 1;

AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof (doChangeDefaultRoute), &doChangeDefaultRoute);

//Jonas' Code Ends ----------------

//Activate the customized audio session

[[AVAudioSession sharedInstance] setActive: YES error: &activationErr];

iPhone Killer: The Pomegranate NS08

The All-In-One Phone

The All-In-One Phone

Startup Technology – PortableYou

Strietzel – December 15, 2008 | Jon Snoddy

Startup Life – People who frequent Big Stage Joint tend to dream big. Kind of an unspoken requirement I guess. We started this thing with the vision of digitizing humanity… all of it… everybody. We wanted to create a technology so transformative that it would launch an unstoppable series of domino falls that would result in a planet sized population of digital people, all dressed up and looking for somewhere to go. For this to happen, we knew that the tech would have to be really easy to use. It would have to rely on hardware that everybody has laying around and it would have to happen fast because we are all so crazy busy. We set goals: a standard digital camera, a couple of photos in a couple of minutes, and your friends have to recognize the results, and who would have thought; we’re there, and more. Woo hoo! Let’s go digitize a species.

To entertain the digital us, we took the next step with the launch of our Startup,, our social network in which you create and share the digital you in cool digital content. Adding yourself to content you like is great good fun and sharing it is hard to resist, so pretty much everyone gets

That’s now rolling so we are on to our third act in which
“The Digital You” gets up and walks out the damn door! We call it PortableYou and we are inviting all our friends are to the party. Any web site, video game or virtual world can adopt PortableYou and add instant personalization to their world. They can play, fight, learn, travel in the wonders of cyberspace, with their friends, as themselves. Life is good in Digitalville. You can digitize yourself before breakfast at, dash off to a class at, then star in the film, The Spirit on your iPhone, and close out the day hanging with the digital star of a hit MTV show. Yes, the digital life is sweet.

Read more