1

我正在尝试进行屏幕捕获并写入视频文件。

assetWriterTimer = [NSTimer scheduledTimerWithTimeInterval:0.5
                                                    target:self
                                                  selector:@selector (writeSample:)
                                                  userInfo:nil
                                                   repeats:YES] ;

-(void) writeSample: (NSTimer*) _timer
{
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
           //capture and save image to video
        });
}

为了停止记录,我写

-(void) stopRecording 
{

[assetWriterTimer invalidate];
assetWriterTimer = nil;
[assetWriterTimer release];

[assetWriter finishWritingWithCompletionHandler:^(){
    NSLog (@"finished writing completion handler");
}];

NSLog (@"finished writing");
}

但是,我大多会收到此错误和应用程序崩溃。我应该怎么做?
-[AVAssetWriter finishWriting] 状态为 2' 时无法调用方法

4

1 回答 1

1

你在某处打电话给 [assetWriter startWriting] 吗?

这个错误基本上意味着作者现在并没有真正写作,所以它不能真正停止写作。如果您确实查看了AVWriter 的状态代码的含义,您会看到 2 表示它完成写入的时间。

enum {
 AVAssetWriterStatusUnknown = 0,
 AVAssetWriterStatusWriting,
 AVAssetWriterStatusCompleted,
 AVAssetWriterStatusFailed,
 AVAssetWriterStatusCancelled
};
于 2014-02-21T19:21:45.633 回答