Turn your Android device webcam (Camera) , flash light

Hello to all dear friends

I am Iranian. I am weak in English. The question text was translated by Google Translate.

The first question in the forum.

I’m making a game or app for Android with Unity.

At the same time I need to start my webcam device and flash light.

I can tell by the webcam into a texture.


WebCamDevice[] devices;
WebCamTexture texture;
 
devices = WebCamTexture.devices;
 
if (devices.Length == 2) {
texture = new WebCamTexture (devices [1].name, 1024, 768, 100000000);
 
texture.Play ();
 
this.renderer.material.mainTexture = texture;
}

You can also create a plug-in to Eclipse,

Turn your Android device with Flash light through it.


AndroidJavaObject camera;
 
 AndroidJavaClass cameraClass = new AndroidJavaClass("android.hardware.Camera");
 
 int camID = 0;
 camera = cameraClass.CallStatic<AndroidJavaObject>("open", camID);
 
 if (camera != null){
 AndroidJavaObject cameraParameters = camera.Call<AndroidJavaObject>("getParameters");
 cameraParameters.Call("setFlashMode","torch");
 camera.Call("setParameters",cameraParameters);
 }

But now the problem is,
I had the great test,
I found a code that only allow access to the camera is turned off.
If the code is used to take the first turning on the device Nvrflsh,


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

The second code to turn on your webcam or camera is not running.


texture.Play ();

And vice versa.

Now, dear friends help me. How do I do (webcam) and (flash light) on my Android device ???

Excuse me for disturbing text !

I am waiting for a response.

Hello Iranian,

Did you add your “open” method in your Android Activity ??

Unfortunately I can not speak French.

I would not use the code below in the Unity.

WebCamDevice[] devices;
WebCamTexture texture;
devices = WebCamTexture.devices;
if (devices.Length == 2) {
texture = new WebCamTexture (devices [1].name, 1024, 768, 100000000);
texture.Play ();
this.renderer.material.mainTexture = texture;
}

And the
Now I want (camera flash light) torch on

I hope you understand

Have you checked out NatCam? It supports flash and many other features. And running the camera while flash is on is planned for the upcoming version.

There is as well Camera Capture Kit which allows you to use the Native camera functionality in Unity.

Hi,

Did you find any solution to flash camera light while using Webcamtexture?

Just paste this line and you phone will start flashing… C#

CameraDevice.Instance.SetFlashTorchMode(true);