- Home /
Webcam Texture and Flashlite (Android)
Hello everyone, I had a problem to start the webcam of my Android smartphone with the torch. If I run before the code of the webcam you can be seen, but the flash does not light! but if I leave before the flash he works, but the webcam can not see! how do I fix?
This is the code in C#
// ############## FLASH ON #############################
AndroidJavaObject javaCamera;
AndroidJavaClass cameraClass = new AndroidJavaClass("android.hardware.Camera");
int camID = 0;
javaCamera = cameraClass.CallStatic<AndroidJavaObject>("open", camID);
AndroidJavaObject cameraParameters = javaCamera.Call<AndroidJavaObject>("getParameters");
cameraParameters.Call("setFlashMode", "torch");
javaCamera.Call("setParameters", cameraParameters);
// ############## FLASH ON #############################
// ############## WEBCAM PLAY #############################
WebCamTexture webcamTexture = new WebCamTexture();
Renderer renderer = GetComponent<Renderer>();
renderer.material.mainTexture = webcamTexture;
webcamTexture.Play();renderer.material.mainTexture = webcamTexture;
webcamTexture.Play();
// ############## WEBCAM PLAY #############################
I included these codes in the function start ();
The script must be applied on a 3D Panel
I'm looking into this, Can you answer some questions please:
When you say 3D Panel you mean a plane?
What version of Unity are you using?
What device are you building to?
Ben Stoneman
I'm using Unity in company with version 5.1.3 I meant a Plane, and I was developing on Android 4.3. (I downloaded all the sdk)
I'm unable to get your script to work.
When making one from scratch I found that turning the flashlight off and on requires a plug-in:
http://answers.unity3d.com/questions/270832/how-to-turn-on-camera-light-make-a-flashlight-on-i.html
Yes, but this only works for IOS and Android no :( it is possible that there is no one who can do this on Android?
Answer by GDesmoulins · Oct 12, 2015 at 12:52 PM
Hello Fedybix93, It seems that it's not possible to access both camera and Flash at the same time ! after days of tests and discussion with plugin makers, you can start a camera, or start using Flashlight, but no possible ways to use both with WebCamTexture ... i'm trying to use alternate ways, but it seems difficult... Don't hésitate to post there good tips ...
For the moment, the only effective solution i found was to use Vuforia pluggin, wich seems to use $$anonymous$$ovieTexture ins$$anonymous$$d of WebcamTextures ...
Your answer
Follow this Question
Related Questions
How to turn on flashlight when WebCamTexture is on? (Android camera2 api) 0 Answers
Webcamtexture with Android flashlight 0 Answers
Turn your Android device webcam (Camera) , flash light 3 Answers
How do I enable the Android lock screen in developer mode? 1 Answer
WebCamTexture.devices.Length returning 0 in Unity 2020.3.8f1 0 Answers