2012-08-07 218 views
-2

可能重複:
Sound stop playingMP3文件播放失敗的ios

我真的很新的對iPhone應用程序開發。我想在我的應用程序中播放.mp3文件。 這是我試圖做的代碼片段。「dd.mp3」是在支持文件下的文件。但它不起作用。我做了什麼錯了嗎?

NSError *error=nil; 
NSURL *audioURL =[[NSBundle mainBundle] URLForResource:@"dd" withExtension:@"mp3"]; 
AVAudioPlayer *avPlayerObject = [[AVAudioPlayer alloc] initWithContentsOfURL:audioURL error:&error]; 

if(avPlayerObject) 
{ 
[avPlayerObject play]; 
} 

當我運行此代碼時我收到以下錯誤輸出。

2012-08-08 06:46:30.802 serviceTest [408:10703]錯誤加載/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn:dlopen的(/系統/圖書館/擴展/ AudioIPCDriver.kext /內容/資源/ AudioIPCPlugIn.bundle /內容/ MacOS的/ AudioIPCPlugIn,262):找不到符號:___CFObjCIsCollectable 從引用:/System/Library/Frameworks/Security.framework/Versions/A /安全 預計於:/Volumes/Xcode/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 2012-08-08 06:46:30.895 serviceTest [408:10703] Er ROR裝載/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):未找到符號:___CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 預計位於:/Volumes/Xcode/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 2012-08-08 06:46:31.196 serviceTest [408:10703]錯誤加載/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn:dlopen的(/系統/圖書館/擴展/ AppleHDA .kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn,262):找不到符號:___CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 預計在:/ Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation in/System/Library/Frameworks/Security。框架/版本/ A /安全 2012-08-08 06:46:31.221 serviceTest [408:10703]錯誤加載/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):符號未找到:___CFObjCIsCollectable 來回引用米:/System/Library/Frameworks/Security.framework/Versions/A/Security 在預期:/Volumes/Xcode/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 2012-08-08 06:46:31.276 serviceTest [408:10703]加載/ System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHluPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn:dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn ,262):未找到符號:___CFObjCIsCollectable 引用自:/ System/Library/Frameworks/Security。框架/版本/ A /安全 預計在:/Volumes/Xcode/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 2012-08-08 06:46:31.301 serviceTest [408:10703] 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):未找到符號:___CFObjCIsCollectable 已引用來自:/System/Library/Frameworks/Security.framework/Versions/A/Security 預計在:/Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhone Simulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation in /System/Library/Frameworks/Security.framework/Versions/A/Security 2012-08-08 06:46:31.358 serviceTest [408: 10703] Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn:dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/內容/ MacOS/AppleHDAHALPlugIn,262):未找到符號:___CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 預計位於:/Volumes/Xcode/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/安全 2012-08-08 06:46:31.382 serviceTest [408:10703]錯誤加載/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn:dlopen的(/系統/ Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn,262):找不到符號:___CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 預計於:/Volumes/Xcode/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 2012-08-08 06:46:31.461 serviceTest [408:10703] Error loading /System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlug In.bundle/Contents/MacOS/AppleHDAHALPlugIn:dlopen(/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn,262):未找到符號:___CFObjCIsCollectable 引用自:/系統/資源庫/框架/ Security.framework /版本/ A /安全 預計於:/Volumes/Xcode/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 2012-08-08 06:46:31.486 serviceTest [408:10703] 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) :S未找到ymbol:___CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 預計位於:/Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/ SDK/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation in /System/Library/Frameworks/Security.framework/Versions/A/Security 2012-08-08 06:46:31.549 serviceTest [ 408:10703] 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):找不到符號:___CFObjCIsCollectable 引用自:/ System/Library/Frameworks/Security。框架/版本/ A /安全 預計在:/Volumes/Xcode/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 2012-08-08 06:46:31.575 serviceTest [408:10703] 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):符號未找到:___CFObjCIsCollectable 引用來自:/System/Library/Frameworks/Security.framework/Versions/A/Security 預計在:/Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhone Simulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation in /System/Library/Frameworks/Security.framework/Versions/A/Security

+0

請發佈您收到的錯誤。 – Dayan 2012-08-07 11:28:21

+0

請參閱此鏈接,這是以前問:http://stackoverflow.com/questions/1103170/how-to-play-a-mp3-file-from-within-the-resources-folder-of-my-application – Dayan 2012-08-07 11:32:25

+0

@Intrus:我認爲「NSSound」適用於mac開發。不是iPhone – sashmarsh 2012-08-08 05:49:28

回答

0
NSString *path = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"caf"]; 
self.audioPlayer =[[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil]; 
[self.audioPlayer setDelegate:self]; 
[self.audioPlayer prepareToPlay]; 
[self.audioPlayer play]; 

CAF是音頻文件格式。

另外,將AVFoundation.framework添加到您的項目中。

添加到'.h'文件中。