- Home /
My cam not open using webcamtexture
I just create augment camera to get feature and play some videos....in my code very well working in android but not in ios...If anybody know about this issue help me..
THis is my code:
using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; using System; using UnityEngine.Rendering; using System.IO; using System.Text; using System.Threading; using System.Text.RegularExpressions; using System.Collections; using System.Collections.Generic; using System.Net; using System.Net.NetworkInformation;
//using DeadMosquito.AndroidGoodies;
public class ohg : MonoBehaviour {// Camera screenshotCamera; //private TextAsset asset; //public Text txt; //private StreamWriter writer; private bool camAvailable; private Texture greenlaser; //private Texture errmsg; //Texture2D snap; private int ll = 0;//public string devid; private WebCamTexture backCam;
private float k2=0;
private Texture defaultBackground;
public RawImage backGround;
public AspectRatioFitter fit;
//public Font f;
//public GameObject neterror;
//public int ccv = 0;
public string Ddf;
private float k=0;// private float k1=0; private float k2=0; public int cls=0;
private float k5=0;
//public int ta = 0;
//public int ll=0;
public void Start()
{
//anim.Play ("Siva");
/* FileInfo theSourceFile11 = new FileInfo(Application.persistentDataPath + "/" + "phnonote.txt");
//FileInfo theSourceFile = new FileInfo (Application.persistentDataPath + "/" + "T.txt");
StreamReader reader11 = theSourceFile11.OpenText();
string texturl11;
texturl11 = reader11.ReadToEnd();
if (texturl11 != null)
{
tables1 = (texturl11.ToString());
//Debug.Log ("cc"+tables);
}
*/
//devid = AGDeviceInfo.GetAndroidId ();
print(Application.persistentDataPath);
//Textdi = GetComponent<Text> ();
defaultBackground = backGround.texture;
WebCamDevice[] devices = WebCamTexture.devices;
if (devices.Length == 0)
{
Debug.Log("No Camera Detected");
camAvailable = false;
return;
}
for (int i = 0; i < devices.Length; i++)
{
print("Webcam available: " + devices[i].name);
if (!devices[i].isFrontFacing)
{
backCam = new WebCamTexture(devices[i].name, 320, 240);
// backCam = new WebCamTexture (devices [i].name,400, 320);
// backCam = new WebCamTexture (devices [i].name,480, 400);
}
}
if (backCam == null)
{
Debug.Log("Unable to find Back camera");
return;
}
backCam.Play();
//backgram
backGround.texture = backCam;
camAvailable = true;
}
private void Update ()
{
//backCam.Play();
//Destroy (snap);
StartCoroutine(Fade());
if (!camAvailable)
return;
float ratio = (float)backCam.width / (float)backCam.height;
fit.aspectRatio = ratio;
float ScaleY = backCam.videoVerticallyMirrored ? -1f : 1f;
backGround.rectTransform.localScale = new Vector3 (1f, ScaleY, 1f);
int orient = -backCam.videoRotationAngle;
backGround.rectTransform.localEulerAngles = new Vector3 (0, 0, orient);
k++;
}
public IEnumerator Fade()
{
Texture2D snap = new Texture2D((backCam.width),(backCam.height),TextureFormat.RGB24,false);
snap.SetPixels (backCam.GetPixels());
byte[] bytes = snap.EncodeToJPG();
//backCam.Stop ();
Destroy(snap);
string base64s = Convert.ToBase64String (bytes);
Debug.Log (backCam.width + "-----" + backCam.height);
string url = "https://www.sun.com:449/";
string customUrl = url + "WebForm1.aspx";
//Debug.Log(tables1);dd
//tables1 = 544445459;
//setup a form
WWWForm form = new WWWForm();
form.AddField ("usd", base64s);
form.AddField ("tables", "targettable");
form.AddField ("phno", "9998877555");
//print (bytes1);
WWW www = new WWW(customUrl, form);
yield return StartCoroutine (WaitForRequest (www));
}
public IEnumerator WaitForRequest(WWW www)
{
//Thread.Sleep (100);
yield return www;
// check for errors
if (www.error == null)
{
Ddf = www.text;
Debug.Log (Ddf);
Handheld.PlayFullScreenMovie(Ddf);
}
else
{
Debug.Log("WWW Error: " + www.error);
}
}
}