How can I turn on the phone flashlight?

+4 votes
asked Aug 2, 2019 by wjrivera (280 points)

2 Answers

+2 votes
answered Aug 3, 2019 by rlmidiaalvs (2,420 points)

Hello!

In ARSession.cs, you can call setFlashTorchMode(bool) in easyarCamera var

bool fls = false;

public void Torch () {

fls = !fls; easyarCamera.setFlashTorchMode (fls);

}

commented Aug 18, 2019 by aninuji (120 points)
Hi! I'm pretty much new and have no idea yet how to access to ARSession code tried with a sigleton in ARSession.cs but when i do in another script:
    public class Flash : MonoBehaviour
    {
        ARSession.singleton.Torch();
    }
It keeps telling me there's no property in ARSession! Any idea on why? Thanks
0 votes
answered 2 days ago by buttheader123 (150 points)

Have the same issue(using easyAR 3.1).
Please, can anyone explain how to initialize CameraDevice and use it.

There isn't any initialization for CameraDevice instance inside ARSession.cs.

When i just tried to create instance via new CameraDevice() and call SetFlashTorchMode(true) nothing happeng, torch still to be toggled off.

I use this code below, pls help if you have any information. Because i didn't find any information about this in docs :(

public class TorchlightController : MonoBehaviour
{
    private bool _active;

    public void ToggleLight()
    {
        _active = !_active;
        
        var camDevice = new CameraDevice();
        camDevice.setFlashTorchMode(_active);
    }
}
commented 2 days ago by wjrivera (280 points)
you must edit the ARSession class and add:

        private bool lightOn = false;
        public void ToggleLight()
        {
            lightOn = !lightOn;
            easyarCamera.setFlashTorchMode(lightOn);
            Debug.Log("LightOn (" + lightOn + ")");
        }
commented 2 days ago by buttheader123 (150 points)
Thank you for answer!
But how could i init easyarCamera variable?

There isn't such variable in ARSession.cs :(
commented 2 days ago by wjrivera (280 points)
you must edit the VideoCameraDevice class and add:

        private bool lightOn = false;
        public void ToggleLight()
        {
            lightOn = !lightOn;
            Device.setFlashTorchMode(lightOn);
            Debug.Log("LightOn (" + lightOn + ")");
        }


sorry for the previous bad answer I use version 3.0
commented 1 day ago by buttheader123 (150 points)
Oh God, Thank you very much! It is working!

Hope, your answer will be helpful for other people too :)
Welcome to EasyAR SDK Q&A, where you can ask questions and receive answers from other members of the community.
...