在ios中播放mp3文件失败[重复]

Posted

技术标签:

【中文标题】在ios中播放mp3文件失败[重复]【英文标题】:mp3 file playing failed in ios [duplicate] 【发布时间】:2012-08-07 11:24:39 【问题描述】:

可能重复:Sound stop playing

我对 iPhone 应用程序开发非常陌生。我想在我的应用程序中播放一个 .mp3 文件。 这是我尝试执行的代码 sn-p。“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.framework/Versions/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/CoreFoundation.framework/CoreFoundation 在 /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(/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.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 在 /System/Library/Frameworks/Security.framework/Versions/A/Security 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/CoreFoundation.framework/CoreFoundation 在 /System/Library/Frameworks/Security.framework/Versions/A/Security 2012-08-08 06:46:31.461 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.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.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 在 /System/Library/Frameworks/Security.framework/Versions/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

【问题讨论】:

请发布您收到的错误。 参考这个链接,之前有人问过这个问题:***.com/questions/1103170/… @Intrus:我认为“NSSound”适用于 mac 开发。不适用于 iPhone 【参考方案1】:

我发布了一条评论,其中包含指向与您类似的另一个堆栈溢出问题的链接,但这里有一个链接可以逐步引导您:

在您的 ios 应用中播放音频:

http://www.devsrealm.com/objective-c/playing-audio-in-your-ios-app/

【讨论】:

感谢 Intrus :) 问题已解决【参考方案2】:
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”文件中。

【讨论】:

以上是关于在ios中播放mp3文件失败[重复]的主要内容,如果未能解决你的问题,请参考以下文章

在 iOS 应用程序中播放 mp3 文件 [重复]

使用 C++ 在 linux 中播放 .mp3 或其他音频文件 [重复]

在 iOS 上播放 MP3 或 AAC 文件都有哪些音频播放选项?

AVPlayer 不在 iOS 文档目录中播放 MP3 音频文件

iOS - mp3 文件不播放,没有错误?

在IOS中通过http播放mp3文件