AVAudioPlayer错误加载文件

我正在尝试使用AVAudioPlayer播放一个简单的声音,我不断收到在控制台中的这个错误:

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 

这是我的代码,应该按下我的button时播放声音:

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

我不知何故在错误的地方有文件? 我只是拖动文件到项目中,如果需要select复制。

编辑:经过更多的testing,我发现运行IOS 4.2模拟器时,我不会得到这个错误,只有在IOS 5模拟器。 我可以认为这是iOS 5中的一个错误吗?

谢谢,

我有同样的问题。 它似乎只是在iOS5模拟器上的一个问题。 我还没有在iOS 5设备上进行testing。 我一直希望XCode升级会使错误消失,但迄今没有运气。

我有同样的错误,但声音播放后,我把variables作为一个类的属性。 如果你放在这里的代码写在一个方法里面,试着移动这个variables。 我猜声音没有播放,因为在方法超出范围后,audioPlayer实例丢失了。

 @implementation SomeAudioController { AVAudioPlayer *tickPlayer; } 

让你的AVAudioPlayer属性w /强大的参考。

来源: AVAudioPlayer拒绝播放任何东西,但没有错误等

上面的答案帮助我在我的模拟器中播放.wav文件,但是我还没有得到它在我的设备上工作。 关于缺less解码器的东西..?

编辑

为了在设备上播放audio,我还必须将以下行添加到AppDelegate.m的didFinishLaunchingWithOptions:

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

尝试检查是否启用了“所有exception”断点,这将导致debugging器在exception处中断。 只需禁用此function并再次构build它。

当我尝试播放一些button点击并编译成iOS5的MP3文件时,也出现了相同types的错误。 当我编译到iOS4时,错误消失,但声音仍然不出来。 没有运行时错误,NSLogs在debugging控制台中正确打印。 你find一种方法来播放你的MP3文件?

从多媒体编程指南:

iOS中的首选audio格式对于未压缩(最高质量)的audio,使用打包在CAF文件中的16位,小端,线性PCMaudio数据。 您可以使用afconvert命令行工具在Mac OS X中将audio文件转换为此格式,如下所示:

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

afconvert工具可以让你转换成各种各样的audio数据格式和文件types。 请参阅afconvert手册页,并在shell提示下inputafconvert -h以获取更多信息。

对于一次播放一个声音时的压缩audio,以及不需要与iPod应用程序同时播放audio时,请使用打包在CAF或m4a文件中的AAC格式。

为了在需要同时播放多个声音时使用更less的内存,请使用IMA4(IMA / ADPCM)压缩。 这样可以减小文件大小,但是在解压缩过程中CPU占用的影响最小。 与线性PCM数据一样,将IMA4数据封装在CAF文件中。