2012-08-07 217 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'文件中。