Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity Android front facing Camera WTF bug

I'm developing an app for Android using Unity. Trying to use front facing camera, getting data from WebCamTexture. Rear-facing works fine, but when I try to flip the camera this awful thing comes out:

**bitstream == (int)0xAFAFAFAF

as an error in the unity console. Then, WebCamTexture stops working AT ALL, even with the rear-facing camera. Any idea?

P.S. using Unity 5.3.3p1... could be a Unity bug?

like image 583
Tiziano Coroneo Avatar asked Jan 06 '23 12:01

Tiziano Coroneo


2 Answers

NOTE

for anyone reading, a new (2016) plugin has appeared for Unity,

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

basically you "have to get this" if you want to use device camera in Unity.

Unity's device-camera stuff is the worst thing in Unity - it's literally not even alpha quality. It's the worst thing in Unity and it's ridiculous they included it, it's just a test run.

it's extremely difficult to write a dual-platform true native, high-speed camera plug in. Now that the first one has appeared there's no real alternative than to use it. Unity's crap is impossible and you can easily spend 2-3 weeks trying to get a rough camera working.


Here's a fairly bulletroof approach for the disaster of changing cameras!

public void CycleCams()
        {
        StartCoroutine(_cycle());
        }
    
    private IEnumerator _cycle()
        {
        WebCamDevice[] d = WebCamTexture.devices;
        if ( d.Length <= 1 )
            {
            Debug.Log("only one.");
            if (d.Length==1) Debug.Log("Name is " +d[0].name);
            yield break;
            }
        
        Debug.Log("0 " +d[0].name);
        Debug.Log("1 " +d[1].name);
        
        if ( wct.deviceName == d[0].name )
            {
            wct.Stop();
            yield return new WaitForSeconds(.1f);
            wct.deviceName = d[1].name;
            yield return new WaitForSeconds(.1f);
            wct.Play();
            
            nameDisplay.text = "\"" +wct.deviceName +"\"";
            yield break;
            }
        
        if ( wct.deviceName == d[1].name )
            {
            wct.Stop();
            yield return new WaitForSeconds(.1f);
            wct.deviceName = d[0].name;
            yield return new WaitForSeconds(.1f);
            wct.Play();
            
            nameDisplay.text = "\"" +wct.deviceName +"\"";
            yield break;
            }
        }
like image 117
Fattie Avatar answered Jan 09 '23 01:01

Fattie


I have to tell you from years of hacking Android ROMs and messing around, you will run into this situation pretty often. And the worst past is due to the firmware the manufactures use, your program might run perfectly on one phone but not the other due to how fragmented the manufacturers are keeping things. Going forward with Marshmallow you will see this less and less due to the constraints they are placing on everyone now. I would recommend just learning the little bit of Java for this portion of your code and calling it directly from Unity.

like image 26
Kevin B Burns Avatar answered Jan 09 '23 03:01

Kevin B Burns