fix: Fix CamcorderProfile
get crash on Samsung devices (#1907)
This commit is contained in:
parent
1cdc3d1d9c
commit
83c0cdb030
@ -6,23 +6,28 @@ import android.os.Build
|
|||||||
import android.util.Size
|
import android.util.Size
|
||||||
|
|
||||||
private fun getMaximumVideoSize(cameraId: String): Size? {
|
private fun getMaximumVideoSize(cameraId: String): Size? {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
try {
|
||||||
val profiles = CamcorderProfile.getAll(cameraId, CamcorderProfile.QUALITY_HIGH)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
if (profiles != null) {
|
val profiles = CamcorderProfile.getAll(cameraId, CamcorderProfile.QUALITY_HIGH)
|
||||||
val largestProfile = profiles.videoProfiles.filterNotNull().maxByOrNull { it.width * it.height }
|
if (profiles != null) {
|
||||||
if (largestProfile != null) {
|
val largestProfile = profiles.videoProfiles.filterNotNull().maxByOrNull { it.width * it.height }
|
||||||
return Size(largestProfile.width, largestProfile.height)
|
if (largestProfile != null) {
|
||||||
|
return Size(largestProfile.width, largestProfile.height)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
val cameraIdInt = cameraId.toIntOrNull()
|
val cameraIdInt = cameraId.toIntOrNull()
|
||||||
if (cameraIdInt != null) {
|
if (cameraIdInt != null) {
|
||||||
val profile = CamcorderProfile.get(cameraIdInt, CamcorderProfile.QUALITY_HIGH)
|
val profile = CamcorderProfile.get(cameraIdInt, CamcorderProfile.QUALITY_HIGH)
|
||||||
return Size(profile.videoFrameWidth, profile.videoFrameHeight)
|
return Size(profile.videoFrameWidth, profile.videoFrameHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
return null
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
// some Samsung phones just crash when trying to get the CamcorderProfile. Only god knows why.
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun CameraCharacteristics.getVideoSizes(cameraId: String, format: Int): List<Size> {
|
fun CameraCharacteristics.getVideoSizes(cameraId: String, format: Int): List<Size> {
|
||||||
|
Loading…
Reference in New Issue
Block a user