force recording to stop on init write failure and fix silent failure
This commit is contained in:
@@ -38,11 +38,27 @@ extension CameraSession {
|
||||
// Callback for when new chunks are ready
|
||||
let onChunkReady: (ChunkedRecorder.Chunk) -> Void = { chunk in
|
||||
guard let delegate = self.delegate else {
|
||||
ReactLogger.log(level: .warning, message: "Chunk ready but delegate is nil, dropping chunk: \(chunk)")
|
||||
return
|
||||
}
|
||||
delegate.onVideoChunkReady(chunk: chunk)
|
||||
}
|
||||
|
||||
// Callback for when a chunk write fails (e.g. init file write failure)
|
||||
let onChunkError: (Error) -> Void = { error in
|
||||
ReactLogger.log(level: .error, message: "Chunk write error, stopping recording: \(error.localizedDescription)")
|
||||
// Stop recording immediately
|
||||
if let session = self.recordingSession {
|
||||
session.stop(clock: self.captureSession.clock)
|
||||
}
|
||||
// Surface error to RN
|
||||
if let cameraError = error as? CameraError {
|
||||
onError(cameraError)
|
||||
} else {
|
||||
onError(.capture(.fileError))
|
||||
}
|
||||
}
|
||||
|
||||
// Callback for when the recording ends
|
||||
let onFinish = { (recordingSession: RecordingSession, status: AVAssetWriter.Status, error: Error?) in
|
||||
defer {
|
||||
@@ -98,6 +114,7 @@ extension CameraSession {
|
||||
let recordingSession = try RecordingSession(outputDiretory: filePath,
|
||||
fileType: options.fileType,
|
||||
onChunkReady: onChunkReady,
|
||||
onChunkError: onChunkError,
|
||||
completion: onFinish)
|
||||
|
||||
// Init Audio + Activate Audio Session (optional)
|
||||
|
||||
Reference in New Issue
Block a user