0

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?

vivek241
  • 666
  • 1
  • 7
  • 18

2 Answers2

0

Hope this helps.

Problem is solved in the thread. You need to pause & resume your audio queue. I have worked on this one year back, I don't remember the exact code but you will idea from here.

how to resume recording after interruption occured in iphone?

Community
  • 1
  • 1
Prem Prakash
  • 146
  • 1
  • 6
  • I have seen that link, isin't there a simpler way? – vivek241 Jul 16 '13 at 11:11
  • I have also worked on this earlier and used this C++ methods to handle Interruptions. Please share code. Once I'll look at the code, I'll try figure out something else – Prem Prakash Jul 16 '13 at 11:43
  • I just have an AVAudioRecorder object in my ViewController and I'm starting recording on a button action. I'm stopping recording on another button action and then playing the file using AVAudioPlayer but it gives error code 1685348671. If you want the code I can share it. – vivek241 Jul 16 '13 at 11:52
  • are you saving file in document directory? Can you directly try to play audio file from your Mac? Looks like your audio file is corrupted. Check it if it works on Mac or not – Prem Prakash Jul 16 '13 at 12:00
  • I'm saving the files in the Library directory. On Mac it works fine. Since I'm trying to handle interruptions, I have to try on the device. – vivek241 Jul 16 '13 at 12:07
  • try adding these lines in Interruption method. - (void)audioRecorderBeginInterruption:(AVAudioRecorder *)recorder { [recorder stop]; [recordingTimer invalidate]; //timer used to update the UI AVAudioSession *audioSession = [AVAudioSession sharedInstance]; [audioSession setActive:NO error:nil]; } – Prem Prakash Jul 16 '13 at 13:11
  • I've updated the question. Turns out it was an issue that was occurring because of the animation of the navigation bar image. – vivek241 Jul 17 '13 at 08:38
  • So the problem is that you are not able to save file at the time of interruption. You can upload the code on google drive and provide access to me(anoopkumar.prem@gmail.com). – Prem Prakash Jul 18 '13 at 07:46
0

Turns out this was an issue with the timer.

The timer is called once every 2.0 / 28.0 = 0.7 seconds. That is what was causing the issue. If I increased the timer duration to 0.2 it worked fine but the animation wasn't very smooth.

With 0.1 as the timer interval it worked most of the time, but not always. It was more easily reproducible on older devices (2nd/3rd generation iPod).

Is it that the OS can't handle such quick updates via the timer?

Could someone please explain what the issue might be?

vivek241
  • 666
  • 1
  • 7
  • 18