force recording to stop on init write failure and fix silent failure
This commit is contained in:
@@ -24,12 +24,14 @@ class ChunkedRecorder: NSObject {
|
||||
|
||||
let outputURL: URL
|
||||
let onChunkReady: ((Chunk) -> Void)
|
||||
let onError: ((Error) -> Void)?
|
||||
|
||||
private var chunkIndex: UInt64 = 0
|
||||
|
||||
init(outputURL: URL, onChunkReady: @escaping ((Chunk) -> Void)) throws {
|
||||
init(outputURL: URL, onChunkReady: @escaping ((Chunk) -> Void), onError: ((Error) -> Void)? = nil) throws {
|
||||
self.outputURL = outputURL
|
||||
self.onChunkReady = onChunkReady
|
||||
self.onError = onError
|
||||
guard FileManager.default.fileExists(atPath: outputURL.path) else {
|
||||
throw CameraError.unknown(message: "output directory does not exist at: \(outputURL.path)", cause: nil)
|
||||
}
|
||||
@@ -56,8 +58,12 @@ extension ChunkedRecorder: AVAssetWriterDelegate {
|
||||
|
||||
private func saveInitSegment(_ data: Data) {
|
||||
let url = outputURL.appendingPathComponent("init.mp4")
|
||||
if save(data: data, url: url) {
|
||||
do {
|
||||
try data.write(to: url)
|
||||
onChunkReady(url: url, type: .initialization)
|
||||
} catch {
|
||||
ReactLogger.log(level: .error, message: "Failed to write init file \(url): \(error.localizedDescription)")
|
||||
onError?(CameraError.capture(.fileError))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user