iOS 8中的AVAudioRecorder无法处理kAudioFormatMPEG4AAC

我的代码工作正常,直到iOS 8 kAudioFormatMPEG4AAC但现在它创建一个空文件。 没有报告错误。 当我将其更改为kAudioFormatLinearPCM它可以工作。 这是我的代码:

 recordSettings = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:AVAudioQualityMin], AVEncoderAudioQualityKey, [NSNumber numberWithInt: kAudioFormatLinearPCM], AVFormatIDKey, [NSNumber numberWithInt:16], AVEncoderBitRateKey, [NSNumber numberWithInt: 1], AVNumberOfChannelsKey, [NSNumber numberWithFloat:32000.0], AVSampleRateKey, nil]; 

请从您的设置字典中删除AVEncoderBitRateKey密钥,它将在iOS8上使用kAudioFormatMPEG4AAC

它可能是AVEncoderBitRateKeyAVNumberOfChannelsKey之间的特定关联。 但我没有使用参数,而是使用默认比特率值来获取工作记录器。

即使对于kAudioFormatMPEG4AAC (每秒16字节),该比特率看起来也很低,可能会尝试16000或64000或更高。

ps为你的NSDictionarysNSArraysNSNumbers尝试新的Objective-C文字,我认为它们是一个改进:

 recordSettings = @{ AVEncoderAudioQualityKey : AVAudioQualityMin, AVFormatIDKey : @(kAudioFormatLinearPCM), AVEncoderBitRateKey : @16000, AVNumberOfChannelsKey : @1, AVSampleRateKey : @32000 };