fix: Fix physical devices detection on Android (#2073)
* fix: Fix physical devices detection on Android * Update useCameraDevices.ts
This commit is contained in:
parent
e1f8e1bd2a
commit
8d65d1d53c
@ -59,6 +59,11 @@ class CameraDeviceDetails(private val cameraManager: CameraManager, private val
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
) ?: Range(1f, characteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM) ?: 1f)
|
) ?: Range(1f, characteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM) ?: 1f)
|
||||||
|
private val physicalDevices = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && characteristics.physicalCameraIds.isNotEmpty()) {
|
||||||
|
characteristics.physicalCameraIds
|
||||||
|
} else {
|
||||||
|
setOf(cameraId)
|
||||||
|
}
|
||||||
private val minZoom = zoomRange.lower.toDouble()
|
private val minZoom = zoomRange.lower.toDouble()
|
||||||
private val maxZoom = zoomRange.upper.toDouble()
|
private val maxZoom = zoomRange.upper.toDouble()
|
||||||
|
|
||||||
@ -108,13 +113,14 @@ class CameraDeviceDetails(private val cameraManager: CameraManager, private val
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getDeviceTypes(): List<DeviceType> {
|
private fun getDeviceTypes(): List<DeviceType> {
|
||||||
val deviceTypes = focalLengths.map { focalLength ->
|
val deviceTypes = physicalDevices.map { id ->
|
||||||
val fov = getFieldOfView(focalLength)
|
val details = CameraDeviceDetails(cameraManager, id)
|
||||||
|
val fov = details.getMaxFieldOfView()
|
||||||
return@map when {
|
return@map when {
|
||||||
fov > 94 -> DeviceType.ULTRA_WIDE_ANGLE
|
fov > 94 -> DeviceType.ULTRA_WIDE_ANGLE
|
||||||
fov in 60f..94f -> DeviceType.WIDE_ANGLE
|
fov in 60f..94f -> DeviceType.WIDE_ANGLE
|
||||||
fov < 60f -> DeviceType.TELEPHOTO
|
fov < 60f -> DeviceType.TELEPHOTO
|
||||||
else -> throw Error("Invalid focal length! (${focalLength}mm)")
|
else -> throw Error("Invalid Field Of View! ($fov)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return deviceTypes
|
return deviceTypes
|
||||||
|
Loading…
Reference in New Issue
Block a user