Skip to content

Commit

Permalink
If recording stops but the user didn't request that it stop, try to r…
Browse files Browse the repository at this point in the history
…esume recording. Don't display an error dialog when the 'maximum allowable length' has been reached, since we can now recover from that.
  • Loading branch information
smokris committed Sep 11, 2018
1 parent 352f642 commit eccf87d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions AVRecorder/AVRecorderDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ @interface AVRecorderDocument () <AVCaptureFileOutputDelegate, AVCaptureFileOutp
@property (retain) AVCaptureVideoPreviewLayer *previewLayer;
@property (assign) NSTimer *audioLevelTimer;
@property (retain) NSArray *observers;
@property BOOL userRequestedStop;

// Methods for internal use
- (void)refreshDevices;
Expand Down Expand Up @@ -404,8 +405,10 @@ - (void)setRecording:(BOOL)record
NSString *path = [[NSString stringWithFormat:@"~/Desktop/%04d%02d%02d-%02d%02d%02d.mov",
timeinfo->tm_year + 1900, timeinfo->tm_mon + 1, timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec] stringByExpandingTildeInPath];
[[self movieFileOutput] startRecordingToOutputFileURL:[NSURL fileURLWithPath:path] recordingDelegate:self];
_userRequestedStop = NO;
} else {
[[self movieFileOutput] stopRecording];
_userRequestedStop = YES;
}
}

Expand Down Expand Up @@ -569,19 +572,18 @@ - (void)captureOutput:(AVCaptureFileOutput *)captureOutput didStartRecordingToOu

- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didPauseRecordingToOutputFileAtURL:(NSURL *)fileURL fromConnections:(NSArray *)connections
{
NSLog(@"Did pause recording to %@", [fileURL description]);
}

- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didResumeRecordingToOutputFileAtURL:(NSURL *)fileURL fromConnections:(NSArray *)connections
{
NSLog(@"Did resume recording to %@", [fileURL description]);
}

- (void)captureOutput:(AVCaptureFileOutput *)captureOutput willFinishRecordingToOutputFileAtURL:(NSURL *)fileURL fromConnections:(NSArray *)connections dueToError:(NSError *)error
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput willFinishRecordingToOutputFileAtURL:(NSURL *)fileURL fromConnections:(NSArray *)connections error:(NSError *)error
{
dispatch_async(dispatch_get_main_queue(), ^(void) {
[self presentError:error];
});
if (error && ![error.localizedFailureReason containsString:@"maximum allowable length"])
dispatch_async(dispatch_get_main_queue(), ^(void) {
[self presentError:error];
});
}

- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)recordError
Expand All @@ -595,6 +597,12 @@ - (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToO
[self presentError:recordError];
});
}

if (!_userRequestedStop)
{
NSLog(@"Warning: Recording unexpectedly stopped. Resuming.");
[self setRecording:YES];
}
}

- (BOOL)captureOutputShouldProvideSampleAccurateRecordingStart:(AVCaptureOutput *)captureOutput
Expand Down

0 comments on commit eccf87d

Please sign in to comment.