From 83943da112fdbaf284dc2f925283754223eda9cf Mon Sep 17 00:00:00 2001 From: Hirbod <504909+hirbod@users.noreply.github.com> Date: Mon, 23 May 2022 14:27:25 +0200 Subject: [PATCH] fix: AVWriter status 1 crash (#996) * Fix AVWriter status 1 crash followup * Update RecordingSession.swift removing trailing semicolon to make linter happy * Update RecordingSession.swift Set hasRunningWritingAttempt to true * Update RecordingSession.swift * Update RecordingSession.swift * Update RecordingSession.swift * Update RecordingSession.swift Make the linter hate me again * Update RecordingSession.swift --- ios/RecordingSession.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ios/RecordingSession.swift b/ios/RecordingSession.swift index d6ed95b..16a7ada 100644 --- a/ios/RecordingSession.swift +++ b/ios/RecordingSession.swift @@ -33,6 +33,7 @@ class RecordingSession { private var initialTimestamp: CMTime? private var latestTimestamp: CMTime? private var hasWrittenFirstVideoFrame = false + private var isFinishing = false var url: URL { return assetWriter.outputURL @@ -193,15 +194,22 @@ class RecordingSession { func finish() { ReactLogger.log(level: .info, message: "Finishing Recording with AssetWriter status \"\(assetWriter.status.descriptor)\"...") + if isFinishing { + ReactLogger.log(level: .warning, message: "Tried calling finish() twice while AssetWriter is still writing!") + return + } + if !hasWrittenFirstVideoFrame { let error = NSError(domain: "capture/aborted", code: 1, userInfo: [NSLocalizedDescriptionKey: "Stopped Recording Session too early, no frames have been recorded!"]) completionHandler(self, .failed, error) } else if assetWriter.status == .writing { + isFinishing = true + bufferAdaptor?.assetWriterInput.markAsFinished() + audioWriter?.markAsFinished() assetWriter.finishWriting { - self.bufferAdaptor?.assetWriterInput.markAsFinished() - self.audioWriter?.markAsFinished() + self.isFinishing = false self.completionHandler(self, self.assetWriter.status, self.assetWriter.error) } } else {