在ios中播放的mp3文件失败了

时间:2012-08-07 11:24:39

标签: ios5 avaudioplayer

  

可能重复:
  Sound stop playing

我对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.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 /扩展/ 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 /扩展/ 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 /扩展/ 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 /扩展/ 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 /扩展/ 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 /扩展/ 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 /扩展/ 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 /扩展/ 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 /扩展/ 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 /扩展/ 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 /扩展/ 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

2 个答案:

答案 0 :(得分:0)

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

在您的iOS应用程序中播放音频:

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

答案 1 :(得分: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'文件中。