23
votes

I am trying to use the AVAudioPlayer to play a simple sound and I keep getting this error in the console:

2011-09-02 20:29:07.369 MusicLog[967:10103] Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn:  dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
  Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
  Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
 in /System/Library/Frameworks/Security.framework/Versions/A/Security

Here is my code that should play a sound when my button is pressed:

NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"tick" ofType:@"caf"];
NSError *error;

    NSURL *soundURL = [NSURL fileURLWithPath:soundPath];
    AVAudioPlayer *tickPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:&error];
[tickPlayer setDelegate:self];
[tickPlayer setNumberOfLoops:0];
[tickPlayer prepareToPlay];
if (tickPlayer == nil)
{
    NSLog(@"%@", [error description]);
}
else
{
    [tickPlayer play];
}

Do I somehow have the file in the wrong place? I just dragged the file into the project and selected copy if needed.

EDIT: After more testing I found that I do not get this error when running IOS 4.2 simulator, only on the IOS 5 simulator. Can I assume that this is a bug in iOS 5?

Thanks,

6

6 Answers

22
votes

I've had the same problem. It only seems to be a problem on iOS5 in simulator. I haven't tested on an iOS 5 device yet. I keep hoping XCode upgrades will make the error go away, but so far no luck.

2
votes

I've had the same error, but the sound played nonetheless after I keep the variable as a class attribute. If the code that you put here is written inside a method, try moving this variable. I guess the sound didn't play because the audioPlayer instance is lost after the method went out of scope.

@implementation SomeAudioController {
    AVAudioPlayer *tickPlayer;
}
1
votes

Make your AVAudioPlayer a property w/ a strong reference.

Source: AVAudioPlayer refuses to play anything, but no error, etc

The above answer helped me to play the .wav file in my simulator, but I haven't gotten it to work on my device yet. Something about missing codecs..?

Edit:

For the audio to play on the device, I also had to add the following line to AppDelegate.m's didFinishLaunchingWithOptions:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];

1
votes

Try to check if you have enabled the "All Exceptions" breakpoint, which will result in the debugger breaks at the exception instead. Just disable this feature and built it again.

0
votes

I also had the same type of error when I tried to play some mp3 files on button click and compiled to iOS5. The error disappeared when I compiled to iOS4 but the sound still doesn't come out. There was no runtime error and the NSLogs printed properly in the debug console. Did you find a way to play your mp3 files?

-1
votes

From Multimedia Programming Guide:

Preferred Audio Formats in iOS For uncompressed (highest quality) audio, use 16-bit, little endian, linear PCM audio data packaged in a CAF file. You can convert an audio file to this format in Mac OS X using the afconvert command-line tool, as shown here:

/usr/bin/afconvert -f caff -d LEI16 {INPUT} {OUTPUT}

The afconvert tool lets you convert to a wide range of audio data formats and file types. See the afconvert man page, and enter afconvert -h at a shell prompt, for more information.

For compressed audio when playing one sound at a time, and when you don’t need to play audio simultaneously with the iPod application, use the AAC format packaged in a CAF or m4a file.

For less memory usage when you need to play multiple sounds simultaneously, use IMA4 (IMA/ADPCM) compression. This reduces file size but entails minimal CPU impact during decompression. As with linear PCM data, package IMA4 data in a CAF file.