我正在使用AVCaptureSession为iOS 5.0制作电影应用。我正在为用户提供开始 - 暂停 - 开始 - 停止录制电影的能力
我定义的三个按钮是
开始录制
停止录制
暂停录制
我能够成功启动&停止录音。我无法做的是暂停录制然后再次恢复。我在堆栈溢出时查看了这个问题/答案,但我不知道他们如何暂停和恢复视频?我确实在这里找到了一些其他帖子,但没有一个我可以用来试用它的示例代码。如果AVAssetWrtier是如何使用它如何与AVCaptureSession一起使用?
Pause & resume video capture for same file with AVFoundation in iOS
这是我的三个按钮的代码
-(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);
}
}
答案 0 :(得分:3)
http://www.gdcl.co.uk/2013/02/20/iPhone-Pause.html上有一个示例iPhone就是这样做的。它使用数据输出而不是电影文件输出,以便将数据传递给应用程序。然后,如果启用了录制,应用程序会将示例传递给AVAssetWriter,暂停/恢复后,会调整时间戳以消除暂停。
答案 1 :(得分:1)
我最终创建了两个文件并将它们合并在一起。以下是示例代码和教程
http://www.raywenderlich.com/13418/how-to-play-record-edit-videos-in-ios