1

I'm making a soundboard for iOS, and use the following code:

#import <AVFoundation/AVAudioPlayer.h>

...

 NSString *path = [[NSBundle mainBundle] pathForResource:@"bg" ofType:@"wav"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];

theAudio.delegate=self;
[theAudio play];
NSLog(@"Audio Played");

I see the "Audio Played" in the log, but I hear nothing.

I'll get this error:

 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: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
 in /System/Library/Frameworks/Security.framework/Versions/A/Security
2013-02-04 09:34:30.988 Ronald Goedemondt[461:1c03] 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: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
 in /System/Library/Frameworks/Security.framework/Versions/A/Security
2013-02-04 09:34:31.051 Ronald Goedemondt[461:1c03] 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: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
 in /System/Library/Frameworks/Security.framework/Versions/A/Security
2013-02-04 09:34:31.066 Ronald Goedemondt[461:1c03] 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: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
 in /System/Library/Frameworks/Security.framework/Versions/A/Security

Who can help me? Thanks!

AYS
  • 23
  • 1
  • 5
  • 1
    Did you check the mute switch on your device? Did you make sure that he path is valid? did you check wether the `AVAudioPlayer` is initialized correctly? – rckoenes Feb 04 '13 at 08:31
  • Yup, Path is valid... Sound is in Sound/Sound-wav/bg.wav – AYS Feb 04 '13 at 08:49

2 Answers2

1

EDIT: The error makes this seeming to be a known bug that occurs when the simulator tries to play sound on iOS 5.1 or lower. This shouldn't happen on an actual device or an iOS 6.0 simulator.

Before the audio file can be played you need to call [theAudio prepareToPlay]; That seems to be the issue here.

#import <AVFoundation/AVAudioPlayer.h>

...

 NSString *path = [[NSBundle mainBundle] pathForResource:@"bg" ofType:@"wav"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];

theAudio.delegate=self;
[theAudio prepareToPlay];
[theAudio play];
NSLog(@"Audio Played");

Aside from that you could check the path of your audio file etc.

if ((sound_file = [[NSBundle mainBundle] pathForResource:@"bg" ofType:@"wav"])
{
     //Audio Stuff
}
else{
     //Error
}
Leon Lucardie
  • 9,541
  • 4
  • 50
  • 70
0

See here : What does this gdb output mean?

This issue is filed by Apple under Bug ID# 10555404. Fixed in XCode 4.5, iOS 6.0

Community
  • 1
  • 1
Dhruv Goel
  • 2,715
  • 1
  • 17
  • 17
  • Dont know about 4.6, but as mentioned in the answer in the above link, the issue persists even in Xcode Version 4.5 when used in conjunction with the iOS 5.1 (or lower) simulators. So maybe its not been fixed for Simulators < 5.1 yet. – Dhruv Goel Feb 04 '13 at 09:01
  • I use my iPhone 4, with iOS 6.1. I'll get no errors, but hear nothing – AYS Feb 04 '13 at 09:04
  • And i have my volume on (mute is off). – AYS Feb 04 '13 at 09:07