2021-02-19 08:28:05 -07:00
|
|
|
//
|
|
|
|
// CameraView+RecordVideo.swift
|
2021-06-21 14:42:46 -06:00
|
|
|
// mrousavy
|
2021-02-19 08:28:05 -07:00
|
|
|
//
|
|
|
|
// Created by Marc Rousavy on 16.12.20.
|
2021-06-01 05:07:57 -06:00
|
|
|
// Copyright © 2020 mrousavy. All rights reserved.
|
2021-02-19 08:28:05 -07:00
|
|
|
//
|
|
|
|
|
|
|
|
import AVFoundation
|
|
|
|
|
2021-05-06 06:11:55 -06:00
|
|
|
// MARK: - CameraView + AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureAudioDataOutputSampleBufferDelegate
|
|
|
|
|
|
|
|
extension CameraView: AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureAudioDataOutputSampleBufferDelegate {
|
2024-07-16 02:50:21 -06:00
|
|
|
func startRecording(options: NSDictionary, filePath: String, callback jsCallback: @escaping RCTResponseSenderBlock) {
|
2023-10-13 10:33:20 -06:00
|
|
|
// Type-safety
|
|
|
|
let callback = Callback(jsCallback)
|
|
|
|
|
|
|
|
do {
|
|
|
|
let options = try RecordVideoOptions(fromJSValue: options)
|
|
|
|
|
|
|
|
// Start Recording with success and error callbacks
|
|
|
|
cameraSession.startRecording(
|
|
|
|
options: options,
|
2024-07-16 02:50:21 -06:00
|
|
|
filePath: filePath,
|
2023-10-13 10:33:20 -06:00
|
|
|
onVideoRecorded: { video in
|
|
|
|
callback.resolve(video.toJSValue())
|
|
|
|
},
|
|
|
|
onError: { error in
|
|
|
|
callback.reject(error: error)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
} catch {
|
|
|
|
// Some error occured while initializing VideoSettings
|
|
|
|
if let error = error as? CameraError {
|
|
|
|
callback.reject(error: error)
|
|
|
|
} else {
|
|
|
|
callback.reject(error: .capture(.unknown(message: error.localizedDescription)), cause: error as NSError)
|
2021-05-06 06:11:55 -06:00
|
|
|
}
|
2021-02-19 08:28:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func stopRecording(promise: Promise) {
|
2023-10-13 10:33:20 -06:00
|
|
|
cameraSession.stopRecording(promise: promise)
|
2021-05-06 06:11:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func pauseRecording(promise: Promise) {
|
2023-10-13 10:33:20 -06:00
|
|
|
cameraSession.pauseRecording(promise: promise)
|
2021-05-06 06:11:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func resumeRecording(promise: Promise) {
|
2023-10-13 10:33:20 -06:00
|
|
|
cameraSession.resumeRecording(promise: promise)
|
2021-06-09 02:57:05 -06:00
|
|
|
}
|
2024-10-08 07:53:47 -06:00
|
|
|
|
|
|
|
func lockExposure(promise: Promise) {
|
|
|
|
cameraSession.lockCurrentExposure(promise: promise)
|
|
|
|
}
|
|
|
|
|
|
|
|
func unlockExposure(promise: Promise) {
|
|
|
|
cameraSession.unlockCurrentExposure(promise: promise)
|
|
|
|
}
|
2021-02-19 08:28:05 -07:00
|
|
|
}
|