【问题标题】:How to detect is a camera is available using isTypePresent in a Windows 10 Universal Application如何在 Windows 10 通用应用程序中使用 isTypePresent 检测相机是否可用
【发布时间】:2015-06-12 17:36:48
【问题描述】:

在为 Windows 10 开发通用应用程序时,建议您使用 IsTypePresent 检测设备特定硬件。 (微软将此功能称为“Light up”)。检查设备后退按钮的example from the documentation 是:

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

这里很明显,字符串"Windows.Phone.UI.Input.HardwareButtons" 作为参数传递给IsTypePresent() 方法。

我想知道是否有一种简单的方法来识别可以用于其他硬件,特别是相机的其他字符串。

【问题讨论】:

    标签: c# windows windows-10 windows-10-mobile


    【解决方案1】:

    IsTypePresent 不用于检测硬件存在,而是用于检测 API 存在。在您的代码 sn-p 中,它检查的是 HardwareButtons 类是否存在以供应用程序调用,而不是设备是否具有硬件按钮(在这种情况下,它们可能会一起出现,但这不是 IsTypePresent 所要寻找的)。

    与相机一起使用的 MediaCapture 类是通用 API 契约的一部分,因此始终存在且可调用。如果没有合适的音频或视频设备,初始化将失败。

    要查找硬件设备,您可以使用 Windows.Devices.Enumeration 命名空间。这是一个快速的 sn-p 查询相机并找到第一个 ID。

    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!
    

    【讨论】:

      猜你喜欢
      • 2016-04-19
      • 2021-09-26
      • 2015-10-31
      • 1970-01-01
      • 1970-01-01
      • 2015-06-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多