I am making a movie app for iOS 5.0 using AVCaptureSession. I am giving the user ability to start-pause-start-stop recording a movie
The three buttons that I have defined are
Start Recording
Stop Recording
Pause Recording
I am able to successfully start & stop a recording. What I am unable to do is pause a recording and then resume it again. I looked at this question/answer on stack overflow but I have no idea how are they pausing and resuming the video? I did find some other posts here but none of them have any sample code that I can use to try it out. If AVAssetWrtier is the way to go how do you use it with AVCaptureSession?
ios - Pause video recording
Pause & resume video capture for same file with AVFoundation in iOS
Here is my code for three buttons
-(IBAction) makeMovieNow
{
NSLog(@"makeMovieNow ...");
[session startRunning];
[movieFileOutput startRecordingToOutputFileURL:movieURL recordingDelegate:self];
}
-(IBAction) makeMovieStop
{
NSLog(@"makeMovieStop ...");
//stop recording
[session stopRunning];
}
-(IBAction) makeMoviePause
{
NSLog(@"makeMoviePause ...");
//pause video??? How?
}
//********** DID FINISH RECORDING TO OUTPUT FILE AT URL **********
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput
didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
fromConnections:(NSArray *)connections
error:(NSError *)error
{
NSLog(@"didFinishRecordingToOutputFileAtURL - enter");
BOOL RecordedSuccessfully = YES;
if ([error code] != noErr)
{
NSLog(@"ERROR RECODING MOVIE!!! - enter");
// A problem occurred: Find out if the recording was successful.
id value = [[error userInfo] objectForKey:AVErrorRecordingSuccessfullyFinishedKey];
if (value)
{
RecordedSuccessfully = [value boolValue];
}
}
if (RecordedSuccessfully)
{
//----- RECORDED SUCESSFULLY -----
NSLog(@"didFinishRecordingToOutputFileAtURL - success");
UISaveVideoAtPathToSavedPhotosAlbum(videoPath2, self, nil, nil);
}
}
There's a sample iPhone at http://www.gdcl.co.uk/2013/02/20/iPhone-Pause.html that does exactly this. It uses a Data Output instead of a Movie File Output so that the data is passed to the app. The app then passes the sample to an AVAssetWriter if recording is enabled, and after a pause/resume, the timestamps are adjusted to remove the pause.
G
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With