-2

可能重复:
声音停止播放

我对 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(/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 在/System/Library/Frameworks/Security。框架/版本/A/Security 2012-08-08 06:46:30.895 serviceTest[408:10703] 加载/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/ /System/Library/Frameworks/Security.framework/Versions/A/Security 中的 CoreFoundation.framework/CoreFoundation 2012-08-08 06:46:31.196 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 在/System/Library/Frameworks/Security.framework/Versions/A/Security 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在 /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/时出错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。/System/Library/Frameworks/Security.framework/Versions/A/Security 中的 0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 2012-08-08 06:46:31.301 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 在/System/Library/Frameworks/Security.framework/Versions/A/Security 2012-08-08 06:46:31.358 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 在/System/Library/Frameworks/Security.framework/Versions/A/Security 2012-08-08 06:46:31.382 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/ /System/Library/Frameworks/Security.framework/Versions/A/Security 2012-08-08 06:46:31.461 serviceTest[408:10703] 加载 /System/Library/Extensions/AppleHDA.kext 中的 CoreFoundation.framework/CoreFoundation /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 在/System/Library/Frameworks/Security.framework/Versions/A/Security 2012-08-08 06:46:31.486 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在/System/Library/Frameworks/Security.framework/Versions/A/Security 2012-08-08 06:46:31.549 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。/System/Library/Frameworks/Security.framework/Versions/A/Security 中的 0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 2012-08-08 06:46:31.575 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 在/System/Library/Frameworks/Security.framework/Versions/A/Security/System/Library/Frameworks/Security.framework/Versions/A/Security 中的 sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 2012-08-08 06:46:31.575 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 在/System/Library/Frameworks/Security.framework/Versions/A/Security/System/Library/Frameworks/Security.framework/Versions/A/Security 中的 sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 2012-08-08 06:46:31.575 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 在/System/Library/Frameworks/Security.framework/Versions/A/Security框架/版本/A/安全框架/版本/A/安全框架/版本/A/安全框架/版本/A/安全/System/Library/Frameworks/Security.framework/Versions/A/Security 中的框架/CoreFoundation 2012-08-08 06:46:31.575 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 /System/Library/Frameworks/Security.framework/Versions/A/Security 中的 /Library/Frameworks/CoreFoundation.framework/CoreFoundation/System/Library/Frameworks/Security.framework/Versions/A/Security 中的框架/CoreFoundation 2012-08-08 06:46:31.575 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 /System/Library/Frameworks/Security.framework/Versions/A/Security 中的 /Library/Frameworks/CoreFoundation.framework/CoreFoundation框架/版本/A/Security 2012-08-08 06:46:31.575 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 在/System /Library/Frameworks/Security.framework/Versions/A/Security框架/版本/A/Security 2012-08-08 06:46:31.575 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 在/System /Library/Frameworks/Security.framework/Versions/A/Securitykext/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。 /System/Library/Frameworks/Security.framework/Versions/A/Security 中的 sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundationkext/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。 /System/Library/Frameworks/Security.framework/Versions/A/Security 中的 sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation___CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 预期在:/Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0。 /System/Library/Frameworks/Security.framework/Versions/A/Security 中的 sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation___CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 预期在:/Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0。 /System/Library/Frameworks/Security.framework/Versions/A/Security 中的 sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation

4

2 回答 2

0
于 2012-08-07T11:37:26.850 回答
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 is the audio file format.

Also, Add AVFoundation.framework into your project.

Add, into '.h' file.

于 2012-08-07T12:02:11.250 回答