add filePath to define recording directory
- add CaptureError.createRecordingDirectoryError - stub RCTViewManager to be able to compile CameraViewManager
This commit is contained in:
@@ -176,6 +176,7 @@ enum CaptureError {
|
||||
case noRecordingInProgress
|
||||
case fileError
|
||||
case createTempFileError(message: String? = nil)
|
||||
case createRecordingDirectoryError(message: String? = nil)
|
||||
case createRecorderError(message: String? = nil)
|
||||
case videoNotEnabled
|
||||
case photoNotEnabled
|
||||
@@ -193,6 +194,8 @@ enum CaptureError {
|
||||
return "file-io-error"
|
||||
case .createTempFileError:
|
||||
return "create-temp-file-error"
|
||||
case .createRecordingDirectoryError:
|
||||
return "create-recording-directory-error"
|
||||
case .createRecorderError:
|
||||
return "create-recorder-error"
|
||||
case .videoNotEnabled:
|
||||
@@ -218,6 +221,8 @@ enum CaptureError {
|
||||
return "An unexpected File IO error occured!"
|
||||
case let .createTempFileError(message: message):
|
||||
return "Failed to create a temporary file! \(message ?? "(no additional message)")"
|
||||
case let .createRecordingDirectoryError(message: message):
|
||||
return "Failed to create a recording directory! \(message ?? "(no additional message)")"
|
||||
case let .createRecorderError(message: message):
|
||||
return "Failed to create the AVAssetWriter (Recorder)! \(message ?? "(no additional message)")"
|
||||
case .videoNotEnabled:
|
||||
|
@@ -15,6 +15,7 @@ extension CameraSession {
|
||||
Starts a video + audio recording with a custom Asset Writer.
|
||||
*/
|
||||
func startRecording(options: RecordVideoOptions,
|
||||
filePath: String,
|
||||
onVideoRecorded: @escaping (_ video: Video) -> Void,
|
||||
onError: @escaping (_ error: CameraError) -> Void) {
|
||||
// Run on Camera Queue
|
||||
@@ -70,7 +71,7 @@ extension CameraSession {
|
||||
} else {
|
||||
if status == .completed {
|
||||
// Recording was successfully saved
|
||||
let video = Video(path: recordingSession.url.absoluteString,
|
||||
let video = Video(path: recordingSession.outputDiretory.absoluteString,
|
||||
duration: recordingSession.duration,
|
||||
size: recordingSession.size ?? CGSize.zero)
|
||||
onVideoRecorded(video)
|
||||
@@ -81,21 +82,20 @@ extension CameraSession {
|
||||
}
|
||||
}
|
||||
|
||||
// Create temporary file
|
||||
let errorPointer = ErrorPointer(nilLiteral: ())
|
||||
let fileExtension = options.fileType.descriptor ?? "mov"
|
||||
guard let tempFilePath = RCTTempFilePath(fileExtension, errorPointer) else {
|
||||
let message = errorPointer?.pointee?.description
|
||||
onError(.capture(.createTempFileError(message: message)))
|
||||
return
|
||||
if !FileManager.default.fileExists(atPath: filePath) {
|
||||
do {
|
||||
try FileManager.default.createDirectory(atPath: filePath, withIntermediateDirectories: true)
|
||||
} catch {
|
||||
onError(.capture(.createRecordingDirectoryError(message: error.localizedDescription)))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
ReactLogger.log(level: .info, message: "Will record to temporary file: \(tempFilePath)")
|
||||
let tempURL = URL(string: "file://\(tempFilePath)")!
|
||||
ReactLogger.log(level: .info, message: "Will record to temporary file: \(filePath)")
|
||||
|
||||
do {
|
||||
// Create RecordingSession for the temp file
|
||||
let recordingSession = try RecordingSession(url: tempURL,
|
||||
let recordingSession = try RecordingSession(outputDiretory: filePath,
|
||||
fileType: options.fileType,
|
||||
onChunkReady: onChunkReady,
|
||||
completion: onFinish)
|
||||
|
@@ -27,8 +27,8 @@ class ChunkedRecorder: NSObject {
|
||||
|
||||
private var chunkIndex: UInt64 = 0
|
||||
|
||||
init(url: URL, onChunkReady: @escaping ((Chunk) -> Void)) throws {
|
||||
outputURL = url
|
||||
init(outputURL: URL, onChunkReady: @escaping ((Chunk) -> Void)) throws {
|
||||
self.outputURL = outputURL
|
||||
self.onChunkReady = onChunkReady
|
||||
guard FileManager.default.fileExists(atPath: outputURL.path) else {
|
||||
throw CameraError.unknown(message: "output directory does not exist at: \(outputURL.path)", cause: nil)
|
||||
|
@@ -49,8 +49,7 @@ class RecordingSession {
|
||||
/**
|
||||
Gets the file URL of the recorded video.
|
||||
*/
|
||||
var url: URL {
|
||||
// FIXME:
|
||||
var outputDiretory: URL {
|
||||
return recorder.outputURL
|
||||
}
|
||||
|
||||
@@ -72,14 +71,15 @@ class RecordingSession {
|
||||
return (lastWrittenTimestamp - startTimestamp).seconds
|
||||
}
|
||||
|
||||
init(url: URL,
|
||||
init(outputDiretory: String,
|
||||
fileType: AVFileType,
|
||||
onChunkReady: @escaping ((ChunkedRecorder.Chunk) -> Void),
|
||||
completion: @escaping (RecordingSession, AVAssetWriter.Status, Error?) -> Void) throws {
|
||||
completionHandler = completion
|
||||
|
||||
do {
|
||||
recorder = try ChunkedRecorder(url: url.deletingLastPathComponent(), onChunkReady: onChunkReady)
|
||||
let outputURL = URL(fileURLWithPath: outputDiretory)
|
||||
recorder = try ChunkedRecorder(outputURL: outputURL, onChunkReady: onChunkReady)
|
||||
assetWriter = AVAssetWriter(contentType: UTType(fileType.rawValue)!)
|
||||
assetWriter.shouldOptimizeForNetworkUse = false
|
||||
assetWriter.outputFileTypeProfile = .mpeg4AppleHLS
|
||||
|
Reference in New Issue
Block a user