How to capture Camera disconnect in using Webcamtexture for Webgl
Hi, I wrote a script where I attempted to handle the edge cases with Unity Webcamtexture. So in case of a sudden camera disconnect an error message should pop up showing 'Camera not available'. While this works perfectly in Unity Editor it fails to work on the actual build. Here's the snippet.
IEnumerator CameraErrCheck()
{
while (WebCamTexture.devices.Length > 0)
{
//Debug.Log(WebCamTexture.devices.Length + "length");
yield return new WaitForSeconds(0.3f);
}
errdialog.throwError("Oops! Camera might have been disconnected!");
}
void WebCamInit()
{
webcamtexture = new WebCamTexture();
webcamtexture.Play();
StartCoroutine(CameraErrCheck());
}
}
Webcaminit goes on to making a webcamtexture object and playing it. This works in Unity Editor but fails in the webversion. Logging Webcamtexture.devices.length I realized that even after camera disconnects, it still gives the length as 1.
Can someone help me out here?
Answer by kvoththebloodless · Sep 01, 2020 at 11:33 PM
It was a Unity bug that I reported and it's sent for resolution. Till then I'm using the browser APIs to get media devices and checking if videoinput is available. Hope that helps someone out there.
Your answer
Follow this Question
Related Questions
WebCamTexture nullpointerexception 1 Answer
WebCam Texture Rotation 0 Answers
When I run getPixel32 () in WebcamTexture, only black pixels are returned. 1 Answer
WebGL build exception 0 Answers