iPhone Music and Sound Effects in Parallel
Tuesday, April 6th, 2010I was trying to find out how to use [MPMusicPlayerController iPodMusicPlayer] and AVAudioPlayer in parallel. I’d read before that I’d need Audio Sessions, but the documentation for that was huge and confusing. Fortunately Andrew pointed me at this post from Mark at Sputnik Games which solved my issue immediately just by copying and pasting 14 lines of code into the applicationDidFinishLaunching method of my application delegate (see below). Sputnik Games’ blog doesn’t seem to support comments, so I thought I’d buy his latest game, Aerolite, and write this post to show my appreciation. Thanks Mark!
OSStatus result = AudioSessionInitialize(NULL, NULL, NULL, self); if (result) { // Init error, handle error here }else { UInt32 category = kAudioSessionCategory_AmbientSound; result = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category); if (result) { // set audio session error, handle error here }else { result = AudioSessionSetActive(true); if (result) { // Set audio session active error, handle error here } } }


![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_c.png?x-id=374b9e2b-0b73-4742-a18f-37c05e7c688b)

![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_c.png?x-id=0cf2b8c8-f36f-4744-a788-958eee3ea64e)