实例化 AVAudioRecorder 失败

Instantiating an AVAudioRecorder fails

我正在尝试像这样实例化一个 AVAudioRecorder:

NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc]init];
[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEGLayer3] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
NSError* error = nil;
NSURL* url = [NSURL URLWithString:filePath];
self.recorder = [[AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&error];

但似乎我在错误中收到 kAudioFormatUnsupportedDataFormatError,因此无法实例化。

有什么想法吗?

将格式设置为 kAudioFormatMPEG4AAC 解决了这个问题:

[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];