g123k / flutter_torch_compat

A plugin to enable or disable the torch of a device that works both on Android (including Android 4.x) and iOS.
https://pub.dev/packages/torch_compat
Apache License 2.0
7 stars 22 forks source link

The plugin lost the camera resource but it does not recover it. #9

Closed pav3lo closed 3 years ago

pav3lo commented 3 years ago

Using this plugin when I was using the torch on in background and open the camera to take a photo with flashlight, when I return to the torch app don't work anymore.

How to recover camera resource?

android.hardware.camera2.CameraAccessException: CAMERA_IN_USE (4): setTorchMode:1606: Torch for camera "0" is not available due to an existing camera user E/DartMessenger(13281): at android.hardware.camera2.CameraManager.throwAsPublicException(CameraManager.java:634) E/DartMessenger(13281): at android.hardware.camera2.CameraManager$CameraManagerGlobal.setTorchMode(CameraManager.java:883) E/DartMessenger(13281): at android.hardware.camera2.CameraManager.setTorchMode(CameraManager.java:495) E/DartMessenger(13281): at fr.g123k.torch_compat.impl.TorchCamera2Impl.turn(TorchCamera2Impl.kt:27) E/DartMessenger(13281): at fr.g123k.torch_compat.impl.TorchCamera2Impl.turnOn(TorchCamera2Impl.kt:18) E/DartMessenger(13281): at fr.g123k.torch_compat.TorchCompatPlugin.onMethodCall(TorchCompatPlugin.kt:48) E/DartMessenger(13281): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:230) E/DartMessenger(13281): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85) E/DartMessenger(13281): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692) E/DartMessenger(13281): at android.os.MessageQueue.nativePollOnce(Native Method) E/DartMessenger(13281): at android.os.MessageQueue.next(MessageQueue.java:323) E/DartMessenger(13281): at android.os.Looper.loop(Looper.java:136) E/DartMessenger(13281): at android.app.ActivityThread.main(ActivityThread.java:6682) E/DartMessenger(13281): at java.lang.reflect.Method.invoke(Native Method) E/DartMessenger(13281): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) E/DartMessenger(13281): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) E/DartMessenger(13281): Caused by: android.os.ServiceSpecificException: setTorchMode:1606: Torch for camera "0" is not available due to an existing camera user E/DartMessenger(13281): at android.os.Parcel.readException(Parcel.java:1715) E/DartMessenger(13281): at android.os.Parcel.readException(Parcel.java:1654) E/DartMessenger(13281): at android.hardware.ICameraService$Stub$Proxy.setTorchMode(ICameraService.java:497) E/DartMessenger(13281): at android.hardware.camera2.CameraManager$CameraManagerGlobal.setTorchMode(CameraManager.java:881) E/DartMessenger(13281): ... 14 more E/flutter (13281): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: MissingPluginException(No implementation found for method turnOn on channel g123k/torch_compat) E/flutter (13281): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159:7) E/flutter (13281): E/flutter (13281): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:334:12) E/flutter (13281): #2 TorchCompat.turnOn (package:torch_compat/torch_compat.dart:9:38)

g123k commented 3 years ago

Hello,

Thanks for your report, unfortunately this is "normal". Only one instance of a camera can be use at the same time. You first have to close the camera to use this plugin.