我正在开发一个应用程序,但目前遇到了难题。在该应用程序中,您可以进入一个视图,其中列出了标准表格视图中所有本地保存的音频文件。从这里,您可以单击它们进行播放,或者在下方点击录制按钮进行新录音,然后自动保存到应用程序沙箱中。
现在,所有这些工作都非常完美,大部分时间都没有问题。我可以坐在那里录制并播放它们。我可以一遍又一遍地测试约45分钟左右,没有任何问题。然后突然间,在随机的时候,我会遇到一个非常奇怪的问题。问题是,录音机突然开始保存除了损坏文件以外的内容,这些文件不能播放,大小恰好为4096字节,无论您录制多长时间。
我按照完全标准的方式使用AVAudioRecorder来设置它:
// Specific settings for the audio recording
NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],
AVEncoderAudioQualityKey,
[NSNumber numberWithInt:8],
AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:22000.0],
AVSampleRateKey,
nil];
NSError *error = nil;
audioRecorder = [[AVAudioRecorder alloc]
initWithURL:contentURL
settings:recordSettings
error:&error];
audioRecorder.delegate = self;
我是这样开始录制的:
if (!isRecording) {
isRecording = YES;
[audioRecorder record];
// Start the timer
recordTiming = [NSDate date];
timeCheck = [NSTimer
scheduledTimerWithTimeInterval:1.0f
target:self
selector:@selector(timeCheck)
userInfo:nil
repeats:YES];
}
然后使用以下内容停止它:
if (isRecording) {
[audioRecorder stop];
// Stop the timer
[timeCheck invalidate];
}
我不知道是什么原因导致了这个问题。到目前为止,我已经尝试了几乎所有可能的方法。我检查确保记录器对象被适当地回收(因此每次现在都有一个新实例),并且旧引用已被解除分配等等,以确保它与其他对象无关,但没有任何解决办法。
有人知道可能会导致文件损坏问题的原因吗?