AVAudioPlayer不适用于所有声音
问题描述:
我有一个iPhone应用程序将通过按按钮播放几个奇怪的声音,但不是所有的声音都在工作。AVAudioPlayer不适用于所有声音
这是我的.h文件的一部分:
{
AVAudioPlayer *hurl;
AVAudioPlayer *fart;
AVAudioPlayer *fart2;
AVAudioPlayer *evillaugh;
AVAudioPlayer *evillaugh2;
AVAudioPlayer *ghost;
AVAudioPlayer *guyhello;
AVAudioPlayer *wetfart;
}
这是我的.m文件的一部分:
- (IBAction)hurlButtonPressed:(id)sender
{
[hurl play];
}
- (IBAction)FartButtonPressed:(id)sender
{
[fart play];
}
- (IBAction)Fart2ButtonPressed:(id)sender
{
[fart2 play];
}
- (IBAction)EvilLaughButtonPressed:(id)sender
{
[evillaugh play];
}
- (IBAction)EvilLaugh2ButtonPressed:(id)sender
{
[evillaugh2 play];
}
- (IBAction)GhostButtonPressed:(id)sender
{
[ghost play];
}
- (IBAction)helloButtonPressed:(id)sender
{
[guyhello play];
}
- (IBAction)WetFartButtonPressed:(id)sender
{
[wetfart play];
}
- (void)viewDidLoad
{
NSURL *url = [[NSBundle mainBundle] URLForResource:@"Hurl" withExtension:@"wav"];
NSError *error;
hurl = [[AVAudioPlayer alloc] initWithContentsOfURL:url error: &error];
if(error != nil)
{
//This happens when the sound cannot be loaded
NSLog(@"Hurl could not be loaded!");
}
url = [[NSBundle mainBundle] URLForResource:@"Fart" withExtension:@"wav"];
fart = [[AVAudioPlayer alloc] initWithContentsOfURL:url error: &error];
if(error != nil)
{
//This happens when the sound cannot be loaded
NSLog(@"Fart could not be loaded!");
}
url = [[NSBundle mainBundle] URLForResource:@"fart_2" withExtension:@"wav"];
fart2 = [[AVAudioPlayer alloc] initWithContentsOfURL:url error: &error];
if(error != nil)
{
//This happens when the sound cannot be loaded
NSLog(@"Fart 2 could not be loaded!");
}
url = [[NSBundle mainBundle] URLForResource:@"evil_laugh" withExtension:@"wav"];
evillaugh = [[AVAudioPlayer alloc] initWithContentsOfURL:url error: &error];
if(error != nil)
{
//This happens when the sound cannot be loaded
NSLog(@"Evil Laugh could not be loaded!");
}
url = [[NSBundle mainBundle] URLForResource:@"evil_laugh_2" withExtension:@"wav"];
evillaugh2 = [[AVAudioPlayer alloc] initWithContentsOfURL:url error: &error];
if(error != nil)
{
//This happens when the sound cannot be loaded
NSLog(@"Evil Laugh 2 could not be loaded!");
}
url = [[NSBundle mainBundle] URLForResource:@"ghost" withExtension:@"wav"];
ghost = [[AVAudioPlayer alloc] initWithContentsOfURL:url error: &error];
if(error != nil)
{
//This happens when the sound cannot be loaded
NSLog(@"Ghost could not be loaded!");
}
url = [[NSBundle mainBundle] URLForResource:@"hello" withExtension:@"wav"];
guyhello = [[AVAudioPlayer alloc] initWithContentsOfURL:url error: &error];
if(error != nil)
{
//This happens when the sound cannot be loaded
NSLog(@"Guy Hello could not be loaded!");
}
url = [[NSBundle mainBundle] URLForResource:@"wet_fart02" withExtension:@"wav"];
wetfart = [[AVAudioPlayer alloc] initWithContentsOfURL:url error: &error];
if(error != nil)
{
//This happens when the sound cannot be loaded
NSLog(@"Wet Fart could not be loaded!");
}
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
然后,当我尝试在模拟器上播放它们,我得到的错误我为其中一些人设立的代码,他们不玩。
"2012-08-05 22:02:24.392 Bathroom Noise Prank[8747:c07] Fart 2 could not be loaded!
2012-08-05 22:02:24.395 Bathroom Noise Prank[8747:c07] Evil Laugh could not be loaded!
2012-08-05 22:02:24.396 Bathroom Noise Prank[8747:c07] Evil Laugh 2 could not be loaded!
2012-08-05 22:02:24.418 Bathroom Noise Prank[8747:c07] Ghost could not be loaded!
2012-08-05 22:02:24.420 Bathroom Noise Prank[8747:c07] Wet Fart could not be loaded!
2012-08-05 22:02:26.774 Bathroom Noise Prank[8747:c07] 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.1.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-08-05 22:02:26.784 Bathroom Noise Prank[8747:c07] 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.1.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-08-05 22:02:26.798 Bathroom Noise Prank[8747:c07] 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.1.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-08-05 22:02:26.805 Bathroom Noise Prank[8747:c07] 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.1.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-08-05 22:02:26.819 Bathroom Noise Prank[8747:c07] 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.1.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-08-05 22:02:26.826 Bathroom Noise Prank[8747:c07] 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.1.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security"
答
实际上我们看到这太 - 我们还没有想出的原因尚未但它似乎是依赖于你用于编码文件的软件;某种WAV格式或某些不一致的位置。
如果您将它们转换为AAC或MP3文件,是否有帮助?或者如果你在一个不同的WAV编辑工具中打开它们并从那里重新保存它们?
+0
奇怪...我用Audacity将它转换成了一个mp3,它工作。非常感谢! – LaurenG 2012-08-06 03:20:45
答
请包括以下框架...
1. SystemConfiguration.framework
2. CoreMedia.framework
3. MobileCoreServies.framework
4. AVFoundation.framework
5. CFNetwroks.framework
6. QuartzCore.framework
7. Secuirty.framework
8. AudioToolBox.framework
9. MediaPlayer.framework
10.CoreLocation.framework
也确保您的音频文件被正确添加。所有上述框架都不用于音频,但大部分都是。我想你应该只添加数字7框架。
它会更有记忆效率,更少的内部程序设计令人头疼,无法设置一个玩家并拥有一个玩家管理的声音库。只是一个提示:) – achi 2012-08-06 04:53:39
您在控制台中看到的错误与模拟器不是纯粹的iOS或OS X有关,它们与您所看到的问题无关。 – 2012-08-06 05:12:16