From c23f49e6bdfceabec788d037c48d41ae01743e69 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Mon, 4 Dec 2023 13:46:21 +0300 Subject: [PATCH] fix: Fix `VideoProfile` possibly being null (#2231) * fix: Fix `VideoProfile` possibly being null * Format --- .../RecordingSession+getRecommendedBitRate.kt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/package/android/src/main/java/com/mrousavy/camera/extensions/RecordingSession+getRecommendedBitRate.kt b/package/android/src/main/java/com/mrousavy/camera/extensions/RecordingSession+getRecommendedBitRate.kt index f51e15a..5fa016b 100644 --- a/package/android/src/main/java/com/mrousavy/camera/extensions/RecordingSession+getRecommendedBitRate.kt +++ b/package/android/src/main/java/com/mrousavy/camera/extensions/RecordingSession+getRecommendedBitRate.kt @@ -31,14 +31,18 @@ fun RecordingSession.getRecommendedBitRate(fps: Int, codec: VideoCodec, hdr: Boo if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { val profiles = CamcorderProfile.getAll(cameraId, quality) if (profiles != null) { - val best = profiles.videoProfiles.minBy { abs(it.width * it.height - targetResolution.width * targetResolution.height) } + val best = profiles.videoProfiles.filterNotNull().minBy { + abs(it.width * it.height - targetResolution.width * targetResolution.height) + } - recommendedProfile = RecommendedProfile( - best.bitrate, - best.codec, - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) best.bitDepth else 8, - best.frameRate - ) + if (best != null) { + recommendedProfile = RecommendedProfile( + best.bitrate, + best.codec, + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) best.bitDepth else 8, + best.frameRate + ) + } } }