How can I turn on the phone flashlight?

+4 votes
asked Aug 2, 2019 by wjrivera (800 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 Jul 3, 2020 by buttheader123 (160 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 Jul 3, 2020 by wjrivera (800 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 Jul 3, 2020 by buttheader123 (160 points)
Thank you for answer!
But how could i init easyarCamera variable?

There isn't such variable in ARSession.cs :(
commented Jul 3, 2020 by wjrivera (800 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 Jul 5, 2020 by buttheader123 (160 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.
...