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.isVideoPreviewEnabled = false
core.isQrcodeVideoPreviewEnabled = false
coreContext.setFrontCamera()
}
super.onPause()

View file

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

View file

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