简体   繁体   中英

Unity3D. Accessing camera torch/flash issues - Torch works but can't access while streaming webcamtexture

I am developing an app in unity in which the user can take photos using their device camera. This is working great using Unity's webcamtexture. However, there is no flash support for webcamtexture, so I have written my own code to access the device Torch. The code WORKS - However it doesn't work while streaming the webcamtexture (the camera is in use so the java service call returns an error). Does anyone have any suggestions for how to get around this issue? Is there any way to use Unity's WebCamTexture to activate the camera torch? Here is my code for activating the camera torch:

AndroidJavaClass cameraClass = new AndroidJavaClass("android.hardware.Camera");
     // This is an ugly hack to make Unity
     // generate Camera permisions
     WebCamDevice[] devices = WebCamTexture.devices;

     int camID = 0;
     camera = cameraClass.CallStatic<AndroidJavaObject>("open", camID);

     // I'm pretty sure camera will never be null at this point
     // It will either be a valid object or Camera.open would throw an exception
     if (camera != null)
     {


         AndroidJavaObject cameraParameters = camera.Call<AndroidJavaObject>("getParameters");
         cameraParameters.Call("setFlashMode","torch");
         camera.Call("setParameters",cameraParameters);
         Active = true;
     }

Try checking out camera capture kit for unity. It gives that functionality you want for Android as well as the source code for it.

https://www.assetstore.unity3d.com/en/#!/content/56673

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM