Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect is a camera is available using isTypePresent in a Windows 10 Universal Application

When developing a Universal Application for Windows 10 you are encouraged to detect device specific hardware using IsTypePresent. (Microsoft refer to this feature as 'Light up'). An example from the documentation that checks for a device's back button is:

if(Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")) Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;

It is clear here that the string "Windows.Phone.UI.Input.HardwareButtons" is passed as an argument to the IsTypePresent() method.

I would like to know if there is an easy way to identify other strings that I could use for other pieces of hardware and, in particular, the camera.

like image 208
Gordonium Avatar asked Jun 12 '15 17:06

Gordonium


People also ask

How do I find the camera on Windows 10?

To open up your webcam or camera, select the Start button, then select All apps, and then select Camera in the list of apps. If you have multiple cameras, you can switch between them by selecting Change Camera at the top right once the Camera app is opened.

Does Windows 10 have inbuilt camera?

If you have Windows 10, open the Start Menu and scroll down the app list until you get to the Camera. Once you've found it, click or tap on it.

Why is camera not showing in Device Manager?

Reboot your computer to complete the installation process. After rebooting your computer, the camera device should work normally. If it is still not visible , then open device manager and then click on View Tab and then select show hidden devices.

Why does Windows not recognize my camera?

Check your settings If you recently updated Windows 10, you might need to give apps permission to use the camera. In newer versions of Windows 10, some apps don't have default access to the camera. To let your device access the camera, select Start , then select Settings > Privacy > Camera .


1 Answers

IsTypePresent isn't used to detect hardware presence but to detect API presence. In your code snippet it's checking if the HardwareButtons class exists for the app to call, not if the device has hardware buttons (in this case they're likely to go together, but that's not what IsTypePresent is looking for).

The MediaCapture class used with the camera is part of the Universal API Contract and so is always there and callable. Initialization will fail if there is no appropriate audio or video device.

To find hardware devices you can use the Windows.Devices.Enumeration namespace. Here's a quick snippet that queries for cameras and finds the ID of the first one.

var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);

if (devices.Count < 1)
{
    // There is no camera. Real code should do something smart here.
    return;
}

// Default to the first device we found
// We could look at properties like EnclosureLocation or Name
// if we wanted a specific camera
string deviceID = devices[0].Id;

// Go do something with that device, like start capturing!
like image 170
Rob Caplan - MSFT Avatar answered Nov 14 '22 22:11

Rob Caplan - MSFT