2012-08-03 78 views
3

我想在我的iPhone app.I播放音频文件播放已经使用这个代码音频文件不与iPhone的SDK

#import <AVFoundation/AVFoundation.h> 

NSBundle *bundle = [NSBundle mainBundle]; 
    NSString *musicPath = [bundle pathForResource:@"audioSample" ofType:@"mp3"]; 
    NSURL *musicURL = [NSURL fileURLWithPath:musicPath]; 
    NSError *error= [NSError errorWithDomain:@"Domain" code:0 userInfo:nil]; 

    AVAudioPlayer *aplayer= [[AVAudioPlayer alloc] initWithContentsOfURL:musicURL error:&error]; 
    aplayer.delegate = self; 
    [aplayer play]; 

但会运行这个程序我得到这个error.Can请人帮忙我解决这个问题。我不明白为什么会出现这个错误。

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): Symbol not found: ___CFObjCIsCollectable 
    Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security 
    Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 
in /System/Library/Frameworks/Security.framework/Versions/A/Security 
2012-08-03 10:12:07.330 SampleAudioCode[591:12003] Error loading /Library/Audio/Plug-Ins/HAL/Digidesign CoreAudio.plugin/Contents/MacOS/Digidesign CoreAudio: dlopen(/Library/Audio/Plug-Ins/HAL/Digidesign CoreAudio.plugin/Contents/MacOS/Digidesign CoreAudio, 262): Symbol not found: ___CFObjCIsCollectable 
    Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security 
    Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 
in /System/Library/Frameworks/Security.framework/Versions/A/Security 
2012-08-03 10:12:07.330 SampleAudioCode[591:12003] Cannot find function pointer NewDigiCoreAudioPlugIn for factory B8A063B5-2F3D-444A-88CB-D0B8F1B22042 in CFBundle/CFPlugIn 0xdc50f50 </Library/Audio/Plug-Ins/HAL/Digidesign CoreAudio.plugin> (bundle, not loaded) 

谢谢您的回答..

+0

你的代码没有问题,看到我的回答如下 – sinh99 2012-08-03 06:50:19

回答

1

这似乎是与AVAudio框架问题只使用了iOS模拟器时。在实际的硬件上测试(在我的情况下,iPad 2 & iPad 1)不会产生这些相同的错误

这个错误只是来自系统框架的控制台噪声,您应该忽略它,它不会影响到您。如果你的应用程序崩溃或未能在其他地方发挥真正的原因。

and please also add CoreFoundation framwork. 
+0

谢谢很多你的答案。我会尝试这个代码与设备。我已经添加了你的建议framework.Do你认为这个代码可能会产生任何问题,iPhone或iPod? – NSP 2012-08-03 07:10:23

+0

没有这只是模拟器问题,我已经测试过它,但不没有发现任何问题:) – sinh99 2012-08-03 08:38:58

+0

非常感谢你:) – NSP 2012-08-03 09:47:29

0

首先,你必须添加AVFoundation框架

对于遵循这个步骤

  • 展开目标分支在组&文件项目面板
  • 按住Control键点按或右键单击AudioPlayer项目
  • 选择添加>现有框架...
  • 单击+按钮在左下下方链接库
  • 选择AVFoundation.framework,然后单击添加
  • AVFoundation.framework现在将根据链接库上市。 关闭窗口

现在.h文件中包含了这一框架和avaudio玩家创建实例

#import <AVFoundation/AVFoundation.h> 

和接口部分

AVAudioPlayer *audioPlayer; 

现在,在您.m文件,请使用此代码您想要播放.mp3文件的位置。

NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/audiofile.mp3", [[NSBundle mainBundle] resourcePath]]]; 

NSError *error; 
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; 
audioPlayer.numberOfLoops = -1; 

if (audioPlayer == nil) 
    NSLog([error description]);    
else 
    [audioPlayer play]; 
+0

谢谢你的答复,但它不是工作me..I都用它,但仍然没有得到解决的错误...... – NSP 2012-08-03 06:47:31

0

我觉得这是非常有用的AudioPlayer ...

-(void)play 
{ 
    [audioPlayer stop]; 

    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@",[soundArry objectAtIndex:pageNo.currentPage]] ofType:@"mp3"]]; 

    audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; 
    [audioPlayer play]; 


} 

soundArry是我SoundArray。 pageNo是My PageControl。

0

我觉得这是非常有用的音频播放:

NSString *filePath=[[NSBundle mainBundle] pathForResource:@"audiofile" ofType:@"mp3"]; 

NSURL *url = [NSURL fileURLWithPath:filePath]; 
NSError *error; 
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; 
audioPlayer.numberOfLoops = -1; 
if (audioPlayer == nil) 
     NSLog([error description]);    
else 
    [audioPlayer play]; 
+0

我得到这个错误。 Domain = NSOSStatusErrorDomain Code = -43“操作无法完成。(OSStatus错误-43。)“ – NSP 2012-08-03 06:51:04

+0

请改变文件路径:NSString * filePath = [[NSBundle mainBundle] pathForResource:@”audiofile“ofType:@”mp3“]; – 2012-08-03 07:44:43

+0

谢谢你的回答,但我已经改变了,但同样的回应。 – NSP 2012-08-03 12:34:11