M. Yoga Nugraha

call unbind.all() before create the preview

@@ -113,7 +113,6 @@ class MobileScanner(private val activity: Activity, private val textureRegistry: @@ -113,7 +113,6 @@ class MobileScanner(private val activity: Activity, private val textureRegistry:
113 113
114 114
115 private var scanner = BarcodeScanning.getClient() 115 private var scanner = BarcodeScanning.getClient()
116 - private lateinit var imageCapture: ImageCapture  
117 116
118 @ExperimentalGetImage 117 @ExperimentalGetImage
119 private fun start(call: MethodCall, result: MethodChannel.Result) { 118 private fun start(call: MethodCall, result: MethodChannel.Result) {
@@ -137,6 +136,7 @@ class MobileScanner(private val activity: Activity, private val textureRegistry: @@ -137,6 +136,7 @@ class MobileScanner(private val activity: Activity, private val textureRegistry:
137 136
138 future.addListener({ 137 future.addListener({
139 cameraProvider = future.get() 138 cameraProvider = future.get()
  139 + cameraProvider!!.unbindAll()
140 textureEntry = textureRegistry.createSurfaceTexture() 140 textureEntry = textureRegistry.createSurfaceTexture()
141 141
142 // Preview 142 // Preview
@@ -162,14 +162,10 @@ class MobileScanner(private val activity: Activity, private val textureRegistry: @@ -162,14 +162,10 @@ class MobileScanner(private val activity: Activity, private val textureRegistry:
162 } 162 }
163 val analysis = analysisBuilder.build().apply { setAnalyzer(executor, analyzer) } 163 val analysis = analysisBuilder.build().apply { setAnalyzer(executor, analyzer) }
164 164
165 - imageCapture = ImageCapture.Builder()  
166 - .setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)  
167 - .build()  
168 -  
169 // Select the correct camera 165 // Select the correct camera
170 val selector = if (facing == 0) CameraSelector.DEFAULT_FRONT_CAMERA else CameraSelector.DEFAULT_BACK_CAMERA 166 val selector = if (facing == 0) CameraSelector.DEFAULT_FRONT_CAMERA else CameraSelector.DEFAULT_BACK_CAMERA
171 167
172 - camera = cameraProvider!!.bindToLifecycle(activity as LifecycleOwner, selector, preview, imageCapture) 168 + camera = cameraProvider!!.bindToLifecycle(activity as LifecycleOwner, selector, preview, analysis)
173 169
174 val analysisSize = analysis.resolutionInfo?.resolution ?: Size(0, 0) 170 val analysisSize = analysis.resolutionInfo?.resolution ?: Size(0, 0)
175 val previewSize = preview.resolutionInfo?.resolution ?: Size(0, 0) 171 val previewSize = preview.resolutionInfo?.resolution ?: Size(0, 0)