I'm animating the navigation bar using a timer when recording starts and stopping it when the recording stops (to make it similar to the Voice Memos app).
Here is the code
//do nav bar animation
_navigationImageCount = 0;
self.navigationBarTimer = [NSTimer scheduledTimerWithTimeInterval:(2.0 / 28.0) target:self selector:@selector(changeNavigationBarImage:) userInfo:nil repeats:YES];
- (void)changeNavigationBarImage:(NSTimer *)timer
{
NSMutableArray *navigationBarImages = [NSMutableArray arrayWithArray:@[@"nav_bar_01.png", @"nav_bar_02.png", @"nav_bar_03.png", @"nav_bar_04.png", @"nav_bar_05.png", @"nav_bar_06.png", @"nav_bar_07.png", @"nav_bar_08.png", @"nav_bar_09.png", @"nav_bar_10.png", @"nav_bar_11.png", @"nav_bar_12.png", @"nav_bar_13.png", @"nav_bar_14.png"]];
[navigationBarImages addObjectsFromArray:[[navigationBarImages reverseObjectEnumerator] allObjects]];
NSInteger imageIndex = _navigationImageCount % 28;
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:navigationBarImages[imageIndex]] forBarMetrics:UIBarMetricsDefault];
_navigationImageCount++;
}
- (void)audioRecorderBeginInterruption:(AVAudioRecorder *)recorder
{
[recorder stop];
[self.recordingTimer invalidate]; //timer used to update the UI
[self.navigationBarTimer invalidate];
}
I am saving the recording to a file to a directory named "MyRecordings" under the Library directory and if print the contents of that directory it shows the file, however when I try to print the duration it gives 0.
If I try to play the file at that url it gives error code 1685348671 (file invalid).
How can the save the first part of the recording be saved properly?