@@ -13,11 +13,14 @@ import android.hardware.display.DisplayManager
13
13
import android.net.Uri
14
14
import android.os.Handler
15
15
import android.os.Looper
16
+ import android.util.Log
16
17
import android.util.Size
17
18
import android.view.Surface
18
19
import androidx.annotation.VisibleForTesting
20
+ import androidx.camera.camera2.Camera2Config
19
21
import androidx.camera.core.Camera
20
22
import androidx.camera.core.CameraSelector
23
+ import androidx.camera.core.CameraXConfig
21
24
import androidx.camera.core.ExperimentalGetImage
22
25
import androidx.camera.core.ImageAnalysis
23
26
import androidx.camera.core.ImageProxy
@@ -42,7 +45,6 @@ import dev.steenbakker.mobile_scanner.utils.serialize
42
45
import io.flutter.view.TextureRegistry
43
46
import kotlinx.coroutines.CoroutineScope
44
47
import kotlinx.coroutines.Dispatchers
45
- import kotlinx.coroutines.coroutineScope
46
48
import kotlinx.coroutines.launch
47
49
import java.io.ByteArrayOutputStream
48
50
import java.io.IOException
@@ -58,6 +60,10 @@ class MobileScanner(
58
60
private val barcodeScannerFactory : (options: BarcodeScannerOptions ? ) -> BarcodeScanner = ::defaultBarcodeScannerFactory,
59
61
) {
60
62
63
+ init {
64
+ configureCameraProcessProvider()
65
+ }
66
+
61
67
// / Internal variables
62
68
private var cameraProvider: ProcessCameraProvider ? = null
63
69
private var camera: Camera ? = null
@@ -78,6 +84,20 @@ class MobileScanner(
78
84
private var isPaused = false
79
85
80
86
companion object {
87
+ // Configure the `ProcessCameraProvider` to only log errors.
88
+ // This prevents the informational log spam from CameraX.
89
+ private fun configureCameraProcessProvider () {
90
+ try {
91
+ val config = CameraXConfig .Builder .fromConfig(Camera2Config .defaultConfig()).apply {
92
+ setMinimumLoggingLevel(Log .ERROR )
93
+ }
94
+ ProcessCameraProvider .configureInstance(config.build())
95
+ } catch (_: IllegalStateException ) {
96
+ // The ProcessCameraProvider was already configured.
97
+ // Do nothing.
98
+ }
99
+ }
100
+
81
101
/* *
82
102
* Create a barcode scanner from the given options.
83
103
*/
0 commit comments