2012-08-03 76 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