AVAudioRecorder leaves a corrupted file on being interrupted

Originator:ullrich.schaefer
Number:rdar://10826320 Date Originated:08-Feb-2012 10:47 AM
Status:Open Resolved:
Product:iPhone SDK Product Version:5.0
Classification:Crash/Hang/Data Loss Reproducible:Always
 
08-Feb-2012 10:47 AM Ullrich Schäfer:
Summary:

AVAudioRecorder leaves a corrupted file when being interrupted while the app is in background.


Steps to Reproduce:

I've got an AVAudioRecorder I create like this:
int numberOfChannels = [[AVAudioSession sharedInstance] currentHardwareInputNumberOfChannels];
recorder = [[AVAudioRecorder alloc] initWithURL:[NSURL fileURLWithPath:self.recordingFilePath]
                                       settings:[NSDictionary dictionaryWithObjectsAndKeys:
                                                 [NSNumber numberWithFloat:44100.0], AVSampleRateKey,
                                                 [NSNumber numberWithInt:kAudioFormatMPEG4AAC], AVFormatIDKey,
                                                 [NSNumber numberWithInt:numberOfChannels], AVNumberOfChannelsKey,
                                                 [NSNumber numberWithInt:AVAudioQualityHigh], AVEncoderAudioQualityKey,
                                                 nil]
                                          error:&error];
recorder.delegate = self;

 
I also implemented the interrupt delegate callbacks from AVAudioRecorderDelegate which get called correctly.
 
When I now start recording, put the app in background and (for example) open the camera app in video mode the recording is interrupted. In the delegate I see that the recoder -isRecording property is NO.
Unfortunetly the resulting file is corrupted and can't be played. Neither with AVAudioPlayer, nor in Quicktime or VLC on the Mac. I also tried calling an additional [recorder stop] to close the file, but this didn't have any effect (the recorder appears to be already stoped anyhow).


Expected Results:

The recorder stops but the file is still playable.


Actual Results:

A file that seems to not have the header written correctly (see enclosures).


Regression:

I don't remember having that problem in iOS pre 5.0


Notes:

Discussion about the issue: https://devforums.apple.com/message/583855

Thanks!

08-Feb-2012 10:47 AM Ullrich Schäfer:
'broken recording.m4a' and 'iMac.spx' were successfully uploaded

Comments

Problem

I am having an issue similar to this on iOS 5.0.

I am recording audio and when the user presses a button, an alert view pops up asking them if they want to save the audio file. When they press the button to get the alert view, if I just pause the audio recorder, then stop it when they click OK on the UIAlertView, the file is corrupt. However, if I stop the audio recorder before I show the UIAlertView, then it is fine. I can't do that because if they cancel, I want them to continue recording.

By connor.m.duggan at Feb. 10, 2012, 11:12 a.m. (reply...)

duplicate

Can you file a bug report at Apple as well? I just heard back from them that they categorize it as a duplicate of #10147878 (which unfortunetly isn't on openradar)

By ullrich.schaefer at Feb. 13, 2012, 3:39 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!