【问题标题】:AVCaptureSession Pause and Resume recordingAVCaptureSession 暂停和恢复录制
【发布时间】:2013-02-26 19:11:51
【问题描述】:

我正在使用 AVCaptureSession 为 iOS 5.0 制作电影应用程序。我让用户能够开始-暂停-开始-停止录制电影

我定义的三个按钮是

  • 开始录制

  • 停止录制

  • 暂停录制

我能够成功开始和停止录制。我无法做的是暂停录音,然后再次恢复。我看了这个关于堆栈溢出的问题/答案,但我不知道他们是如何暂停和恢复视频的?我确实在这里找到了一些其他帖子,但没有一个有任何示例代码可供我试用。如果 AVAssetWrtier 是要走的路,你如何将它与 AVCaptureSession 一起使用?

ios - Pause video recording

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);    

    }
}

【问题讨论】:

标签: iphone ios objective-c avfoundation


【解决方案1】:

http://www.gdcl.co.uk/2013/02/20/iPhone-Pause.html 有一个示例 iPhone,可以做到这一点。它使用数据输出而不是电影文件输出,以便将数据传递给应用程序。如果启用了录制,则应用程序会将样本传递给 AVAssetWriter,并在暂停/恢复之后调整时间戳以消除暂停。

G

【讨论】:

    【解决方案2】:

    我最终创建了两个文件并将它们合并在一起。这是示例代码和教程

    http://www.raywenderlich.com/13418/how-to-play-record-edit-videos-in-ios

    【讨论】:

      猜你喜欢
      • 2015-09-21
      • 1970-01-01
      • 2015-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-18
      • 2011-08-10
      • 1970-01-01
      相关资源
      最近更新 更多