簡體   English   中英

在iPhone上錄制音頻:setPreferredIOBufferDuration出錯

[英]Recording audio on iPhone: error with setPreferredIOBufferDuration

我一直在關注Apple的文檔,使用AVAudioSession類在iPhone上錄制音頻。 我可以設置幾個沒有錯誤的屬性( setActivesetCategorysetPreferredHardwareSampleRate ),但我不能讓Apple的示例代碼適用於setPreferredIOBufferDuration

這是我的代碼:

- (void) initX {
 NSError *setPreferenceError = nil;
 NSTimeInterval preferredBufferDuration = 0.005;

 [[AVAudioSession sharedInstance]
  setPreferredIOBufferDuration: preferredBufferDuration
  error: &setPreferenceError];

 if (setPreferenceError != nil) {
  NSLog( @"%@", setPreferenceError );
 }
}

它產生以下輸出:

錯誤域= NSOSStatusErrorDomain代碼= 561211770“操作無法完成。(OSStatus錯誤561211770.)”

我從主Application Delegate調用此方法,作為applicationDidFinishLaunching方法的一部分。 我正在做的就是在這個階段初始化事物。 在將AVFoundation.framework添加到項目后,我導入了AVFoundation / AVFoundation.h。

看來這是Apple代碼中的一個錯誤; 使用純C接口代替:

OSStatus propertySetError = 0;
Float32 preferredBufferDuration = 0.005;
propertySetError = AudioSessionSetProperty(kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof(preferredBufferDuration), &preferredBufferDuration);

然后檢查錯誤使用

if (propertySetError) NSLog(@"Failed to set shorter I/O buffer on AVAudioSession, code %d", propertySetError);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM