23

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,

Sophie Alpert
  • 139,698
  • 36
  • 220
  • 238
Kyle Rosenbluth
  • 1,672
  • 4
  • 22
  • 38

6 Answers6

22

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.

user453001
  • 244
  • 1
  • 3
  • Reading http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Basics/Basics.html#//apple_ref/doc/uid/TP40007875-CH2-SW9 it doesn't say Playback won't work. However, that's what's happening to me as well. Another thing: The cookbook http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Cookbook/Cookbook.html#//apple_ref/doc/uid/TP40007875-CH6-SW1 has a note on adding conditional code for the simlator. My guess is that the Audio needs rerouting in the simulator. – Sebastian Roth Oct 14 '12 at 08:58
  • Even's apple own sample app Breadcrumb will give this error on ios 5 simulator, so it seems to be simulator problem... http://developer.apple.com/library/ios/#samplecode/Breadcrumb/Introduction/Intro.html – ozba Nov 01 '12 at 15:23
2

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;
}
xvronny
  • 84
  • 5
1

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];

Community
  • 1
  • 1
subjective_c
  • 282
  • 2
  • 10
1

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.

Cocoa Rush
  • 11
  • 2
0

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?

boobami
  • 101
  • 2
  • 11
  • have you tried putting it on a device on IOS5? Although I'm not sure what your problem is cause even though I got the error my sound always played regardless – Kyle Rosenbluth Dec 08 '11 at 03:02
  • Yes, I changed target to iOS4 but run it on an iOS5 device as well as iPhone 5.0 simulation and it works. If I target iOS4 and run it on iPhone 4.0 simulation it doesn't work. – boobami Dec 09 '11 at 02:58
  • By the way, I am not too familiar with memory handling. Does there need to be some variable or object release somewhere in the code? – boobami Dec 09 '11 at 03:01
  • Sorry jih, I'm not sure what your problem is. I only had this warning on IOS 5 sim. – Kyle Rosenbluth Dec 13 '11 at 00:56
-1

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.

Community
  • 1
  • 1
XMLSDK
  • 259
  • 1
  • 10
  • Thanks, but I'm not sure about what you posted. My audio is in .CAF format, shouldn't it work for audio in CAF format? Why would I need to convert my sound? BTW, I am using the sound for the tick of a metronome. Thanks – Kyle Rosenbluth Sep 03 '11 at 14:34
  • Did you try using other sources of caf e.g. downloading from http://www.partnersinrhyme.com/pir/PIRsfx.shtml and test again? – XMLSDK Sep 03 '11 at 14:46
  • my sound is actually taken right out of some Apple sample code, I would think that it would work fine. – Kyle Rosenbluth Sep 03 '11 at 17:06
  • Nope, the AVAudioPlayer works in mp3 as well in iOS4, this is the bug of iOS5. I start having this bug on both device and simulator – vodkhang Oct 16 '11 at 13:17