Problems with AudioToolbox on iOS 5? Read this!

It seems that Apple did some changes on Core Audio and, more specifically, the AudioToolbox Framework for iOS 5. Some users (myself too) are reporting problems with this framework, making the app to hang up on most cases although the audio works fine.

Since the users (and me neither) did not any change to the app since the last iOS version, all the facts points to a bug on iOS 5 related with the audio subsystem, more specifically with AudioToolbox, SystemSound calls, etc. So, do you have to wait for an Apple bug fix release?  NO!

Ok, first of all, don’t panic. Here you’ll find the solution if you are having the same kind of problem.

First of all, to be sure you’re getting the same error, check your console log and look for the following lines:

Error loading

/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn:  dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn, 262): Symbol not found: ___CFObjCIsCollectable

If the previous lines appears.., good! , lets see how to add a workaround until Apple releases a fix for this.

I’m creating another app with the Cocos2d framework that doesn’t have this problem. Cocos2d uses a framework to play background audio and sound effects. It’s called “CocosDenshion” and you can use it directly on your app.

The framework is distributed with cocos2d, so download it from here: http://www.cocos2d-iphone.org/

Once you’ve downloaded it, you will find a folder called CocosDenshion with some .h and .m files. Add all of them to your project along with the frameworks needed:

AVFoundation, OpenAL and AudtioToolbox.

Next, let’s replace your current code to play your sound files:

1.- Add the “SimpleAudioEngine.h” header to your class

[cce lang=”objc”]#import “SimpleAudioEngine.h”[/cce]

2.- Done!, now if you want to play/stop background music:

[cce lang=”objc”]

// Start playing

[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@”background.mp3″ loop:YES];

……

// Stop playing

[[SimpleAudioEngine sharedEngine] stopBackgroundMusic];

[/cce]

3.- Finally, if you wan’t to play some effects:

[cce lang=”objc”]

// Play the effect

[[SimpleAudioEngine sharedEngine] playEffect:@”effect.mp3″];

[/cce]

Now you just need to send your update to Apple and cross your fingers to be released soon. You can try to request for an expedited review (i did it too) on iTunesConnect, arguing your app was working fine until the update of iOS.

If you liked this tutorial, link and send it to your developer friends so the have the same info and check if all is working fine with iOS 5.

Good luck and thanks for reading!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

18 − three =