From 383a3dcb1924a463274ec5a85a64501470e52534 Mon Sep 17 00:00:00 2001 From: Loewy Date: Mon, 11 Mar 2024 23:50:06 -0700 Subject: [PATCH] use filePath --- .../com/mrousavy/camera/CameraView+RecordVideo.kt | 4 ++-- .../main/java/com/mrousavy/camera/CameraViewModule.kt | 4 ++-- .../java/com/mrousavy/camera/core/CameraSession.kt | 4 ++-- .../java/com/mrousavy/camera/core/RecordingSession.kt | 11 ++--------- package/src/Camera.tsx | 4 ++-- 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/package/android/src/main/java/com/mrousavy/camera/CameraView+RecordVideo.kt b/package/android/src/main/java/com/mrousavy/camera/CameraView+RecordVideo.kt index e9a4d71..a049f11 100644 --- a/package/android/src/main/java/com/mrousavy/camera/CameraView+RecordVideo.kt +++ b/package/android/src/main/java/com/mrousavy/camera/CameraView+RecordVideo.kt @@ -13,7 +13,7 @@ import com.mrousavy.camera.types.RecordVideoOptions import com.mrousavy.camera.utils.makeErrorMap import java.util.* -suspend fun CameraView.startRecording(options: RecordVideoOptions, videoId: Int, onRecordCallback: Callback) { +suspend fun CameraView.startRecording(options: RecordVideoOptions, filePath: String, onRecordCallback: Callback) { // check audio permission if (audio == true) { if (ContextCompat.checkSelfPermission(context, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) { @@ -33,7 +33,7 @@ suspend fun CameraView.startRecording(options: RecordVideoOptions, videoId: Int, val errorMap = makeErrorMap(error.code, error.message) onRecordCallback(null, errorMap) } - cameraSession.startRecording(audio == true, options, videoId, callback, onError) + cameraSession.startRecording(audio == true, options, filePath, callback, onError) } @SuppressLint("RestrictedApi") diff --git a/package/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt b/package/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt index 1f975c9..5765d97 100644 --- a/package/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt +++ b/package/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt @@ -95,12 +95,12 @@ class CameraViewModule(reactContext: ReactApplicationContext) : ReactContextBase // TODO: startRecording() cannot be awaited, because I can't have a Promise and a onRecordedCallback in the same function. Hopefully TurboModules allows that @ReactMethod - fun startRecording(viewTag: Int, jsOptions: ReadableMap, videoId: Int, onRecordCallback: Callback) { + fun startRecording(viewTag: Int, jsOptions: ReadableMap, filePath: String, onRecordCallback: Callback) { coroutineScope.launch { val view = findCameraView(viewTag) try { val options = RecordVideoOptions(jsOptions) - view.startRecording(options, videoId, onRecordCallback) + view.startRecording(options, filePath, onRecordCallback) } catch (error: CameraError) { val map = makeErrorMap("${error.domain}/${error.id}", error.message, error) onRecordCallback(null, map) diff --git a/package/android/src/main/java/com/mrousavy/camera/core/CameraSession.kt b/package/android/src/main/java/com/mrousavy/camera/core/CameraSession.kt index 448f0d2..3476249 100644 --- a/package/android/src/main/java/com/mrousavy/camera/core/CameraSession.kt +++ b/package/android/src/main/java/com/mrousavy/camera/core/CameraSession.kt @@ -621,7 +621,7 @@ class CameraSession(private val context: Context, private val cameraManager: Cam suspend fun startRecording( enableAudio: Boolean, options: RecordVideoOptions, - videoId: Int, + filePath: String, callback: (video: RecordingSession.Video) -> Unit, onError: (error: CameraError) -> Unit ) { @@ -641,7 +641,7 @@ class CameraSession(private val context: Context, private val cameraManager: Cam videoOutput.enableHdr, orientation, options, - videoId, + filePath, callback, onError, this.callback, diff --git a/package/android/src/main/java/com/mrousavy/camera/core/RecordingSession.kt b/package/android/src/main/java/com/mrousavy/camera/core/RecordingSession.kt index df67bf4..1d61188 100644 --- a/package/android/src/main/java/com/mrousavy/camera/core/RecordingSession.kt +++ b/package/android/src/main/java/com/mrousavy/camera/core/RecordingSession.kt @@ -23,7 +23,7 @@ class RecordingSession( private val hdr: Boolean = false, private val cameraOrientation: Orientation, private val options: RecordVideoOptions, - private val videoId: Int, + private val filePath: String, private val callback: (video: Video) -> Unit, private val onError: (error: CameraError) -> Unit, private val allCallbacks: CameraSession.Callback, @@ -38,14 +38,7 @@ class RecordingSession( data class Video(val path: String, val durationMs: Long, val size: Size) -private val outputPath = run { - val videoDir = context.filesDir - val fileExtension = options.fileType.toExtension() - val sdf = SimpleDateFormat("yyyy_MM_dd_HH_mm_ss_SSS", Locale.US) - val videoFileName = "VID_${videoId}_${sdf.format(Date())}.$fileExtension" - val outputFile = File(videoDir, videoFileName) - outputFile -} + private val outputPath: File = File(filePath) private val bitRate = getBitRate() private val recorder = ChunkedRecordingManager.fromParams( diff --git a/package/src/Camera.tsx b/package/src/Camera.tsx index 82cc153..c9e556c 100644 --- a/package/src/Camera.tsx +++ b/package/src/Camera.tsx @@ -173,7 +173,7 @@ export class Camera extends React.PureComponent { * }, 5000) * ``` */ - public startRecording(options: RecordVideoOptions, videoId: number): void { + public startRecording(options: RecordVideoOptions, filePath: string): void { const { onRecordingError, onRecordingFinished, videoBitRate, ...passThruOptions } = options if (typeof onRecordingError !== 'function' || typeof onRecordingFinished !== 'function') throw new CameraRuntimeError('parameter/invalid-parameter', 'The onRecordingError or onRecordingFinished functions were not set!') @@ -207,7 +207,7 @@ export class Camera extends React.PureComponent { } try { // TODO: Use TurboModules to make this awaitable. - CameraModule.startRecording(this.handle, nativeOptions, videoId, onRecordCallback) + CameraModule.startRecording(this.handle, nativeOptions, filePath, onRecordCallback) } catch (e) { throw tryParseNativeCameraError(e) }