How to use External USB Camera with Android Tablet
I am try to use External Webcam camera attached to android tablet via OTG cable.
External Camera is not showing in webcam array . I have also added Permissions in Android Manifest. but still no luck Build never asks for usb external camera permission.
// Addition in Android Manifest
//<uses-feature android:name="android.hardware.camera.external" android:required="true"/>
//<uses-feature android:name="android.hardware.usb.host" />
// Addition in Android Manifest
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class phoneCamera : MonoBehaviour
{
private bool camAvailable;
private WebCamTexture backCam;
private Texture defaultBackground;
public RawImage background;
// Use this for initialization
void Start()
{
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++)
{
if (!devices[i].isFrontFacing)
{
backCam = new WebCamTexture(devices[i].name, Screen.width, Screen.height);
}
}
if (backCam == null)
{
Debug.Log("Unable to Find Back Camera");
return;
}
backCam.Play();
background.texture = backCam;
camAvailable = true;
}
}
// devices.Length is always 2, Camera 0 and Camera 1
Answer by enigmatic · Mar 27, 2019 at 11:58 AM
The external cameras are not detected by default hardware.camera package in android. You'll need some native plugin to access it and then expose that to unity.
I have found the following open source project which does just this: https://github.com/TimGroeneboom/libuvc_android_unity
Hope it helps, others looking for same,
Your answer
Follow this Question
Related Questions
Camera changing Scene 1 Answer
3rd person controller with static camera 1 Answer
complimentary cameras seam problem 1 Answer
Run script only when camera is looking away 1 Answer
Canvas not rendered by camera 1 Answer