实例化AVAudioRecorder失败

时间:2018-02-27 15:00:18

标签: ios avfoundation avaudiorecorder

我正在尝试像这样实例化一个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,因此无法实例化。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

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

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