2012-08-06 46 views
-1

我有一個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" 
+1

它會更有記憶效率,更少的內部程序設計令人頭疼,無法設置一個玩家並擁有一個玩家管理的聲音庫。只是一個提示:) – achi 2012-08-06 04:53:39

+1

您在控制檯中看到的錯誤與模擬器不是純粹的iOS或OS X有關,它們與您所看到的問題無關。 – 2012-08-06 05:12:16

回答

0

實際上我們看到這太 - 我們還沒有想出的原因尚未但它似乎是依賴於你用於編碼文件的軟件;某種WAV格式或某些不一致的位置。

如果您將它們轉換爲AAC或MP3文件,是否有幫助?或者如果你在一個不同的WAV編輯工具中打開它們並從那裏重新保存它們?

+0

奇怪...我用Audacity將它轉換成了一個mp3,它工作。非常感謝! – LaurenG 2012-08-06 03:20:45

0

請包括以下框架...

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框架。