fix: camera discovery
This commit is contained in:
1 parent
c1020d11d2
commit
c3d9a3b577
1 file changed
+8
-1
@@ -127,7 +127,8 @@ class Camera2Controller(private val context: Context) {
|
||||
fun initialize() {
|
||||
PLog.i(TAG, "初始化相机控制器")
|
||||
startBackgroundThread()
|
||||
discoverCameras()
|
||||
// 不再在初始化时立即发现相机,延迟到第一次打开相机时
|
||||
// discoverCameras()
|
||||
}
|
||||
|
||||
private fun startBackgroundThread() {
|
||||
@@ -185,6 +186,12 @@ class Camera2Controller(private val context: Context) {
|
||||
// 先关闭旧的相机和资源,防止资源泄漏
|
||||
closeCamera()
|
||||
|
||||
// 确保在权限已授予后才发现相机(延迟初始化)
|
||||
if (_state.value.availableCameras.isEmpty()) {
|
||||
PLog.i(TAG, "首次打开相机,开始发现可用摄像头")
|
||||
discoverCameras()
|
||||
}
|
||||
|
||||
val cameraId = _state.value.currentCameraId
|
||||
val aspectRatio = _state.value.aspectRatio
|
||||
if (cameraId.isEmpty()) {
|
||||
|
||||
Reference in new issue
Block a user