2012-01-05 79 views
4

我目前正在從遠程服務器上下載.mp3文件,一旦文件加載,我將它存儲在Caches目錄中。然後,我創建AVAudioPlayer實例和數據加載到它:AVAudioPlayer阻止和iOS 5問題

- (void)playAudio:(NSString *)path 
{ 
    NSLog(@"start playing audio at path %@", path); 
    NSError *error = nil; 
    NSData *audioData = [NSData dataWithContentsOfFile:path]; 
    _audioPlayer = [[AVAudioPlayer alloc] initWithData:audioData error:&error]; 
    if (error == nil) 
    { 
     [_audioPlayer play];  
    } 
} 

在這個文件開始播放,一些動畫也發生的時間。如果我允許AVAudioPlayer開始播放,它似乎會阻止用戶界面,動畫會被凍結,直到歌曲播放一兩秒鐘。這是在模擬器上,FYI。我想知道是否與AVAudio在開始播放時吐出的(可能的)錯誤/日誌有關?有什麼方法可以在不影響用戶界面/動畫的情況下播放音頻文件?

如果我將[_audioPlayer play]註釋掉,動畫運行正常,所以問題似乎不在initWithData:call中。

以下是iOS 5的問題未登錄的狀態,以及:

2012-01-05 14:32:27.427 Lovebind[53526:207] Error loading /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: _CFXMLNodeGetInfoPtr 
    Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security 
    Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 
in /System/Library/Frameworks/Security.framework/Versions/A/Security 
2012-01-05 14:32:27.433 Lovebind[53526:207] Error loading /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: _CFXMLNodeGetInfoPtr 
    Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security 
    Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 
in /System/Library/Frameworks/Security.framework/Versions/A/Security 
2012-01-05 14:32:27.556 Lovebind[53526:207] Error loading /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): Symbol not found: _CFXMLNodeGetInfoPtr 
    Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security 
    Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 
in /System/Library/Frameworks/Security.framework/Versions/A/Security 
2012-01-05 14:32:27.562 Lovebind[53526:207] Error loading /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): Symbol not found: _CFXMLNodeGetInfoPtr 
    Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security 
    Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 
in /System/Library/Frameworks/Security.framework/Versions/A/Security 
2012-01-05 14:32:27.572 Lovebind[53526:207] Error loading /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): Symbol not found: _CFXMLNodeGetInfoPtr 
    Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security 
    Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 
in /System/Library/Frameworks/Security.framework/Versions/A/Security 
2012-01-05 14:32:27.578 Lovebind[53526:207] Error loading /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): Symbol not found: _CFXMLNodeGetInfoPtr 
    Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security 
    Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 
in /System/Library/Frameworks/Security.framework/Versions/A/Security 
2012-01-05 14:32:27.589 Lovebind[53526:207] Error loading /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): Symbol not found: _CFXMLNodeGetInfoPtr 
    Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security 
    Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 
in /System/Library/Frameworks/Security.framework/Versions/A/Security 
2012-01-05 14:32:27.595 Lovebind[53526:207] Error loading /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): Symbol not found: _CFXMLNodeGetInfoPtr 
    Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security 
    Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 
in /System/Library/Frameworks/Security.framework/Versions/A/Security 

回答

9

其實,我要把我的意見(現已刪除)到官方的回答:

1)你的 「錯誤加載」 線當您將CoreFoundation.framework添加到您的項目時應該消失。

2)發揮你的聲音在一個單獨的線程,我懷疑你的阻塞問題會自行消失。

做到這一點最簡單的方法就是做:

- (void)playingAudioOnSeparateThread: (NSString *) path 
{ 
    if(_audioPlayer) 
    { 
     [_audioPlayer release]; 
     _audioPlayer = nil; // doing this while a sound is playing might crash... 
    } 

    NSLog(@"start playing audio at path %@", path); 
    NSError *error = nil; 
    NSData *audioData = [NSData dataWithContentsOfFile:path]; 
    _audioPlayer = [[AVAudioPlayer alloc] initWithData:audioData error:&error]; 
    if (error == nil) 
    { 
     [_audioPlayer play];  
    } 
} 

- (void)playAudio:(NSString *)path 
{ 
    [NSThread detachNewThreadSelector: @selector(playingAudioOnSeparateThread:) toTarget: self withObject: path]; 
} 

檢查此代碼爲健全或錯誤檢查。這是你的工作。 :-)

+0

如何在單獨的線程上播放聲音?有沒有一個簡單的方法,或者我必須手動創建一個新的線程或什麼?謝謝,邁克爾,我會嘗試添加CoreFoundation,看看是否有幫助。 – typeoneerror 2012-01-05 23:19:32

+0

添加CoreFoundation以清除錯誤沒有骰子。 – typeoneerror 2012-01-05 23:26:40

+0

我編輯了我的答案給你一個代碼片段。我不確定您的項目中包含了哪些框架,因此請嘗試添加一些額外的音頻框架以查看是否可以解決缺失的符號錯誤。 – 2012-01-05 23:32:56