fix: Fix VideoProfile possibly being null (#2231)

* fix: Fix `VideoProfile` possibly being null

* Format
This commit is contained in:
Marc Rousavy 2023-12-04 13:46:21 +03:00 committed by GitHub
parent 9df46670a8
commit c23f49e6bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,8 +31,11 @@ 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)
}
if (best != null) {
recommendedProfile = RecommendedProfile(
best.bitrate,
best.codec,
@ -41,6 +44,7 @@ fun RecordingSession.getRecommendedBitRate(fps: Int, codec: VideoCodec, hdr: Boo
)
}
}
}
if (recommendedProfile == null) {
val cameraIdInt = cameraId.toIntOrNull()