Skip to content

Commit

Permalink
fix: AVWriter status 1 crash (#996)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
hirbod committed May 23, 2022
1 parent fce7994 commit 83943da
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ios/RecordingSession.swift
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 83943da

Please sign in to comment.