This commit is contained in:
终究是寂寞
2026-03-08 19:22:22 +08:00
parent 416d4eeb3a
commit 662755e97a
274 changed files with 895 additions and 1310 deletions
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>
@@ -59,11 +59,11 @@ open class CameraHelper {
val characteristics = this.cameraManager.getCameraCharacteristics(id)
val lensFacing = characteristics.get(CameraCharacteristics.LENS_FACING)
if (lensFacing !== null && lensFacing === (if (facing === "BACK") {
CameraCharacteristics.LENS_FACING_BACK
} else {
CameraCharacteristics.LENS_FACING_FRONT
}
)) {
CameraCharacteristics.LENS_FACING_BACK
} else {
CameraCharacteristics.LENS_FACING_FRONT
}
)) {
targetCameraId = id
break
}
@@ -76,16 +76,16 @@ open class CameraHelper {
} else {
"前置"
}
) + "\u6444\u50CF\u5934ID\uFF1A" + targetCameraId)
) + "\u6444\u50CF\u5934ID\uFF1A" + targetCameraId)
return targetCameraId
}
catch (e: Throwable) {
catch (e: Throwable) {
console.error("CameraHelper: \u83B7\u53D6" + (if (facing === "BACK") {
"后置"
} else {
"前置"
}
) + "\u6444\u50CF\u5934ID\u5F02\u5E38\uFF1A", e.message)
) + "\u6444\u50CF\u5934ID\u5F02\u5E38\uFF1A", e.message)
throw UTSError()
}
}
@@ -94,7 +94,7 @@ open class CameraHelper {
try {
cameraId = this.getCameraIdByFacing(facing)
}
catch (e: Throwable) {
catch (e: Throwable) {
throw UTSError()
}
val characteristics = this.cameraManager.getCameraCharacteristics(cameraId)
@@ -225,7 +225,7 @@ fun yuvToJpegBase64(image: android.media.Image): String {
outputStream.close()
return base64Jpeg
}
catch (e: Throwable) {
catch (e: Throwable) {
console.error("YUV转JPEG/Base64失败:", e)
return ""
}
@@ -316,7 +316,7 @@ fun startCameraPreview(options: MyApiOptions): Unit {
val cameraStateCallback = CustomCameraStateCallback()
cameraHelper.openCameraByFacing("FRONT", cameraStateCallback, backgroundHandler)
}
catch (e: Throwable) {
catch (e: Throwable) {
console.error("启动摄像头失败:", e)
}
}
@@ -330,10 +330,10 @@ fun stopCameraPreview(): Unit {
captureSession!!!!.close()
console.log("采集会话已释放")
}
catch (e: Throwable) {
catch (e: Throwable) {
console.warn("释放采集会话时出现异常:", e)
}
finally{
finally{
captureSession = null
}
}
@@ -342,10 +342,10 @@ fun stopCameraPreview(): Unit {
cameraDevice!!!!.close()
console.log("相机设备已关闭")
}
catch (e: Throwable) {
catch (e: Throwable) {
console.warn("关闭相机设备时出现异常:", e)
}
finally{
finally{
cameraDevice = null
}
}
@@ -354,10 +354,10 @@ fun stopCameraPreview(): Unit {
imageReader!!!!.close()
console.log("ImageReader已释放")
}
catch (e: Throwable) {
catch (e: Throwable) {
console.warn("释放ImageReader时出现异常:", e)
}
finally{
finally{
imageReader = null
}
}
@@ -372,16 +372,16 @@ fun stopCameraPreview(): Unit {
handlerThread!!!!.join()
console.log("后台线程已停止")
}
catch (e: Throwable) {
catch (e: Throwable) {
console.warn("停止后台线程时出现异常:", e)
}
finally{
finally{
handlerThread = null
}
}
console.log("摄像头资源释放完成")
}
catch (e: Throwable) {
catch (e: Throwable) {
console.error("释放摄像头资源时发生全局异常:", e)
}
}
@@ -395,12 +395,12 @@ fun startCameraPreviewByJs(options: MyApiOptionsJSONObject): Unit {
return startCameraPreview(MyApiOptions(paramA = options.paramA, success = fun(res: String): Unit {
options.success?.invoke(res)
}
, fail = fun(res: MyApiFail): Unit {
options.fail?.invoke(res)
}
, complete = fun(res: Any): Unit {
options.complete?.invoke(res)
}
, fail = fun(res: MyApiFail): Unit {
options.fail?.invoke(res)
}
, complete = fun(res: Any): Unit {
options.complete?.invoke(res)
}
))
}
fun stopCameraPreviewByJs(): Unit {