2012-07-13 59 views
0

我想當按下一個UIButton播放聲音..添加聲音的UIButton

這是我的代碼

-(IBAction) playSound:(id)sender{ 

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

    theAudio.delegate=self; 
    [theAudio play]; 

} 

這是當按鈕被按下輸出

2012-07-13 16:41:02.803 squeek[1475:12103] Error loading /System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn: dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn, 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-07-13 16:41:02.811 squeek[1475:12103] Error loading /System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn: dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn, 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-07-13 16:41:03.389 squeek[1475:12103] 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-07-13 16:41:03.396 squeek[1475:12103] 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-07-13 16:41:03.409 squeek[1475:12103] 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-07-13 16:41:03.417 squeek[1475:12103] 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-07-13 16:41:03.431 squeek[1475:12103] 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-07-13 16:41:03.440 squeek[1475:12103] 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 

IBAction與UIButton連接起來,增加了內部特徵,我也添加了avfoundation框架。

任何幫助將不勝感激。

+0

這個問題是完全複製爲http://stackoverflow.com/questions/7961840/what-does-this-gdb-output-mean – 2012-07-13 05:02:10

+0

不要在設備上工作....我已經嘗試過,但由於某種原因,只是不想在設備上播放。 – HurkNburkS 2012-07-13 05:05:34

+0

嘗試添加Security.framework ...根據您的日誌,它可能工作... – Dhruv 2012-07-13 05:16:06

回答

1

@HurkNburkS

你只需要在堆棧溢出問同樣的問題以前多了幾分搜索。無論檢查下面的問題並嘗試解決方案。

Sound not playing with AVAudioPlayer

Supported Audio file formats in iPhone

退房音頻格式可能是一個問題,或者你的 「theAudio」 實例應該被釋放。

嘗試像這樣和打印錯誤...

NSError *error; 
audioPlayer = [[AVAudioPlayer alloc] 
       initWithContentsOfURL:url 
       error:&error]; 
if (error) 
{ 
     NSLog(@"Error in audioPlayer: %@", 
       [error localizedDescription]); 
} else { 
     audioPlayer.delegate = self; 
     [audioPlayer prepareToPlay]; 
}