Damonvvong/DevNotes

stop时crash finishWritingWithCompletionHandler

tailangjun opened this issue · 2 comments

crash必现,即使在前面加上markAsFinished还是crash

dispatch_async(_dispatchQueue, ^{
    [_videoWriterInput markAsFinished];
    [_audioWriterInput markAsFinished];
    [_assetWriter finishWritingWithCompletionHandler:^{

知道原因了,是重复调用stop,在前清空即可

dispatch_async(_dispatchQueue, ^{
    [_videoWriterInput markAsFinished];
    [_audioWriterInput markAsFinished];
    [_assetWriter finishWritingWithCompletionHandler:^{
        if (_assetWriter.status == AVAssetWriterStatusCompleted) {
            dispatch_async(dispatch_get_main_queue(), ^{
                if ([_delegate respondsToSelector:@selector(videoWriter:didOutputVideoAtPath:)]) {
                    [_delegate videoWriter:self didOutputVideoAtPath:_assetWriter.outputURL];
                }
            });
        }
    }];
    _assetWriter = nil;
});

好的。我关闭了