我有一个使用 AVAudioRecorder 录制音频的应用程序。它在运行 iOS 5.1 之前的 iOS 版本的设备上运行良好,但在最新版本中,它不会增加音频录制文件的大小,保持在恒定的 4k。
// init audio recorder here so recording could be started immediately
NSDictionary *recordSettings = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kAudioFormatAppleIMA4],
AVFormatIDKey,
[NSNumber numberWithInt: 1],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:44100.0],
AVSampleRateKey,
nil];
// Get temp path name
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachePath = [paths objectAtIndex:0];
BOOL isDir = NO;
NSError *error = nil;
if (![[NSFileManager defaultManager] fileExistsAtPath:cachePath isDirectory:&isDir] && isDir == NO) {
[[NSFileManager defaultManager] createDirectoryAtPath:cachePath withIntermediateDirectories:NO attributes:nil error:&error];
}
self.audioFilePath = [cachePath stringByAppendingPathComponent:@"audio.ima4"];
NSURL *audioFileURL = [NSURL fileURLWithPath:self.audioFilePath];
AVAudioRecorder *anAudioRecorder = [[AVAudioRecorder alloc] initWithURL:audioFileURL
settings:recordSettings
error:&error];
self.audioRecorder = anAudioRecorder;
[anAudioRecorder release];
[self.audioRecorder prepareToRecord];
(稍等,用户按下录音)[self.audioRecorder 录音];(稍等,5-10 秒,用户按下停止)[self.audioRecorder stop];
我已经放置了检查临时文件大小的调试语句,它在整个记录过程中是 4096 字节,在调用 stop 之后只有 4130 字节。
我没有办法解决这个问题。这是 iOS 5.1 中的错误吗?