From 9a187c6d19fc0b4995c14849150c3d9b859faeab Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Tue, 12 Dec 2023 16:43:57 +0100 Subject: [PATCH] feat: Add `width` and `height` to `VideoFile` output (#2281) * feat: Add `width` and `height` to `VideoFile` output * Format --- .../java/com/mrousavy/camera/CameraView+RecordVideo.kt | 2 ++ .../java/com/mrousavy/camera/core/RecordingSession.kt | 4 ++-- package/ios/Core/CameraSession+Video.swift | 3 ++- package/ios/Core/RecordingSession.swift | 7 +++++++ package/ios/Types/Video.swift | 6 ++++++ package/src/VideoFile.ts | 8 ++++++++ 6 files changed, 27 insertions(+), 3 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 4cbdf82..53642c8 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 @@ -25,6 +25,8 @@ suspend fun CameraView.startRecording(options: RecordVideoOptions, onRecordCallb val map = Arguments.createMap() map.putString("path", video.path) map.putDouble("duration", video.durationMs.toDouble() / 1000.0) + map.putInt("width", video.size.width) + map.putInt("height", video.size.height) onRecordCallback(map, null) } val onError = { error: RecorderError -> 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 6e285fb..7c9d735 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 @@ -32,7 +32,7 @@ class RecordingSession( private const val AUDIO_CHANNELS = 1 } - data class Video(val path: String, val durationMs: Long) + data class Video(val path: String, val durationMs: Long, val size: Size) private val bitRate = getBitRate() private val recorder: MediaRecorder @@ -106,7 +106,7 @@ class RecordingSession( val stopTime = System.currentTimeMillis() val durationMs = stopTime - (startTime ?: stopTime) - callback(Video(outputFile.absolutePath, durationMs)) + callback(Video(outputFile.absolutePath, durationMs, size)) } } diff --git a/package/ios/Core/CameraSession+Video.swift b/package/ios/Core/CameraSession+Video.swift index 8836b71..3edf5e5 100644 --- a/package/ios/Core/CameraSession+Video.swift +++ b/package/ios/Core/CameraSession+Video.swift @@ -61,7 +61,8 @@ extension CameraSession { if status == .completed { // Recording was successfully saved let video = Video(path: recordingSession.url.absoluteString, - duration: recordingSession.duration) + duration: recordingSession.duration, + size: recordingSession.size ?? CGSize.zero) onVideoRecorded(video) } else { // Recording wasn't saved and we don't have an error either. diff --git a/package/ios/Core/RecordingSession.swift b/package/ios/Core/RecordingSession.swift index fe250cd..85e9c62 100644 --- a/package/ios/Core/RecordingSession.swift +++ b/package/ios/Core/RecordingSession.swift @@ -52,6 +52,13 @@ class RecordingSession { return assetWriter.outputURL } + /** + Gets the size of the recorded video, in pixels. + */ + var size: CGSize? { + return videoWriter?.naturalSize + } + /** Get the duration (in seconds) of the recorded video. */ diff --git a/package/ios/Types/Video.swift b/package/ios/Types/Video.swift index 64cdfa3..dd40ae7 100644 --- a/package/ios/Types/Video.swift +++ b/package/ios/Types/Video.swift @@ -18,11 +18,17 @@ struct Video { Duration of the recorded video (in seconds) */ var duration: Double + /** + * The size of the video, in pixels. + */ + var size: CGSize func toJSValue() -> NSDictionary { return [ "path": path, "duration": duration, + "width": size.width, + "height": size.height, ] } } diff --git a/package/src/VideoFile.ts b/package/src/VideoFile.ts index 0633531..65d3722 100644 --- a/package/src/VideoFile.ts +++ b/package/src/VideoFile.ts @@ -53,4 +53,12 @@ export interface VideoFile extends TemporaryFile { * Represents the duration of the video, in seconds. */ duration: number + /** + * The width of the video, in pixels. + */ + width: number + /** + * The height of the video, in pixels. + */ + height: number }