Force front camera as default device when leaving QR code fragment

This commit is contained in:
Sylvain Berfini 2025-12-03 14:19:35 +01:00
parent bf4b5a51f5
commit 7817e6603c
4 changed files with 40 additions and 24 deletions

View file

@ -1269,4 +1269,26 @@ class CoreContext
} }
} }
} }
fun setBackCamera(): Boolean {
for (camera in core.videoDevicesList) {
if (camera.contains("Back")) {
Log.i("TAG Found back facing camera [$camera], using it")
coreContext.core.videoDevice = camera
return true
}
}
return false
}
fun setFrontCamera(): Boolean {
for (camera in core.videoDevicesList) {
if (camera.contains("Front")) {
Log.i("$TAG Found front facing camera [$camera], using it")
coreContext.core.videoDevice = camera
return true
}
}
return false
}
} }

View file

@ -147,6 +147,8 @@ class QrCodeScannerFragment : GenericFragment() {
core.nativePreviewWindowId = null core.nativePreviewWindowId = null
core.isVideoPreviewEnabled = false core.isVideoPreviewEnabled = false
core.isQrcodeVideoPreviewEnabled = false core.isQrcodeVideoPreviewEnabled = false
coreContext.setFrontCamera()
} }
super.onPause() super.onPause()

View file

@ -122,23 +122,17 @@ class QrCodeViewModel
// this is required right after granting the CAMERA permission // this is required right after granting the CAMERA permission
core.reloadVideoDevices() core.reloadVideoDevices()
for (camera in core.videoDevicesList) { if (!coreContext.setBackCamera()) {
if (camera.contains("Back")) { for (camera in core.videoDevicesList) {
Log.i("$TAG Found back facing camera [$camera], using it") if (camera != "StaticImage: Static picture") {
coreContext.core.videoDevice = camera Log.w("$TAG No back facing camera found, using first one available [$camera]")
return@postOnCoreThread coreContext.core.videoDevice = camera
return@postOnCoreThread
}
} }
}
for (camera in core.videoDevicesList) { Log.e("$TAG No camera device found!")
if (camera != "StaticImage: Static picture") {
Log.w("$TAG No back facing camera found, using first one available [$camera]")
coreContext.core.videoDevice = camera
return@postOnCoreThread
}
} }
Log.e("$TAG No camera device found!")
} }
} }
} }

View file

@ -212,18 +212,16 @@ class MeetingWaitingRoomViewModel
@UiThread @UiThread
fun setFrontCamera() { fun setFrontCamera() {
coreContext.postOnCoreThread { core -> coreContext.postOnCoreThread { core ->
for (camera in core.videoDevicesList) { if (!coreContext.setFrontCamera()) {
if (camera.contains("Front")) { for (camera in core.videoDevicesList) {
Log.i("$TAG Found front facing camera [$camera], using it") if (camera != "StaticImage: Static picture") {
coreContext.core.videoDevice = camera Log.w("$TAG No front facing camera found, using first one available [$camera]")
return@postOnCoreThread coreContext.core.videoDevice = camera
return@postOnCoreThread
}
} }
}
val first = core.videoDevicesList.firstOrNull() Log.e("$TAG No camera device found!")
if (first != null) {
Log.w("$TAG No front facing camera found, using first one available [$first]")
coreContext.core.videoDevice = first
} }
} }
} }